Stop masking the owned bit on a freshly-cloned object
[ldk-java] / src / main / jni / bindings.c
1 #include "org_ldk_impl_bindings.h"
2 #include <rust_types.h>
3 #include <lightning.h>
4 #include <string.h>
5 #include <stdatomic.h>
6 #include <assert.h>
7 // Always run a, then assert it is true:
8 #define DO_ASSERT(a) do { bool _assert_val = (a); assert(_assert_val); } while(0)
9 // Assert a is true or do nothing
10 #define CHECK(a) DO_ASSERT(a)
11
12 // Running a leak check across all the allocations and frees of the JDK is a mess,
13 // so instead we implement our own naive leak checker here, relying on the -wrap
14 // linker option to wrap malloc/calloc/realloc/free, tracking everyhing allocated
15 // and free'd in Rust or C across the generated bindings shared library.
16 #include <threads.h>
17 #include <execinfo.h>
18 #include <unistd.h>
19 static mtx_t allocation_mtx;
20
21 void __attribute__((constructor)) init_mtx() {
22         DO_ASSERT(mtx_init(&allocation_mtx, mtx_plain) == thrd_success);
23 }
24
25 #define BT_MAX 128
26 typedef struct allocation {
27         struct allocation* next;
28         void* ptr;
29         const char* struct_name;
30         void* bt[BT_MAX];
31         int bt_len;
32 } allocation;
33 static allocation* allocation_ll = NULL;
34
35 void* __real_malloc(size_t len);
36 void* __real_calloc(size_t nmemb, size_t len);
37 static void new_allocation(void* res, const char* struct_name) {
38         allocation* new_alloc = __real_malloc(sizeof(allocation));
39         new_alloc->ptr = res;
40         new_alloc->struct_name = struct_name;
41         new_alloc->bt_len = backtrace(new_alloc->bt, BT_MAX);
42         DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
43         new_alloc->next = allocation_ll;
44         allocation_ll = new_alloc;
45         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
46 }
47 static void* MALLOC(size_t len, const char* struct_name) {
48         void* res = __real_malloc(len);
49         new_allocation(res, struct_name);
50         return res;
51 }
52 void __real_free(void* ptr);
53 static void alloc_freed(void* ptr) {
54         allocation* p = NULL;
55         DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
56         allocation* it = allocation_ll;
57         while (it->ptr != ptr) {
58                 p = it; it = it->next;
59                 if (it == NULL) {
60                         fprintf(stderr, "Tried to free unknown pointer %p at:\n", ptr);
61                         void* bt[BT_MAX];
62                         int bt_len = backtrace(bt, BT_MAX);
63                         backtrace_symbols_fd(bt, bt_len, STDERR_FILENO);
64                         fprintf(stderr, "\n\n");
65                         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
66                         return; // addrsan should catch malloc-unknown and print more info than we have
67                 }
68         }
69         if (p) { p->next = it->next; } else { allocation_ll = it->next; }
70         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
71         DO_ASSERT(it->ptr == ptr);
72         __real_free(it);
73 }
74 static void FREE(void* ptr) {
75         if ((long)ptr < 1024) return; // Rust loves to create pointers to the NULL page for dummys
76         alloc_freed(ptr);
77         __real_free(ptr);
78 }
79
80 void* __wrap_malloc(size_t len) {
81         void* res = __real_malloc(len);
82         new_allocation(res, "malloc call");
83         return res;
84 }
85 void* __wrap_calloc(size_t nmemb, size_t len) {
86         void* res = __real_calloc(nmemb, len);
87         new_allocation(res, "calloc call");
88         return res;
89 }
90 void __wrap_free(void* ptr) {
91         if (ptr == NULL) return;
92         alloc_freed(ptr);
93         __real_free(ptr);
94 }
95
96 void* __real_realloc(void* ptr, size_t newlen);
97 void* __wrap_realloc(void* ptr, size_t len) {
98         if (ptr != NULL) alloc_freed(ptr);
99         void* res = __real_realloc(ptr, len);
100         new_allocation(res, "realloc call");
101         return res;
102 }
103 void __wrap_reallocarray(void* ptr, size_t new_sz) {
104         // Rust doesn't seem to use reallocarray currently
105         assert(false);
106 }
107
108 void __attribute__((destructor)) check_leaks() {
109         for (allocation* a = allocation_ll; a != NULL; a = a->next) {
110                 fprintf(stderr, "%s %p remains:\n", a->struct_name, a->ptr);
111                 backtrace_symbols_fd(a->bt, a->bt_len, STDERR_FILENO);
112                 fprintf(stderr, "\n\n");
113         }
114         DO_ASSERT(allocation_ll == NULL);
115 }
116 static jclass arr_of_B_clz = NULL;
117 JNIEXPORT void Java_org_ldk_impl_bindings_init_1class_1cache(JNIEnv * env, jclass _b) {
118         arr_of_B_clz = (*env)->FindClass(env, "[B");
119         CHECK(arr_of_B_clz != NULL);
120         arr_of_B_clz = (*env)->NewGlobalRef(env, arr_of_B_clz);
121 }
122
123 static jmethodID ordinal_meth = NULL;
124 static jmethodID slicedef_meth = NULL;
125 static jclass slicedef_cls = NULL;
126 JNIEXPORT void Java_org_ldk_impl_bindings_init(JNIEnv * env, jclass _b, jclass enum_class, jclass slicedef_class) {
127         ordinal_meth = (*env)->GetMethodID(env, enum_class, "ordinal", "()I");
128         CHECK(ordinal_meth != NULL);
129         slicedef_meth = (*env)->GetMethodID(env, slicedef_class, "<init>", "(JJJ)V");
130         CHECK(slicedef_meth != NULL);
131         slicedef_cls = (*env)->NewGlobalRef(env, slicedef_class);
132         CHECK(slicedef_cls != NULL);
133 }
134
135 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_deref_1bool (JNIEnv * env, jclass _a, jlong ptr) {
136         return *((bool*)ptr);
137 }
138 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_deref_1long (JNIEnv * env, jclass _a, jlong ptr) {
139         return *((long*)ptr);
140 }
141 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_free_1heap_1ptr (JNIEnv * env, jclass _a, jlong ptr) {
142         FREE((void*)ptr);
143 }
144 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_read_1bytes (JNIEnv * _env, jclass _b, jlong ptr, jlong len) {
145         jbyteArray ret_arr = (*_env)->NewByteArray(_env, len);
146         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, len, (unsigned char*)ptr);
147         return ret_arr;
148 }
149 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_get_1u8_1slice_1bytes (JNIEnv * _env, jclass _b, jlong slice_ptr) {
150         LDKu8slice *slice = (LDKu8slice*)slice_ptr;
151         jbyteArray ret_arr = (*_env)->NewByteArray(_env, slice->datalen);
152         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, slice->datalen, slice->data);
153         return ret_arr;
154 }
155 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec (JNIEnv * _env, jclass _b, jbyteArray bytes) {
156         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "LDKCVec_u8");
157         vec->datalen = (*_env)->GetArrayLength(_env, bytes);
158         vec->data = (uint8_t*)MALLOC(vec->datalen, "LDKCVec_u8Z Bytes");
159         (*_env)->GetByteArrayRegion (_env, bytes, 0, vec->datalen, vec->data);
160         return (long)vec;
161 }
162 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_txpointer_1get_1buffer (JNIEnv * env, jclass _b, jlong ptr) {
163         LDKTransaction *txdata = (LDKTransaction*)ptr;
164         LDKu8slice slice;
165         slice.data = txdata->data;
166         slice.datalen = txdata->datalen;
167         return Java_org_ldk_impl_bindings_get_1u8_1slice_1bytes(env, _b, (long)&slice);
168 }
169 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data (JNIEnv * env, jclass _b, jbyteArray bytes) {
170         LDKTransaction *txdata = (LDKTransaction*)MALLOC(sizeof(LDKTransaction), "LDKTransaction");
171         txdata->datalen = (*env)->GetArrayLength(env, bytes);
172         txdata->data = (uint8_t*)MALLOC(txdata->datalen, "Tx Data Bytes");
173         txdata->data_is_owned = false;
174         (*env)->GetByteArrayRegion (env, bytes, 0, txdata->datalen, txdata->data);
175         return (long)txdata;
176 }
177 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_txpointer_1free (JNIEnv * env, jclass _b, jlong ptr) {
178         LDKTransaction *tx = (LDKTransaction*)ptr;
179         tx->data_is_owned = true;
180         Transaction_free(*tx);
181         FREE((void*)ptr);
182 }
183 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) {
184         // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
185         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically");
186         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically");
187         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically");
188         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_C2Tuple_usizeTransactionZZ, datalen), "Vec<*> needs to be mapped identically");
189         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
190         return (long)vec->datalen;
191 }
192 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec (JNIEnv * _env, jclass _b) {
193         // Check sizes of a few Vec types are all consistent as we're meant to be generic across types
194         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_SignatureZ), "Vec<*> needs to be mapped identically");
195         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_MessageSendEventZ), "Vec<*> needs to be mapped identically");
196         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_EventZ), "Vec<*> needs to be mapped identically");
197         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "Vec<*> needs to be mapped identically");
198         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "Empty LDKCVec");
199         vec->data = NULL;
200         vec->datalen = 0;
201         return (long)vec;
202 }
203
204 // We assume that CVec_u8Z and u8slice are the same size and layout (and thus pointers to the two can be mixed)
205 _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKu8slice), "Vec<u8> and [u8] need to have been mapped identically");
206 _Static_assert(offsetof(LDKCVec_u8Z, data) == offsetof(LDKu8slice, data), "Vec<u8> and [u8] need to have been mapped identically");
207 _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen), "Vec<u8> and [u8] need to have been mapped identically");
208
209 static inline LDKAccessError LDKAccessError_from_java(JNIEnv *env, jclass val) {
210         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
211                 case 0: return LDKAccessError_UnknownChain;
212                 case 1: return LDKAccessError_UnknownTx;
213         }
214         abort();
215 }
216 static jclass LDKAccessError_class = NULL;
217 static jfieldID LDKAccessError_LDKAccessError_UnknownChain = NULL;
218 static jfieldID LDKAccessError_LDKAccessError_UnknownTx = NULL;
219 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKAccessError_init (JNIEnv * env, jclass clz) {
220         LDKAccessError_class = (*env)->NewGlobalRef(env, clz);
221         CHECK(LDKAccessError_class != NULL);
222         LDKAccessError_LDKAccessError_UnknownChain = (*env)->GetStaticFieldID(env, LDKAccessError_class, "LDKAccessError_UnknownChain", "Lorg/ldk/enums/LDKAccessError;");
223         CHECK(LDKAccessError_LDKAccessError_UnknownChain != NULL);
224         LDKAccessError_LDKAccessError_UnknownTx = (*env)->GetStaticFieldID(env, LDKAccessError_class, "LDKAccessError_UnknownTx", "Lorg/ldk/enums/LDKAccessError;");
225         CHECK(LDKAccessError_LDKAccessError_UnknownTx != NULL);
226 }
227 static inline jclass LDKAccessError_to_java(JNIEnv *env, LDKAccessError val) {
228         switch (val) {
229                 case LDKAccessError_UnknownChain:
230                         return (*env)->GetStaticObjectField(env, LDKAccessError_class, LDKAccessError_LDKAccessError_UnknownChain);
231                 case LDKAccessError_UnknownTx:
232                         return (*env)->GetStaticObjectField(env, LDKAccessError_class, LDKAccessError_LDKAccessError_UnknownTx);
233                 default: abort();
234         }
235 }
236
237 static inline LDKChannelMonitorUpdateErr LDKChannelMonitorUpdateErr_from_java(JNIEnv *env, jclass val) {
238         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
239                 case 0: return LDKChannelMonitorUpdateErr_TemporaryFailure;
240                 case 1: return LDKChannelMonitorUpdateErr_PermanentFailure;
241         }
242         abort();
243 }
244 static jclass LDKChannelMonitorUpdateErr_class = NULL;
245 static jfieldID LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure = NULL;
246 static jfieldID LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure = NULL;
247 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKChannelMonitorUpdateErr_init (JNIEnv * env, jclass clz) {
248         LDKChannelMonitorUpdateErr_class = (*env)->NewGlobalRef(env, clz);
249         CHECK(LDKChannelMonitorUpdateErr_class != NULL);
250         LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure = (*env)->GetStaticFieldID(env, LDKChannelMonitorUpdateErr_class, "LDKChannelMonitorUpdateErr_TemporaryFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
251         CHECK(LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure != NULL);
252         LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure = (*env)->GetStaticFieldID(env, LDKChannelMonitorUpdateErr_class, "LDKChannelMonitorUpdateErr_PermanentFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
253         CHECK(LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure != NULL);
254 }
255 static inline jclass LDKChannelMonitorUpdateErr_to_java(JNIEnv *env, LDKChannelMonitorUpdateErr val) {
256         switch (val) {
257                 case LDKChannelMonitorUpdateErr_TemporaryFailure:
258                         return (*env)->GetStaticObjectField(env, LDKChannelMonitorUpdateErr_class, LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure);
259                 case LDKChannelMonitorUpdateErr_PermanentFailure:
260                         return (*env)->GetStaticObjectField(env, LDKChannelMonitorUpdateErr_class, LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure);
261                 default: abort();
262         }
263 }
264
265 static inline LDKConfirmationTarget LDKConfirmationTarget_from_java(JNIEnv *env, jclass val) {
266         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
267                 case 0: return LDKConfirmationTarget_Background;
268                 case 1: return LDKConfirmationTarget_Normal;
269                 case 2: return LDKConfirmationTarget_HighPriority;
270         }
271         abort();
272 }
273 static jclass LDKConfirmationTarget_class = NULL;
274 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_Background = NULL;
275 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_Normal = NULL;
276 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_HighPriority = NULL;
277 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKConfirmationTarget_init (JNIEnv * env, jclass clz) {
278         LDKConfirmationTarget_class = (*env)->NewGlobalRef(env, clz);
279         CHECK(LDKConfirmationTarget_class != NULL);
280         LDKConfirmationTarget_LDKConfirmationTarget_Background = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_Background", "Lorg/ldk/enums/LDKConfirmationTarget;");
281         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_Background != NULL);
282         LDKConfirmationTarget_LDKConfirmationTarget_Normal = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_Normal", "Lorg/ldk/enums/LDKConfirmationTarget;");
283         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_Normal != NULL);
284         LDKConfirmationTarget_LDKConfirmationTarget_HighPriority = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_HighPriority", "Lorg/ldk/enums/LDKConfirmationTarget;");
285         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_HighPriority != NULL);
286 }
287 static inline jclass LDKConfirmationTarget_to_java(JNIEnv *env, LDKConfirmationTarget val) {
288         switch (val) {
289                 case LDKConfirmationTarget_Background:
290                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_Background);
291                 case LDKConfirmationTarget_Normal:
292                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_Normal);
293                 case LDKConfirmationTarget_HighPriority:
294                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_HighPriority);
295                 default: abort();
296         }
297 }
298
299 static inline LDKLevel LDKLevel_from_java(JNIEnv *env, jclass val) {
300         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
301                 case 0: return LDKLevel_Off;
302                 case 1: return LDKLevel_Error;
303                 case 2: return LDKLevel_Warn;
304                 case 3: return LDKLevel_Info;
305                 case 4: return LDKLevel_Debug;
306                 case 5: return LDKLevel_Trace;
307         }
308         abort();
309 }
310 static jclass LDKLevel_class = NULL;
311 static jfieldID LDKLevel_LDKLevel_Off = NULL;
312 static jfieldID LDKLevel_LDKLevel_Error = NULL;
313 static jfieldID LDKLevel_LDKLevel_Warn = NULL;
314 static jfieldID LDKLevel_LDKLevel_Info = NULL;
315 static jfieldID LDKLevel_LDKLevel_Debug = NULL;
316 static jfieldID LDKLevel_LDKLevel_Trace = NULL;
317 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKLevel_init (JNIEnv * env, jclass clz) {
318         LDKLevel_class = (*env)->NewGlobalRef(env, clz);
319         CHECK(LDKLevel_class != NULL);
320         LDKLevel_LDKLevel_Off = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Off", "Lorg/ldk/enums/LDKLevel;");
321         CHECK(LDKLevel_LDKLevel_Off != NULL);
322         LDKLevel_LDKLevel_Error = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Error", "Lorg/ldk/enums/LDKLevel;");
323         CHECK(LDKLevel_LDKLevel_Error != NULL);
324         LDKLevel_LDKLevel_Warn = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Warn", "Lorg/ldk/enums/LDKLevel;");
325         CHECK(LDKLevel_LDKLevel_Warn != NULL);
326         LDKLevel_LDKLevel_Info = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Info", "Lorg/ldk/enums/LDKLevel;");
327         CHECK(LDKLevel_LDKLevel_Info != NULL);
328         LDKLevel_LDKLevel_Debug = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Debug", "Lorg/ldk/enums/LDKLevel;");
329         CHECK(LDKLevel_LDKLevel_Debug != NULL);
330         LDKLevel_LDKLevel_Trace = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Trace", "Lorg/ldk/enums/LDKLevel;");
331         CHECK(LDKLevel_LDKLevel_Trace != NULL);
332 }
333 static inline jclass LDKLevel_to_java(JNIEnv *env, LDKLevel val) {
334         switch (val) {
335                 case LDKLevel_Off:
336                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Off);
337                 case LDKLevel_Error:
338                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Error);
339                 case LDKLevel_Warn:
340                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Warn);
341                 case LDKLevel_Info:
342                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Info);
343                 case LDKLevel_Debug:
344                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Debug);
345                 case LDKLevel_Trace:
346                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Trace);
347                 default: abort();
348         }
349 }
350
351 static inline LDKNetwork LDKNetwork_from_java(JNIEnv *env, jclass val) {
352         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
353                 case 0: return LDKNetwork_Bitcoin;
354                 case 1: return LDKNetwork_Testnet;
355                 case 2: return LDKNetwork_Regtest;
356         }
357         abort();
358 }
359 static jclass LDKNetwork_class = NULL;
360 static jfieldID LDKNetwork_LDKNetwork_Bitcoin = NULL;
361 static jfieldID LDKNetwork_LDKNetwork_Testnet = NULL;
362 static jfieldID LDKNetwork_LDKNetwork_Regtest = NULL;
363 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKNetwork_init (JNIEnv * env, jclass clz) {
364         LDKNetwork_class = (*env)->NewGlobalRef(env, clz);
365         CHECK(LDKNetwork_class != NULL);
366         LDKNetwork_LDKNetwork_Bitcoin = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Bitcoin", "Lorg/ldk/enums/LDKNetwork;");
367         CHECK(LDKNetwork_LDKNetwork_Bitcoin != NULL);
368         LDKNetwork_LDKNetwork_Testnet = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Testnet", "Lorg/ldk/enums/LDKNetwork;");
369         CHECK(LDKNetwork_LDKNetwork_Testnet != NULL);
370         LDKNetwork_LDKNetwork_Regtest = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Regtest", "Lorg/ldk/enums/LDKNetwork;");
371         CHECK(LDKNetwork_LDKNetwork_Regtest != NULL);
372 }
373 static inline jclass LDKNetwork_to_java(JNIEnv *env, LDKNetwork val) {
374         switch (val) {
375                 case LDKNetwork_Bitcoin:
376                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Bitcoin);
377                 case LDKNetwork_Testnet:
378                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Testnet);
379                 case LDKNetwork_Regtest:
380                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Regtest);
381                 default: abort();
382         }
383 }
384
385 static inline LDKSecp256k1Error LDKSecp256k1Error_from_java(JNIEnv *env, jclass val) {
386         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
387                 case 0: return LDKSecp256k1Error_IncorrectSignature;
388                 case 1: return LDKSecp256k1Error_InvalidMessage;
389                 case 2: return LDKSecp256k1Error_InvalidPublicKey;
390                 case 3: return LDKSecp256k1Error_InvalidSignature;
391                 case 4: return LDKSecp256k1Error_InvalidSecretKey;
392                 case 5: return LDKSecp256k1Error_InvalidRecoveryId;
393                 case 6: return LDKSecp256k1Error_InvalidTweak;
394                 case 7: return LDKSecp256k1Error_NotEnoughMemory;
395                 case 8: return LDKSecp256k1Error_CallbackPanicked;
396         }
397         abort();
398 }
399 static jclass LDKSecp256k1Error_class = NULL;
400 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature = NULL;
401 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage = NULL;
402 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey = NULL;
403 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature = NULL;
404 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey = NULL;
405 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId = NULL;
406 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak = NULL;
407 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory = NULL;
408 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked = NULL;
409 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKSecp256k1Error_init (JNIEnv * env, jclass clz) {
410         LDKSecp256k1Error_class = (*env)->NewGlobalRef(env, clz);
411         CHECK(LDKSecp256k1Error_class != NULL);
412         LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_IncorrectSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
413         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature != NULL);
414         LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidMessage", "Lorg/ldk/enums/LDKSecp256k1Error;");
415         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage != NULL);
416         LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidPublicKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
417         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey != NULL);
418         LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
419         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature != NULL);
420         LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidSecretKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
421         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey != NULL);
422         LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidRecoveryId", "Lorg/ldk/enums/LDKSecp256k1Error;");
423         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId != NULL);
424         LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidTweak", "Lorg/ldk/enums/LDKSecp256k1Error;");
425         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak != NULL);
426         LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_NotEnoughMemory", "Lorg/ldk/enums/LDKSecp256k1Error;");
427         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory != NULL);
428         LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_CallbackPanicked", "Lorg/ldk/enums/LDKSecp256k1Error;");
429         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked != NULL);
430 }
431 static inline jclass LDKSecp256k1Error_to_java(JNIEnv *env, LDKSecp256k1Error val) {
432         switch (val) {
433                 case LDKSecp256k1Error_IncorrectSignature:
434                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature);
435                 case LDKSecp256k1Error_InvalidMessage:
436                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage);
437                 case LDKSecp256k1Error_InvalidPublicKey:
438                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey);
439                 case LDKSecp256k1Error_InvalidSignature:
440                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature);
441                 case LDKSecp256k1Error_InvalidSecretKey:
442                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey);
443                 case LDKSecp256k1Error_InvalidRecoveryId:
444                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId);
445                 case LDKSecp256k1Error_InvalidTweak:
446                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak);
447                 case LDKSecp256k1Error_NotEnoughMemory:
448                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory);
449                 case LDKSecp256k1Error_CallbackPanicked:
450                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked);
451                 default: abort();
452         }
453 }
454
455 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u8_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
456         LDKCVecTempl_u8 *vec = (LDKCVecTempl_u8*)ptr;
457         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(uint8_t));
458 }
459 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u8_1new(JNIEnv *env, jclass _b, jbyteArray elems){
460         LDKCVecTempl_u8 *ret = MALLOC(sizeof(LDKCVecTempl_u8), "LDKCVecTempl_u8");
461         ret->datalen = (*env)->GetArrayLength(env, elems);
462         if (ret->datalen == 0) {
463                 ret->data = NULL;
464         } else {
465                 ret->data = MALLOC(sizeof(uint8_t) * ret->datalen, "LDKCVecTempl_u8 Data");
466                 jbyte *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
467                 for (size_t i = 0; i < ret->datalen; i++) {
468                         ret->data[i] = java_elems[i];
469                 }
470                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
471         }
472         return (long)ret;
473 }
474 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1usize_1_1Transaction_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) {
475         LDKC2TupleTempl_usize__Transaction* ret = MALLOC(sizeof(LDKC2TupleTempl_usize__Transaction), "LDKC2TupleTempl_usize__Transaction");
476         ret->a = a;
477         LDKTransaction b_ref;
478         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
479         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
480         (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data);
481         b_ref.data_is_owned = false;
482         ret->b = b_ref;
483         return (long)ret;
484 }
485 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
486         LDKC2TupleTempl_usize__Transaction *tuple = (LDKC2TupleTempl_usize__Transaction*)ptr;
487         return tuple->a;
488 }
489 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
490         LDKC2TupleTempl_usize__Transaction *tuple = (LDKC2TupleTempl_usize__Transaction*)ptr;
491         LDKTransaction b_var = tuple->b;
492         jbyteArray b_arr = (*_env)->NewByteArray(_env, b_var.datalen);
493         (*_env)->SetByteArrayRegion(_env, b_arr, 0, b_var.datalen, b_var.data);
494         return b_arr;
495 }
496 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
497         return ((LDKCResult_NoneChannelMonitorUpdateErrZ*)arg)->result_ok;
498 }
499 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
500         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
501         CHECK(val->result_ok);
502         return *val->contents.result;
503 }
504 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
505         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
506         CHECK(!val->result_ok);
507         jclass err_conv = LDKChannelMonitorUpdateErr_to_java(_env, (*val->contents.err));
508         return err_conv;
509 }
510 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
511         return ((LDKCResult_NoneMonitorUpdateErrorZ*)arg)->result_ok;
512 }
513 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
514         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
515         CHECK(val->result_ok);
516         return *val->contents.result;
517 }
518 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
519         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
520         CHECK(!val->result_ok);
521         LDKMonitorUpdateError err_var = (*val->contents.err);
522         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
523         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
524         long err_ref = (long)err_var.inner & ~1;
525         return err_ref;
526 }
527 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1OutPoint_1_1CVec_1u8Z_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) {
528         LDKC2TupleTempl_OutPoint__CVec_u8Z* ret = MALLOC(sizeof(LDKC2TupleTempl_OutPoint__CVec_u8Z), "LDKC2TupleTempl_OutPoint__CVec_u8Z");
529         LDKOutPoint a_conv;
530         a_conv.inner = (void*)(a & (~1));
531         a_conv.is_owned = (a & 1) || (a == 0);
532         if (a_conv.inner != NULL)
533                 a_conv = OutPoint_clone(&a_conv);
534         ret->a = a_conv;
535         LDKCVec_u8Z b_ref;
536         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
537         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
538         (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data);
539         ret->b = b_ref;
540         return (long)ret;
541 }
542 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
543         LDKC2TupleTempl_OutPoint__CVec_u8Z *tuple = (LDKC2TupleTempl_OutPoint__CVec_u8Z*)ptr;
544         LDKOutPoint a_var = tuple->a;
545         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
546         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
547         long a_ref = (long)a_var.inner & ~1;
548         return a_ref;
549 }
550 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
551         LDKC2TupleTempl_OutPoint__CVec_u8Z *tuple = (LDKC2TupleTempl_OutPoint__CVec_u8Z*)ptr;
552         LDKCVec_u8Z b_var = tuple->b;
553         jbyteArray b_arr = (*_env)->NewByteArray(_env, b_var.datalen);
554         (*_env)->SetByteArrayRegion(_env, b_arr, 0, b_var.datalen, b_var.data);
555         return b_arr;
556 }
557 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1TxOut_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
558         LDKCVecTempl_TxOut *vec = (LDKCVecTempl_TxOut*)ptr;
559         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKTxOut));
560 }
561 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1TxOut_1new(JNIEnv *env, jclass _b, jlongArray elems){
562         LDKCVecTempl_TxOut *ret = MALLOC(sizeof(LDKCVecTempl_TxOut), "LDKCVecTempl_TxOut");
563         ret->datalen = (*env)->GetArrayLength(env, elems);
564         if (ret->datalen == 0) {
565                 ret->data = NULL;
566         } else {
567                 ret->data = MALLOC(sizeof(LDKTxOut) * ret->datalen, "LDKCVecTempl_TxOut Data");
568                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
569                 for (size_t i = 0; i < ret->datalen; i++) {
570                         jlong arr_elem = java_elems[i];
571                         LDKTxOut arr_elem_conv = *(LDKTxOut*)arr_elem;
572                         FREE((void*)arr_elem);
573                         ret->data[i] = arr_elem_conv;
574                 }
575                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
576         }
577         return (long)ret;
578 }
579 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1ThirtyTwoBytes_1_1CVecTempl_1TxOut_1new(JNIEnv *_env, jclass _b, jbyteArray a, jlongArray b) {
580         LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut* ret = MALLOC(sizeof(LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut), "LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut");
581         LDKThirtyTwoBytes a_ref;
582         CHECK((*_env)->GetArrayLength (_env, a) == 32);
583         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
584         ret->a = a_ref;
585         LDKCVecTempl_TxOut b_constr;
586         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
587         if (b_constr.datalen > 0)
588                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKTxOut), "LDKCVecTempl_TxOut Elements");
589         else
590                 b_constr.data = NULL;
591         long* b_vals = (*_env)->GetLongArrayElements (_env, b, NULL);
592         for (size_t h = 0; h < b_constr.datalen; h++) {
593                 long arr_conv_7 = b_vals[h];
594                 LDKTxOut arr_conv_7_conv = *(LDKTxOut*)arr_conv_7;
595                 FREE((void*)arr_conv_7);
596                 b_constr.data[h] = arr_conv_7_conv;
597         }
598         (*_env)->ReleaseLongArrayElements (_env, b, b_vals, 0);
599         ret->b = b_constr;
600         return (long)ret;
601 }
602 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1TxidCVec_1TxOutZZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
603         LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut *tuple = (LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut*)ptr;
604         jbyteArray a_arr = (*_env)->NewByteArray(_env, 32);
605         (*_env)->SetByteArrayRegion(_env, a_arr, 0, 32, tuple->a.data);
606         return a_arr;
607 }
608 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1TxidCVec_1TxOutZZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
609         LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut *tuple = (LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut*)ptr;
610         LDKCVecTempl_TxOut b_var = tuple->b;
611         jlongArray b_arr = (*_env)->NewLongArray(_env, b_var.datalen);
612         jlong *b_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, b_arr, NULL);
613         for (size_t h = 0; h < b_var.datalen; h++) {
614                 long arr_conv_7_ref = (long)&b_var.data[h];
615                 b_arr_ptr[h] = arr_conv_7_ref;
616         }
617         (*_env)->ReleasePrimitiveArrayCritical(_env, b_arr, b_arr_ptr, 0);
618         return b_arr;
619 }
620 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1u64_1_1u64_1new(JNIEnv *_env, jclass _b, jlong a, jlong b) {
621         LDKC2TupleTempl_u64__u64* ret = MALLOC(sizeof(LDKC2TupleTempl_u64__u64), "LDKC2TupleTempl_u64__u64");
622         ret->a = a;
623         ret->b = b;
624         return (long)ret;
625 }
626 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u64u64Z_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
627         LDKC2TupleTempl_u64__u64 *tuple = (LDKC2TupleTempl_u64__u64*)ptr;
628         return tuple->a;
629 }
630 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u64u64Z_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
631         LDKC2TupleTempl_u64__u64 *tuple = (LDKC2TupleTempl_u64__u64*)ptr;
632         return tuple->b;
633 }
634 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Signature_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
635         LDKCVecTempl_Signature *vec = (LDKCVecTempl_Signature*)ptr;
636         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKSignature));
637 }
638 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1Signature_1_1CVecTempl_1Signature_1new(JNIEnv *_env, jclass _b, jbyteArray a, jobjectArray b) {
639         LDKC2TupleTempl_Signature__CVecTempl_Signature* ret = MALLOC(sizeof(LDKC2TupleTempl_Signature__CVecTempl_Signature), "LDKC2TupleTempl_Signature__CVecTempl_Signature");
640         LDKSignature a_ref;
641         CHECK((*_env)->GetArrayLength (_env, a) == 64);
642         (*_env)->GetByteArrayRegion (_env, a, 0, 64, a_ref.compact_form);
643         ret->a = a_ref;
644         LDKCVecTempl_Signature b_constr;
645         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
646         if (b_constr.datalen > 0)
647                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVecTempl_Signature Elements");
648         else
649                 b_constr.data = NULL;
650         for (size_t i = 0; i < b_constr.datalen; i++) {
651                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, b, i);
652                 LDKSignature arr_conv_8_ref;
653                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
654                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
655                 b_constr.data[i] = arr_conv_8_ref;
656         }
657         ret->b = b_constr;
658         return (long)ret;
659 }
660 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1SignatureCVec_1SignatureZZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
661         LDKC2TupleTempl_Signature__CVecTempl_Signature *tuple = (LDKC2TupleTempl_Signature__CVecTempl_Signature*)ptr;
662         jbyteArray a_arr = (*_env)->NewByteArray(_env, 64);
663         (*_env)->SetByteArrayRegion(_env, a_arr, 0, 64, tuple->a.compact_form);
664         return a_arr;
665 }
666 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1SignatureCVec_1SignatureZZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
667         LDKC2TupleTempl_Signature__CVecTempl_Signature *tuple = (LDKC2TupleTempl_Signature__CVecTempl_Signature*)ptr;
668         LDKCVecTempl_Signature b_var = tuple->b;
669         jobjectArray b_arr = (*_env)->NewObjectArray(_env, b_var.datalen, arr_of_B_clz, NULL);
670         for (size_t i = 0; i < b_var.datalen; i++) {
671                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 64);
672                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 64, b_var.data[i].compact_form);
673                 (*_env)->SetObjectArrayElement(_env, b_arr, i, arr_conv_8_arr);
674         }
675         return b_arr;
676 }
677 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
678         return ((LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg)->result_ok;
679 }
680 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
681         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
682         CHECK(val->result_ok);
683         long res_ref = (long)&(*val->contents.result);
684         return res_ref;
685 }
686 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
687         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
688         CHECK(!val->result_ok);
689         return *val->contents.err;
690 }
691 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
692         return ((LDKCResult_SignatureNoneZ*)arg)->result_ok;
693 }
694 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
695         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
696         CHECK(val->result_ok);
697         jbyteArray res_arr = (*_env)->NewByteArray(_env, 64);
698         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 64, (*val->contents.result).compact_form);
699         return res_arr;
700 }
701 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
702         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
703         CHECK(!val->result_ok);
704         return *val->contents.err;
705 }
706 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
707         return ((LDKCResult_CVec_SignatureZNoneZ*)arg)->result_ok;
708 }
709 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
710         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
711         CHECK(val->result_ok);
712         LDKCVecTempl_Signature res_var = (*val->contents.result);
713         jobjectArray res_arr = (*_env)->NewObjectArray(_env, res_var.datalen, arr_of_B_clz, NULL);
714         for (size_t i = 0; i < res_var.datalen; i++) {
715                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 64);
716                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 64, res_var.data[i].compact_form);
717                 (*_env)->SetObjectArrayElement(_env, res_arr, i, arr_conv_8_arr);
718         }
719         return res_arr;
720 }
721 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
722         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
723         CHECK(!val->result_ok);
724         return *val->contents.err;
725 }
726 static jclass LDKAPIError_APIMisuseError_class = NULL;
727 static jmethodID LDKAPIError_APIMisuseError_meth = NULL;
728 static jclass LDKAPIError_FeeRateTooHigh_class = NULL;
729 static jmethodID LDKAPIError_FeeRateTooHigh_meth = NULL;
730 static jclass LDKAPIError_RouteError_class = NULL;
731 static jmethodID LDKAPIError_RouteError_meth = NULL;
732 static jclass LDKAPIError_ChannelUnavailable_class = NULL;
733 static jmethodID LDKAPIError_ChannelUnavailable_meth = NULL;
734 static jclass LDKAPIError_MonitorUpdateFailed_class = NULL;
735 static jmethodID LDKAPIError_MonitorUpdateFailed_meth = NULL;
736 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKAPIError_init (JNIEnv * env, jclass _a) {
737         LDKAPIError_APIMisuseError_class =
738                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$APIMisuseError;"));
739         CHECK(LDKAPIError_APIMisuseError_class != NULL);
740         LDKAPIError_APIMisuseError_meth = (*env)->GetMethodID(env, LDKAPIError_APIMisuseError_class, "<init>", "([B)V");
741         CHECK(LDKAPIError_APIMisuseError_meth != NULL);
742         LDKAPIError_FeeRateTooHigh_class =
743                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$FeeRateTooHigh;"));
744         CHECK(LDKAPIError_FeeRateTooHigh_class != NULL);
745         LDKAPIError_FeeRateTooHigh_meth = (*env)->GetMethodID(env, LDKAPIError_FeeRateTooHigh_class, "<init>", "([BI)V");
746         CHECK(LDKAPIError_FeeRateTooHigh_meth != NULL);
747         LDKAPIError_RouteError_class =
748                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$RouteError;"));
749         CHECK(LDKAPIError_RouteError_class != NULL);
750         LDKAPIError_RouteError_meth = (*env)->GetMethodID(env, LDKAPIError_RouteError_class, "<init>", "(Ljava/lang/String;)V");
751         CHECK(LDKAPIError_RouteError_meth != NULL);
752         LDKAPIError_ChannelUnavailable_class =
753                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$ChannelUnavailable;"));
754         CHECK(LDKAPIError_ChannelUnavailable_class != NULL);
755         LDKAPIError_ChannelUnavailable_meth = (*env)->GetMethodID(env, LDKAPIError_ChannelUnavailable_class, "<init>", "([B)V");
756         CHECK(LDKAPIError_ChannelUnavailable_meth != NULL);
757         LDKAPIError_MonitorUpdateFailed_class =
758                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$MonitorUpdateFailed;"));
759         CHECK(LDKAPIError_MonitorUpdateFailed_class != NULL);
760         LDKAPIError_MonitorUpdateFailed_meth = (*env)->GetMethodID(env, LDKAPIError_MonitorUpdateFailed_class, "<init>", "()V");
761         CHECK(LDKAPIError_MonitorUpdateFailed_meth != NULL);
762 }
763 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAPIError_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
764         LDKAPIError *obj = (LDKAPIError*)ptr;
765         switch(obj->tag) {
766                 case LDKAPIError_APIMisuseError: {
767                         LDKCVec_u8Z err_var = obj->api_misuse_error.err;
768                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
769                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
770                         return (*_env)->NewObject(_env, LDKAPIError_APIMisuseError_class, LDKAPIError_APIMisuseError_meth, err_arr);
771                 }
772                 case LDKAPIError_FeeRateTooHigh: {
773                         LDKCVec_u8Z err_var = obj->fee_rate_too_high.err;
774                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
775                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
776                         return (*_env)->NewObject(_env, LDKAPIError_FeeRateTooHigh_class, LDKAPIError_FeeRateTooHigh_meth, err_arr, obj->fee_rate_too_high.feerate);
777                 }
778                 case LDKAPIError_RouteError: {
779                         LDKStr err_str = obj->route_error.err;
780                         char* err_buf = MALLOC(err_str.len + 1, "str conv buf");
781                         memcpy(err_buf, err_str.chars, err_str.len);
782                         err_buf[err_str.len] = 0;
783                         jstring err_conv = (*_env)->NewStringUTF(_env, err_str.chars);
784                         FREE(err_buf);
785                         return (*_env)->NewObject(_env, LDKAPIError_RouteError_class, LDKAPIError_RouteError_meth, err_conv);
786                 }
787                 case LDKAPIError_ChannelUnavailable: {
788                         LDKCVec_u8Z err_var = obj->channel_unavailable.err;
789                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
790                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
791                         return (*_env)->NewObject(_env, LDKAPIError_ChannelUnavailable_class, LDKAPIError_ChannelUnavailable_meth, err_arr);
792                 }
793                 case LDKAPIError_MonitorUpdateFailed: {
794                         return (*_env)->NewObject(_env, LDKAPIError_MonitorUpdateFailed_class, LDKAPIError_MonitorUpdateFailed_meth);
795                 }
796                 default: abort();
797         }
798 }
799 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
800         return ((LDKCResult_NoneAPIErrorZ*)arg)->result_ok;
801 }
802 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
803         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
804         CHECK(val->result_ok);
805         return *val->contents.result;
806 }
807 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
808         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
809         CHECK(!val->result_ok);
810         long err_ref = (long)&(*val->contents.err);
811         return err_ref;
812 }
813 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
814         return ((LDKCResult_NonePaymentSendFailureZ*)arg)->result_ok;
815 }
816 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
817         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
818         CHECK(val->result_ok);
819         return *val->contents.result;
820 }
821 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
822         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
823         CHECK(!val->result_ok);
824         LDKPaymentSendFailure err_var = (*val->contents.err);
825         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
826         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
827         long err_ref = (long)err_var.inner & ~1;
828         return err_ref;
829 }
830 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) {
831         LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate* ret = MALLOC(sizeof(LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate), "LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate");
832         LDKChannelAnnouncement a_conv;
833         a_conv.inner = (void*)(a & (~1));
834         a_conv.is_owned = (a & 1) || (a == 0);
835         if (a_conv.inner != NULL)
836                 a_conv = ChannelAnnouncement_clone(&a_conv);
837         ret->a = a_conv;
838         LDKChannelUpdate b_conv;
839         b_conv.inner = (void*)(b & (~1));
840         b_conv.is_owned = (b & 1) || (b == 0);
841         if (b_conv.inner != NULL)
842                 b_conv = ChannelUpdate_clone(&b_conv);
843         ret->b = b_conv;
844         LDKChannelUpdate c_conv;
845         c_conv.inner = (void*)(c & (~1));
846         c_conv.is_owned = (c & 1) || (c == 0);
847         if (c_conv.inner != NULL)
848                 c_conv = ChannelUpdate_clone(&c_conv);
849         ret->c = c_conv;
850         return (long)ret;
851 }
852 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
853         LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate *tuple = (LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate*)ptr;
854         LDKChannelAnnouncement a_var = tuple->a;
855         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
856         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
857         long a_ref = (long)a_var.inner & ~1;
858         return a_ref;
859 }
860 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
861         LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate *tuple = (LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate*)ptr;
862         LDKChannelUpdate b_var = tuple->b;
863         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
864         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
865         long b_ref = (long)b_var.inner & ~1;
866         return b_ref;
867 }
868 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1c(JNIEnv *_env, jclass _b, jlong ptr) {
869         LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate *tuple = (LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate*)ptr;
870         LDKChannelUpdate c_var = tuple->c;
871         CHECK((((long)c_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
872         CHECK((((long)&c_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
873         long c_ref = (long)c_var.inner & ~1;
874         return c_ref;
875 }
876 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
877         return ((LDKCResult_NonePeerHandleErrorZ*)arg)->result_ok;
878 }
879 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
880         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
881         CHECK(val->result_ok);
882         return *val->contents.result;
883 }
884 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
885         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
886         CHECK(!val->result_ok);
887         LDKPeerHandleError err_var = (*val->contents.err);
888         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
889         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
890         long err_ref = (long)err_var.inner & ~1;
891         return err_ref;
892 }
893 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1HTLCOutputInCommitment_1_1Signature_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) {
894         LDKC2TupleTempl_HTLCOutputInCommitment__Signature* ret = MALLOC(sizeof(LDKC2TupleTempl_HTLCOutputInCommitment__Signature), "LDKC2TupleTempl_HTLCOutputInCommitment__Signature");
895         LDKHTLCOutputInCommitment a_conv;
896         a_conv.inner = (void*)(a & (~1));
897         a_conv.is_owned = (a & 1) || (a == 0);
898         if (a_conv.inner != NULL)
899                 a_conv = HTLCOutputInCommitment_clone(&a_conv);
900         ret->a = a_conv;
901         LDKSignature b_ref;
902         CHECK((*_env)->GetArrayLength (_env, b) == 64);
903         (*_env)->GetByteArrayRegion (_env, b, 0, 64, b_ref.compact_form);
904         ret->b = b_ref;
905         return (long)ret;
906 }
907 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1HTLCOutputInCommitmentSignatureZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
908         LDKC2TupleTempl_HTLCOutputInCommitment__Signature *tuple = (LDKC2TupleTempl_HTLCOutputInCommitment__Signature*)ptr;
909         LDKHTLCOutputInCommitment a_var = tuple->a;
910         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
911         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
912         long a_ref = (long)a_var.inner & ~1;
913         return a_ref;
914 }
915 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1HTLCOutputInCommitmentSignatureZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
916         LDKC2TupleTempl_HTLCOutputInCommitment__Signature *tuple = (LDKC2TupleTempl_HTLCOutputInCommitment__Signature*)ptr;
917         jbyteArray b_arr = (*_env)->NewByteArray(_env, 64);
918         (*_env)->SetByteArrayRegion(_env, b_arr, 0, 64, tuple->b.compact_form);
919         return b_arr;
920 }
921 static jclass LDKSpendableOutputDescriptor_StaticOutput_class = NULL;
922 static jmethodID LDKSpendableOutputDescriptor_StaticOutput_meth = NULL;
923 static jclass LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class = NULL;
924 static jmethodID LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = NULL;
925 static jclass LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class = NULL;
926 static jmethodID LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = NULL;
927 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKSpendableOutputDescriptor_init (JNIEnv * env, jclass _a) {
928         LDKSpendableOutputDescriptor_StaticOutput_class =
929                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$StaticOutput;"));
930         CHECK(LDKSpendableOutputDescriptor_StaticOutput_class != NULL);
931         LDKSpendableOutputDescriptor_StaticOutput_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_StaticOutput_class, "<init>", "(JJ)V");
932         CHECK(LDKSpendableOutputDescriptor_StaticOutput_meth != NULL);
933         LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class =
934                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$DynamicOutputP2WSH;"));
935         CHECK(LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class != NULL);
936         LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class, "<init>", "(J[BSJJ[B)V");
937         CHECK(LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth != NULL);
938         LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class =
939                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$StaticOutputCounterpartyPayment;"));
940         CHECK(LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class != NULL);
941         LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class, "<init>", "(JJJ)V");
942         CHECK(LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth != NULL);
943 }
944 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSpendableOutputDescriptor_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
945         LDKSpendableOutputDescriptor *obj = (LDKSpendableOutputDescriptor*)ptr;
946         switch(obj->tag) {
947                 case LDKSpendableOutputDescriptor_StaticOutput: {
948                         LDKOutPoint outpoint_var = obj->static_output.outpoint;
949                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
950                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
951                         long outpoint_ref = (long)outpoint_var.inner & ~1;
952                         long output_ref = (long)&obj->static_output.output;
953                         return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_StaticOutput_class, LDKSpendableOutputDescriptor_StaticOutput_meth, outpoint_ref, output_ref);
954                 }
955                 case LDKSpendableOutputDescriptor_DynamicOutputP2WSH: {
956                         LDKOutPoint outpoint_var = obj->dynamic_output_p2wsh.outpoint;
957                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
958                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
959                         long outpoint_ref = (long)outpoint_var.inner & ~1;
960                         jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33);
961                         (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, obj->dynamic_output_p2wsh.per_commitment_point.compressed_form);
962                         long output_ref = (long)&obj->dynamic_output_p2wsh.output;
963                         long key_derivation_params_ref = (long)&obj->dynamic_output_p2wsh.key_derivation_params;
964                         jbyteArray revocation_pubkey_arr = (*_env)->NewByteArray(_env, 33);
965                         (*_env)->SetByteArrayRegion(_env, revocation_pubkey_arr, 0, 33, obj->dynamic_output_p2wsh.revocation_pubkey.compressed_form);
966                         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);
967                 }
968                 case LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment: {
969                         LDKOutPoint outpoint_var = obj->static_output_counterparty_payment.outpoint;
970                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
971                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
972                         long outpoint_ref = (long)outpoint_var.inner & ~1;
973                         long output_ref = (long)&obj->static_output_counterparty_payment.output;
974                         long key_derivation_params_ref = (long)&obj->static_output_counterparty_payment.key_derivation_params;
975                         return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth, outpoint_ref, output_ref, key_derivation_params_ref);
976                 }
977                 default: abort();
978         }
979 }
980 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1SpendableOutputDescriptor_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
981         LDKCVecTempl_SpendableOutputDescriptor *vec = (LDKCVecTempl_SpendableOutputDescriptor*)ptr;
982         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKSpendableOutputDescriptor));
983 }
984 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1SpendableOutputDescriptor_1new(JNIEnv *env, jclass _b, jlongArray elems){
985         LDKCVecTempl_SpendableOutputDescriptor *ret = MALLOC(sizeof(LDKCVecTempl_SpendableOutputDescriptor), "LDKCVecTempl_SpendableOutputDescriptor");
986         ret->datalen = (*env)->GetArrayLength(env, elems);
987         if (ret->datalen == 0) {
988                 ret->data = NULL;
989         } else {
990                 ret->data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * ret->datalen, "LDKCVecTempl_SpendableOutputDescriptor Data");
991                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
992                 for (size_t i = 0; i < ret->datalen; i++) {
993                         jlong arr_elem = java_elems[i];
994                         LDKSpendableOutputDescriptor arr_elem_conv = *(LDKSpendableOutputDescriptor*)arr_elem;
995                         FREE((void*)arr_elem);
996                         ret->data[i] = arr_elem_conv;
997                 }
998                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
999         }
1000         return (long)ret;
1001 }
1002 static jclass LDKEvent_FundingGenerationReady_class = NULL;
1003 static jmethodID LDKEvent_FundingGenerationReady_meth = NULL;
1004 static jclass LDKEvent_FundingBroadcastSafe_class = NULL;
1005 static jmethodID LDKEvent_FundingBroadcastSafe_meth = NULL;
1006 static jclass LDKEvent_PaymentReceived_class = NULL;
1007 static jmethodID LDKEvent_PaymentReceived_meth = NULL;
1008 static jclass LDKEvent_PaymentSent_class = NULL;
1009 static jmethodID LDKEvent_PaymentSent_meth = NULL;
1010 static jclass LDKEvent_PaymentFailed_class = NULL;
1011 static jmethodID LDKEvent_PaymentFailed_meth = NULL;
1012 static jclass LDKEvent_PendingHTLCsForwardable_class = NULL;
1013 static jmethodID LDKEvent_PendingHTLCsForwardable_meth = NULL;
1014 static jclass LDKEvent_SpendableOutputs_class = NULL;
1015 static jmethodID LDKEvent_SpendableOutputs_meth = NULL;
1016 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKEvent_init (JNIEnv * env, jclass _a) {
1017         LDKEvent_FundingGenerationReady_class =
1018                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$FundingGenerationReady;"));
1019         CHECK(LDKEvent_FundingGenerationReady_class != NULL);
1020         LDKEvent_FundingGenerationReady_meth = (*env)->GetMethodID(env, LDKEvent_FundingGenerationReady_class, "<init>", "([BJ[BJ)V");
1021         CHECK(LDKEvent_FundingGenerationReady_meth != NULL);
1022         LDKEvent_FundingBroadcastSafe_class =
1023                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$FundingBroadcastSafe;"));
1024         CHECK(LDKEvent_FundingBroadcastSafe_class != NULL);
1025         LDKEvent_FundingBroadcastSafe_meth = (*env)->GetMethodID(env, LDKEvent_FundingBroadcastSafe_class, "<init>", "(JJ)V");
1026         CHECK(LDKEvent_FundingBroadcastSafe_meth != NULL);
1027         LDKEvent_PaymentReceived_class =
1028                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentReceived;"));
1029         CHECK(LDKEvent_PaymentReceived_class != NULL);
1030         LDKEvent_PaymentReceived_meth = (*env)->GetMethodID(env, LDKEvent_PaymentReceived_class, "<init>", "([B[BJ)V");
1031         CHECK(LDKEvent_PaymentReceived_meth != NULL);
1032         LDKEvent_PaymentSent_class =
1033                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentSent;"));
1034         CHECK(LDKEvent_PaymentSent_class != NULL);
1035         LDKEvent_PaymentSent_meth = (*env)->GetMethodID(env, LDKEvent_PaymentSent_class, "<init>", "([B)V");
1036         CHECK(LDKEvent_PaymentSent_meth != NULL);
1037         LDKEvent_PaymentFailed_class =
1038                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentFailed;"));
1039         CHECK(LDKEvent_PaymentFailed_class != NULL);
1040         LDKEvent_PaymentFailed_meth = (*env)->GetMethodID(env, LDKEvent_PaymentFailed_class, "<init>", "([BZ)V");
1041         CHECK(LDKEvent_PaymentFailed_meth != NULL);
1042         LDKEvent_PendingHTLCsForwardable_class =
1043                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PendingHTLCsForwardable;"));
1044         CHECK(LDKEvent_PendingHTLCsForwardable_class != NULL);
1045         LDKEvent_PendingHTLCsForwardable_meth = (*env)->GetMethodID(env, LDKEvent_PendingHTLCsForwardable_class, "<init>", "(J)V");
1046         CHECK(LDKEvent_PendingHTLCsForwardable_meth != NULL);
1047         LDKEvent_SpendableOutputs_class =
1048                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$SpendableOutputs;"));
1049         CHECK(LDKEvent_SpendableOutputs_class != NULL);
1050         LDKEvent_SpendableOutputs_meth = (*env)->GetMethodID(env, LDKEvent_SpendableOutputs_class, "<init>", "([J)V");
1051         CHECK(LDKEvent_SpendableOutputs_meth != NULL);
1052 }
1053 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEvent_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
1054         LDKEvent *obj = (LDKEvent*)ptr;
1055         switch(obj->tag) {
1056                 case LDKEvent_FundingGenerationReady: {
1057                         jbyteArray temporary_channel_id_arr = (*_env)->NewByteArray(_env, 32);
1058                         (*_env)->SetByteArrayRegion(_env, temporary_channel_id_arr, 0, 32, obj->funding_generation_ready.temporary_channel_id.data);
1059                         LDKCVec_u8Z output_script_var = obj->funding_generation_ready.output_script;
1060                         jbyteArray output_script_arr = (*_env)->NewByteArray(_env, output_script_var.datalen);
1061                         (*_env)->SetByteArrayRegion(_env, output_script_arr, 0, output_script_var.datalen, output_script_var.data);
1062                         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);
1063                 }
1064                 case LDKEvent_FundingBroadcastSafe: {
1065                         LDKOutPoint funding_txo_var = obj->funding_broadcast_safe.funding_txo;
1066                         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1067                         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1068                         long funding_txo_ref = (long)funding_txo_var.inner & ~1;
1069                         return (*_env)->NewObject(_env, LDKEvent_FundingBroadcastSafe_class, LDKEvent_FundingBroadcastSafe_meth, funding_txo_ref, obj->funding_broadcast_safe.user_channel_id);
1070                 }
1071                 case LDKEvent_PaymentReceived: {
1072                         jbyteArray payment_hash_arr = (*_env)->NewByteArray(_env, 32);
1073                         (*_env)->SetByteArrayRegion(_env, payment_hash_arr, 0, 32, obj->payment_received.payment_hash.data);
1074                         jbyteArray payment_secret_arr = (*_env)->NewByteArray(_env, 32);
1075                         (*_env)->SetByteArrayRegion(_env, payment_secret_arr, 0, 32, obj->payment_received.payment_secret.data);
1076                         return (*_env)->NewObject(_env, LDKEvent_PaymentReceived_class, LDKEvent_PaymentReceived_meth, payment_hash_arr, payment_secret_arr, obj->payment_received.amt);
1077                 }
1078                 case LDKEvent_PaymentSent: {
1079                         jbyteArray payment_preimage_arr = (*_env)->NewByteArray(_env, 32);
1080                         (*_env)->SetByteArrayRegion(_env, payment_preimage_arr, 0, 32, obj->payment_sent.payment_preimage.data);
1081                         return (*_env)->NewObject(_env, LDKEvent_PaymentSent_class, LDKEvent_PaymentSent_meth, payment_preimage_arr);
1082                 }
1083                 case LDKEvent_PaymentFailed: {
1084                         jbyteArray payment_hash_arr = (*_env)->NewByteArray(_env, 32);
1085                         (*_env)->SetByteArrayRegion(_env, payment_hash_arr, 0, 32, obj->payment_failed.payment_hash.data);
1086                         return (*_env)->NewObject(_env, LDKEvent_PaymentFailed_class, LDKEvent_PaymentFailed_meth, payment_hash_arr, obj->payment_failed.rejected_by_dest);
1087                 }
1088                 case LDKEvent_PendingHTLCsForwardable: {
1089                         return (*_env)->NewObject(_env, LDKEvent_PendingHTLCsForwardable_class, LDKEvent_PendingHTLCsForwardable_meth, obj->pending_htl_cs_forwardable.time_forwardable);
1090                 }
1091                 case LDKEvent_SpendableOutputs: {
1092                         LDKCVec_SpendableOutputDescriptorZ outputs_var = obj->spendable_outputs.outputs;
1093                         jlongArray outputs_arr = (*_env)->NewLongArray(_env, outputs_var.datalen);
1094                         jlong *outputs_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, outputs_arr, NULL);
1095                         for (size_t b = 0; b < outputs_var.datalen; b++) {
1096                                 long arr_conv_27_ref = (long)&outputs_var.data[b];
1097                                 outputs_arr_ptr[b] = arr_conv_27_ref;
1098                         }
1099                         (*_env)->ReleasePrimitiveArrayCritical(_env, outputs_arr, outputs_arr_ptr, 0);
1100                         return (*_env)->NewObject(_env, LDKEvent_SpendableOutputs_class, LDKEvent_SpendableOutputs_meth, outputs_arr);
1101                 }
1102                 default: abort();
1103         }
1104 }
1105 static jclass LDKErrorAction_DisconnectPeer_class = NULL;
1106 static jmethodID LDKErrorAction_DisconnectPeer_meth = NULL;
1107 static jclass LDKErrorAction_IgnoreError_class = NULL;
1108 static jmethodID LDKErrorAction_IgnoreError_meth = NULL;
1109 static jclass LDKErrorAction_SendErrorMessage_class = NULL;
1110 static jmethodID LDKErrorAction_SendErrorMessage_meth = NULL;
1111 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKErrorAction_init (JNIEnv * env, jclass _a) {
1112         LDKErrorAction_DisconnectPeer_class =
1113                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$DisconnectPeer;"));
1114         CHECK(LDKErrorAction_DisconnectPeer_class != NULL);
1115         LDKErrorAction_DisconnectPeer_meth = (*env)->GetMethodID(env, LDKErrorAction_DisconnectPeer_class, "<init>", "(J)V");
1116         CHECK(LDKErrorAction_DisconnectPeer_meth != NULL);
1117         LDKErrorAction_IgnoreError_class =
1118                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$IgnoreError;"));
1119         CHECK(LDKErrorAction_IgnoreError_class != NULL);
1120         LDKErrorAction_IgnoreError_meth = (*env)->GetMethodID(env, LDKErrorAction_IgnoreError_class, "<init>", "()V");
1121         CHECK(LDKErrorAction_IgnoreError_meth != NULL);
1122         LDKErrorAction_SendErrorMessage_class =
1123                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$SendErrorMessage;"));
1124         CHECK(LDKErrorAction_SendErrorMessage_class != NULL);
1125         LDKErrorAction_SendErrorMessage_meth = (*env)->GetMethodID(env, LDKErrorAction_SendErrorMessage_class, "<init>", "(J)V");
1126         CHECK(LDKErrorAction_SendErrorMessage_meth != NULL);
1127 }
1128 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKErrorAction_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
1129         LDKErrorAction *obj = (LDKErrorAction*)ptr;
1130         switch(obj->tag) {
1131                 case LDKErrorAction_DisconnectPeer: {
1132                         LDKErrorMessage msg_var = obj->disconnect_peer.msg;
1133                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1134                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1135                         long msg_ref = (long)msg_var.inner & ~1;
1136                         return (*_env)->NewObject(_env, LDKErrorAction_DisconnectPeer_class, LDKErrorAction_DisconnectPeer_meth, msg_ref);
1137                 }
1138                 case LDKErrorAction_IgnoreError: {
1139                         return (*_env)->NewObject(_env, LDKErrorAction_IgnoreError_class, LDKErrorAction_IgnoreError_meth);
1140                 }
1141                 case LDKErrorAction_SendErrorMessage: {
1142                         LDKErrorMessage msg_var = obj->send_error_message.msg;
1143                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1144                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1145                         long msg_ref = (long)msg_var.inner & ~1;
1146                         return (*_env)->NewObject(_env, LDKErrorAction_SendErrorMessage_class, LDKErrorAction_SendErrorMessage_meth, msg_ref);
1147                 }
1148                 default: abort();
1149         }
1150 }
1151 static jclass LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class = NULL;
1152 static jmethodID LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = NULL;
1153 static jclass LDKHTLCFailChannelUpdate_ChannelClosed_class = NULL;
1154 static jmethodID LDKHTLCFailChannelUpdate_ChannelClosed_meth = NULL;
1155 static jclass LDKHTLCFailChannelUpdate_NodeFailure_class = NULL;
1156 static jmethodID LDKHTLCFailChannelUpdate_NodeFailure_meth = NULL;
1157 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKHTLCFailChannelUpdate_init (JNIEnv * env, jclass _a) {
1158         LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class =
1159                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$ChannelUpdateMessage;"));
1160         CHECK(LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class != NULL);
1161         LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class, "<init>", "(J)V");
1162         CHECK(LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth != NULL);
1163         LDKHTLCFailChannelUpdate_ChannelClosed_class =
1164                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$ChannelClosed;"));
1165         CHECK(LDKHTLCFailChannelUpdate_ChannelClosed_class != NULL);
1166         LDKHTLCFailChannelUpdate_ChannelClosed_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_ChannelClosed_class, "<init>", "(JZ)V");
1167         CHECK(LDKHTLCFailChannelUpdate_ChannelClosed_meth != NULL);
1168         LDKHTLCFailChannelUpdate_NodeFailure_class =
1169                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$NodeFailure;"));
1170         CHECK(LDKHTLCFailChannelUpdate_NodeFailure_class != NULL);
1171         LDKHTLCFailChannelUpdate_NodeFailure_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_NodeFailure_class, "<init>", "([BZ)V");
1172         CHECK(LDKHTLCFailChannelUpdate_NodeFailure_meth != NULL);
1173 }
1174 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKHTLCFailChannelUpdate_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
1175         LDKHTLCFailChannelUpdate *obj = (LDKHTLCFailChannelUpdate*)ptr;
1176         switch(obj->tag) {
1177                 case LDKHTLCFailChannelUpdate_ChannelUpdateMessage: {
1178                         LDKChannelUpdate msg_var = obj->channel_update_message.msg;
1179                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1180                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1181                         long msg_ref = (long)msg_var.inner & ~1;
1182                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth, msg_ref);
1183                 }
1184                 case LDKHTLCFailChannelUpdate_ChannelClosed: {
1185                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_ChannelClosed_class, LDKHTLCFailChannelUpdate_ChannelClosed_meth, obj->channel_closed.short_channel_id, obj->channel_closed.is_permanent);
1186                 }
1187                 case LDKHTLCFailChannelUpdate_NodeFailure: {
1188                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1189                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->node_failure.node_id.compressed_form);
1190                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_NodeFailure_class, LDKHTLCFailChannelUpdate_NodeFailure_meth, node_id_arr, obj->node_failure.is_permanent);
1191                 }
1192                 default: abort();
1193         }
1194 }
1195 static jclass LDKMessageSendEvent_SendAcceptChannel_class = NULL;
1196 static jmethodID LDKMessageSendEvent_SendAcceptChannel_meth = NULL;
1197 static jclass LDKMessageSendEvent_SendOpenChannel_class = NULL;
1198 static jmethodID LDKMessageSendEvent_SendOpenChannel_meth = NULL;
1199 static jclass LDKMessageSendEvent_SendFundingCreated_class = NULL;
1200 static jmethodID LDKMessageSendEvent_SendFundingCreated_meth = NULL;
1201 static jclass LDKMessageSendEvent_SendFundingSigned_class = NULL;
1202 static jmethodID LDKMessageSendEvent_SendFundingSigned_meth = NULL;
1203 static jclass LDKMessageSendEvent_SendFundingLocked_class = NULL;
1204 static jmethodID LDKMessageSendEvent_SendFundingLocked_meth = NULL;
1205 static jclass LDKMessageSendEvent_SendAnnouncementSignatures_class = NULL;
1206 static jmethodID LDKMessageSendEvent_SendAnnouncementSignatures_meth = NULL;
1207 static jclass LDKMessageSendEvent_UpdateHTLCs_class = NULL;
1208 static jmethodID LDKMessageSendEvent_UpdateHTLCs_meth = NULL;
1209 static jclass LDKMessageSendEvent_SendRevokeAndACK_class = NULL;
1210 static jmethodID LDKMessageSendEvent_SendRevokeAndACK_meth = NULL;
1211 static jclass LDKMessageSendEvent_SendClosingSigned_class = NULL;
1212 static jmethodID LDKMessageSendEvent_SendClosingSigned_meth = NULL;
1213 static jclass LDKMessageSendEvent_SendShutdown_class = NULL;
1214 static jmethodID LDKMessageSendEvent_SendShutdown_meth = NULL;
1215 static jclass LDKMessageSendEvent_SendChannelReestablish_class = NULL;
1216 static jmethodID LDKMessageSendEvent_SendChannelReestablish_meth = NULL;
1217 static jclass LDKMessageSendEvent_BroadcastChannelAnnouncement_class = NULL;
1218 static jmethodID LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = NULL;
1219 static jclass LDKMessageSendEvent_BroadcastNodeAnnouncement_class = NULL;
1220 static jmethodID LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = NULL;
1221 static jclass LDKMessageSendEvent_BroadcastChannelUpdate_class = NULL;
1222 static jmethodID LDKMessageSendEvent_BroadcastChannelUpdate_meth = NULL;
1223 static jclass LDKMessageSendEvent_HandleError_class = NULL;
1224 static jmethodID LDKMessageSendEvent_HandleError_meth = NULL;
1225 static jclass LDKMessageSendEvent_PaymentFailureNetworkUpdate_class = NULL;
1226 static jmethodID LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = NULL;
1227 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKMessageSendEvent_init (JNIEnv * env, jclass _a) {
1228         LDKMessageSendEvent_SendAcceptChannel_class =
1229                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendAcceptChannel;"));
1230         CHECK(LDKMessageSendEvent_SendAcceptChannel_class != NULL);
1231         LDKMessageSendEvent_SendAcceptChannel_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendAcceptChannel_class, "<init>", "([BJ)V");
1232         CHECK(LDKMessageSendEvent_SendAcceptChannel_meth != NULL);
1233         LDKMessageSendEvent_SendOpenChannel_class =
1234                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendOpenChannel;"));
1235         CHECK(LDKMessageSendEvent_SendOpenChannel_class != NULL);
1236         LDKMessageSendEvent_SendOpenChannel_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendOpenChannel_class, "<init>", "([BJ)V");
1237         CHECK(LDKMessageSendEvent_SendOpenChannel_meth != NULL);
1238         LDKMessageSendEvent_SendFundingCreated_class =
1239                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingCreated;"));
1240         CHECK(LDKMessageSendEvent_SendFundingCreated_class != NULL);
1241         LDKMessageSendEvent_SendFundingCreated_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingCreated_class, "<init>", "([BJ)V");
1242         CHECK(LDKMessageSendEvent_SendFundingCreated_meth != NULL);
1243         LDKMessageSendEvent_SendFundingSigned_class =
1244                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingSigned;"));
1245         CHECK(LDKMessageSendEvent_SendFundingSigned_class != NULL);
1246         LDKMessageSendEvent_SendFundingSigned_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingSigned_class, "<init>", "([BJ)V");
1247         CHECK(LDKMessageSendEvent_SendFundingSigned_meth != NULL);
1248         LDKMessageSendEvent_SendFundingLocked_class =
1249                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingLocked;"));
1250         CHECK(LDKMessageSendEvent_SendFundingLocked_class != NULL);
1251         LDKMessageSendEvent_SendFundingLocked_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingLocked_class, "<init>", "([BJ)V");
1252         CHECK(LDKMessageSendEvent_SendFundingLocked_meth != NULL);
1253         LDKMessageSendEvent_SendAnnouncementSignatures_class =
1254                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendAnnouncementSignatures;"));
1255         CHECK(LDKMessageSendEvent_SendAnnouncementSignatures_class != NULL);
1256         LDKMessageSendEvent_SendAnnouncementSignatures_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendAnnouncementSignatures_class, "<init>", "([BJ)V");
1257         CHECK(LDKMessageSendEvent_SendAnnouncementSignatures_meth != NULL);
1258         LDKMessageSendEvent_UpdateHTLCs_class =
1259                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$UpdateHTLCs;"));
1260         CHECK(LDKMessageSendEvent_UpdateHTLCs_class != NULL);
1261         LDKMessageSendEvent_UpdateHTLCs_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_UpdateHTLCs_class, "<init>", "([BJ)V");
1262         CHECK(LDKMessageSendEvent_UpdateHTLCs_meth != NULL);
1263         LDKMessageSendEvent_SendRevokeAndACK_class =
1264                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendRevokeAndACK;"));
1265         CHECK(LDKMessageSendEvent_SendRevokeAndACK_class != NULL);
1266         LDKMessageSendEvent_SendRevokeAndACK_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendRevokeAndACK_class, "<init>", "([BJ)V");
1267         CHECK(LDKMessageSendEvent_SendRevokeAndACK_meth != NULL);
1268         LDKMessageSendEvent_SendClosingSigned_class =
1269                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendClosingSigned;"));
1270         CHECK(LDKMessageSendEvent_SendClosingSigned_class != NULL);
1271         LDKMessageSendEvent_SendClosingSigned_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendClosingSigned_class, "<init>", "([BJ)V");
1272         CHECK(LDKMessageSendEvent_SendClosingSigned_meth != NULL);
1273         LDKMessageSendEvent_SendShutdown_class =
1274                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendShutdown;"));
1275         CHECK(LDKMessageSendEvent_SendShutdown_class != NULL);
1276         LDKMessageSendEvent_SendShutdown_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendShutdown_class, "<init>", "([BJ)V");
1277         CHECK(LDKMessageSendEvent_SendShutdown_meth != NULL);
1278         LDKMessageSendEvent_SendChannelReestablish_class =
1279                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendChannelReestablish;"));
1280         CHECK(LDKMessageSendEvent_SendChannelReestablish_class != NULL);
1281         LDKMessageSendEvent_SendChannelReestablish_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendChannelReestablish_class, "<init>", "([BJ)V");
1282         CHECK(LDKMessageSendEvent_SendChannelReestablish_meth != NULL);
1283         LDKMessageSendEvent_BroadcastChannelAnnouncement_class =
1284                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastChannelAnnouncement;"));
1285         CHECK(LDKMessageSendEvent_BroadcastChannelAnnouncement_class != NULL);
1286         LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastChannelAnnouncement_class, "<init>", "(JJ)V");
1287         CHECK(LDKMessageSendEvent_BroadcastChannelAnnouncement_meth != NULL);
1288         LDKMessageSendEvent_BroadcastNodeAnnouncement_class =
1289                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastNodeAnnouncement;"));
1290         CHECK(LDKMessageSendEvent_BroadcastNodeAnnouncement_class != NULL);
1291         LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastNodeAnnouncement_class, "<init>", "(J)V");
1292         CHECK(LDKMessageSendEvent_BroadcastNodeAnnouncement_meth != NULL);
1293         LDKMessageSendEvent_BroadcastChannelUpdate_class =
1294                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastChannelUpdate;"));
1295         CHECK(LDKMessageSendEvent_BroadcastChannelUpdate_class != NULL);
1296         LDKMessageSendEvent_BroadcastChannelUpdate_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastChannelUpdate_class, "<init>", "(J)V");
1297         CHECK(LDKMessageSendEvent_BroadcastChannelUpdate_meth != NULL);
1298         LDKMessageSendEvent_HandleError_class =
1299                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$HandleError;"));
1300         CHECK(LDKMessageSendEvent_HandleError_class != NULL);
1301         LDKMessageSendEvent_HandleError_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_HandleError_class, "<init>", "([BJ)V");
1302         CHECK(LDKMessageSendEvent_HandleError_meth != NULL);
1303         LDKMessageSendEvent_PaymentFailureNetworkUpdate_class =
1304                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$PaymentFailureNetworkUpdate;"));
1305         CHECK(LDKMessageSendEvent_PaymentFailureNetworkUpdate_class != NULL);
1306         LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_PaymentFailureNetworkUpdate_class, "<init>", "(J)V");
1307         CHECK(LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth != NULL);
1308 }
1309 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
1310         LDKMessageSendEvent *obj = (LDKMessageSendEvent*)ptr;
1311         switch(obj->tag) {
1312                 case LDKMessageSendEvent_SendAcceptChannel: {
1313                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1314                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_accept_channel.node_id.compressed_form);
1315                         LDKAcceptChannel msg_var = obj->send_accept_channel.msg;
1316                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1317                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1318                         long msg_ref = (long)msg_var.inner & ~1;
1319                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendAcceptChannel_class, LDKMessageSendEvent_SendAcceptChannel_meth, node_id_arr, msg_ref);
1320                 }
1321                 case LDKMessageSendEvent_SendOpenChannel: {
1322                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1323                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_open_channel.node_id.compressed_form);
1324                         LDKOpenChannel msg_var = obj->send_open_channel.msg;
1325                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1326                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1327                         long msg_ref = (long)msg_var.inner & ~1;
1328                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendOpenChannel_class, LDKMessageSendEvent_SendOpenChannel_meth, node_id_arr, msg_ref);
1329                 }
1330                 case LDKMessageSendEvent_SendFundingCreated: {
1331                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1332                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_created.node_id.compressed_form);
1333                         LDKFundingCreated msg_var = obj->send_funding_created.msg;
1334                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1335                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1336                         long msg_ref = (long)msg_var.inner & ~1;
1337                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingCreated_class, LDKMessageSendEvent_SendFundingCreated_meth, node_id_arr, msg_ref);
1338                 }
1339                 case LDKMessageSendEvent_SendFundingSigned: {
1340                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1341                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_signed.node_id.compressed_form);
1342                         LDKFundingSigned msg_var = obj->send_funding_signed.msg;
1343                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1344                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1345                         long msg_ref = (long)msg_var.inner & ~1;
1346                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingSigned_class, LDKMessageSendEvent_SendFundingSigned_meth, node_id_arr, msg_ref);
1347                 }
1348                 case LDKMessageSendEvent_SendFundingLocked: {
1349                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1350                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_locked.node_id.compressed_form);
1351                         LDKFundingLocked msg_var = obj->send_funding_locked.msg;
1352                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1353                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1354                         long msg_ref = (long)msg_var.inner & ~1;
1355                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingLocked_class, LDKMessageSendEvent_SendFundingLocked_meth, node_id_arr, msg_ref);
1356                 }
1357                 case LDKMessageSendEvent_SendAnnouncementSignatures: {
1358                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1359                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_announcement_signatures.node_id.compressed_form);
1360                         LDKAnnouncementSignatures msg_var = obj->send_announcement_signatures.msg;
1361                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1362                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1363                         long msg_ref = (long)msg_var.inner & ~1;
1364                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendAnnouncementSignatures_class, LDKMessageSendEvent_SendAnnouncementSignatures_meth, node_id_arr, msg_ref);
1365                 }
1366                 case LDKMessageSendEvent_UpdateHTLCs: {
1367                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1368                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->update_htl_cs.node_id.compressed_form);
1369                         LDKCommitmentUpdate updates_var = obj->update_htl_cs.updates;
1370                         CHECK((((long)updates_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1371                         CHECK((((long)&updates_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1372                         long updates_ref = (long)updates_var.inner & ~1;
1373                         return (*_env)->NewObject(_env, LDKMessageSendEvent_UpdateHTLCs_class, LDKMessageSendEvent_UpdateHTLCs_meth, node_id_arr, updates_ref);
1374                 }
1375                 case LDKMessageSendEvent_SendRevokeAndACK: {
1376                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1377                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_revoke_and_ack.node_id.compressed_form);
1378                         LDKRevokeAndACK msg_var = obj->send_revoke_and_ack.msg;
1379                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1380                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1381                         long msg_ref = (long)msg_var.inner & ~1;
1382                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendRevokeAndACK_class, LDKMessageSendEvent_SendRevokeAndACK_meth, node_id_arr, msg_ref);
1383                 }
1384                 case LDKMessageSendEvent_SendClosingSigned: {
1385                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1386                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_closing_signed.node_id.compressed_form);
1387                         LDKClosingSigned msg_var = obj->send_closing_signed.msg;
1388                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1389                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1390                         long msg_ref = (long)msg_var.inner & ~1;
1391                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendClosingSigned_class, LDKMessageSendEvent_SendClosingSigned_meth, node_id_arr, msg_ref);
1392                 }
1393                 case LDKMessageSendEvent_SendShutdown: {
1394                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1395                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_shutdown.node_id.compressed_form);
1396                         LDKShutdown msg_var = obj->send_shutdown.msg;
1397                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1398                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1399                         long msg_ref = (long)msg_var.inner & ~1;
1400                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendShutdown_class, LDKMessageSendEvent_SendShutdown_meth, node_id_arr, msg_ref);
1401                 }
1402                 case LDKMessageSendEvent_SendChannelReestablish: {
1403                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1404                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_channel_reestablish.node_id.compressed_form);
1405                         LDKChannelReestablish msg_var = obj->send_channel_reestablish.msg;
1406                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1407                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1408                         long msg_ref = (long)msg_var.inner & ~1;
1409                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendChannelReestablish_class, LDKMessageSendEvent_SendChannelReestablish_meth, node_id_arr, msg_ref);
1410                 }
1411                 case LDKMessageSendEvent_BroadcastChannelAnnouncement: {
1412                         LDKChannelAnnouncement msg_var = obj->broadcast_channel_announcement.msg;
1413                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1414                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1415                         long msg_ref = (long)msg_var.inner & ~1;
1416                         LDKChannelUpdate update_msg_var = obj->broadcast_channel_announcement.update_msg;
1417                         CHECK((((long)update_msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1418                         CHECK((((long)&update_msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1419                         long update_msg_ref = (long)update_msg_var.inner & ~1;
1420                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastChannelAnnouncement_class, LDKMessageSendEvent_BroadcastChannelAnnouncement_meth, msg_ref, update_msg_ref);
1421                 }
1422                 case LDKMessageSendEvent_BroadcastNodeAnnouncement: {
1423                         LDKNodeAnnouncement msg_var = obj->broadcast_node_announcement.msg;
1424                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1425                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1426                         long msg_ref = (long)msg_var.inner & ~1;
1427                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastNodeAnnouncement_class, LDKMessageSendEvent_BroadcastNodeAnnouncement_meth, msg_ref);
1428                 }
1429                 case LDKMessageSendEvent_BroadcastChannelUpdate: {
1430                         LDKChannelUpdate msg_var = obj->broadcast_channel_update.msg;
1431                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1432                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1433                         long msg_ref = (long)msg_var.inner & ~1;
1434                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastChannelUpdate_class, LDKMessageSendEvent_BroadcastChannelUpdate_meth, msg_ref);
1435                 }
1436                 case LDKMessageSendEvent_HandleError: {
1437                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1438                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->handle_error.node_id.compressed_form);
1439                         long action_ref = (long)&obj->handle_error.action;
1440                         return (*_env)->NewObject(_env, LDKMessageSendEvent_HandleError_class, LDKMessageSendEvent_HandleError_meth, node_id_arr, action_ref);
1441                 }
1442                 case LDKMessageSendEvent_PaymentFailureNetworkUpdate: {
1443                         long update_ref = (long)&obj->payment_failure_network_update.update;
1444                         return (*_env)->NewObject(_env, LDKMessageSendEvent_PaymentFailureNetworkUpdate_class, LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth, update_ref);
1445                 }
1446                 default: abort();
1447         }
1448 }
1449 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MessageSendEvent_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1450         LDKCVecTempl_MessageSendEvent *vec = (LDKCVecTempl_MessageSendEvent*)ptr;
1451         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKMessageSendEvent));
1452 }
1453 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MessageSendEvent_1new(JNIEnv *env, jclass _b, jlongArray elems){
1454         LDKCVecTempl_MessageSendEvent *ret = MALLOC(sizeof(LDKCVecTempl_MessageSendEvent), "LDKCVecTempl_MessageSendEvent");
1455         ret->datalen = (*env)->GetArrayLength(env, elems);
1456         if (ret->datalen == 0) {
1457                 ret->data = NULL;
1458         } else {
1459                 ret->data = MALLOC(sizeof(LDKMessageSendEvent) * ret->datalen, "LDKCVecTempl_MessageSendEvent Data");
1460                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1461                 for (size_t i = 0; i < ret->datalen; i++) {
1462                         jlong arr_elem = java_elems[i];
1463                         LDKMessageSendEvent arr_elem_conv = *(LDKMessageSendEvent*)arr_elem;
1464                         FREE((void*)arr_elem);
1465                         ret->data[i] = arr_elem_conv;
1466                 }
1467                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1468         }
1469         return (long)ret;
1470 }
1471 typedef struct LDKMessageSendEventsProvider_JCalls {
1472         atomic_size_t refcnt;
1473         JavaVM *vm;
1474         jweak o;
1475         jmethodID get_and_clear_pending_msg_events_meth;
1476 } LDKMessageSendEventsProvider_JCalls;
1477 LDKCVec_MessageSendEventZ get_and_clear_pending_msg_events_jcall(const void* this_arg) {
1478         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
1479         JNIEnv *_env;
1480         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1481         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1482         CHECK(obj != NULL);
1483         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_and_clear_pending_msg_events_meth);
1484         LDKCVec_MessageSendEventZ arg_constr;
1485         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
1486         if (arg_constr.datalen > 0)
1487                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
1488         else
1489                 arg_constr.data = NULL;
1490         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
1491         for (size_t s = 0; s < arg_constr.datalen; s++) {
1492                 long arr_conv_18 = arg_vals[s];
1493                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
1494                 FREE((void*)arr_conv_18);
1495                 arg_constr.data[s] = arr_conv_18_conv;
1496         }
1497         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
1498         return arg_constr;
1499 }
1500 static void LDKMessageSendEventsProvider_JCalls_free(void* this_arg) {
1501         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
1502         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1503                 JNIEnv *env;
1504                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1505                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1506                 FREE(j_calls);
1507         }
1508 }
1509 static void* LDKMessageSendEventsProvider_JCalls_clone(const void* this_arg) {
1510         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
1511         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1512         return (void*) this_arg;
1513 }
1514 static inline LDKMessageSendEventsProvider LDKMessageSendEventsProvider_init (JNIEnv * env, jclass _a, jobject o) {
1515         jclass c = (*env)->GetObjectClass(env, o);
1516         CHECK(c != NULL);
1517         LDKMessageSendEventsProvider_JCalls *calls = MALLOC(sizeof(LDKMessageSendEventsProvider_JCalls), "LDKMessageSendEventsProvider_JCalls");
1518         atomic_init(&calls->refcnt, 1);
1519         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1520         calls->o = (*env)->NewWeakGlobalRef(env, o);
1521         calls->get_and_clear_pending_msg_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_msg_events", "()[J");
1522         CHECK(calls->get_and_clear_pending_msg_events_meth != NULL);
1523
1524         LDKMessageSendEventsProvider ret = {
1525                 .this_arg = (void*) calls,
1526                 .get_and_clear_pending_msg_events = get_and_clear_pending_msg_events_jcall,
1527                 .free = LDKMessageSendEventsProvider_JCalls_free,
1528         };
1529         return ret;
1530 }
1531 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1new (JNIEnv * env, jclass _a, jobject o) {
1532         LDKMessageSendEventsProvider *res_ptr = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
1533         *res_ptr = LDKMessageSendEventsProvider_init(env, _a, o);
1534         return (long)res_ptr;
1535 }
1536 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1537         jobject ret = (*env)->NewLocalRef(env, ((LDKMessageSendEventsProvider_JCalls*)val)->o);
1538         CHECK(ret != NULL);
1539         return ret;
1540 }
1541 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1get_1and_1clear_1pending_1msg_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
1542         LDKMessageSendEventsProvider* this_arg_conv = (LDKMessageSendEventsProvider*)this_arg;
1543         LDKCVec_MessageSendEventZ ret_var = (this_arg_conv->get_and_clear_pending_msg_events)(this_arg_conv->this_arg);
1544         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
1545         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
1546         for (size_t s = 0; s < ret_var.datalen; s++) {
1547                 LDKMessageSendEvent *arr_conv_18_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
1548                 *arr_conv_18_copy = MessageSendEvent_clone(&ret_var.data[s]);
1549                 long arr_conv_18_ref = (long)arr_conv_18_copy;
1550                 ret_arr_ptr[s] = arr_conv_18_ref;
1551         }
1552         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
1553         CVec_MessageSendEventZ_free(ret_var);
1554         return ret_arr;
1555 }
1556
1557 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Event_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1558         LDKCVecTempl_Event *vec = (LDKCVecTempl_Event*)ptr;
1559         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKEvent));
1560 }
1561 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Event_1new(JNIEnv *env, jclass _b, jlongArray elems){
1562         LDKCVecTempl_Event *ret = MALLOC(sizeof(LDKCVecTempl_Event), "LDKCVecTempl_Event");
1563         ret->datalen = (*env)->GetArrayLength(env, elems);
1564         if (ret->datalen == 0) {
1565                 ret->data = NULL;
1566         } else {
1567                 ret->data = MALLOC(sizeof(LDKEvent) * ret->datalen, "LDKCVecTempl_Event Data");
1568                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1569                 for (size_t i = 0; i < ret->datalen; i++) {
1570                         jlong arr_elem = java_elems[i];
1571                         LDKEvent arr_elem_conv = *(LDKEvent*)arr_elem;
1572                         FREE((void*)arr_elem);
1573                         ret->data[i] = arr_elem_conv;
1574                 }
1575                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1576         }
1577         return (long)ret;
1578 }
1579 typedef struct LDKEventsProvider_JCalls {
1580         atomic_size_t refcnt;
1581         JavaVM *vm;
1582         jweak o;
1583         jmethodID get_and_clear_pending_events_meth;
1584 } LDKEventsProvider_JCalls;
1585 LDKCVec_EventZ get_and_clear_pending_events_jcall(const void* this_arg) {
1586         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
1587         JNIEnv *_env;
1588         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1589         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1590         CHECK(obj != NULL);
1591         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_and_clear_pending_events_meth);
1592         LDKCVec_EventZ arg_constr;
1593         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
1594         if (arg_constr.datalen > 0)
1595                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
1596         else
1597                 arg_constr.data = NULL;
1598         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
1599         for (size_t h = 0; h < arg_constr.datalen; h++) {
1600                 long arr_conv_7 = arg_vals[h];
1601                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
1602                 FREE((void*)arr_conv_7);
1603                 arg_constr.data[h] = arr_conv_7_conv;
1604         }
1605         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
1606         return arg_constr;
1607 }
1608 static void LDKEventsProvider_JCalls_free(void* this_arg) {
1609         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
1610         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1611                 JNIEnv *env;
1612                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1613                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1614                 FREE(j_calls);
1615         }
1616 }
1617 static void* LDKEventsProvider_JCalls_clone(const void* this_arg) {
1618         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
1619         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1620         return (void*) this_arg;
1621 }
1622 static inline LDKEventsProvider LDKEventsProvider_init (JNIEnv * env, jclass _a, jobject o) {
1623         jclass c = (*env)->GetObjectClass(env, o);
1624         CHECK(c != NULL);
1625         LDKEventsProvider_JCalls *calls = MALLOC(sizeof(LDKEventsProvider_JCalls), "LDKEventsProvider_JCalls");
1626         atomic_init(&calls->refcnt, 1);
1627         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1628         calls->o = (*env)->NewWeakGlobalRef(env, o);
1629         calls->get_and_clear_pending_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_events", "()[J");
1630         CHECK(calls->get_and_clear_pending_events_meth != NULL);
1631
1632         LDKEventsProvider ret = {
1633                 .this_arg = (void*) calls,
1634                 .get_and_clear_pending_events = get_and_clear_pending_events_jcall,
1635                 .free = LDKEventsProvider_JCalls_free,
1636         };
1637         return ret;
1638 }
1639 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1new (JNIEnv * env, jclass _a, jobject o) {
1640         LDKEventsProvider *res_ptr = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
1641         *res_ptr = LDKEventsProvider_init(env, _a, o);
1642         return (long)res_ptr;
1643 }
1644 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1645         jobject ret = (*env)->NewLocalRef(env, ((LDKEventsProvider_JCalls*)val)->o);
1646         CHECK(ret != NULL);
1647         return ret;
1648 }
1649 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_EventsProvider_1get_1and_1clear_1pending_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
1650         LDKEventsProvider* this_arg_conv = (LDKEventsProvider*)this_arg;
1651         LDKCVec_EventZ ret_var = (this_arg_conv->get_and_clear_pending_events)(this_arg_conv->this_arg);
1652         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
1653         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
1654         for (size_t h = 0; h < ret_var.datalen; h++) {
1655                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
1656                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
1657                 long arr_conv_7_ref = (long)arr_conv_7_copy;
1658                 ret_arr_ptr[h] = arr_conv_7_ref;
1659         }
1660         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
1661         CVec_EventZ_free(ret_var);
1662         return ret_arr;
1663 }
1664
1665 typedef struct LDKLogger_JCalls {
1666         atomic_size_t refcnt;
1667         JavaVM *vm;
1668         jweak o;
1669         jmethodID log_meth;
1670 } LDKLogger_JCalls;
1671 void log_jcall(const void* this_arg, const char *record) {
1672         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
1673         JNIEnv *_env;
1674         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1675         jstring record_conv = (*_env)->NewStringUTF(_env, record);
1676         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1677         CHECK(obj != NULL);
1678         return (*_env)->CallVoidMethod(_env, obj, j_calls->log_meth, record_conv);
1679 }
1680 static void LDKLogger_JCalls_free(void* this_arg) {
1681         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
1682         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1683                 JNIEnv *env;
1684                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1685                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1686                 FREE(j_calls);
1687         }
1688 }
1689 static void* LDKLogger_JCalls_clone(const void* this_arg) {
1690         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
1691         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1692         return (void*) this_arg;
1693 }
1694 static inline LDKLogger LDKLogger_init (JNIEnv * env, jclass _a, jobject o) {
1695         jclass c = (*env)->GetObjectClass(env, o);
1696         CHECK(c != NULL);
1697         LDKLogger_JCalls *calls = MALLOC(sizeof(LDKLogger_JCalls), "LDKLogger_JCalls");
1698         atomic_init(&calls->refcnt, 1);
1699         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1700         calls->o = (*env)->NewWeakGlobalRef(env, o);
1701         calls->log_meth = (*env)->GetMethodID(env, c, "log", "(Ljava/lang/String;)V");
1702         CHECK(calls->log_meth != NULL);
1703
1704         LDKLogger ret = {
1705                 .this_arg = (void*) calls,
1706                 .log = log_jcall,
1707                 .free = LDKLogger_JCalls_free,
1708         };
1709         return ret;
1710 }
1711 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKLogger_1new (JNIEnv * env, jclass _a, jobject o) {
1712         LDKLogger *res_ptr = MALLOC(sizeof(LDKLogger), "LDKLogger");
1713         *res_ptr = LDKLogger_init(env, _a, o);
1714         return (long)res_ptr;
1715 }
1716 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKLogger_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1717         jobject ret = (*env)->NewLocalRef(env, ((LDKLogger_JCalls*)val)->o);
1718         CHECK(ret != NULL);
1719         return ret;
1720 }
1721 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1722         return ((LDKCResult_TxOutAccessErrorZ*)arg)->result_ok;
1723 }
1724 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1725         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
1726         CHECK(val->result_ok);
1727         long res_ref = (long)&(*val->contents.result);
1728         return res_ref;
1729 }
1730 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1731         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
1732         CHECK(!val->result_ok);
1733         jclass err_conv = LDKAccessError_to_java(_env, (*val->contents.err));
1734         return err_conv;
1735 }
1736 typedef struct LDKAccess_JCalls {
1737         atomic_size_t refcnt;
1738         JavaVM *vm;
1739         jweak o;
1740         jmethodID get_utxo_meth;
1741 } LDKAccess_JCalls;
1742 LDKCResult_TxOutAccessErrorZ get_utxo_jcall(const void* this_arg, const uint8_t (*genesis_hash)[32], uint64_t short_channel_id) {
1743         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
1744         JNIEnv *_env;
1745         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1746         jbyteArray genesis_hash_arr = (*_env)->NewByteArray(_env, 32);
1747         (*_env)->SetByteArrayRegion(_env, genesis_hash_arr, 0, 32, *genesis_hash);
1748         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1749         CHECK(obj != NULL);
1750         LDKCResult_TxOutAccessErrorZ* ret = (LDKCResult_TxOutAccessErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->get_utxo_meth, genesis_hash_arr, short_channel_id);
1751         LDKCResult_TxOutAccessErrorZ ret_conv = *(LDKCResult_TxOutAccessErrorZ*)ret;
1752         FREE((void*)ret);
1753         return ret_conv;
1754 }
1755 static void LDKAccess_JCalls_free(void* this_arg) {
1756         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
1757         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1758                 JNIEnv *env;
1759                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1760                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1761                 FREE(j_calls);
1762         }
1763 }
1764 static void* LDKAccess_JCalls_clone(const void* this_arg) {
1765         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
1766         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1767         return (void*) this_arg;
1768 }
1769 static inline LDKAccess LDKAccess_init (JNIEnv * env, jclass _a, jobject o) {
1770         jclass c = (*env)->GetObjectClass(env, o);
1771         CHECK(c != NULL);
1772         LDKAccess_JCalls *calls = MALLOC(sizeof(LDKAccess_JCalls), "LDKAccess_JCalls");
1773         atomic_init(&calls->refcnt, 1);
1774         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1775         calls->o = (*env)->NewWeakGlobalRef(env, o);
1776         calls->get_utxo_meth = (*env)->GetMethodID(env, c, "get_utxo", "([BJ)J");
1777         CHECK(calls->get_utxo_meth != NULL);
1778
1779         LDKAccess ret = {
1780                 .this_arg = (void*) calls,
1781                 .get_utxo = get_utxo_jcall,
1782                 .free = LDKAccess_JCalls_free,
1783         };
1784         return ret;
1785 }
1786 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKAccess_1new (JNIEnv * env, jclass _a, jobject o) {
1787         LDKAccess *res_ptr = MALLOC(sizeof(LDKAccess), "LDKAccess");
1788         *res_ptr = LDKAccess_init(env, _a, o);
1789         return (long)res_ptr;
1790 }
1791 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAccess_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1792         jobject ret = (*env)->NewLocalRef(env, ((LDKAccess_JCalls*)val)->o);
1793         CHECK(ret != NULL);
1794         return ret;
1795 }
1796 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) {
1797         LDKAccess* this_arg_conv = (LDKAccess*)this_arg;
1798         unsigned char genesis_hash_arr[32];
1799         CHECK((*_env)->GetArrayLength (_env, genesis_hash) == 32);
1800         (*_env)->GetByteArrayRegion (_env, genesis_hash, 0, 32, genesis_hash_arr);
1801         unsigned char (*genesis_hash_ref)[32] = &genesis_hash_arr;
1802         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
1803         *ret_conv = (this_arg_conv->get_utxo)(this_arg_conv->this_arg, genesis_hash_ref, short_channel_id);
1804         return (long)ret_conv;
1805 }
1806
1807 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1HTLCOutputInCommitment_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1808         LDKCVecTempl_HTLCOutputInCommitment *vec = (LDKCVecTempl_HTLCOutputInCommitment*)ptr;
1809         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
1810         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
1811         for (size_t i = 0; i < vec->datalen; i++) {
1812                 CHECK((((long)vec->data[i].inner) & 1) == 0);
1813                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
1814         }
1815         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
1816         return ret;
1817 }
1818 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1HTLCOutputInCommitment_1new(JNIEnv *env, jclass _b, jlongArray elems){
1819         LDKCVecTempl_HTLCOutputInCommitment *ret = MALLOC(sizeof(LDKCVecTempl_HTLCOutputInCommitment), "LDKCVecTempl_HTLCOutputInCommitment");
1820         ret->datalen = (*env)->GetArrayLength(env, elems);
1821         if (ret->datalen == 0) {
1822                 ret->data = NULL;
1823         } else {
1824                 ret->data = MALLOC(sizeof(LDKHTLCOutputInCommitment) * ret->datalen, "LDKCVecTempl_HTLCOutputInCommitment Data");
1825                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1826                 for (size_t i = 0; i < ret->datalen; i++) {
1827                         jlong arr_elem = java_elems[i];
1828                         LDKHTLCOutputInCommitment arr_elem_conv;
1829                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
1830                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
1831                         if (arr_elem_conv.inner != NULL)
1832                                 arr_elem_conv = HTLCOutputInCommitment_clone(&arr_elem_conv);
1833                         ret->data[i] = arr_elem_conv;
1834                 }
1835                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1836         }
1837         return (long)ret;
1838 }
1839 typedef struct LDKChannelKeys_JCalls {
1840         atomic_size_t refcnt;
1841         JavaVM *vm;
1842         jweak o;
1843         jmethodID get_per_commitment_point_meth;
1844         jmethodID release_commitment_secret_meth;
1845         jmethodID key_derivation_params_meth;
1846         jmethodID sign_counterparty_commitment_meth;
1847         jmethodID sign_holder_commitment_meth;
1848         jmethodID sign_holder_commitment_htlc_transactions_meth;
1849         jmethodID sign_justice_transaction_meth;
1850         jmethodID sign_counterparty_htlc_transaction_meth;
1851         jmethodID sign_closing_transaction_meth;
1852         jmethodID sign_channel_announcement_meth;
1853         jmethodID on_accept_meth;
1854 } LDKChannelKeys_JCalls;
1855 LDKPublicKey get_per_commitment_point_jcall(const void* this_arg, uint64_t idx) {
1856         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1857         JNIEnv *_env;
1858         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1859         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1860         CHECK(obj != NULL);
1861         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_per_commitment_point_meth, idx);
1862         LDKPublicKey arg_ref;
1863         CHECK((*_env)->GetArrayLength (_env, arg) == 33);
1864         (*_env)->GetByteArrayRegion (_env, arg, 0, 33, arg_ref.compressed_form);
1865         return arg_ref;
1866 }
1867 LDKThirtyTwoBytes release_commitment_secret_jcall(const void* this_arg, uint64_t idx) {
1868         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1869         JNIEnv *_env;
1870         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1871         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1872         CHECK(obj != NULL);
1873         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->release_commitment_secret_meth, idx);
1874         LDKThirtyTwoBytes arg_ref;
1875         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
1876         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.data);
1877         return arg_ref;
1878 }
1879 LDKC2Tuple_u64u64Z key_derivation_params_jcall(const void* this_arg) {
1880         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1881         JNIEnv *_env;
1882         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1883         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1884         CHECK(obj != NULL);
1885         LDKC2Tuple_u64u64Z* ret = (LDKC2Tuple_u64u64Z*)(*_env)->CallLongMethod(_env, obj, j_calls->key_derivation_params_meth);
1886         LDKC2Tuple_u64u64Z ret_conv = *(LDKC2Tuple_u64u64Z*)ret;
1887         FREE((void*)ret);
1888         return ret_conv;
1889 }
1890 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) {
1891         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1892         JNIEnv *_env;
1893         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1894         LDKTransaction commitment_tx_var = commitment_tx;
1895         jbyteArray commitment_tx_arr = (*_env)->NewByteArray(_env, commitment_tx_var.datalen);
1896         (*_env)->SetByteArrayRegion(_env, commitment_tx_arr, 0, commitment_tx_var.datalen, commitment_tx_var.data);
1897         Transaction_free(commitment_tx_var);
1898         LDKPreCalculatedTxCreationKeys keys_var = *keys;
1899         if (keys->inner != NULL)
1900                 keys_var = PreCalculatedTxCreationKeys_clone(keys);
1901         CHECK((((long)keys_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1902         CHECK((((long)&keys_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1903         long keys_ref = (long)keys_var.inner;
1904         if (keys_var.is_owned) {
1905                 keys_ref |= 1;
1906         }
1907         LDKCVec_HTLCOutputInCommitmentZ htlcs_var = htlcs;
1908         jlongArray htlcs_arr = (*_env)->NewLongArray(_env, htlcs_var.datalen);
1909         jlong *htlcs_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, htlcs_arr, NULL);
1910         for (size_t y = 0; y < htlcs_var.datalen; y++) {
1911                 LDKHTLCOutputInCommitment arr_conv_24_var = htlcs_var.data[y];
1912                 CHECK((((long)arr_conv_24_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1913                 CHECK((((long)&arr_conv_24_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1914                 long arr_conv_24_ref = (long)arr_conv_24_var.inner;
1915                 if (arr_conv_24_var.is_owned) {
1916                         arr_conv_24_ref |= 1;
1917                 }
1918                 htlcs_arr_ptr[y] = arr_conv_24_ref;
1919         }
1920         (*_env)->ReleasePrimitiveArrayCritical(_env, htlcs_arr, htlcs_arr_ptr, 0);
1921         FREE(htlcs_var.data);
1922         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1923         CHECK(obj != NULL);
1924         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_counterparty_commitment_meth, feerate_per_kw, commitment_tx_arr, keys_ref, htlcs_arr);
1925         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)ret;
1926         FREE((void*)ret);
1927         return ret_conv;
1928 }
1929 LDKCResult_SignatureNoneZ sign_holder_commitment_jcall(const void* this_arg, const LDKHolderCommitmentTransaction *holder_commitment_tx) {
1930         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1931         JNIEnv *_env;
1932         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1933         LDKHolderCommitmentTransaction holder_commitment_tx_var = *holder_commitment_tx;
1934         if (holder_commitment_tx->inner != NULL)
1935                 holder_commitment_tx_var = HolderCommitmentTransaction_clone(holder_commitment_tx);
1936         CHECK((((long)holder_commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1937         CHECK((((long)&holder_commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1938         long holder_commitment_tx_ref = (long)holder_commitment_tx_var.inner;
1939         if (holder_commitment_tx_var.is_owned) {
1940                 holder_commitment_tx_ref |= 1;
1941         }
1942         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1943         CHECK(obj != NULL);
1944         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_holder_commitment_meth, holder_commitment_tx_ref);
1945         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1946         FREE((void*)ret);
1947         return ret_conv;
1948 }
1949 LDKCResult_CVec_SignatureZNoneZ sign_holder_commitment_htlc_transactions_jcall(const void* this_arg, const LDKHolderCommitmentTransaction *holder_commitment_tx) {
1950         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1951         JNIEnv *_env;
1952         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1953         LDKHolderCommitmentTransaction holder_commitment_tx_var = *holder_commitment_tx;
1954         if (holder_commitment_tx->inner != NULL)
1955                 holder_commitment_tx_var = HolderCommitmentTransaction_clone(holder_commitment_tx);
1956         CHECK((((long)holder_commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1957         CHECK((((long)&holder_commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1958         long holder_commitment_tx_ref = (long)holder_commitment_tx_var.inner;
1959         if (holder_commitment_tx_var.is_owned) {
1960                 holder_commitment_tx_ref |= 1;
1961         }
1962         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1963         CHECK(obj != NULL);
1964         LDKCResult_CVec_SignatureZNoneZ* ret = (LDKCResult_CVec_SignatureZNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_holder_commitment_htlc_transactions_meth, holder_commitment_tx_ref);
1965         LDKCResult_CVec_SignatureZNoneZ ret_conv = *(LDKCResult_CVec_SignatureZNoneZ*)ret;
1966         FREE((void*)ret);
1967         return ret_conv;
1968 }
1969 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) {
1970         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1971         JNIEnv *_env;
1972         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1973         LDKTransaction justice_tx_var = justice_tx;
1974         jbyteArray justice_tx_arr = (*_env)->NewByteArray(_env, justice_tx_var.datalen);
1975         (*_env)->SetByteArrayRegion(_env, justice_tx_arr, 0, justice_tx_var.datalen, justice_tx_var.data);
1976         Transaction_free(justice_tx_var);
1977         jbyteArray per_commitment_key_arr = (*_env)->NewByteArray(_env, 32);
1978         (*_env)->SetByteArrayRegion(_env, per_commitment_key_arr, 0, 32, *per_commitment_key);
1979         LDKHTLCOutputInCommitment htlc_var = *htlc;
1980         if (htlc->inner != NULL)
1981                 htlc_var = HTLCOutputInCommitment_clone(htlc);
1982         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1983         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1984         long htlc_ref = (long)htlc_var.inner;
1985         if (htlc_var.is_owned) {
1986                 htlc_ref |= 1;
1987         }
1988         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1989         CHECK(obj != NULL);
1990         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_justice_transaction_meth, justice_tx_arr, input, amount, per_commitment_key_arr, htlc_ref);
1991         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1992         FREE((void*)ret);
1993         return ret_conv;
1994 }
1995 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) {
1996         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1997         JNIEnv *_env;
1998         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1999         LDKTransaction htlc_tx_var = htlc_tx;
2000         jbyteArray htlc_tx_arr = (*_env)->NewByteArray(_env, htlc_tx_var.datalen);
2001         (*_env)->SetByteArrayRegion(_env, htlc_tx_arr, 0, htlc_tx_var.datalen, htlc_tx_var.data);
2002         Transaction_free(htlc_tx_var);
2003         jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33);
2004         (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, per_commitment_point.compressed_form);
2005         LDKHTLCOutputInCommitment htlc_var = *htlc;
2006         if (htlc->inner != NULL)
2007                 htlc_var = HTLCOutputInCommitment_clone(htlc);
2008         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2009         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2010         long htlc_ref = (long)htlc_var.inner;
2011         if (htlc_var.is_owned) {
2012                 htlc_ref |= 1;
2013         }
2014         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2015         CHECK(obj != NULL);
2016         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_counterparty_htlc_transaction_meth, htlc_tx_arr, input, amount, per_commitment_point_arr, htlc_ref);
2017         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
2018         FREE((void*)ret);
2019         return ret_conv;
2020 }
2021 LDKCResult_SignatureNoneZ sign_closing_transaction_jcall(const void* this_arg, LDKTransaction closing_tx) {
2022         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
2023         JNIEnv *_env;
2024         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2025         LDKTransaction closing_tx_var = closing_tx;
2026         jbyteArray closing_tx_arr = (*_env)->NewByteArray(_env, closing_tx_var.datalen);
2027         (*_env)->SetByteArrayRegion(_env, closing_tx_arr, 0, closing_tx_var.datalen, closing_tx_var.data);
2028         Transaction_free(closing_tx_var);
2029         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2030         CHECK(obj != NULL);
2031         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_closing_transaction_meth, closing_tx_arr);
2032         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
2033         FREE((void*)ret);
2034         return ret_conv;
2035 }
2036 LDKCResult_SignatureNoneZ sign_channel_announcement_jcall(const void* this_arg, const LDKUnsignedChannelAnnouncement *msg) {
2037         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
2038         JNIEnv *_env;
2039         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2040         LDKUnsignedChannelAnnouncement msg_var = *msg;
2041         if (msg->inner != NULL)
2042                 msg_var = UnsignedChannelAnnouncement_clone(msg);
2043         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2044         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2045         long msg_ref = (long)msg_var.inner;
2046         if (msg_var.is_owned) {
2047                 msg_ref |= 1;
2048         }
2049         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2050         CHECK(obj != NULL);
2051         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_channel_announcement_meth, msg_ref);
2052         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
2053         FREE((void*)ret);
2054         return ret_conv;
2055 }
2056 void on_accept_jcall(void* this_arg, const LDKChannelPublicKeys *channel_points, uint16_t counterparty_selected_contest_delay, uint16_t holder_selected_contest_delay) {
2057         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
2058         JNIEnv *_env;
2059         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2060         LDKChannelPublicKeys channel_points_var = *channel_points;
2061         if (channel_points->inner != NULL)
2062                 channel_points_var = ChannelPublicKeys_clone(channel_points);
2063         CHECK((((long)channel_points_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2064         CHECK((((long)&channel_points_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2065         long channel_points_ref = (long)channel_points_var.inner;
2066         if (channel_points_var.is_owned) {
2067                 channel_points_ref |= 1;
2068         }
2069         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2070         CHECK(obj != NULL);
2071         return (*_env)->CallVoidMethod(_env, obj, j_calls->on_accept_meth, channel_points_ref, counterparty_selected_contest_delay, holder_selected_contest_delay);
2072 }
2073 static void LDKChannelKeys_JCalls_free(void* this_arg) {
2074         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
2075         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2076                 JNIEnv *env;
2077                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2078                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2079                 FREE(j_calls);
2080         }
2081 }
2082 static void* LDKChannelKeys_JCalls_clone(const void* this_arg) {
2083         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
2084         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2085         return (void*) this_arg;
2086 }
2087 static inline LDKChannelKeys LDKChannelKeys_init (JNIEnv * env, jclass _a, jobject o, jlong pubkeys) {
2088         jclass c = (*env)->GetObjectClass(env, o);
2089         CHECK(c != NULL);
2090         LDKChannelKeys_JCalls *calls = MALLOC(sizeof(LDKChannelKeys_JCalls), "LDKChannelKeys_JCalls");
2091         atomic_init(&calls->refcnt, 1);
2092         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2093         calls->o = (*env)->NewWeakGlobalRef(env, o);
2094         calls->get_per_commitment_point_meth = (*env)->GetMethodID(env, c, "get_per_commitment_point", "(J)[B");
2095         CHECK(calls->get_per_commitment_point_meth != NULL);
2096         calls->release_commitment_secret_meth = (*env)->GetMethodID(env, c, "release_commitment_secret", "(J)[B");
2097         CHECK(calls->release_commitment_secret_meth != NULL);
2098         calls->key_derivation_params_meth = (*env)->GetMethodID(env, c, "key_derivation_params", "()J");
2099         CHECK(calls->key_derivation_params_meth != NULL);
2100         calls->sign_counterparty_commitment_meth = (*env)->GetMethodID(env, c, "sign_counterparty_commitment", "(I[BJ[J)J");
2101         CHECK(calls->sign_counterparty_commitment_meth != NULL);
2102         calls->sign_holder_commitment_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment", "(J)J");
2103         CHECK(calls->sign_holder_commitment_meth != NULL);
2104         calls->sign_holder_commitment_htlc_transactions_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment_htlc_transactions", "(J)J");
2105         CHECK(calls->sign_holder_commitment_htlc_transactions_meth != NULL);
2106         calls->sign_justice_transaction_meth = (*env)->GetMethodID(env, c, "sign_justice_transaction", "([BJJ[BJ)J");
2107         CHECK(calls->sign_justice_transaction_meth != NULL);
2108         calls->sign_counterparty_htlc_transaction_meth = (*env)->GetMethodID(env, c, "sign_counterparty_htlc_transaction", "([BJJ[BJ)J");
2109         CHECK(calls->sign_counterparty_htlc_transaction_meth != NULL);
2110         calls->sign_closing_transaction_meth = (*env)->GetMethodID(env, c, "sign_closing_transaction", "([B)J");
2111         CHECK(calls->sign_closing_transaction_meth != NULL);
2112         calls->sign_channel_announcement_meth = (*env)->GetMethodID(env, c, "sign_channel_announcement", "(J)J");
2113         CHECK(calls->sign_channel_announcement_meth != NULL);
2114         calls->on_accept_meth = (*env)->GetMethodID(env, c, "on_accept", "(JSS)V");
2115         CHECK(calls->on_accept_meth != NULL);
2116
2117         LDKChannelPublicKeys pubkeys_conv;
2118         pubkeys_conv.inner = (void*)(pubkeys & (~1));
2119         pubkeys_conv.is_owned = (pubkeys & 1) || (pubkeys == 0);
2120         if (pubkeys_conv.inner != NULL)
2121                 pubkeys_conv = ChannelPublicKeys_clone(&pubkeys_conv);
2122
2123         LDKChannelKeys ret = {
2124                 .this_arg = (void*) calls,
2125                 .get_per_commitment_point = get_per_commitment_point_jcall,
2126                 .release_commitment_secret = release_commitment_secret_jcall,
2127                 .key_derivation_params = key_derivation_params_jcall,
2128                 .sign_counterparty_commitment = sign_counterparty_commitment_jcall,
2129                 .sign_holder_commitment = sign_holder_commitment_jcall,
2130                 .sign_holder_commitment_htlc_transactions = sign_holder_commitment_htlc_transactions_jcall,
2131                 .sign_justice_transaction = sign_justice_transaction_jcall,
2132                 .sign_counterparty_htlc_transaction = sign_counterparty_htlc_transaction_jcall,
2133                 .sign_closing_transaction = sign_closing_transaction_jcall,
2134                 .sign_channel_announcement = sign_channel_announcement_jcall,
2135                 .on_accept = on_accept_jcall,
2136                 .clone = LDKChannelKeys_JCalls_clone,
2137                 .free = LDKChannelKeys_JCalls_free,
2138                 .pubkeys = pubkeys_conv,
2139                 .set_pubkeys = NULL,
2140         };
2141         return ret;
2142 }
2143 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1new (JNIEnv * env, jclass _a, jobject o, jlong pubkeys) {
2144         LDKChannelKeys *res_ptr = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
2145         *res_ptr = LDKChannelKeys_init(env, _a, o, pubkeys);
2146         return (long)res_ptr;
2147 }
2148 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2149         jobject ret = (*env)->NewLocalRef(env, ((LDKChannelKeys_JCalls*)val)->o);
2150         CHECK(ret != NULL);
2151         return ret;
2152 }
2153 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_arg, jlong idx) {
2154         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2155         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
2156         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (this_arg_conv->get_per_commitment_point)(this_arg_conv->this_arg, idx).compressed_form);
2157         return arg_arr;
2158 }
2159
2160 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1release_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_arg, jlong idx) {
2161         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2162         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
2163         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->release_commitment_secret)(this_arg_conv->this_arg, idx).data);
2164         return arg_arr;
2165 }
2166
2167 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1key_1derivation_1params(JNIEnv * _env, jclass _b, jlong this_arg) {
2168         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2169         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
2170         *ret_ref = (this_arg_conv->key_derivation_params)(this_arg_conv->this_arg);
2171         return (long)ret_ref;
2172 }
2173
2174 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jint feerate_per_kw, jbyteArray commitment_tx, jlong keys, jlongArray htlcs) {
2175         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2176         LDKTransaction commitment_tx_ref;
2177         commitment_tx_ref.datalen = (*_env)->GetArrayLength (_env, commitment_tx);
2178         commitment_tx_ref.data = MALLOC(commitment_tx_ref.datalen, "LDKTransaction Bytes");
2179         (*_env)->GetByteArrayRegion(_env, commitment_tx, 0, commitment_tx_ref.datalen, commitment_tx_ref.data);
2180         commitment_tx_ref.data_is_owned = true;
2181         LDKPreCalculatedTxCreationKeys keys_conv;
2182         keys_conv.inner = (void*)(keys & (~1));
2183         keys_conv.is_owned = false;
2184         LDKCVec_HTLCOutputInCommitmentZ htlcs_constr;
2185         htlcs_constr.datalen = (*_env)->GetArrayLength (_env, htlcs);
2186         if (htlcs_constr.datalen > 0)
2187                 htlcs_constr.data = MALLOC(htlcs_constr.datalen * sizeof(LDKHTLCOutputInCommitment), "LDKCVec_HTLCOutputInCommitmentZ Elements");
2188         else
2189                 htlcs_constr.data = NULL;
2190         long* htlcs_vals = (*_env)->GetLongArrayElements (_env, htlcs, NULL);
2191         for (size_t y = 0; y < htlcs_constr.datalen; y++) {
2192                 long arr_conv_24 = htlcs_vals[y];
2193                 LDKHTLCOutputInCommitment arr_conv_24_conv;
2194                 arr_conv_24_conv.inner = (void*)(arr_conv_24 & (~1));
2195                 arr_conv_24_conv.is_owned = (arr_conv_24 & 1) || (arr_conv_24 == 0);
2196                 if (arr_conv_24_conv.inner != NULL)
2197                         arr_conv_24_conv = HTLCOutputInCommitment_clone(&arr_conv_24_conv);
2198                 htlcs_constr.data[y] = arr_conv_24_conv;
2199         }
2200         (*_env)->ReleaseLongArrayElements (_env, htlcs, htlcs_vals, 0);
2201         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
2202         *ret_conv = (this_arg_conv->sign_counterparty_commitment)(this_arg_conv->this_arg, feerate_per_kw, commitment_tx_ref, &keys_conv, htlcs_constr);
2203         return (long)ret_conv;
2204 }
2205
2206 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jlong holder_commitment_tx) {
2207         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2208         LDKHolderCommitmentTransaction holder_commitment_tx_conv;
2209         holder_commitment_tx_conv.inner = (void*)(holder_commitment_tx & (~1));
2210         holder_commitment_tx_conv.is_owned = false;
2211         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2212         *ret_conv = (this_arg_conv->sign_holder_commitment)(this_arg_conv->this_arg, &holder_commitment_tx_conv);
2213         return (long)ret_conv;
2214 }
2215
2216 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) {
2217         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2218         LDKHolderCommitmentTransaction holder_commitment_tx_conv;
2219         holder_commitment_tx_conv.inner = (void*)(holder_commitment_tx & (~1));
2220         holder_commitment_tx_conv.is_owned = false;
2221         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
2222         *ret_conv = (this_arg_conv->sign_holder_commitment_htlc_transactions)(this_arg_conv->this_arg, &holder_commitment_tx_conv);
2223         return (long)ret_conv;
2224 }
2225
2226 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1justice_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray justice_tx, jlong input, jlong amount, jbyteArray per_commitment_key, jlong htlc) {
2227         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2228         LDKTransaction justice_tx_ref;
2229         justice_tx_ref.datalen = (*_env)->GetArrayLength (_env, justice_tx);
2230         justice_tx_ref.data = MALLOC(justice_tx_ref.datalen, "LDKTransaction Bytes");
2231         (*_env)->GetByteArrayRegion(_env, justice_tx, 0, justice_tx_ref.datalen, justice_tx_ref.data);
2232         justice_tx_ref.data_is_owned = true;
2233         unsigned char per_commitment_key_arr[32];
2234         CHECK((*_env)->GetArrayLength (_env, per_commitment_key) == 32);
2235         (*_env)->GetByteArrayRegion (_env, per_commitment_key, 0, 32, per_commitment_key_arr);
2236         unsigned char (*per_commitment_key_ref)[32] = &per_commitment_key_arr;
2237         LDKHTLCOutputInCommitment htlc_conv;
2238         htlc_conv.inner = (void*)(htlc & (~1));
2239         htlc_conv.is_owned = false;
2240         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2241         *ret_conv = (this_arg_conv->sign_justice_transaction)(this_arg_conv->this_arg, justice_tx_ref, input, amount, per_commitment_key_ref, &htlc_conv);
2242         return (long)ret_conv;
2243 }
2244
2245 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1htlc_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray htlc_tx, jlong input, jlong amount, jbyteArray per_commitment_point, jlong htlc) {
2246         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2247         LDKTransaction htlc_tx_ref;
2248         htlc_tx_ref.datalen = (*_env)->GetArrayLength (_env, htlc_tx);
2249         htlc_tx_ref.data = MALLOC(htlc_tx_ref.datalen, "LDKTransaction Bytes");
2250         (*_env)->GetByteArrayRegion(_env, htlc_tx, 0, htlc_tx_ref.datalen, htlc_tx_ref.data);
2251         htlc_tx_ref.data_is_owned = true;
2252         LDKPublicKey per_commitment_point_ref;
2253         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
2254         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
2255         LDKHTLCOutputInCommitment htlc_conv;
2256         htlc_conv.inner = (void*)(htlc & (~1));
2257         htlc_conv.is_owned = false;
2258         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2259         *ret_conv = (this_arg_conv->sign_counterparty_htlc_transaction)(this_arg_conv->this_arg, htlc_tx_ref, input, amount, per_commitment_point_ref, &htlc_conv);
2260         return (long)ret_conv;
2261 }
2262
2263 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1closing_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray closing_tx) {
2264         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2265         LDKTransaction closing_tx_ref;
2266         closing_tx_ref.datalen = (*_env)->GetArrayLength (_env, closing_tx);
2267         closing_tx_ref.data = MALLOC(closing_tx_ref.datalen, "LDKTransaction Bytes");
2268         (*_env)->GetByteArrayRegion(_env, closing_tx, 0, closing_tx_ref.datalen, closing_tx_ref.data);
2269         closing_tx_ref.data_is_owned = true;
2270         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2271         *ret_conv = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_ref);
2272         return (long)ret_conv;
2273 }
2274
2275 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1channel_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
2276         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2277         LDKUnsignedChannelAnnouncement msg_conv;
2278         msg_conv.inner = (void*)(msg & (~1));
2279         msg_conv.is_owned = false;
2280         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2281         *ret_conv = (this_arg_conv->sign_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
2282         return (long)ret_conv;
2283 }
2284
2285 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) {
2286         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2287         LDKChannelPublicKeys channel_points_conv;
2288         channel_points_conv.inner = (void*)(channel_points & (~1));
2289         channel_points_conv.is_owned = false;
2290         (this_arg_conv->on_accept)(this_arg_conv->this_arg, &channel_points_conv, counterparty_selected_contest_delay, holder_selected_contest_delay);
2291 }
2292
2293 LDKChannelPublicKeys LDKChannelKeys_set_get_pubkeys(LDKChannelKeys* this_arg) {
2294         if (this_arg->set_pubkeys != NULL)
2295                 this_arg->set_pubkeys(this_arg);
2296         return this_arg->pubkeys;
2297 }
2298 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
2299         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2300         LDKChannelPublicKeys ret_var = LDKChannelKeys_set_get_pubkeys(this_arg_conv);
2301         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2302         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2303         long ret_ref = (long)ret_var.inner;
2304         if (ret_var.is_owned) {
2305                 ret_ref |= 1;
2306         }
2307         return ret_ref;
2308 }
2309
2310 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MonitorEvent_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2311         LDKCVecTempl_MonitorEvent *vec = (LDKCVecTempl_MonitorEvent*)ptr;
2312         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
2313         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
2314         for (size_t i = 0; i < vec->datalen; i++) {
2315                 CHECK((((long)vec->data[i].inner) & 1) == 0);
2316                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
2317         }
2318         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
2319         return ret;
2320 }
2321 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MonitorEvent_1new(JNIEnv *env, jclass _b, jlongArray elems){
2322         LDKCVecTempl_MonitorEvent *ret = MALLOC(sizeof(LDKCVecTempl_MonitorEvent), "LDKCVecTempl_MonitorEvent");
2323         ret->datalen = (*env)->GetArrayLength(env, elems);
2324         if (ret->datalen == 0) {
2325                 ret->data = NULL;
2326         } else {
2327                 ret->data = MALLOC(sizeof(LDKMonitorEvent) * ret->datalen, "LDKCVecTempl_MonitorEvent Data");
2328                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2329                 for (size_t i = 0; i < ret->datalen; i++) {
2330                         jlong arr_elem = java_elems[i];
2331                         LDKMonitorEvent arr_elem_conv;
2332                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2333                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2334                         if (arr_elem_conv.inner != NULL)
2335                                 arr_elem_conv = MonitorEvent_clone(&arr_elem_conv);
2336                         ret->data[i] = arr_elem_conv;
2337                 }
2338                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2339         }
2340         return (long)ret;
2341 }
2342 typedef struct LDKWatch_JCalls {
2343         atomic_size_t refcnt;
2344         JavaVM *vm;
2345         jweak o;
2346         jmethodID watch_channel_meth;
2347         jmethodID update_channel_meth;
2348         jmethodID release_pending_monitor_events_meth;
2349 } LDKWatch_JCalls;
2350 LDKCResult_NoneChannelMonitorUpdateErrZ watch_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) {
2351         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2352         JNIEnv *_env;
2353         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2354         LDKOutPoint funding_txo_var = funding_txo;
2355         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2356         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2357         long funding_txo_ref = (long)funding_txo_var.inner;
2358         if (funding_txo_var.is_owned) {
2359                 funding_txo_ref |= 1;
2360         }
2361         LDKChannelMonitor monitor_var = monitor;
2362         CHECK((((long)monitor_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2363         CHECK((((long)&monitor_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2364         long monitor_ref = (long)monitor_var.inner;
2365         if (monitor_var.is_owned) {
2366                 monitor_ref |= 1;
2367         }
2368         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2369         CHECK(obj != NULL);
2370         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->watch_channel_meth, funding_txo_ref, monitor_ref);
2371         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2372         FREE((void*)ret);
2373         return ret_conv;
2374 }
2375 LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitorUpdate update) {
2376         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2377         JNIEnv *_env;
2378         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2379         LDKOutPoint funding_txo_var = funding_txo;
2380         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2381         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2382         long funding_txo_ref = (long)funding_txo_var.inner;
2383         if (funding_txo_var.is_owned) {
2384                 funding_txo_ref |= 1;
2385         }
2386         LDKChannelMonitorUpdate update_var = update;
2387         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2388         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2389         long update_ref = (long)update_var.inner;
2390         if (update_var.is_owned) {
2391                 update_ref |= 1;
2392         }
2393         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2394         CHECK(obj != NULL);
2395         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->update_channel_meth, funding_txo_ref, update_ref);
2396         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2397         FREE((void*)ret);
2398         return ret_conv;
2399 }
2400 LDKCVec_MonitorEventZ release_pending_monitor_events_jcall(const void* this_arg) {
2401         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2402         JNIEnv *_env;
2403         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2404         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2405         CHECK(obj != NULL);
2406         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->release_pending_monitor_events_meth);
2407         LDKCVec_MonitorEventZ arg_constr;
2408         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
2409         if (arg_constr.datalen > 0)
2410                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
2411         else
2412                 arg_constr.data = NULL;
2413         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
2414         for (size_t o = 0; o < arg_constr.datalen; o++) {
2415                 long arr_conv_14 = arg_vals[o];
2416                 LDKMonitorEvent arr_conv_14_conv;
2417                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
2418                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
2419                 if (arr_conv_14_conv.inner != NULL)
2420                         arr_conv_14_conv = MonitorEvent_clone(&arr_conv_14_conv);
2421                 arg_constr.data[o] = arr_conv_14_conv;
2422         }
2423         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
2424         return arg_constr;
2425 }
2426 static void LDKWatch_JCalls_free(void* this_arg) {
2427         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2428         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2429                 JNIEnv *env;
2430                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2431                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2432                 FREE(j_calls);
2433         }
2434 }
2435 static void* LDKWatch_JCalls_clone(const void* this_arg) {
2436         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2437         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2438         return (void*) this_arg;
2439 }
2440 static inline LDKWatch LDKWatch_init (JNIEnv * env, jclass _a, jobject o) {
2441         jclass c = (*env)->GetObjectClass(env, o);
2442         CHECK(c != NULL);
2443         LDKWatch_JCalls *calls = MALLOC(sizeof(LDKWatch_JCalls), "LDKWatch_JCalls");
2444         atomic_init(&calls->refcnt, 1);
2445         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2446         calls->o = (*env)->NewWeakGlobalRef(env, o);
2447         calls->watch_channel_meth = (*env)->GetMethodID(env, c, "watch_channel", "(JJ)J");
2448         CHECK(calls->watch_channel_meth != NULL);
2449         calls->update_channel_meth = (*env)->GetMethodID(env, c, "update_channel", "(JJ)J");
2450         CHECK(calls->update_channel_meth != NULL);
2451         calls->release_pending_monitor_events_meth = (*env)->GetMethodID(env, c, "release_pending_monitor_events", "()[J");
2452         CHECK(calls->release_pending_monitor_events_meth != NULL);
2453
2454         LDKWatch ret = {
2455                 .this_arg = (void*) calls,
2456                 .watch_channel = watch_channel_jcall,
2457                 .update_channel = update_channel_jcall,
2458                 .release_pending_monitor_events = release_pending_monitor_events_jcall,
2459                 .free = LDKWatch_JCalls_free,
2460         };
2461         return ret;
2462 }
2463 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKWatch_1new (JNIEnv * env, jclass _a, jobject o) {
2464         LDKWatch *res_ptr = MALLOC(sizeof(LDKWatch), "LDKWatch");
2465         *res_ptr = LDKWatch_init(env, _a, o);
2466         return (long)res_ptr;
2467 }
2468 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKWatch_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2469         jobject ret = (*env)->NewLocalRef(env, ((LDKWatch_JCalls*)val)->o);
2470         CHECK(ret != NULL);
2471         return ret;
2472 }
2473 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Watch_1watch_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong funding_txo, jlong monitor) {
2474         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2475         LDKOutPoint funding_txo_conv;
2476         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2477         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2478         if (funding_txo_conv.inner != NULL)
2479                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2480         LDKChannelMonitor monitor_conv;
2481         monitor_conv.inner = (void*)(monitor & (~1));
2482         monitor_conv.is_owned = (monitor & 1) || (monitor == 0);
2483         // Warning: we may need a move here but can't clone!
2484         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2485         *ret_conv = (this_arg_conv->watch_channel)(this_arg_conv->this_arg, funding_txo_conv, monitor_conv);
2486         return (long)ret_conv;
2487 }
2488
2489 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Watch_1update_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong funding_txo, jlong update) {
2490         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2491         LDKOutPoint funding_txo_conv;
2492         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2493         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2494         if (funding_txo_conv.inner != NULL)
2495                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2496         LDKChannelMonitorUpdate update_conv;
2497         update_conv.inner = (void*)(update & (~1));
2498         update_conv.is_owned = (update & 1) || (update == 0);
2499         if (update_conv.inner != NULL)
2500                 update_conv = ChannelMonitorUpdate_clone(&update_conv);
2501         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2502         *ret_conv = (this_arg_conv->update_channel)(this_arg_conv->this_arg, funding_txo_conv, update_conv);
2503         return (long)ret_conv;
2504 }
2505
2506 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_Watch_1release_1pending_1monitor_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
2507         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2508         LDKCVec_MonitorEventZ ret_var = (this_arg_conv->release_pending_monitor_events)(this_arg_conv->this_arg);
2509         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
2510         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
2511         for (size_t o = 0; o < ret_var.datalen; o++) {
2512                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
2513                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2514                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2515                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
2516                 if (arr_conv_14_var.is_owned) {
2517                         arr_conv_14_ref |= 1;
2518                 }
2519                 ret_arr_ptr[o] = arr_conv_14_ref;
2520         }
2521         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
2522         FREE(ret_var.data);
2523         return ret_arr;
2524 }
2525
2526 typedef struct LDKFilter_JCalls {
2527         atomic_size_t refcnt;
2528         JavaVM *vm;
2529         jweak o;
2530         jmethodID register_tx_meth;
2531         jmethodID register_output_meth;
2532 } LDKFilter_JCalls;
2533 void register_tx_jcall(const void* this_arg, const uint8_t (*txid)[32], LDKu8slice script_pubkey) {
2534         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
2535         JNIEnv *_env;
2536         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2537         jbyteArray txid_arr = (*_env)->NewByteArray(_env, 32);
2538         (*_env)->SetByteArrayRegion(_env, txid_arr, 0, 32, *txid);
2539         LDKu8slice script_pubkey_var = script_pubkey;
2540         jbyteArray script_pubkey_arr = (*_env)->NewByteArray(_env, script_pubkey_var.datalen);
2541         (*_env)->SetByteArrayRegion(_env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
2542         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2543         CHECK(obj != NULL);
2544         return (*_env)->CallVoidMethod(_env, obj, j_calls->register_tx_meth, txid_arr, script_pubkey_arr);
2545 }
2546 void register_output_jcall(const void* this_arg, const LDKOutPoint *outpoint, LDKu8slice script_pubkey) {
2547         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
2548         JNIEnv *_env;
2549         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2550         LDKOutPoint outpoint_var = *outpoint;
2551         if (outpoint->inner != NULL)
2552                 outpoint_var = OutPoint_clone(outpoint);
2553         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2554         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2555         long outpoint_ref = (long)outpoint_var.inner;
2556         if (outpoint_var.is_owned) {
2557                 outpoint_ref |= 1;
2558         }
2559         LDKu8slice script_pubkey_var = script_pubkey;
2560         jbyteArray script_pubkey_arr = (*_env)->NewByteArray(_env, script_pubkey_var.datalen);
2561         (*_env)->SetByteArrayRegion(_env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
2562         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2563         CHECK(obj != NULL);
2564         return (*_env)->CallVoidMethod(_env, obj, j_calls->register_output_meth, outpoint_ref, script_pubkey_arr);
2565 }
2566 static void LDKFilter_JCalls_free(void* this_arg) {
2567         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
2568         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2569                 JNIEnv *env;
2570                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2571                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2572                 FREE(j_calls);
2573         }
2574 }
2575 static void* LDKFilter_JCalls_clone(const void* this_arg) {
2576         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
2577         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2578         return (void*) this_arg;
2579 }
2580 static inline LDKFilter LDKFilter_init (JNIEnv * env, jclass _a, jobject o) {
2581         jclass c = (*env)->GetObjectClass(env, o);
2582         CHECK(c != NULL);
2583         LDKFilter_JCalls *calls = MALLOC(sizeof(LDKFilter_JCalls), "LDKFilter_JCalls");
2584         atomic_init(&calls->refcnt, 1);
2585         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2586         calls->o = (*env)->NewWeakGlobalRef(env, o);
2587         calls->register_tx_meth = (*env)->GetMethodID(env, c, "register_tx", "([B[B)V");
2588         CHECK(calls->register_tx_meth != NULL);
2589         calls->register_output_meth = (*env)->GetMethodID(env, c, "register_output", "(J[B)V");
2590         CHECK(calls->register_output_meth != NULL);
2591
2592         LDKFilter ret = {
2593                 .this_arg = (void*) calls,
2594                 .register_tx = register_tx_jcall,
2595                 .register_output = register_output_jcall,
2596                 .free = LDKFilter_JCalls_free,
2597         };
2598         return ret;
2599 }
2600 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFilter_1new (JNIEnv * env, jclass _a, jobject o) {
2601         LDKFilter *res_ptr = MALLOC(sizeof(LDKFilter), "LDKFilter");
2602         *res_ptr = LDKFilter_init(env, _a, o);
2603         return (long)res_ptr;
2604 }
2605 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFilter_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2606         jobject ret = (*env)->NewLocalRef(env, ((LDKFilter_JCalls*)val)->o);
2607         CHECK(ret != NULL);
2608         return ret;
2609 }
2610 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1tx(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray txid, jbyteArray script_pubkey) {
2611         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
2612         unsigned char txid_arr[32];
2613         CHECK((*_env)->GetArrayLength (_env, txid) == 32);
2614         (*_env)->GetByteArrayRegion (_env, txid, 0, 32, txid_arr);
2615         unsigned char (*txid_ref)[32] = &txid_arr;
2616         LDKu8slice script_pubkey_ref;
2617         script_pubkey_ref.datalen = (*_env)->GetArrayLength (_env, script_pubkey);
2618         script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL);
2619         (this_arg_conv->register_tx)(this_arg_conv->this_arg, txid_ref, script_pubkey_ref);
2620         (*_env)->ReleaseByteArrayElements(_env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
2621 }
2622
2623 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1output(JNIEnv * _env, jclass _b, jlong this_arg, jlong outpoint, jbyteArray script_pubkey) {
2624         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
2625         LDKOutPoint outpoint_conv;
2626         outpoint_conv.inner = (void*)(outpoint & (~1));
2627         outpoint_conv.is_owned = false;
2628         LDKu8slice script_pubkey_ref;
2629         script_pubkey_ref.datalen = (*_env)->GetArrayLength (_env, script_pubkey);
2630         script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL);
2631         (this_arg_conv->register_output)(this_arg_conv->this_arg, &outpoint_conv, script_pubkey_ref);
2632         (*_env)->ReleaseByteArrayElements(_env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
2633 }
2634
2635 typedef struct LDKBroadcasterInterface_JCalls {
2636         atomic_size_t refcnt;
2637         JavaVM *vm;
2638         jweak o;
2639         jmethodID broadcast_transaction_meth;
2640 } LDKBroadcasterInterface_JCalls;
2641 void broadcast_transaction_jcall(const void* this_arg, LDKTransaction tx) {
2642         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2643         JNIEnv *_env;
2644         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2645         LDKTransaction tx_var = tx;
2646         jbyteArray tx_arr = (*_env)->NewByteArray(_env, tx_var.datalen);
2647         (*_env)->SetByteArrayRegion(_env, tx_arr, 0, tx_var.datalen, tx_var.data);
2648         Transaction_free(tx_var);
2649         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2650         CHECK(obj != NULL);
2651         return (*_env)->CallVoidMethod(_env, obj, j_calls->broadcast_transaction_meth, tx_arr);
2652 }
2653 static void LDKBroadcasterInterface_JCalls_free(void* this_arg) {
2654         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2655         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2656                 JNIEnv *env;
2657                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2658                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2659                 FREE(j_calls);
2660         }
2661 }
2662 static void* LDKBroadcasterInterface_JCalls_clone(const void* this_arg) {
2663         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2664         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2665         return (void*) this_arg;
2666 }
2667 static inline LDKBroadcasterInterface LDKBroadcasterInterface_init (JNIEnv * env, jclass _a, jobject o) {
2668         jclass c = (*env)->GetObjectClass(env, o);
2669         CHECK(c != NULL);
2670         LDKBroadcasterInterface_JCalls *calls = MALLOC(sizeof(LDKBroadcasterInterface_JCalls), "LDKBroadcasterInterface_JCalls");
2671         atomic_init(&calls->refcnt, 1);
2672         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2673         calls->o = (*env)->NewWeakGlobalRef(env, o);
2674         calls->broadcast_transaction_meth = (*env)->GetMethodID(env, c, "broadcast_transaction", "([B)V");
2675         CHECK(calls->broadcast_transaction_meth != NULL);
2676
2677         LDKBroadcasterInterface ret = {
2678                 .this_arg = (void*) calls,
2679                 .broadcast_transaction = broadcast_transaction_jcall,
2680                 .free = LDKBroadcasterInterface_JCalls_free,
2681         };
2682         return ret;
2683 }
2684 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1new (JNIEnv * env, jclass _a, jobject o) {
2685         LDKBroadcasterInterface *res_ptr = MALLOC(sizeof(LDKBroadcasterInterface), "LDKBroadcasterInterface");
2686         *res_ptr = LDKBroadcasterInterface_init(env, _a, o);
2687         return (long)res_ptr;
2688 }
2689 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2690         jobject ret = (*env)->NewLocalRef(env, ((LDKBroadcasterInterface_JCalls*)val)->o);
2691         CHECK(ret != NULL);
2692         return ret;
2693 }
2694 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1broadcast_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray tx) {
2695         LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg;
2696         LDKTransaction tx_ref;
2697         tx_ref.datalen = (*_env)->GetArrayLength (_env, tx);
2698         tx_ref.data = MALLOC(tx_ref.datalen, "LDKTransaction Bytes");
2699         (*_env)->GetByteArrayRegion(_env, tx, 0, tx_ref.datalen, tx_ref.data);
2700         tx_ref.data_is_owned = true;
2701         (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_ref);
2702 }
2703
2704 typedef struct LDKFeeEstimator_JCalls {
2705         atomic_size_t refcnt;
2706         JavaVM *vm;
2707         jweak o;
2708         jmethodID get_est_sat_per_1000_weight_meth;
2709 } LDKFeeEstimator_JCalls;
2710 uint32_t get_est_sat_per_1000_weight_jcall(const void* this_arg, LDKConfirmationTarget confirmation_target) {
2711         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2712         JNIEnv *_env;
2713         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2714         jclass confirmation_target_conv = LDKConfirmationTarget_to_java(_env, confirmation_target);
2715         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2716         CHECK(obj != NULL);
2717         return (*_env)->CallIntMethod(_env, obj, j_calls->get_est_sat_per_1000_weight_meth, confirmation_target_conv);
2718 }
2719 static void LDKFeeEstimator_JCalls_free(void* this_arg) {
2720         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2721         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2722                 JNIEnv *env;
2723                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2724                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2725                 FREE(j_calls);
2726         }
2727 }
2728 static void* LDKFeeEstimator_JCalls_clone(const void* this_arg) {
2729         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2730         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2731         return (void*) this_arg;
2732 }
2733 static inline LDKFeeEstimator LDKFeeEstimator_init (JNIEnv * env, jclass _a, jobject o) {
2734         jclass c = (*env)->GetObjectClass(env, o);
2735         CHECK(c != NULL);
2736         LDKFeeEstimator_JCalls *calls = MALLOC(sizeof(LDKFeeEstimator_JCalls), "LDKFeeEstimator_JCalls");
2737         atomic_init(&calls->refcnt, 1);
2738         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2739         calls->o = (*env)->NewWeakGlobalRef(env, o);
2740         calls->get_est_sat_per_1000_weight_meth = (*env)->GetMethodID(env, c, "get_est_sat_per_1000_weight", "(Lorg/ldk/enums/LDKConfirmationTarget;)I");
2741         CHECK(calls->get_est_sat_per_1000_weight_meth != NULL);
2742
2743         LDKFeeEstimator ret = {
2744                 .this_arg = (void*) calls,
2745                 .get_est_sat_per_1000_weight = get_est_sat_per_1000_weight_jcall,
2746                 .free = LDKFeeEstimator_JCalls_free,
2747         };
2748         return ret;
2749 }
2750 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1new (JNIEnv * env, jclass _a, jobject o) {
2751         LDKFeeEstimator *res_ptr = MALLOC(sizeof(LDKFeeEstimator), "LDKFeeEstimator");
2752         *res_ptr = LDKFeeEstimator_init(env, _a, o);
2753         return (long)res_ptr;
2754 }
2755 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2756         jobject ret = (*env)->NewLocalRef(env, ((LDKFeeEstimator_JCalls*)val)->o);
2757         CHECK(ret != NULL);
2758         return ret;
2759 }
2760 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) {
2761         LDKFeeEstimator* this_arg_conv = (LDKFeeEstimator*)this_arg;
2762         LDKConfirmationTarget confirmation_target_conv = LDKConfirmationTarget_from_java(_env, confirmation_target);
2763         jint ret_val = (this_arg_conv->get_est_sat_per_1000_weight)(this_arg_conv->this_arg, confirmation_target_conv);
2764         return ret_val;
2765 }
2766
2767 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1usize_1_1Transaction_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2768         LDKCVecTempl_C2TupleTempl_usize__Transaction *vec = (LDKCVecTempl_C2TupleTempl_usize__Transaction*)ptr;
2769         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2TupleTempl_usize__Transaction));
2770 }
2771 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1usize_1_1Transaction_1new(JNIEnv *env, jclass _b, jlongArray elems){
2772         LDKCVecTempl_C2TupleTempl_usize__Transaction *ret = MALLOC(sizeof(LDKCVecTempl_C2TupleTempl_usize__Transaction), "LDKCVecTempl_C2TupleTempl_usize__Transaction");
2773         ret->datalen = (*env)->GetArrayLength(env, elems);
2774         if (ret->datalen == 0) {
2775                 ret->data = NULL;
2776         } else {
2777                 ret->data = MALLOC(sizeof(LDKC2TupleTempl_usize__Transaction) * ret->datalen, "LDKCVecTempl_C2TupleTempl_usize__Transaction Data");
2778                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2779                 for (size_t i = 0; i < ret->datalen; i++) {
2780                         jlong arr_elem = java_elems[i];
2781                         LDKC2TupleTempl_usize__Transaction arr_elem_conv = *(LDKC2TupleTempl_usize__Transaction*)arr_elem;
2782                         FREE((void*)arr_elem);
2783                         ret->data[i] = arr_elem_conv;
2784                 }
2785                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2786         }
2787         return (long)ret;
2788 }
2789 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Transaction_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2790         LDKCVecTempl_Transaction *vec = (LDKCVecTempl_Transaction*)ptr;
2791         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKTransaction));
2792 }
2793 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1ThirtyTwoBytes_1_1CVecTempl_1TxOut_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2794         LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut *vec = (LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut*)ptr;
2795         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut));
2796 }
2797 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1ThirtyTwoBytes_1_1CVecTempl_1TxOut_1new(JNIEnv *env, jclass _b, jlongArray elems){
2798         LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut *ret = MALLOC(sizeof(LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut), "LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut");
2799         ret->datalen = (*env)->GetArrayLength(env, elems);
2800         if (ret->datalen == 0) {
2801                 ret->data = NULL;
2802         } else {
2803                 ret->data = MALLOC(sizeof(LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut) * ret->datalen, "LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut Data");
2804                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2805                 for (size_t i = 0; i < ret->datalen; i++) {
2806                         jlong arr_elem = java_elems[i];
2807                         LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut arr_elem_conv = *(LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut*)arr_elem;
2808                         FREE((void*)arr_elem);
2809                         ret->data[i] = arr_elem_conv;
2810                 }
2811                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2812         }
2813         return (long)ret;
2814 }
2815 typedef struct LDKKeysInterface_JCalls {
2816         atomic_size_t refcnt;
2817         JavaVM *vm;
2818         jweak o;
2819         jmethodID get_node_secret_meth;
2820         jmethodID get_destination_script_meth;
2821         jmethodID get_shutdown_pubkey_meth;
2822         jmethodID get_channel_keys_meth;
2823         jmethodID get_secure_random_bytes_meth;
2824 } LDKKeysInterface_JCalls;
2825 LDKSecretKey get_node_secret_jcall(const void* this_arg) {
2826         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2827         JNIEnv *_env;
2828         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2829         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2830         CHECK(obj != NULL);
2831         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_node_secret_meth);
2832         LDKSecretKey arg_ref;
2833         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
2834         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.bytes);
2835         return arg_ref;
2836 }
2837 LDKCVec_u8Z get_destination_script_jcall(const void* this_arg) {
2838         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2839         JNIEnv *_env;
2840         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2841         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2842         CHECK(obj != NULL);
2843         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_destination_script_meth);
2844         LDKCVec_u8Z arg_ref;
2845         arg_ref.datalen = (*_env)->GetArrayLength (_env, arg);
2846         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
2847         (*_env)->GetByteArrayRegion(_env, arg, 0, arg_ref.datalen, arg_ref.data);
2848         return arg_ref;
2849 }
2850 LDKPublicKey get_shutdown_pubkey_jcall(const void* this_arg) {
2851         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2852         JNIEnv *_env;
2853         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2854         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2855         CHECK(obj != NULL);
2856         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_shutdown_pubkey_meth);
2857         LDKPublicKey arg_ref;
2858         CHECK((*_env)->GetArrayLength (_env, arg) == 33);
2859         (*_env)->GetByteArrayRegion (_env, arg, 0, 33, arg_ref.compressed_form);
2860         return arg_ref;
2861 }
2862 LDKChannelKeys get_channel_keys_jcall(const void* this_arg, bool inbound, uint64_t channel_value_satoshis) {
2863         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2864         JNIEnv *_env;
2865         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2866         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2867         CHECK(obj != NULL);
2868         LDKChannelKeys* ret = (LDKChannelKeys*)(*_env)->CallLongMethod(_env, obj, j_calls->get_channel_keys_meth, inbound, channel_value_satoshis);
2869         LDKChannelKeys ret_conv = *(LDKChannelKeys*)ret;
2870         if (ret_conv.free == LDKChannelKeys_JCalls_free) {
2871                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
2872                 LDKChannelKeys_JCalls_clone(ret_conv.this_arg);
2873         }
2874         return ret_conv;
2875 }
2876 LDKThirtyTwoBytes get_secure_random_bytes_jcall(const void* this_arg) {
2877         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2878         JNIEnv *_env;
2879         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2880         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2881         CHECK(obj != NULL);
2882         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_secure_random_bytes_meth);
2883         LDKThirtyTwoBytes arg_ref;
2884         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
2885         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.data);
2886         return arg_ref;
2887 }
2888 static void LDKKeysInterface_JCalls_free(void* this_arg) {
2889         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2890         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2891                 JNIEnv *env;
2892                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2893                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2894                 FREE(j_calls);
2895         }
2896 }
2897 static void* LDKKeysInterface_JCalls_clone(const void* this_arg) {
2898         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2899         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2900         return (void*) this_arg;
2901 }
2902 static inline LDKKeysInterface LDKKeysInterface_init (JNIEnv * env, jclass _a, jobject o) {
2903         jclass c = (*env)->GetObjectClass(env, o);
2904         CHECK(c != NULL);
2905         LDKKeysInterface_JCalls *calls = MALLOC(sizeof(LDKKeysInterface_JCalls), "LDKKeysInterface_JCalls");
2906         atomic_init(&calls->refcnt, 1);
2907         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2908         calls->o = (*env)->NewWeakGlobalRef(env, o);
2909         calls->get_node_secret_meth = (*env)->GetMethodID(env, c, "get_node_secret", "()[B");
2910         CHECK(calls->get_node_secret_meth != NULL);
2911         calls->get_destination_script_meth = (*env)->GetMethodID(env, c, "get_destination_script", "()[B");
2912         CHECK(calls->get_destination_script_meth != NULL);
2913         calls->get_shutdown_pubkey_meth = (*env)->GetMethodID(env, c, "get_shutdown_pubkey", "()[B");
2914         CHECK(calls->get_shutdown_pubkey_meth != NULL);
2915         calls->get_channel_keys_meth = (*env)->GetMethodID(env, c, "get_channel_keys", "(ZJ)J");
2916         CHECK(calls->get_channel_keys_meth != NULL);
2917         calls->get_secure_random_bytes_meth = (*env)->GetMethodID(env, c, "get_secure_random_bytes", "()[B");
2918         CHECK(calls->get_secure_random_bytes_meth != NULL);
2919
2920         LDKKeysInterface ret = {
2921                 .this_arg = (void*) calls,
2922                 .get_node_secret = get_node_secret_jcall,
2923                 .get_destination_script = get_destination_script_jcall,
2924                 .get_shutdown_pubkey = get_shutdown_pubkey_jcall,
2925                 .get_channel_keys = get_channel_keys_jcall,
2926                 .get_secure_random_bytes = get_secure_random_bytes_jcall,
2927                 .free = LDKKeysInterface_JCalls_free,
2928         };
2929         return ret;
2930 }
2931 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1new (JNIEnv * env, jclass _a, jobject o) {
2932         LDKKeysInterface *res_ptr = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
2933         *res_ptr = LDKKeysInterface_init(env, _a, o);
2934         return (long)res_ptr;
2935 }
2936 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2937         jobject ret = (*env)->NewLocalRef(env, ((LDKKeysInterface_JCalls*)val)->o);
2938         CHECK(ret != NULL);
2939         return ret;
2940 }
2941 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1node_1secret(JNIEnv * _env, jclass _b, jlong this_arg) {
2942         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2943         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
2944         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->get_node_secret)(this_arg_conv->this_arg).bytes);
2945         return arg_arr;
2946 }
2947
2948 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1destination_1script(JNIEnv * _env, jclass _b, jlong this_arg) {
2949         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2950         LDKCVec_u8Z arg_var = (this_arg_conv->get_destination_script)(this_arg_conv->this_arg);
2951         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
2952         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
2953         CVec_u8Z_free(arg_var);
2954         return arg_arr;
2955 }
2956
2957 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_arg) {
2958         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2959         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
2960         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (this_arg_conv->get_shutdown_pubkey)(this_arg_conv->this_arg).compressed_form);
2961         return arg_arr;
2962 }
2963
2964 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) {
2965         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2966         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
2967         *ret = (this_arg_conv->get_channel_keys)(this_arg_conv->this_arg, inbound, channel_value_satoshis);
2968         return (long)ret;
2969 }
2970
2971 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1secure_1random_1bytes(JNIEnv * _env, jclass _b, jlong this_arg) {
2972         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2973         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
2974         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->get_secure_random_bytes)(this_arg_conv->this_arg).data);
2975         return arg_arr;
2976 }
2977
2978 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1ChannelDetails_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2979         LDKCVecTempl_ChannelDetails *vec = (LDKCVecTempl_ChannelDetails*)ptr;
2980         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
2981         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
2982         for (size_t i = 0; i < vec->datalen; i++) {
2983                 CHECK((((long)vec->data[i].inner) & 1) == 0);
2984                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
2985         }
2986         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
2987         return ret;
2988 }
2989 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1ChannelDetails_1new(JNIEnv *env, jclass _b, jlongArray elems){
2990         LDKCVecTempl_ChannelDetails *ret = MALLOC(sizeof(LDKCVecTempl_ChannelDetails), "LDKCVecTempl_ChannelDetails");
2991         ret->datalen = (*env)->GetArrayLength(env, elems);
2992         if (ret->datalen == 0) {
2993                 ret->data = NULL;
2994         } else {
2995                 ret->data = MALLOC(sizeof(LDKChannelDetails) * ret->datalen, "LDKCVecTempl_ChannelDetails Data");
2996                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2997                 for (size_t i = 0; i < ret->datalen; i++) {
2998                         jlong arr_elem = java_elems[i];
2999                         LDKChannelDetails arr_elem_conv;
3000                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3001                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3002                         if (arr_elem_conv.inner != NULL)
3003                                 arr_elem_conv = ChannelDetails_clone(&arr_elem_conv);
3004                         ret->data[i] = arr_elem_conv;
3005                 }
3006                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3007         }
3008         return (long)ret;
3009 }
3010 static jclass LDKNetAddress_IPv4_class = NULL;
3011 static jmethodID LDKNetAddress_IPv4_meth = NULL;
3012 static jclass LDKNetAddress_IPv6_class = NULL;
3013 static jmethodID LDKNetAddress_IPv6_meth = NULL;
3014 static jclass LDKNetAddress_OnionV2_class = NULL;
3015 static jmethodID LDKNetAddress_OnionV2_meth = NULL;
3016 static jclass LDKNetAddress_OnionV3_class = NULL;
3017 static jmethodID LDKNetAddress_OnionV3_meth = NULL;
3018 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKNetAddress_init (JNIEnv * env, jclass _a) {
3019         LDKNetAddress_IPv4_class =
3020                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv4;"));
3021         CHECK(LDKNetAddress_IPv4_class != NULL);
3022         LDKNetAddress_IPv4_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv4_class, "<init>", "([BS)V");
3023         CHECK(LDKNetAddress_IPv4_meth != NULL);
3024         LDKNetAddress_IPv6_class =
3025                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv6;"));
3026         CHECK(LDKNetAddress_IPv6_class != NULL);
3027         LDKNetAddress_IPv6_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv6_class, "<init>", "([BS)V");
3028         CHECK(LDKNetAddress_IPv6_meth != NULL);
3029         LDKNetAddress_OnionV2_class =
3030                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV2;"));
3031         CHECK(LDKNetAddress_OnionV2_class != NULL);
3032         LDKNetAddress_OnionV2_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV2_class, "<init>", "([BS)V");
3033         CHECK(LDKNetAddress_OnionV2_meth != NULL);
3034         LDKNetAddress_OnionV3_class =
3035                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV3;"));
3036         CHECK(LDKNetAddress_OnionV3_class != NULL);
3037         LDKNetAddress_OnionV3_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV3_class, "<init>", "([BSBS)V");
3038         CHECK(LDKNetAddress_OnionV3_meth != NULL);
3039 }
3040 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKNetAddress_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
3041         LDKNetAddress *obj = (LDKNetAddress*)ptr;
3042         switch(obj->tag) {
3043                 case LDKNetAddress_IPv4: {
3044                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 4);
3045                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 4, obj->i_pv4.addr.data);
3046                         return (*_env)->NewObject(_env, LDKNetAddress_IPv4_class, LDKNetAddress_IPv4_meth, addr_arr, obj->i_pv4.port);
3047                 }
3048                 case LDKNetAddress_IPv6: {
3049                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 16);
3050                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 16, obj->i_pv6.addr.data);
3051                         return (*_env)->NewObject(_env, LDKNetAddress_IPv6_class, LDKNetAddress_IPv6_meth, addr_arr, obj->i_pv6.port);
3052                 }
3053                 case LDKNetAddress_OnionV2: {
3054                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 10);
3055                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 10, obj->onion_v2.addr.data);
3056                         return (*_env)->NewObject(_env, LDKNetAddress_OnionV2_class, LDKNetAddress_OnionV2_meth, addr_arr, obj->onion_v2.port);
3057                 }
3058                 case LDKNetAddress_OnionV3: {
3059                         jbyteArray ed25519_pubkey_arr = (*_env)->NewByteArray(_env, 32);
3060                         (*_env)->SetByteArrayRegion(_env, ed25519_pubkey_arr, 0, 32, obj->onion_v3.ed25519_pubkey.data);
3061                         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);
3062                 }
3063                 default: abort();
3064         }
3065 }
3066 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1NetAddress_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3067         LDKCVecTempl_NetAddress *vec = (LDKCVecTempl_NetAddress*)ptr;
3068         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKNetAddress));
3069 }
3070 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1NetAddress_1new(JNIEnv *env, jclass _b, jlongArray elems){
3071         LDKCVecTempl_NetAddress *ret = MALLOC(sizeof(LDKCVecTempl_NetAddress), "LDKCVecTempl_NetAddress");
3072         ret->datalen = (*env)->GetArrayLength(env, elems);
3073         if (ret->datalen == 0) {
3074                 ret->data = NULL;
3075         } else {
3076                 ret->data = MALLOC(sizeof(LDKNetAddress) * ret->datalen, "LDKCVecTempl_NetAddress Data");
3077                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3078                 for (size_t i = 0; i < ret->datalen; i++) {
3079                         jlong arr_elem = java_elems[i];
3080                         LDKNetAddress arr_elem_conv = *(LDKNetAddress*)arr_elem;
3081                         FREE((void*)arr_elem);
3082                         ret->data[i] = arr_elem_conv;
3083                 }
3084                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3085         }
3086         return (long)ret;
3087 }
3088 typedef struct LDKChannelMessageHandler_JCalls {
3089         atomic_size_t refcnt;
3090         JavaVM *vm;
3091         jweak o;
3092         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
3093         jmethodID handle_open_channel_meth;
3094         jmethodID handle_accept_channel_meth;
3095         jmethodID handle_funding_created_meth;
3096         jmethodID handle_funding_signed_meth;
3097         jmethodID handle_funding_locked_meth;
3098         jmethodID handle_shutdown_meth;
3099         jmethodID handle_closing_signed_meth;
3100         jmethodID handle_update_add_htlc_meth;
3101         jmethodID handle_update_fulfill_htlc_meth;
3102         jmethodID handle_update_fail_htlc_meth;
3103         jmethodID handle_update_fail_malformed_htlc_meth;
3104         jmethodID handle_commitment_signed_meth;
3105         jmethodID handle_revoke_and_ack_meth;
3106         jmethodID handle_update_fee_meth;
3107         jmethodID handle_announcement_signatures_meth;
3108         jmethodID peer_disconnected_meth;
3109         jmethodID peer_connected_meth;
3110         jmethodID handle_channel_reestablish_meth;
3111         jmethodID handle_error_meth;
3112 } LDKChannelMessageHandler_JCalls;
3113 void handle_open_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKOpenChannel *msg) {
3114         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3115         JNIEnv *_env;
3116         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3117         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3118         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3119         LDKInitFeatures their_features_var = their_features;
3120         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3121         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3122         long their_features_ref = (long)their_features_var.inner;
3123         if (their_features_var.is_owned) {
3124                 their_features_ref |= 1;
3125         }
3126         LDKOpenChannel msg_var = *msg;
3127         if (msg->inner != NULL)
3128                 msg_var = OpenChannel_clone(msg);
3129         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3130         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3131         long msg_ref = (long)msg_var.inner;
3132         if (msg_var.is_owned) {
3133                 msg_ref |= 1;
3134         }
3135         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3136         CHECK(obj != NULL);
3137         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_open_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
3138 }
3139 void handle_accept_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKAcceptChannel *msg) {
3140         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3141         JNIEnv *_env;
3142         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3143         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3144         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3145         LDKInitFeatures their_features_var = their_features;
3146         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3147         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3148         long their_features_ref = (long)their_features_var.inner;
3149         if (their_features_var.is_owned) {
3150                 their_features_ref |= 1;
3151         }
3152         LDKAcceptChannel msg_var = *msg;
3153         if (msg->inner != NULL)
3154                 msg_var = AcceptChannel_clone(msg);
3155         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3156         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3157         long msg_ref = (long)msg_var.inner;
3158         if (msg_var.is_owned) {
3159                 msg_ref |= 1;
3160         }
3161         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3162         CHECK(obj != NULL);
3163         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_accept_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
3164 }
3165 void handle_funding_created_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingCreated *msg) {
3166         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3167         JNIEnv *_env;
3168         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3169         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3170         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3171         LDKFundingCreated msg_var = *msg;
3172         if (msg->inner != NULL)
3173                 msg_var = FundingCreated_clone(msg);
3174         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3175         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3176         long msg_ref = (long)msg_var.inner;
3177         if (msg_var.is_owned) {
3178                 msg_ref |= 1;
3179         }
3180         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3181         CHECK(obj != NULL);
3182         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_created_meth, their_node_id_arr, msg_ref);
3183 }
3184 void handle_funding_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingSigned *msg) {
3185         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3186         JNIEnv *_env;
3187         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3188         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3189         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3190         LDKFundingSigned msg_var = *msg;
3191         if (msg->inner != NULL)
3192                 msg_var = FundingSigned_clone(msg);
3193         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3194         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3195         long msg_ref = (long)msg_var.inner;
3196         if (msg_var.is_owned) {
3197                 msg_ref |= 1;
3198         }
3199         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3200         CHECK(obj != NULL);
3201         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_signed_meth, their_node_id_arr, msg_ref);
3202 }
3203 void handle_funding_locked_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingLocked *msg) {
3204         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3205         JNIEnv *_env;
3206         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3207         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3208         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3209         LDKFundingLocked msg_var = *msg;
3210         if (msg->inner != NULL)
3211                 msg_var = FundingLocked_clone(msg);
3212         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3213         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3214         long msg_ref = (long)msg_var.inner;
3215         if (msg_var.is_owned) {
3216                 msg_ref |= 1;
3217         }
3218         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3219         CHECK(obj != NULL);
3220         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_locked_meth, their_node_id_arr, msg_ref);
3221 }
3222 void handle_shutdown_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKShutdown *msg) {
3223         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3224         JNIEnv *_env;
3225         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3226         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3227         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3228         LDKShutdown msg_var = *msg;
3229         if (msg->inner != NULL)
3230                 msg_var = Shutdown_clone(msg);
3231         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3232         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3233         long msg_ref = (long)msg_var.inner;
3234         if (msg_var.is_owned) {
3235                 msg_ref |= 1;
3236         }
3237         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3238         CHECK(obj != NULL);
3239         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_shutdown_meth, their_node_id_arr, msg_ref);
3240 }
3241 void handle_closing_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKClosingSigned *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         LDKClosingSigned msg_var = *msg;
3248         if (msg->inner != NULL)
3249                 msg_var = ClosingSigned_clone(msg);
3250         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3251         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3252         long msg_ref = (long)msg_var.inner;
3253         if (msg_var.is_owned) {
3254                 msg_ref |= 1;
3255         }
3256         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3257         CHECK(obj != NULL);
3258         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_closing_signed_meth, their_node_id_arr, msg_ref);
3259 }
3260 void handle_update_add_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateAddHTLC *msg) {
3261         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3262         JNIEnv *_env;
3263         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3264         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3265         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3266         LDKUpdateAddHTLC msg_var = *msg;
3267         if (msg->inner != NULL)
3268                 msg_var = UpdateAddHTLC_clone(msg);
3269         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3270         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3271         long msg_ref = (long)msg_var.inner;
3272         if (msg_var.is_owned) {
3273                 msg_ref |= 1;
3274         }
3275         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3276         CHECK(obj != NULL);
3277         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_add_htlc_meth, their_node_id_arr, msg_ref);
3278 }
3279 void handle_update_fulfill_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFulfillHTLC *msg) {
3280         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3281         JNIEnv *_env;
3282         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3283         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3284         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3285         LDKUpdateFulfillHTLC msg_var = *msg;
3286         if (msg->inner != NULL)
3287                 msg_var = UpdateFulfillHTLC_clone(msg);
3288         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3289         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3290         long msg_ref = (long)msg_var.inner;
3291         if (msg_var.is_owned) {
3292                 msg_ref |= 1;
3293         }
3294         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3295         CHECK(obj != NULL);
3296         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fulfill_htlc_meth, their_node_id_arr, msg_ref);
3297 }
3298 void handle_update_fail_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailHTLC *msg) {
3299         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3300         JNIEnv *_env;
3301         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3302         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3303         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3304         LDKUpdateFailHTLC msg_var = *msg;
3305         if (msg->inner != NULL)
3306                 msg_var = UpdateFailHTLC_clone(msg);
3307         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3308         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3309         long msg_ref = (long)msg_var.inner;
3310         if (msg_var.is_owned) {
3311                 msg_ref |= 1;
3312         }
3313         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3314         CHECK(obj != NULL);
3315         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fail_htlc_meth, their_node_id_arr, msg_ref);
3316 }
3317 void handle_update_fail_malformed_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailMalformedHTLC *msg) {
3318         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3319         JNIEnv *_env;
3320         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3321         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3322         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3323         LDKUpdateFailMalformedHTLC msg_var = *msg;
3324         if (msg->inner != NULL)
3325                 msg_var = UpdateFailMalformedHTLC_clone(msg);
3326         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3327         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3328         long msg_ref = (long)msg_var.inner;
3329         if (msg_var.is_owned) {
3330                 msg_ref |= 1;
3331         }
3332         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3333         CHECK(obj != NULL);
3334         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fail_malformed_htlc_meth, their_node_id_arr, msg_ref);
3335 }
3336 void handle_commitment_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKCommitmentSigned *msg) {
3337         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3338         JNIEnv *_env;
3339         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3340         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3341         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3342         LDKCommitmentSigned msg_var = *msg;
3343         if (msg->inner != NULL)
3344                 msg_var = CommitmentSigned_clone(msg);
3345         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3346         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3347         long msg_ref = (long)msg_var.inner;
3348         if (msg_var.is_owned) {
3349                 msg_ref |= 1;
3350         }
3351         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3352         CHECK(obj != NULL);
3353         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_commitment_signed_meth, their_node_id_arr, msg_ref);
3354 }
3355 void handle_revoke_and_ack_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKRevokeAndACK *msg) {
3356         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3357         JNIEnv *_env;
3358         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3359         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3360         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3361         LDKRevokeAndACK msg_var = *msg;
3362         if (msg->inner != NULL)
3363                 msg_var = RevokeAndACK_clone(msg);
3364         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3365         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3366         long msg_ref = (long)msg_var.inner;
3367         if (msg_var.is_owned) {
3368                 msg_ref |= 1;
3369         }
3370         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3371         CHECK(obj != NULL);
3372         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_revoke_and_ack_meth, their_node_id_arr, msg_ref);
3373 }
3374 void handle_update_fee_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFee *msg) {
3375         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3376         JNIEnv *_env;
3377         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3378         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3379         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3380         LDKUpdateFee msg_var = *msg;
3381         if (msg->inner != NULL)
3382                 msg_var = UpdateFee_clone(msg);
3383         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3384         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3385         long msg_ref = (long)msg_var.inner;
3386         if (msg_var.is_owned) {
3387                 msg_ref |= 1;
3388         }
3389         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3390         CHECK(obj != NULL);
3391         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fee_meth, their_node_id_arr, msg_ref);
3392 }
3393 void handle_announcement_signatures_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKAnnouncementSignatures *msg) {
3394         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3395         JNIEnv *_env;
3396         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3397         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3398         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3399         LDKAnnouncementSignatures msg_var = *msg;
3400         if (msg->inner != NULL)
3401                 msg_var = AnnouncementSignatures_clone(msg);
3402         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3403         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3404         long msg_ref = (long)msg_var.inner;
3405         if (msg_var.is_owned) {
3406                 msg_ref |= 1;
3407         }
3408         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3409         CHECK(obj != NULL);
3410         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_announcement_signatures_meth, their_node_id_arr, msg_ref);
3411 }
3412 void peer_disconnected_jcall(const void* this_arg, LDKPublicKey their_node_id, bool no_connection_possible) {
3413         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3414         JNIEnv *_env;
3415         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3416         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3417         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3418         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3419         CHECK(obj != NULL);
3420         return (*_env)->CallVoidMethod(_env, obj, j_calls->peer_disconnected_meth, their_node_id_arr, no_connection_possible);
3421 }
3422 void peer_connected_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKInit *msg) {
3423         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3424         JNIEnv *_env;
3425         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3426         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3427         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3428         LDKInit msg_var = *msg;
3429         if (msg->inner != NULL)
3430                 msg_var = Init_clone(msg);
3431         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3432         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3433         long msg_ref = (long)msg_var.inner;
3434         if (msg_var.is_owned) {
3435                 msg_ref |= 1;
3436         }
3437         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3438         CHECK(obj != NULL);
3439         return (*_env)->CallVoidMethod(_env, obj, j_calls->peer_connected_meth, their_node_id_arr, msg_ref);
3440 }
3441 void handle_channel_reestablish_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKChannelReestablish *msg) {
3442         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3443         JNIEnv *_env;
3444         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3445         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3446         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3447         LDKChannelReestablish msg_var = *msg;
3448         if (msg->inner != NULL)
3449                 msg_var = ChannelReestablish_clone(msg);
3450         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3451         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3452         long msg_ref = (long)msg_var.inner;
3453         if (msg_var.is_owned) {
3454                 msg_ref |= 1;
3455         }
3456         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3457         CHECK(obj != NULL);
3458         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_channel_reestablish_meth, their_node_id_arr, msg_ref);
3459 }
3460 void handle_error_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKErrorMessage *msg) {
3461         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3462         JNIEnv *_env;
3463         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3464         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3465         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3466         LDKErrorMessage msg_var = *msg;
3467         if (msg->inner != NULL)
3468                 msg_var = ErrorMessage_clone(msg);
3469         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3470         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3471         long msg_ref = (long)msg_var.inner;
3472         if (msg_var.is_owned) {
3473                 msg_ref |= 1;
3474         }
3475         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3476         CHECK(obj != NULL);
3477         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_error_meth, their_node_id_arr, msg_ref);
3478 }
3479 static void LDKChannelMessageHandler_JCalls_free(void* this_arg) {
3480         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3481         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3482                 JNIEnv *env;
3483                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3484                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
3485                 FREE(j_calls);
3486         }
3487 }
3488 static void* LDKChannelMessageHandler_JCalls_clone(const void* this_arg) {
3489         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3490         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3491         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
3492         return (void*) this_arg;
3493 }
3494 static inline LDKChannelMessageHandler LDKChannelMessageHandler_init (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
3495         jclass c = (*env)->GetObjectClass(env, o);
3496         CHECK(c != NULL);
3497         LDKChannelMessageHandler_JCalls *calls = MALLOC(sizeof(LDKChannelMessageHandler_JCalls), "LDKChannelMessageHandler_JCalls");
3498         atomic_init(&calls->refcnt, 1);
3499         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
3500         calls->o = (*env)->NewWeakGlobalRef(env, o);
3501         calls->handle_open_channel_meth = (*env)->GetMethodID(env, c, "handle_open_channel", "([BJJ)V");
3502         CHECK(calls->handle_open_channel_meth != NULL);
3503         calls->handle_accept_channel_meth = (*env)->GetMethodID(env, c, "handle_accept_channel", "([BJJ)V");
3504         CHECK(calls->handle_accept_channel_meth != NULL);
3505         calls->handle_funding_created_meth = (*env)->GetMethodID(env, c, "handle_funding_created", "([BJ)V");
3506         CHECK(calls->handle_funding_created_meth != NULL);
3507         calls->handle_funding_signed_meth = (*env)->GetMethodID(env, c, "handle_funding_signed", "([BJ)V");
3508         CHECK(calls->handle_funding_signed_meth != NULL);
3509         calls->handle_funding_locked_meth = (*env)->GetMethodID(env, c, "handle_funding_locked", "([BJ)V");
3510         CHECK(calls->handle_funding_locked_meth != NULL);
3511         calls->handle_shutdown_meth = (*env)->GetMethodID(env, c, "handle_shutdown", "([BJ)V");
3512         CHECK(calls->handle_shutdown_meth != NULL);
3513         calls->handle_closing_signed_meth = (*env)->GetMethodID(env, c, "handle_closing_signed", "([BJ)V");
3514         CHECK(calls->handle_closing_signed_meth != NULL);
3515         calls->handle_update_add_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_add_htlc", "([BJ)V");
3516         CHECK(calls->handle_update_add_htlc_meth != NULL);
3517         calls->handle_update_fulfill_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fulfill_htlc", "([BJ)V");
3518         CHECK(calls->handle_update_fulfill_htlc_meth != NULL);
3519         calls->handle_update_fail_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_htlc", "([BJ)V");
3520         CHECK(calls->handle_update_fail_htlc_meth != NULL);
3521         calls->handle_update_fail_malformed_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_malformed_htlc", "([BJ)V");
3522         CHECK(calls->handle_update_fail_malformed_htlc_meth != NULL);
3523         calls->handle_commitment_signed_meth = (*env)->GetMethodID(env, c, "handle_commitment_signed", "([BJ)V");
3524         CHECK(calls->handle_commitment_signed_meth != NULL);
3525         calls->handle_revoke_and_ack_meth = (*env)->GetMethodID(env, c, "handle_revoke_and_ack", "([BJ)V");
3526         CHECK(calls->handle_revoke_and_ack_meth != NULL);
3527         calls->handle_update_fee_meth = (*env)->GetMethodID(env, c, "handle_update_fee", "([BJ)V");
3528         CHECK(calls->handle_update_fee_meth != NULL);
3529         calls->handle_announcement_signatures_meth = (*env)->GetMethodID(env, c, "handle_announcement_signatures", "([BJ)V");
3530         CHECK(calls->handle_announcement_signatures_meth != NULL);
3531         calls->peer_disconnected_meth = (*env)->GetMethodID(env, c, "peer_disconnected", "([BZ)V");
3532         CHECK(calls->peer_disconnected_meth != NULL);
3533         calls->peer_connected_meth = (*env)->GetMethodID(env, c, "peer_connected", "([BJ)V");
3534         CHECK(calls->peer_connected_meth != NULL);
3535         calls->handle_channel_reestablish_meth = (*env)->GetMethodID(env, c, "handle_channel_reestablish", "([BJ)V");
3536         CHECK(calls->handle_channel_reestablish_meth != NULL);
3537         calls->handle_error_meth = (*env)->GetMethodID(env, c, "handle_error", "([BJ)V");
3538         CHECK(calls->handle_error_meth != NULL);
3539
3540         LDKChannelMessageHandler ret = {
3541                 .this_arg = (void*) calls,
3542                 .handle_open_channel = handle_open_channel_jcall,
3543                 .handle_accept_channel = handle_accept_channel_jcall,
3544                 .handle_funding_created = handle_funding_created_jcall,
3545                 .handle_funding_signed = handle_funding_signed_jcall,
3546                 .handle_funding_locked = handle_funding_locked_jcall,
3547                 .handle_shutdown = handle_shutdown_jcall,
3548                 .handle_closing_signed = handle_closing_signed_jcall,
3549                 .handle_update_add_htlc = handle_update_add_htlc_jcall,
3550                 .handle_update_fulfill_htlc = handle_update_fulfill_htlc_jcall,
3551                 .handle_update_fail_htlc = handle_update_fail_htlc_jcall,
3552                 .handle_update_fail_malformed_htlc = handle_update_fail_malformed_htlc_jcall,
3553                 .handle_commitment_signed = handle_commitment_signed_jcall,
3554                 .handle_revoke_and_ack = handle_revoke_and_ack_jcall,
3555                 .handle_update_fee = handle_update_fee_jcall,
3556                 .handle_announcement_signatures = handle_announcement_signatures_jcall,
3557                 .peer_disconnected = peer_disconnected_jcall,
3558                 .peer_connected = peer_connected_jcall,
3559                 .handle_channel_reestablish = handle_channel_reestablish_jcall,
3560                 .handle_error = handle_error_jcall,
3561                 .free = LDKChannelMessageHandler_JCalls_free,
3562                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(env, _a, MessageSendEventsProvider),
3563         };
3564         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
3565         return ret;
3566 }
3567 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1new (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
3568         LDKChannelMessageHandler *res_ptr = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
3569         *res_ptr = LDKChannelMessageHandler_init(env, _a, o, MessageSendEventsProvider);
3570         return (long)res_ptr;
3571 }
3572 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
3573         jobject ret = (*env)->NewLocalRef(env, ((LDKChannelMessageHandler_JCalls*)val)->o);
3574         CHECK(ret != NULL);
3575         return ret;
3576 }
3577 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) {
3578         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3579         LDKPublicKey their_node_id_ref;
3580         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3581         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3582         LDKInitFeatures their_features_conv;
3583         their_features_conv.inner = (void*)(their_features & (~1));
3584         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
3585         // Warning: we may need a move here but can't clone!
3586         LDKOpenChannel msg_conv;
3587         msg_conv.inner = (void*)(msg & (~1));
3588         msg_conv.is_owned = false;
3589         (this_arg_conv->handle_open_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
3590 }
3591
3592 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) {
3593         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3594         LDKPublicKey their_node_id_ref;
3595         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3596         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3597         LDKInitFeatures their_features_conv;
3598         their_features_conv.inner = (void*)(their_features & (~1));
3599         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
3600         // Warning: we may need a move here but can't clone!
3601         LDKAcceptChannel msg_conv;
3602         msg_conv.inner = (void*)(msg & (~1));
3603         msg_conv.is_owned = false;
3604         (this_arg_conv->handle_accept_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
3605 }
3606
3607 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) {
3608         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3609         LDKPublicKey their_node_id_ref;
3610         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3611         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3612         LDKFundingCreated msg_conv;
3613         msg_conv.inner = (void*)(msg & (~1));
3614         msg_conv.is_owned = false;
3615         (this_arg_conv->handle_funding_created)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3616 }
3617
3618 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) {
3619         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3620         LDKPublicKey their_node_id_ref;
3621         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3622         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3623         LDKFundingSigned msg_conv;
3624         msg_conv.inner = (void*)(msg & (~1));
3625         msg_conv.is_owned = false;
3626         (this_arg_conv->handle_funding_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3627 }
3628
3629 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) {
3630         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3631         LDKPublicKey their_node_id_ref;
3632         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3633         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3634         LDKFundingLocked msg_conv;
3635         msg_conv.inner = (void*)(msg & (~1));
3636         msg_conv.is_owned = false;
3637         (this_arg_conv->handle_funding_locked)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3638 }
3639
3640 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1shutdown(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
3641         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3642         LDKPublicKey their_node_id_ref;
3643         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3644         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3645         LDKShutdown msg_conv;
3646         msg_conv.inner = (void*)(msg & (~1));
3647         msg_conv.is_owned = false;
3648         (this_arg_conv->handle_shutdown)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3649 }
3650
3651 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) {
3652         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3653         LDKPublicKey their_node_id_ref;
3654         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3655         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3656         LDKClosingSigned msg_conv;
3657         msg_conv.inner = (void*)(msg & (~1));
3658         msg_conv.is_owned = false;
3659         (this_arg_conv->handle_closing_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3660 }
3661
3662 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) {
3663         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3664         LDKPublicKey their_node_id_ref;
3665         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3666         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3667         LDKUpdateAddHTLC msg_conv;
3668         msg_conv.inner = (void*)(msg & (~1));
3669         msg_conv.is_owned = false;
3670         (this_arg_conv->handle_update_add_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3671 }
3672
3673 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) {
3674         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3675         LDKPublicKey their_node_id_ref;
3676         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3677         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3678         LDKUpdateFulfillHTLC msg_conv;
3679         msg_conv.inner = (void*)(msg & (~1));
3680         msg_conv.is_owned = false;
3681         (this_arg_conv->handle_update_fulfill_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3682 }
3683
3684 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) {
3685         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3686         LDKPublicKey their_node_id_ref;
3687         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3688         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3689         LDKUpdateFailHTLC msg_conv;
3690         msg_conv.inner = (void*)(msg & (~1));
3691         msg_conv.is_owned = false;
3692         (this_arg_conv->handle_update_fail_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3693 }
3694
3695 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) {
3696         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3697         LDKPublicKey their_node_id_ref;
3698         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3699         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3700         LDKUpdateFailMalformedHTLC msg_conv;
3701         msg_conv.inner = (void*)(msg & (~1));
3702         msg_conv.is_owned = false;
3703         (this_arg_conv->handle_update_fail_malformed_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3704 }
3705
3706 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) {
3707         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3708         LDKPublicKey their_node_id_ref;
3709         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3710         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3711         LDKCommitmentSigned msg_conv;
3712         msg_conv.inner = (void*)(msg & (~1));
3713         msg_conv.is_owned = false;
3714         (this_arg_conv->handle_commitment_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3715 }
3716
3717 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) {
3718         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3719         LDKPublicKey their_node_id_ref;
3720         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3721         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3722         LDKRevokeAndACK msg_conv;
3723         msg_conv.inner = (void*)(msg & (~1));
3724         msg_conv.is_owned = false;
3725         (this_arg_conv->handle_revoke_and_ack)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3726 }
3727
3728 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) {
3729         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3730         LDKPublicKey their_node_id_ref;
3731         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3732         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3733         LDKUpdateFee msg_conv;
3734         msg_conv.inner = (void*)(msg & (~1));
3735         msg_conv.is_owned = false;
3736         (this_arg_conv->handle_update_fee)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3737 }
3738
3739 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) {
3740         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3741         LDKPublicKey their_node_id_ref;
3742         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3743         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3744         LDKAnnouncementSignatures msg_conv;
3745         msg_conv.inner = (void*)(msg & (~1));
3746         msg_conv.is_owned = false;
3747         (this_arg_conv->handle_announcement_signatures)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3748 }
3749
3750 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) {
3751         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3752         LDKPublicKey their_node_id_ref;
3753         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3754         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3755         (this_arg_conv->peer_disconnected)(this_arg_conv->this_arg, their_node_id_ref, no_connection_possible);
3756 }
3757
3758 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1peer_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
3759         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3760         LDKPublicKey their_node_id_ref;
3761         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3762         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3763         LDKInit msg_conv;
3764         msg_conv.inner = (void*)(msg & (~1));
3765         msg_conv.is_owned = false;
3766         (this_arg_conv->peer_connected)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3767 }
3768
3769 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) {
3770         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3771         LDKPublicKey their_node_id_ref;
3772         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3773         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3774         LDKChannelReestablish msg_conv;
3775         msg_conv.inner = (void*)(msg & (~1));
3776         msg_conv.is_owned = false;
3777         (this_arg_conv->handle_channel_reestablish)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3778 }
3779
3780 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1error(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
3781         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3782         LDKPublicKey their_node_id_ref;
3783         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3784         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3785         LDKErrorMessage msg_conv;
3786         msg_conv.inner = (void*)(msg & (~1));
3787         msg_conv.is_owned = false;
3788         (this_arg_conv->handle_error)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3789 }
3790
3791 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1ChannelMonitor_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3792         LDKCVecTempl_ChannelMonitor *vec = (LDKCVecTempl_ChannelMonitor*)ptr;
3793         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3794         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3795         for (size_t i = 0; i < vec->datalen; i++) {
3796                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3797                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3798         }
3799         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3800         return ret;
3801 }
3802 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1ChannelMonitor_1new(JNIEnv *env, jclass _b, jlongArray elems){
3803         LDKCVecTempl_ChannelMonitor *ret = MALLOC(sizeof(LDKCVecTempl_ChannelMonitor), "LDKCVecTempl_ChannelMonitor");
3804         ret->datalen = (*env)->GetArrayLength(env, elems);
3805         if (ret->datalen == 0) {
3806                 ret->data = NULL;
3807         } else {
3808                 ret->data = MALLOC(sizeof(LDKChannelMonitor) * ret->datalen, "LDKCVecTempl_ChannelMonitor Data");
3809                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3810                 for (size_t i = 0; i < ret->datalen; i++) {
3811                         jlong arr_elem = java_elems[i];
3812                         LDKChannelMonitor arr_elem_conv;
3813                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3814                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3815                         // Warning: we may need a move here but can't clone!
3816                         ret->data[i] = arr_elem_conv;
3817                 }
3818                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3819         }
3820         return (long)ret;
3821 }
3822 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u64_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3823         LDKCVecTempl_u64 *vec = (LDKCVecTempl_u64*)ptr;
3824         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(uint64_t));
3825 }
3826 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u64_1new(JNIEnv *env, jclass _b, jlongArray elems){
3827         LDKCVecTempl_u64 *ret = MALLOC(sizeof(LDKCVecTempl_u64), "LDKCVecTempl_u64");
3828         ret->datalen = (*env)->GetArrayLength(env, elems);
3829         if (ret->datalen == 0) {
3830                 ret->data = NULL;
3831         } else {
3832                 ret->data = MALLOC(sizeof(uint64_t) * ret->datalen, "LDKCVecTempl_u64 Data");
3833                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3834                 for (size_t i = 0; i < ret->datalen; i++) {
3835                         ret->data[i] = java_elems[i];
3836                 }
3837                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3838         }
3839         return (long)ret;
3840 }
3841 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateAddHTLC_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3842         LDKCVecTempl_UpdateAddHTLC *vec = (LDKCVecTempl_UpdateAddHTLC*)ptr;
3843         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3844         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3845         for (size_t i = 0; i < vec->datalen; i++) {
3846                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3847                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3848         }
3849         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3850         return ret;
3851 }
3852 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateAddHTLC_1new(JNIEnv *env, jclass _b, jlongArray elems){
3853         LDKCVecTempl_UpdateAddHTLC *ret = MALLOC(sizeof(LDKCVecTempl_UpdateAddHTLC), "LDKCVecTempl_UpdateAddHTLC");
3854         ret->datalen = (*env)->GetArrayLength(env, elems);
3855         if (ret->datalen == 0) {
3856                 ret->data = NULL;
3857         } else {
3858                 ret->data = MALLOC(sizeof(LDKUpdateAddHTLC) * ret->datalen, "LDKCVecTempl_UpdateAddHTLC Data");
3859                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3860                 for (size_t i = 0; i < ret->datalen; i++) {
3861                         jlong arr_elem = java_elems[i];
3862                         LDKUpdateAddHTLC arr_elem_conv;
3863                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3864                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3865                         if (arr_elem_conv.inner != NULL)
3866                                 arr_elem_conv = UpdateAddHTLC_clone(&arr_elem_conv);
3867                         ret->data[i] = arr_elem_conv;
3868                 }
3869                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3870         }
3871         return (long)ret;
3872 }
3873 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFulfillHTLC_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3874         LDKCVecTempl_UpdateFulfillHTLC *vec = (LDKCVecTempl_UpdateFulfillHTLC*)ptr;
3875         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3876         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3877         for (size_t i = 0; i < vec->datalen; i++) {
3878                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3879                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3880         }
3881         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3882         return ret;
3883 }
3884 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFulfillHTLC_1new(JNIEnv *env, jclass _b, jlongArray elems){
3885         LDKCVecTempl_UpdateFulfillHTLC *ret = MALLOC(sizeof(LDKCVecTempl_UpdateFulfillHTLC), "LDKCVecTempl_UpdateFulfillHTLC");
3886         ret->datalen = (*env)->GetArrayLength(env, elems);
3887         if (ret->datalen == 0) {
3888                 ret->data = NULL;
3889         } else {
3890                 ret->data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * ret->datalen, "LDKCVecTempl_UpdateFulfillHTLC Data");
3891                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3892                 for (size_t i = 0; i < ret->datalen; i++) {
3893                         jlong arr_elem = java_elems[i];
3894                         LDKUpdateFulfillHTLC arr_elem_conv;
3895                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3896                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3897                         if (arr_elem_conv.inner != NULL)
3898                                 arr_elem_conv = UpdateFulfillHTLC_clone(&arr_elem_conv);
3899                         ret->data[i] = arr_elem_conv;
3900                 }
3901                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3902         }
3903         return (long)ret;
3904 }
3905 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailHTLC_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3906         LDKCVecTempl_UpdateFailHTLC *vec = (LDKCVecTempl_UpdateFailHTLC*)ptr;
3907         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3908         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3909         for (size_t i = 0; i < vec->datalen; i++) {
3910                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3911                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3912         }
3913         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3914         return ret;
3915 }
3916 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailHTLC_1new(JNIEnv *env, jclass _b, jlongArray elems){
3917         LDKCVecTempl_UpdateFailHTLC *ret = MALLOC(sizeof(LDKCVecTempl_UpdateFailHTLC), "LDKCVecTempl_UpdateFailHTLC");
3918         ret->datalen = (*env)->GetArrayLength(env, elems);
3919         if (ret->datalen == 0) {
3920                 ret->data = NULL;
3921         } else {
3922                 ret->data = MALLOC(sizeof(LDKUpdateFailHTLC) * ret->datalen, "LDKCVecTempl_UpdateFailHTLC Data");
3923                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3924                 for (size_t i = 0; i < ret->datalen; i++) {
3925                         jlong arr_elem = java_elems[i];
3926                         LDKUpdateFailHTLC arr_elem_conv;
3927                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3928                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3929                         if (arr_elem_conv.inner != NULL)
3930                                 arr_elem_conv = UpdateFailHTLC_clone(&arr_elem_conv);
3931                         ret->data[i] = arr_elem_conv;
3932                 }
3933                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3934         }
3935         return (long)ret;
3936 }
3937 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailMalformedHTLC_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3938         LDKCVecTempl_UpdateFailMalformedHTLC *vec = (LDKCVecTempl_UpdateFailMalformedHTLC*)ptr;
3939         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3940         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3941         for (size_t i = 0; i < vec->datalen; i++) {
3942                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3943                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3944         }
3945         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3946         return ret;
3947 }
3948 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailMalformedHTLC_1new(JNIEnv *env, jclass _b, jlongArray elems){
3949         LDKCVecTempl_UpdateFailMalformedHTLC *ret = MALLOC(sizeof(LDKCVecTempl_UpdateFailMalformedHTLC), "LDKCVecTempl_UpdateFailMalformedHTLC");
3950         ret->datalen = (*env)->GetArrayLength(env, elems);
3951         if (ret->datalen == 0) {
3952                 ret->data = NULL;
3953         } else {
3954                 ret->data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * ret->datalen, "LDKCVecTempl_UpdateFailMalformedHTLC Data");
3955                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3956                 for (size_t i = 0; i < ret->datalen; i++) {
3957                         jlong arr_elem = java_elems[i];
3958                         LDKUpdateFailMalformedHTLC arr_elem_conv;
3959                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3960                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3961                         if (arr_elem_conv.inner != NULL)
3962                                 arr_elem_conv = UpdateFailMalformedHTLC_clone(&arr_elem_conv);
3963                         ret->data[i] = arr_elem_conv;
3964                 }
3965                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3966         }
3967         return (long)ret;
3968 }
3969 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3970         return ((LDKCResult_boolLightningErrorZ*)arg)->result_ok;
3971 }
3972 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3973         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3974         CHECK(val->result_ok);
3975         return *val->contents.result;
3976 }
3977 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3978         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3979         CHECK(!val->result_ok);
3980         LDKLightningError err_var = (*val->contents.err);
3981         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3982         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3983         long err_ref = (long)err_var.inner & ~1;
3984         return err_ref;
3985 }
3986 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C3TupleTempl_1ChannelAnnouncement_1_1ChannelUpdate_1_1ChannelUpdate_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3987         LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate *vec = (LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate*)ptr;
3988         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate));
3989 }
3990 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C3TupleTempl_1ChannelAnnouncement_1_1ChannelUpdate_1_1ChannelUpdate_1new(JNIEnv *env, jclass _b, jlongArray elems){
3991         LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate *ret = MALLOC(sizeof(LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate), "LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate");
3992         ret->datalen = (*env)->GetArrayLength(env, elems);
3993         if (ret->datalen == 0) {
3994                 ret->data = NULL;
3995         } else {
3996                 ret->data = MALLOC(sizeof(LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate) * ret->datalen, "LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate Data");
3997                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3998                 for (size_t i = 0; i < ret->datalen; i++) {
3999                         jlong arr_elem = java_elems[i];
4000                         LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate arr_elem_conv = *(LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate*)arr_elem;
4001                         FREE((void*)arr_elem);
4002                         ret->data[i] = arr_elem_conv;
4003                 }
4004                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
4005         }
4006         return (long)ret;
4007 }
4008 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1NodeAnnouncement_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4009         LDKCVecTempl_NodeAnnouncement *vec = (LDKCVecTempl_NodeAnnouncement*)ptr;
4010         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
4011         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
4012         for (size_t i = 0; i < vec->datalen; i++) {
4013                 CHECK((((long)vec->data[i].inner) & 1) == 0);
4014                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
4015         }
4016         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
4017         return ret;
4018 }
4019 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1NodeAnnouncement_1new(JNIEnv *env, jclass _b, jlongArray elems){
4020         LDKCVecTempl_NodeAnnouncement *ret = MALLOC(sizeof(LDKCVecTempl_NodeAnnouncement), "LDKCVecTempl_NodeAnnouncement");
4021         ret->datalen = (*env)->GetArrayLength(env, elems);
4022         if (ret->datalen == 0) {
4023                 ret->data = NULL;
4024         } else {
4025                 ret->data = MALLOC(sizeof(LDKNodeAnnouncement) * ret->datalen, "LDKCVecTempl_NodeAnnouncement Data");
4026                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
4027                 for (size_t i = 0; i < ret->datalen; i++) {
4028                         jlong arr_elem = java_elems[i];
4029                         LDKNodeAnnouncement arr_elem_conv;
4030                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
4031                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
4032                         if (arr_elem_conv.inner != NULL)
4033                                 arr_elem_conv = NodeAnnouncement_clone(&arr_elem_conv);
4034                         ret->data[i] = arr_elem_conv;
4035                 }
4036                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
4037         }
4038         return (long)ret;
4039 }
4040 typedef struct LDKRoutingMessageHandler_JCalls {
4041         atomic_size_t refcnt;
4042         JavaVM *vm;
4043         jweak o;
4044         jmethodID handle_node_announcement_meth;
4045         jmethodID handle_channel_announcement_meth;
4046         jmethodID handle_channel_update_meth;
4047         jmethodID handle_htlc_fail_channel_update_meth;
4048         jmethodID get_next_channel_announcements_meth;
4049         jmethodID get_next_node_announcements_meth;
4050         jmethodID should_request_full_sync_meth;
4051 } LDKRoutingMessageHandler_JCalls;
4052 LDKCResult_boolLightningErrorZ handle_node_announcement_jcall(const void* this_arg, const LDKNodeAnnouncement *msg) {
4053         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4054         JNIEnv *_env;
4055         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4056         LDKNodeAnnouncement msg_var = *msg;
4057         if (msg->inner != NULL)
4058                 msg_var = NodeAnnouncement_clone(msg);
4059         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4060         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4061         long msg_ref = (long)msg_var.inner;
4062         if (msg_var.is_owned) {
4063                 msg_ref |= 1;
4064         }
4065         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4066         CHECK(obj != NULL);
4067         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_node_announcement_meth, msg_ref);
4068         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
4069         FREE((void*)ret);
4070         return ret_conv;
4071 }
4072 LDKCResult_boolLightningErrorZ handle_channel_announcement_jcall(const void* this_arg, const LDKChannelAnnouncement *msg) {
4073         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4074         JNIEnv *_env;
4075         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4076         LDKChannelAnnouncement msg_var = *msg;
4077         if (msg->inner != NULL)
4078                 msg_var = ChannelAnnouncement_clone(msg);
4079         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4080         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4081         long msg_ref = (long)msg_var.inner;
4082         if (msg_var.is_owned) {
4083                 msg_ref |= 1;
4084         }
4085         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4086         CHECK(obj != NULL);
4087         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_channel_announcement_meth, msg_ref);
4088         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
4089         FREE((void*)ret);
4090         return ret_conv;
4091 }
4092 LDKCResult_boolLightningErrorZ handle_channel_update_jcall(const void* this_arg, const LDKChannelUpdate *msg) {
4093         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4094         JNIEnv *_env;
4095         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4096         LDKChannelUpdate msg_var = *msg;
4097         if (msg->inner != NULL)
4098                 msg_var = ChannelUpdate_clone(msg);
4099         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4100         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4101         long msg_ref = (long)msg_var.inner;
4102         if (msg_var.is_owned) {
4103                 msg_ref |= 1;
4104         }
4105         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4106         CHECK(obj != NULL);
4107         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_channel_update_meth, msg_ref);
4108         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
4109         FREE((void*)ret);
4110         return ret_conv;
4111 }
4112 void handle_htlc_fail_channel_update_jcall(const void* this_arg, const LDKHTLCFailChannelUpdate *update) {
4113         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4114         JNIEnv *_env;
4115         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4116         long ret_update = (long)update;
4117         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4118         CHECK(obj != NULL);
4119         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_htlc_fail_channel_update_meth, ret_update);
4120 }
4121 LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcements_jcall(const void* this_arg, uint64_t starting_point, uint8_t batch_amount) {
4122         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4123         JNIEnv *_env;
4124         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4125         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4126         CHECK(obj != NULL);
4127         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_next_channel_announcements_meth, starting_point, batch_amount);
4128         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ arg_constr;
4129         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4130         if (arg_constr.datalen > 0)
4131                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
4132         else
4133                 arg_constr.data = NULL;
4134         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4135         for (size_t l = 0; l < arg_constr.datalen; l++) {
4136                 long arr_conv_63 = arg_vals[l];
4137                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
4138                 FREE((void*)arr_conv_63);
4139                 arg_constr.data[l] = arr_conv_63_conv;
4140         }
4141         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4142         return arg_constr;
4143 }
4144 LDKCVec_NodeAnnouncementZ get_next_node_announcements_jcall(const void* this_arg, LDKPublicKey starting_point, uint8_t batch_amount) {
4145         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4146         JNIEnv *_env;
4147         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4148         jbyteArray starting_point_arr = (*_env)->NewByteArray(_env, 33);
4149         (*_env)->SetByteArrayRegion(_env, starting_point_arr, 0, 33, starting_point.compressed_form);
4150         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4151         CHECK(obj != NULL);
4152         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_next_node_announcements_meth, starting_point_arr, batch_amount);
4153         LDKCVec_NodeAnnouncementZ arg_constr;
4154         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4155         if (arg_constr.datalen > 0)
4156                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
4157         else
4158                 arg_constr.data = NULL;
4159         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4160         for (size_t s = 0; s < arg_constr.datalen; s++) {
4161                 long arr_conv_18 = arg_vals[s];
4162                 LDKNodeAnnouncement arr_conv_18_conv;
4163                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
4164                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
4165                 if (arr_conv_18_conv.inner != NULL)
4166                         arr_conv_18_conv = NodeAnnouncement_clone(&arr_conv_18_conv);
4167                 arg_constr.data[s] = arr_conv_18_conv;
4168         }
4169         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4170         return arg_constr;
4171 }
4172 bool should_request_full_sync_jcall(const void* this_arg, LDKPublicKey node_id) {
4173         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4174         JNIEnv *_env;
4175         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4176         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
4177         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, node_id.compressed_form);
4178         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4179         CHECK(obj != NULL);
4180         return (*_env)->CallBooleanMethod(_env, obj, j_calls->should_request_full_sync_meth, node_id_arr);
4181 }
4182 static void LDKRoutingMessageHandler_JCalls_free(void* this_arg) {
4183         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4184         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4185                 JNIEnv *env;
4186                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4187                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4188                 FREE(j_calls);
4189         }
4190 }
4191 static void* LDKRoutingMessageHandler_JCalls_clone(const void* this_arg) {
4192         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
4193         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4194         return (void*) this_arg;
4195 }
4196 static inline LDKRoutingMessageHandler LDKRoutingMessageHandler_init (JNIEnv * env, jclass _a, jobject o) {
4197         jclass c = (*env)->GetObjectClass(env, o);
4198         CHECK(c != NULL);
4199         LDKRoutingMessageHandler_JCalls *calls = MALLOC(sizeof(LDKRoutingMessageHandler_JCalls), "LDKRoutingMessageHandler_JCalls");
4200         atomic_init(&calls->refcnt, 1);
4201         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4202         calls->o = (*env)->NewWeakGlobalRef(env, o);
4203         calls->handle_node_announcement_meth = (*env)->GetMethodID(env, c, "handle_node_announcement", "(J)J");
4204         CHECK(calls->handle_node_announcement_meth != NULL);
4205         calls->handle_channel_announcement_meth = (*env)->GetMethodID(env, c, "handle_channel_announcement", "(J)J");
4206         CHECK(calls->handle_channel_announcement_meth != NULL);
4207         calls->handle_channel_update_meth = (*env)->GetMethodID(env, c, "handle_channel_update", "(J)J");
4208         CHECK(calls->handle_channel_update_meth != NULL);
4209         calls->handle_htlc_fail_channel_update_meth = (*env)->GetMethodID(env, c, "handle_htlc_fail_channel_update", "(J)V");
4210         CHECK(calls->handle_htlc_fail_channel_update_meth != NULL);
4211         calls->get_next_channel_announcements_meth = (*env)->GetMethodID(env, c, "get_next_channel_announcements", "(JB)[J");
4212         CHECK(calls->get_next_channel_announcements_meth != NULL);
4213         calls->get_next_node_announcements_meth = (*env)->GetMethodID(env, c, "get_next_node_announcements", "([BB)[J");
4214         CHECK(calls->get_next_node_announcements_meth != NULL);
4215         calls->should_request_full_sync_meth = (*env)->GetMethodID(env, c, "should_request_full_sync", "([B)Z");
4216         CHECK(calls->should_request_full_sync_meth != NULL);
4217
4218         LDKRoutingMessageHandler ret = {
4219                 .this_arg = (void*) calls,
4220                 .handle_node_announcement = handle_node_announcement_jcall,
4221                 .handle_channel_announcement = handle_channel_announcement_jcall,
4222                 .handle_channel_update = handle_channel_update_jcall,
4223                 .handle_htlc_fail_channel_update = handle_htlc_fail_channel_update_jcall,
4224                 .get_next_channel_announcements = get_next_channel_announcements_jcall,
4225                 .get_next_node_announcements = get_next_node_announcements_jcall,
4226                 .should_request_full_sync = should_request_full_sync_jcall,
4227                 .free = LDKRoutingMessageHandler_JCalls_free,
4228         };
4229         return ret;
4230 }
4231 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1new (JNIEnv * env, jclass _a, jobject o) {
4232         LDKRoutingMessageHandler *res_ptr = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
4233         *res_ptr = LDKRoutingMessageHandler_init(env, _a, o);
4234         return (long)res_ptr;
4235 }
4236 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4237         jobject ret = (*env)->NewLocalRef(env, ((LDKRoutingMessageHandler_JCalls*)val)->o);
4238         CHECK(ret != NULL);
4239         return ret;
4240 }
4241 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1node_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
4242         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4243         LDKNodeAnnouncement msg_conv;
4244         msg_conv.inner = (void*)(msg & (~1));
4245         msg_conv.is_owned = false;
4246         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4247         *ret_conv = (this_arg_conv->handle_node_announcement)(this_arg_conv->this_arg, &msg_conv);
4248         return (long)ret_conv;
4249 }
4250
4251 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
4252         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4253         LDKChannelAnnouncement msg_conv;
4254         msg_conv.inner = (void*)(msg & (~1));
4255         msg_conv.is_owned = false;
4256         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4257         *ret_conv = (this_arg_conv->handle_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
4258         return (long)ret_conv;
4259 }
4260
4261 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1update(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
4262         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4263         LDKChannelUpdate msg_conv;
4264         msg_conv.inner = (void*)(msg & (~1));
4265         msg_conv.is_owned = false;
4266         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4267         *ret_conv = (this_arg_conv->handle_channel_update)(this_arg_conv->this_arg, &msg_conv);
4268         return (long)ret_conv;
4269 }
4270
4271 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1htlc_1fail_1channel_1update(JNIEnv * _env, jclass _b, jlong this_arg, jlong update) {
4272         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4273         LDKHTLCFailChannelUpdate* update_conv = (LDKHTLCFailChannelUpdate*)update;
4274         (this_arg_conv->handle_htlc_fail_channel_update)(this_arg_conv->this_arg, update_conv);
4275 }
4276
4277 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) {
4278         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4279         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret_var = (this_arg_conv->get_next_channel_announcements)(this_arg_conv->this_arg, starting_point, batch_amount);
4280         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
4281         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
4282         for (size_t l = 0; l < ret_var.datalen; l++) {
4283                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* arr_conv_63_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
4284                 *arr_conv_63_ref = ret_var.data[l];
4285                 ret_arr_ptr[l] = (long)arr_conv_63_ref;
4286         }
4287         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
4288         CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(ret_var);
4289         return ret_arr;
4290 }
4291
4292 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) {
4293         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4294         LDKPublicKey starting_point_ref;
4295         CHECK((*_env)->GetArrayLength (_env, starting_point) == 33);
4296         (*_env)->GetByteArrayRegion (_env, starting_point, 0, 33, starting_point_ref.compressed_form);
4297         LDKCVec_NodeAnnouncementZ ret_var = (this_arg_conv->get_next_node_announcements)(this_arg_conv->this_arg, starting_point_ref, batch_amount);
4298         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
4299         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
4300         for (size_t s = 0; s < ret_var.datalen; s++) {
4301                 LDKNodeAnnouncement arr_conv_18_var = ret_var.data[s];
4302                 CHECK((((long)arr_conv_18_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4303                 CHECK((((long)&arr_conv_18_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4304                 long arr_conv_18_ref = (long)arr_conv_18_var.inner;
4305                 if (arr_conv_18_var.is_owned) {
4306                         arr_conv_18_ref |= 1;
4307                 }
4308                 ret_arr_ptr[s] = arr_conv_18_ref;
4309         }
4310         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
4311         FREE(ret_var.data);
4312         return ret_arr;
4313 }
4314
4315 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1should_1request_1full_1sync(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray node_id) {
4316         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
4317         LDKPublicKey node_id_ref;
4318         CHECK((*_env)->GetArrayLength (_env, node_id) == 33);
4319         (*_env)->GetByteArrayRegion (_env, node_id, 0, 33, node_id_ref.compressed_form);
4320         jboolean ret_val = (this_arg_conv->should_request_full_sync)(this_arg_conv->this_arg, node_id_ref);
4321         return ret_val;
4322 }
4323
4324 typedef struct LDKSocketDescriptor_JCalls {
4325         atomic_size_t refcnt;
4326         JavaVM *vm;
4327         jweak o;
4328         jmethodID send_data_meth;
4329         jmethodID disconnect_socket_meth;
4330         jmethodID eq_meth;
4331         jmethodID hash_meth;
4332 } LDKSocketDescriptor_JCalls;
4333 uintptr_t send_data_jcall(void* this_arg, LDKu8slice data, bool resume_read) {
4334         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4335         JNIEnv *_env;
4336         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4337         LDKu8slice data_var = data;
4338         jbyteArray data_arr = (*_env)->NewByteArray(_env, data_var.datalen);
4339         (*_env)->SetByteArrayRegion(_env, data_arr, 0, data_var.datalen, data_var.data);
4340         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4341         CHECK(obj != NULL);
4342         return (*_env)->CallLongMethod(_env, obj, j_calls->send_data_meth, data_arr, resume_read);
4343 }
4344 void disconnect_socket_jcall(void* this_arg) {
4345         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4346         JNIEnv *_env;
4347         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4348         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4349         CHECK(obj != NULL);
4350         return (*_env)->CallVoidMethod(_env, obj, j_calls->disconnect_socket_meth);
4351 }
4352 bool eq_jcall(const void* this_arg, const void *other_arg) {
4353         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4354         JNIEnv *_env;
4355         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4356         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4357         CHECK(obj != NULL);
4358         return (*_env)->CallBooleanMethod(_env, obj, j_calls->eq_meth, other_arg);
4359 }
4360 uint64_t hash_jcall(const void* this_arg) {
4361         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4362         JNIEnv *_env;
4363         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4364         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4365         CHECK(obj != NULL);
4366         return (*_env)->CallLongMethod(_env, obj, j_calls->hash_meth);
4367 }
4368 static void LDKSocketDescriptor_JCalls_free(void* this_arg) {
4369         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4370         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4371                 JNIEnv *env;
4372                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4373                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4374                 FREE(j_calls);
4375         }
4376 }
4377 static void* LDKSocketDescriptor_JCalls_clone(const void* this_arg) {
4378         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4379         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4380         return (void*) this_arg;
4381 }
4382 static inline LDKSocketDescriptor LDKSocketDescriptor_init (JNIEnv * env, jclass _a, jobject o) {
4383         jclass c = (*env)->GetObjectClass(env, o);
4384         CHECK(c != NULL);
4385         LDKSocketDescriptor_JCalls *calls = MALLOC(sizeof(LDKSocketDescriptor_JCalls), "LDKSocketDescriptor_JCalls");
4386         atomic_init(&calls->refcnt, 1);
4387         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4388         calls->o = (*env)->NewWeakGlobalRef(env, o);
4389         calls->send_data_meth = (*env)->GetMethodID(env, c, "send_data", "([BZ)J");
4390         CHECK(calls->send_data_meth != NULL);
4391         calls->disconnect_socket_meth = (*env)->GetMethodID(env, c, "disconnect_socket", "()V");
4392         CHECK(calls->disconnect_socket_meth != NULL);
4393         calls->eq_meth = (*env)->GetMethodID(env, c, "eq", "(J)Z");
4394         CHECK(calls->eq_meth != NULL);
4395         calls->hash_meth = (*env)->GetMethodID(env, c, "hash", "()J");
4396         CHECK(calls->hash_meth != NULL);
4397
4398         LDKSocketDescriptor ret = {
4399                 .this_arg = (void*) calls,
4400                 .send_data = send_data_jcall,
4401                 .disconnect_socket = disconnect_socket_jcall,
4402                 .eq = eq_jcall,
4403                 .hash = hash_jcall,
4404                 .clone = LDKSocketDescriptor_JCalls_clone,
4405                 .free = LDKSocketDescriptor_JCalls_free,
4406         };
4407         return ret;
4408 }
4409 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1new (JNIEnv * env, jclass _a, jobject o) {
4410         LDKSocketDescriptor *res_ptr = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
4411         *res_ptr = LDKSocketDescriptor_init(env, _a, o);
4412         return (long)res_ptr;
4413 }
4414 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4415         jobject ret = (*env)->NewLocalRef(env, ((LDKSocketDescriptor_JCalls*)val)->o);
4416         CHECK(ret != NULL);
4417         return ret;
4418 }
4419 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1send_1data(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray data, jboolean resume_read) {
4420         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4421         LDKu8slice data_ref;
4422         data_ref.datalen = (*_env)->GetArrayLength (_env, data);
4423         data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL);
4424         jlong ret_val = (this_arg_conv->send_data)(this_arg_conv->this_arg, data_ref, resume_read);
4425         (*_env)->ReleaseByteArrayElements(_env, data, (int8_t*)data_ref.data, 0);
4426         return ret_val;
4427 }
4428
4429 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1disconnect_1socket(JNIEnv * _env, jclass _b, jlong this_arg) {
4430         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4431         (this_arg_conv->disconnect_socket)(this_arg_conv->this_arg);
4432 }
4433
4434 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1hash(JNIEnv * _env, jclass _b, jlong this_arg) {
4435         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4436         jlong ret_val = (this_arg_conv->hash)(this_arg_conv->this_arg);
4437         return ret_val;
4438 }
4439
4440 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1PublicKey_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4441         LDKCVecTempl_PublicKey *vec = (LDKCVecTempl_PublicKey*)ptr;
4442         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKPublicKey));
4443 }
4444 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4445         return ((LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg)->result_ok;
4446 }
4447 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4448         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
4449         CHECK(val->result_ok);
4450         LDKCVecTempl_u8 res_var = (*val->contents.result);
4451         jbyteArray res_arr = (*_env)->NewByteArray(_env, res_var.datalen);
4452         (*_env)->SetByteArrayRegion(_env, res_arr, 0, res_var.datalen, res_var.data);
4453         return res_arr;
4454 }
4455 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4456         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
4457         CHECK(!val->result_ok);
4458         LDKPeerHandleError err_var = (*val->contents.err);
4459         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4460         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4461         long err_ref = (long)err_var.inner & ~1;
4462         return err_ref;
4463 }
4464 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4465         return ((LDKCResult_boolPeerHandleErrorZ*)arg)->result_ok;
4466 }
4467 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4468         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
4469         CHECK(val->result_ok);
4470         return *val->contents.result;
4471 }
4472 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4473         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
4474         CHECK(!val->result_ok);
4475         LDKPeerHandleError err_var = (*val->contents.err);
4476         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4477         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4478         long err_ref = (long)err_var.inner & ~1;
4479         return err_ref;
4480 }
4481 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4482         return ((LDKCResult_SecretKeySecpErrorZ*)arg)->result_ok;
4483 }
4484 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4485         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
4486         CHECK(val->result_ok);
4487         jbyteArray res_arr = (*_env)->NewByteArray(_env, 32);
4488         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 32, (*val->contents.result).bytes);
4489         return res_arr;
4490 }
4491 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4492         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
4493         CHECK(!val->result_ok);
4494         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
4495         return err_conv;
4496 }
4497 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4498         return ((LDKCResult_PublicKeySecpErrorZ*)arg)->result_ok;
4499 }
4500 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4501         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
4502         CHECK(val->result_ok);
4503         jbyteArray res_arr = (*_env)->NewByteArray(_env, 33);
4504         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 33, (*val->contents.result).compressed_form);
4505         return res_arr;
4506 }
4507 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4508         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
4509         CHECK(!val->result_ok);
4510         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
4511         return err_conv;
4512 }
4513 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4514         return ((LDKCResult_TxCreationKeysSecpErrorZ*)arg)->result_ok;
4515 }
4516 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4517         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
4518         CHECK(val->result_ok);
4519         LDKTxCreationKeys res_var = (*val->contents.result);
4520         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4521         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4522         long res_ref = (long)res_var.inner & ~1;
4523         return res_ref;
4524 }
4525 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4526         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
4527         CHECK(!val->result_ok);
4528         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
4529         return err_conv;
4530 }
4531 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1HTLCOutputInCommitment_1_1Signature_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4532         LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature *vec = (LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature*)ptr;
4533         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2TupleTempl_HTLCOutputInCommitment__Signature));
4534 }
4535 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1HTLCOutputInCommitment_1_1Signature_1new(JNIEnv *env, jclass _b, jlongArray elems){
4536         LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature *ret = MALLOC(sizeof(LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature), "LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature");
4537         ret->datalen = (*env)->GetArrayLength(env, elems);
4538         if (ret->datalen == 0) {
4539                 ret->data = NULL;
4540         } else {
4541                 ret->data = MALLOC(sizeof(LDKC2TupleTempl_HTLCOutputInCommitment__Signature) * ret->datalen, "LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature Data");
4542                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
4543                 for (size_t i = 0; i < ret->datalen; i++) {
4544                         jlong arr_elem = java_elems[i];
4545                         LDKC2TupleTempl_HTLCOutputInCommitment__Signature arr_elem_conv = *(LDKC2TupleTempl_HTLCOutputInCommitment__Signature*)arr_elem;
4546                         FREE((void*)arr_elem);
4547                         ret->data[i] = arr_elem_conv;
4548                 }
4549                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
4550         }
4551         return (long)ret;
4552 }
4553 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHop_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4554         LDKCVecTempl_RouteHop *vec = (LDKCVecTempl_RouteHop*)ptr;
4555         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
4556         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
4557         for (size_t i = 0; i < vec->datalen; i++) {
4558                 CHECK((((long)vec->data[i].inner) & 1) == 0);
4559                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
4560         }
4561         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
4562         return ret;
4563 }
4564 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHop_1new(JNIEnv *env, jclass _b, jlongArray elems){
4565         LDKCVecTempl_RouteHop *ret = MALLOC(sizeof(LDKCVecTempl_RouteHop), "LDKCVecTempl_RouteHop");
4566         ret->datalen = (*env)->GetArrayLength(env, elems);
4567         if (ret->datalen == 0) {
4568                 ret->data = NULL;
4569         } else {
4570                 ret->data = MALLOC(sizeof(LDKRouteHop) * ret->datalen, "LDKCVecTempl_RouteHop Data");
4571                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
4572                 for (size_t i = 0; i < ret->datalen; i++) {
4573                         jlong arr_elem = java_elems[i];
4574                         LDKRouteHop arr_elem_conv;
4575                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
4576                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
4577                         if (arr_elem_conv.inner != NULL)
4578                                 arr_elem_conv = RouteHop_clone(&arr_elem_conv);
4579                         ret->data[i] = arr_elem_conv;
4580                 }
4581                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
4582         }
4583         return (long)ret;
4584 }
4585 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1CVecTempl_1RouteHop_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4586         LDKCVecTempl_CVecTempl_RouteHop *vec = (LDKCVecTempl_CVecTempl_RouteHop*)ptr;
4587         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKCVecTempl_RouteHop));
4588 }
4589 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4590         return ((LDKCResult_RouteLightningErrorZ*)arg)->result_ok;
4591 }
4592 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4593         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
4594         CHECK(val->result_ok);
4595         LDKRoute res_var = (*val->contents.result);
4596         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4597         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4598         long res_ref = (long)res_var.inner & ~1;
4599         return res_ref;
4600 }
4601 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4602         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
4603         CHECK(!val->result_ok);
4604         LDKLightningError err_var = (*val->contents.err);
4605         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4606         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4607         long err_ref = (long)err_var.inner & ~1;
4608         return err_ref;
4609 }
4610 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHint_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4611         LDKCVecTempl_RouteHint *vec = (LDKCVecTempl_RouteHint*)ptr;
4612         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
4613         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
4614         for (size_t i = 0; i < vec->datalen; i++) {
4615                 CHECK((((long)vec->data[i].inner) & 1) == 0);
4616                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
4617         }
4618         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
4619         return ret;
4620 }
4621 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHint_1new(JNIEnv *env, jclass _b, jlongArray elems){
4622         LDKCVecTempl_RouteHint *ret = MALLOC(sizeof(LDKCVecTempl_RouteHint), "LDKCVecTempl_RouteHint");
4623         ret->datalen = (*env)->GetArrayLength(env, elems);
4624         if (ret->datalen == 0) {
4625                 ret->data = NULL;
4626         } else {
4627                 ret->data = MALLOC(sizeof(LDKRouteHint) * ret->datalen, "LDKCVecTempl_RouteHint Data");
4628                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
4629                 for (size_t i = 0; i < ret->datalen; i++) {
4630                         jlong arr_elem = java_elems[i];
4631                         LDKRouteHint arr_elem_conv;
4632                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
4633                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
4634                         if (arr_elem_conv.inner != NULL)
4635                                 arr_elem_conv = RouteHint_clone(&arr_elem_conv);
4636                         ret->data[i] = arr_elem_conv;
4637                 }
4638                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
4639         }
4640         return (long)ret;
4641 }
4642 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1HTLCOutputInCommitmentSignatureZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4643         LDKC2Tuple_HTLCOutputInCommitmentSignatureZ arg_conv = *(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ*)arg;
4644         FREE((void*)arg);
4645         C2Tuple_HTLCOutputInCommitmentSignatureZ_free(arg_conv);
4646 }
4647
4648 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4649         LDKC2Tuple_OutPointScriptZ arg_conv = *(LDKC2Tuple_OutPointScriptZ*)arg;
4650         FREE((void*)arg);
4651         C2Tuple_OutPointScriptZ_free(arg_conv);
4652 }
4653
4654 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4655         LDKC2Tuple_SignatureCVec_SignatureZZ arg_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)arg;
4656         FREE((void*)arg);
4657         C2Tuple_SignatureCVec_SignatureZZ_free(arg_conv);
4658 }
4659
4660 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1TxOutZZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4661         LDKC2Tuple_TxidCVec_TxOutZZ arg_conv = *(LDKC2Tuple_TxidCVec_TxOutZZ*)arg;
4662         FREE((void*)arg);
4663         C2Tuple_TxidCVec_TxOutZZ_free(arg_conv);
4664 }
4665
4666 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1free(JNIEnv * _env, jclass _b, jlong arg) {
4667         LDKC2Tuple_u64u64Z arg_conv = *(LDKC2Tuple_u64u64Z*)arg;
4668         FREE((void*)arg);
4669         C2Tuple_u64u64Z_free(arg_conv);
4670 }
4671
4672 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4673         LDKC2Tuple_usizeTransactionZ arg_conv = *(LDKC2Tuple_usizeTransactionZ*)arg;
4674         FREE((void*)arg);
4675         C2Tuple_usizeTransactionZ_free(arg_conv);
4676 }
4677
4678 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4679         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arg_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arg;
4680         FREE((void*)arg);
4681         C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(arg_conv);
4682 }
4683
4684 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4685         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ arg_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
4686         FREE((void*)arg);
4687         CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(arg_conv);
4688 }
4689
4690 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1ok(JNIEnv * _env, jclass _b, jlong arg) {
4691         LDKC2Tuple_SignatureCVec_SignatureZZ arg_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)arg;
4692         FREE((void*)arg);
4693         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
4694         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(arg_conv);
4695         return (long)ret_conv;
4696 }
4697
4698 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4699         LDKCResult_CVec_SignatureZNoneZ arg_conv = *(LDKCResult_CVec_SignatureZNoneZ*)arg;
4700         FREE((void*)arg);
4701         CResult_CVec_SignatureZNoneZ_free(arg_conv);
4702 }
4703
4704 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1ok(JNIEnv * _env, jclass _b, jobjectArray arg) {
4705         LDKCVec_SignatureZ arg_constr;
4706         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4707         if (arg_constr.datalen > 0)
4708                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
4709         else
4710                 arg_constr.data = NULL;
4711         for (size_t i = 0; i < arg_constr.datalen; i++) {
4712                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, arg, i);
4713                 LDKSignature arr_conv_8_ref;
4714                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
4715                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
4716                 arg_constr.data[i] = arr_conv_8_ref;
4717         }
4718         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
4719         *ret_conv = CResult_CVec_SignatureZNoneZ_ok(arg_constr);
4720         return (long)ret_conv;
4721 }
4722
4723 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4724         LDKPeerHandleError arg_conv = *(LDKPeerHandleError*)arg;
4725         FREE((void*)arg);
4726         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
4727         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_err(arg_conv);
4728         return (long)ret_conv;
4729 }
4730
4731 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4732         LDKCResult_CVec_u8ZPeerHandleErrorZ arg_conv = *(LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
4733         FREE((void*)arg);
4734         CResult_CVec_u8ZPeerHandleErrorZ_free(arg_conv);
4735 }
4736
4737 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) {
4738         LDKCVec_u8Z arg_ref;
4739         arg_ref.datalen = (*_env)->GetArrayLength (_env, arg);
4740         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
4741         (*_env)->GetByteArrayRegion(_env, arg, 0, arg_ref.datalen, arg_ref.data);
4742         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
4743         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_ok(arg_ref);
4744         return (long)ret_conv;
4745 }
4746
4747 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4748         LDKAPIError arg_conv = *(LDKAPIError*)arg;
4749         FREE((void*)arg);
4750         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
4751         *ret_conv = CResult_NoneAPIErrorZ_err(arg_conv);
4752         return (long)ret_conv;
4753 }
4754
4755 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4756         LDKCResult_NoneAPIErrorZ arg_conv = *(LDKCResult_NoneAPIErrorZ*)arg;
4757         FREE((void*)arg);
4758         CResult_NoneAPIErrorZ_free(arg_conv);
4759 }
4760
4761 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4762         LDKChannelMonitorUpdateErr arg_conv = *(LDKChannelMonitorUpdateErr*)arg;
4763         FREE((void*)arg);
4764         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4765         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_err(arg_conv);
4766         return (long)ret_conv;
4767 }
4768
4769 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4770         LDKCResult_NoneChannelMonitorUpdateErrZ arg_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
4771         FREE((void*)arg);
4772         CResult_NoneChannelMonitorUpdateErrZ_free(arg_conv);
4773 }
4774
4775 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4776         LDKMonitorUpdateError arg_conv = *(LDKMonitorUpdateError*)arg;
4777         FREE((void*)arg);
4778         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
4779         *ret_conv = CResult_NoneMonitorUpdateErrorZ_err(arg_conv);
4780         return (long)ret_conv;
4781 }
4782
4783 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4784         LDKCResult_NoneMonitorUpdateErrorZ arg_conv = *(LDKCResult_NoneMonitorUpdateErrorZ*)arg;
4785         FREE((void*)arg);
4786         CResult_NoneMonitorUpdateErrorZ_free(arg_conv);
4787 }
4788
4789 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4790         LDKPaymentSendFailure arg_conv = *(LDKPaymentSendFailure*)arg;
4791         FREE((void*)arg);
4792         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
4793         *ret_conv = CResult_NonePaymentSendFailureZ_err(arg_conv);
4794         return (long)ret_conv;
4795 }
4796
4797 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4798         LDKCResult_NonePaymentSendFailureZ arg_conv = *(LDKCResult_NonePaymentSendFailureZ*)arg;
4799         FREE((void*)arg);
4800         CResult_NonePaymentSendFailureZ_free(arg_conv);
4801 }
4802
4803 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4804         LDKPeerHandleError arg_conv = *(LDKPeerHandleError*)arg;
4805         FREE((void*)arg);
4806         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
4807         *ret_conv = CResult_NonePeerHandleErrorZ_err(arg_conv);
4808         return (long)ret_conv;
4809 }
4810
4811 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4812         LDKCResult_NonePeerHandleErrorZ arg_conv = *(LDKCResult_NonePeerHandleErrorZ*)arg;
4813         FREE((void*)arg);
4814         CResult_NonePeerHandleErrorZ_free(arg_conv);
4815 }
4816
4817 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4818         LDKSecp256k1Error arg_conv = *(LDKSecp256k1Error*)arg;
4819         FREE((void*)arg);
4820         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
4821         *ret_conv = CResult_PublicKeySecpErrorZ_err(arg_conv);
4822         return (long)ret_conv;
4823 }
4824
4825 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4826         LDKCResult_PublicKeySecpErrorZ arg_conv = *(LDKCResult_PublicKeySecpErrorZ*)arg;
4827         FREE((void*)arg);
4828         CResult_PublicKeySecpErrorZ_free(arg_conv);
4829 }
4830
4831 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) {
4832         LDKPublicKey arg_ref;
4833         CHECK((*_env)->GetArrayLength (_env, arg) == 33);
4834         (*_env)->GetByteArrayRegion (_env, arg, 0, 33, arg_ref.compressed_form);
4835         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
4836         *ret_conv = CResult_PublicKeySecpErrorZ_ok(arg_ref);
4837         return (long)ret_conv;
4838 }
4839
4840 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4841         LDKLightningError arg_conv = *(LDKLightningError*)arg;
4842         FREE((void*)arg);
4843         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
4844         *ret_conv = CResult_RouteLightningErrorZ_err(arg_conv);
4845         return (long)ret_conv;
4846 }
4847
4848 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4849         LDKCResult_RouteLightningErrorZ arg_conv = *(LDKCResult_RouteLightningErrorZ*)arg;
4850         FREE((void*)arg);
4851         CResult_RouteLightningErrorZ_free(arg_conv);
4852 }
4853
4854 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1ok(JNIEnv * _env, jclass _b, jlong arg) {
4855         LDKRoute arg_conv = *(LDKRoute*)arg;
4856         FREE((void*)arg);
4857         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
4858         *ret_conv = CResult_RouteLightningErrorZ_ok(arg_conv);
4859         return (long)ret_conv;
4860 }
4861
4862 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4863         LDKSecp256k1Error arg_conv = *(LDKSecp256k1Error*)arg;
4864         FREE((void*)arg);
4865         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
4866         *ret_conv = CResult_SecretKeySecpErrorZ_err(arg_conv);
4867         return (long)ret_conv;
4868 }
4869
4870 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4871         LDKCResult_SecretKeySecpErrorZ arg_conv = *(LDKCResult_SecretKeySecpErrorZ*)arg;
4872         FREE((void*)arg);
4873         CResult_SecretKeySecpErrorZ_free(arg_conv);
4874 }
4875
4876 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) {
4877         LDKSecretKey arg_ref;
4878         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
4879         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.bytes);
4880         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
4881         *ret_conv = CResult_SecretKeySecpErrorZ_ok(arg_ref);
4882         return (long)ret_conv;
4883 }
4884
4885 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4886         LDKCResult_SignatureNoneZ arg_conv = *(LDKCResult_SignatureNoneZ*)arg;
4887         FREE((void*)arg);
4888         CResult_SignatureNoneZ_free(arg_conv);
4889 }
4890
4891 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) {
4892         LDKSignature arg_ref;
4893         CHECK((*_env)->GetArrayLength (_env, arg) == 64);
4894         (*_env)->GetByteArrayRegion (_env, arg, 0, 64, arg_ref.compact_form);
4895         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
4896         *ret_conv = CResult_SignatureNoneZ_ok(arg_ref);
4897         return (long)ret_conv;
4898 }
4899
4900 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4901         LDKSecp256k1Error arg_conv = *(LDKSecp256k1Error*)arg;
4902         FREE((void*)arg);
4903         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
4904         *ret_conv = CResult_TxCreationKeysSecpErrorZ_err(arg_conv);
4905         return (long)ret_conv;
4906 }
4907
4908 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4909         LDKCResult_TxCreationKeysSecpErrorZ arg_conv = *(LDKCResult_TxCreationKeysSecpErrorZ*)arg;
4910         FREE((void*)arg);
4911         CResult_TxCreationKeysSecpErrorZ_free(arg_conv);
4912 }
4913
4914 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1ok(JNIEnv * _env, jclass _b, jlong arg) {
4915         LDKTxCreationKeys arg_conv = *(LDKTxCreationKeys*)arg;
4916         FREE((void*)arg);
4917         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
4918         *ret_conv = CResult_TxCreationKeysSecpErrorZ_ok(arg_conv);
4919         return (long)ret_conv;
4920 }
4921
4922 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4923         LDKAccessError arg_conv = *(LDKAccessError*)arg;
4924         FREE((void*)arg);
4925         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
4926         *ret_conv = CResult_TxOutAccessErrorZ_err(arg_conv);
4927         return (long)ret_conv;
4928 }
4929
4930 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4931         LDKCResult_TxOutAccessErrorZ arg_conv = *(LDKCResult_TxOutAccessErrorZ*)arg;
4932         FREE((void*)arg);
4933         CResult_TxOutAccessErrorZ_free(arg_conv);
4934 }
4935
4936 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1ok(JNIEnv * _env, jclass _b, jlong arg) {
4937         LDKTxOut arg_conv = *(LDKTxOut*)arg;
4938         FREE((void*)arg);
4939         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
4940         *ret_conv = CResult_TxOutAccessErrorZ_ok(arg_conv);
4941         return (long)ret_conv;
4942 }
4943
4944 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4945         LDKLightningError arg_conv = *(LDKLightningError*)arg;
4946         FREE((void*)arg);
4947         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4948         *ret_conv = CResult_boolLightningErrorZ_err(arg_conv);
4949         return (long)ret_conv;
4950 }
4951
4952 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4953         LDKCResult_boolLightningErrorZ arg_conv = *(LDKCResult_boolLightningErrorZ*)arg;
4954         FREE((void*)arg);
4955         CResult_boolLightningErrorZ_free(arg_conv);
4956 }
4957
4958 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1ok(JNIEnv * _env, jclass _b, jboolean arg) {
4959         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4960         *ret_conv = CResult_boolLightningErrorZ_ok(arg);
4961         return (long)ret_conv;
4962 }
4963
4964 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4965         LDKPeerHandleError arg_conv = *(LDKPeerHandleError*)arg;
4966         FREE((void*)arg);
4967         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
4968         *ret_conv = CResult_boolPeerHandleErrorZ_err(arg_conv);
4969         return (long)ret_conv;
4970 }
4971
4972 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4973         LDKCResult_boolPeerHandleErrorZ arg_conv = *(LDKCResult_boolPeerHandleErrorZ*)arg;
4974         FREE((void*)arg);
4975         CResult_boolPeerHandleErrorZ_free(arg_conv);
4976 }
4977
4978 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b, jboolean arg) {
4979         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
4980         *ret_conv = CResult_boolPeerHandleErrorZ_ok(arg);
4981         return (long)ret_conv;
4982 }
4983
4984 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1HTLCOutputInCommitmentSignatureZZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4985         LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ arg_constr;
4986         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4987         if (arg_constr.datalen > 0)
4988                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ), "LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ Elements");
4989         else
4990                 arg_constr.data = NULL;
4991         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4992         for (size_t q = 0; q < arg_constr.datalen; q++) {
4993                 long arr_conv_42 = arg_vals[q];
4994                 LDKC2Tuple_HTLCOutputInCommitmentSignatureZ arr_conv_42_conv = *(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ*)arr_conv_42;
4995                 FREE((void*)arr_conv_42);
4996                 arg_constr.data[q] = arr_conv_42_conv;
4997         }
4998         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4999         CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ_free(arg_constr);
5000 }
5001
5002 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1TxidCVec_1TxOutZZZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5003         LDKCVec_C2Tuple_TxidCVec_TxOutZZZ arg_constr;
5004         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5005         if (arg_constr.datalen > 0)
5006                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC2Tuple_TxidCVec_TxOutZZ), "LDKCVec_C2Tuple_TxidCVec_TxOutZZZ Elements");
5007         else
5008                 arg_constr.data = NULL;
5009         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5010         for (size_t b = 0; b < arg_constr.datalen; b++) {
5011                 long arr_conv_27 = arg_vals[b];
5012                 LDKC2Tuple_TxidCVec_TxOutZZ arr_conv_27_conv = *(LDKC2Tuple_TxidCVec_TxOutZZ*)arr_conv_27;
5013                 FREE((void*)arr_conv_27);
5014                 arg_constr.data[b] = arr_conv_27_conv;
5015         }
5016         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5017         CVec_C2Tuple_TxidCVec_TxOutZZZ_free(arg_constr);
5018 }
5019
5020 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1usizeTransactionZZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5021         LDKCVec_C2Tuple_usizeTransactionZZ arg_constr;
5022         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5023         if (arg_constr.datalen > 0)
5024                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
5025         else
5026                 arg_constr.data = NULL;
5027         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5028         for (size_t y = 0; y < arg_constr.datalen; y++) {
5029                 long arr_conv_24 = arg_vals[y];
5030                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
5031                 FREE((void*)arr_conv_24);
5032                 arg_constr.data[y] = arr_conv_24_conv;
5033         }
5034         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5035         CVec_C2Tuple_usizeTransactionZZ_free(arg_constr);
5036 }
5037
5038 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5039         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ 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(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
5043         else
5044                 arg_constr.data = NULL;
5045         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5046         for (size_t l = 0; l < arg_constr.datalen; l++) {
5047                 long arr_conv_63 = arg_vals[l];
5048                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
5049                 FREE((void*)arr_conv_63);
5050                 arg_constr.data[l] = arr_conv_63_conv;
5051         }
5052         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5053         CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(arg_constr);
5054 }
5055
5056 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1CVec_1RouteHopZZ_1free(JNIEnv * _env, jclass _b, jobjectArray arg) {
5057         LDKCVec_CVec_RouteHopZZ 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(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
5061         else
5062                 arg_constr.data = NULL;
5063         for (size_t m = 0; m < arg_constr.datalen; m++) {
5064                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, arg, m);
5065                 LDKCVec_RouteHopZ arr_conv_12_constr;
5066                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
5067                 if (arr_conv_12_constr.datalen > 0)
5068                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
5069                 else
5070                         arr_conv_12_constr.data = NULL;
5071                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
5072                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
5073                         long arr_conv_10 = arr_conv_12_vals[k];
5074                         LDKRouteHop arr_conv_10_conv;
5075                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
5076                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
5077                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
5078                 }
5079                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
5080                 arg_constr.data[m] = arr_conv_12_constr;
5081         }
5082         CVec_CVec_RouteHopZZ_free(arg_constr);
5083 }
5084
5085 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelDetailsZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5086         LDKCVec_ChannelDetailsZ arg_constr;
5087         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5088         if (arg_constr.datalen > 0)
5089                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
5090         else
5091                 arg_constr.data = NULL;
5092         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5093         for (size_t q = 0; q < arg_constr.datalen; q++) {
5094                 long arr_conv_16 = arg_vals[q];
5095                 LDKChannelDetails arr_conv_16_conv;
5096                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5097                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5098                 arg_constr.data[q] = arr_conv_16_conv;
5099         }
5100         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5101         CVec_ChannelDetailsZ_free(arg_constr);
5102 }
5103
5104 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelMonitorZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5105         LDKCVec_ChannelMonitorZ arg_constr;
5106         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5107         if (arg_constr.datalen > 0)
5108                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
5109         else
5110                 arg_constr.data = NULL;
5111         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5112         for (size_t q = 0; q < arg_constr.datalen; q++) {
5113                 long arr_conv_16 = arg_vals[q];
5114                 LDKChannelMonitor arr_conv_16_conv;
5115                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5116                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5117                 arg_constr.data[q] = arr_conv_16_conv;
5118         }
5119         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5120         CVec_ChannelMonitorZ_free(arg_constr);
5121 }
5122
5123 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1EventZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5124         LDKCVec_EventZ arg_constr;
5125         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5126         if (arg_constr.datalen > 0)
5127                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
5128         else
5129                 arg_constr.data = NULL;
5130         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5131         for (size_t h = 0; h < arg_constr.datalen; h++) {
5132                 long arr_conv_7 = arg_vals[h];
5133                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
5134                 FREE((void*)arr_conv_7);
5135                 arg_constr.data[h] = arr_conv_7_conv;
5136         }
5137         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5138         CVec_EventZ_free(arg_constr);
5139 }
5140
5141 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1HTLCOutputInCommitmentZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5142         LDKCVec_HTLCOutputInCommitmentZ arg_constr;
5143         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5144         if (arg_constr.datalen > 0)
5145                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKHTLCOutputInCommitment), "LDKCVec_HTLCOutputInCommitmentZ Elements");
5146         else
5147                 arg_constr.data = NULL;
5148         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5149         for (size_t y = 0; y < arg_constr.datalen; y++) {
5150                 long arr_conv_24 = arg_vals[y];
5151                 LDKHTLCOutputInCommitment arr_conv_24_conv;
5152                 arr_conv_24_conv.inner = (void*)(arr_conv_24 & (~1));
5153                 arr_conv_24_conv.is_owned = (arr_conv_24 & 1) || (arr_conv_24 == 0);
5154                 arg_constr.data[y] = arr_conv_24_conv;
5155         }
5156         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5157         CVec_HTLCOutputInCommitmentZ_free(arg_constr);
5158 }
5159
5160 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MessageSendEventZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5161         LDKCVec_MessageSendEventZ arg_constr;
5162         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5163         if (arg_constr.datalen > 0)
5164                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
5165         else
5166                 arg_constr.data = NULL;
5167         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5168         for (size_t s = 0; s < arg_constr.datalen; s++) {
5169                 long arr_conv_18 = arg_vals[s];
5170                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
5171                 FREE((void*)arr_conv_18);
5172                 arg_constr.data[s] = arr_conv_18_conv;
5173         }
5174         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5175         CVec_MessageSendEventZ_free(arg_constr);
5176 }
5177
5178 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MonitorEventZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5179         LDKCVec_MonitorEventZ arg_constr;
5180         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5181         if (arg_constr.datalen > 0)
5182                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
5183         else
5184                 arg_constr.data = NULL;
5185         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5186         for (size_t o = 0; o < arg_constr.datalen; o++) {
5187                 long arr_conv_14 = arg_vals[o];
5188                 LDKMonitorEvent arr_conv_14_conv;
5189                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
5190                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
5191                 arg_constr.data[o] = arr_conv_14_conv;
5192         }
5193         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5194         CVec_MonitorEventZ_free(arg_constr);
5195 }
5196
5197 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NetAddressZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5198         LDKCVec_NetAddressZ arg_constr;
5199         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5200         if (arg_constr.datalen > 0)
5201                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
5202         else
5203                 arg_constr.data = NULL;
5204         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5205         for (size_t m = 0; m < arg_constr.datalen; m++) {
5206                 long arr_conv_12 = arg_vals[m];
5207                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
5208                 FREE((void*)arr_conv_12);
5209                 arg_constr.data[m] = arr_conv_12_conv;
5210         }
5211         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5212         CVec_NetAddressZ_free(arg_constr);
5213 }
5214
5215 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NodeAnnouncementZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5216         LDKCVec_NodeAnnouncementZ arg_constr;
5217         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5218         if (arg_constr.datalen > 0)
5219                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
5220         else
5221                 arg_constr.data = NULL;
5222         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5223         for (size_t s = 0; s < arg_constr.datalen; s++) {
5224                 long arr_conv_18 = arg_vals[s];
5225                 LDKNodeAnnouncement arr_conv_18_conv;
5226                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
5227                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
5228                 arg_constr.data[s] = arr_conv_18_conv;
5229         }
5230         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5231         CVec_NodeAnnouncementZ_free(arg_constr);
5232 }
5233
5234 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1PublicKeyZ_1free(JNIEnv * _env, jclass _b, jobjectArray arg) {
5235         LDKCVec_PublicKeyZ arg_constr;
5236         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5237         if (arg_constr.datalen > 0)
5238                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKPublicKey), "LDKCVec_PublicKeyZ Elements");
5239         else
5240                 arg_constr.data = NULL;
5241         for (size_t i = 0; i < arg_constr.datalen; i++) {
5242                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, arg, i);
5243                 LDKPublicKey arr_conv_8_ref;
5244                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 33);
5245                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 33, arr_conv_8_ref.compressed_form);
5246                 arg_constr.data[i] = arr_conv_8_ref;
5247         }
5248         CVec_PublicKeyZ_free(arg_constr);
5249 }
5250
5251 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHintZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5252         LDKCVec_RouteHintZ arg_constr;
5253         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5254         if (arg_constr.datalen > 0)
5255                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
5256         else
5257                 arg_constr.data = NULL;
5258         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5259         for (size_t l = 0; l < arg_constr.datalen; l++) {
5260                 long arr_conv_11 = arg_vals[l];
5261                 LDKRouteHint arr_conv_11_conv;
5262                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
5263                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
5264                 arg_constr.data[l] = arr_conv_11_conv;
5265         }
5266         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5267         CVec_RouteHintZ_free(arg_constr);
5268 }
5269
5270 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHopZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5271         LDKCVec_RouteHopZ arg_constr;
5272         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5273         if (arg_constr.datalen > 0)
5274                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
5275         else
5276                 arg_constr.data = NULL;
5277         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5278         for (size_t k = 0; k < arg_constr.datalen; k++) {
5279                 long arr_conv_10 = arg_vals[k];
5280                 LDKRouteHop arr_conv_10_conv;
5281                 arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
5282                 arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
5283                 arg_constr.data[k] = arr_conv_10_conv;
5284         }
5285         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5286         CVec_RouteHopZ_free(arg_constr);
5287 }
5288
5289 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SignatureZ_1free(JNIEnv * _env, jclass _b, jobjectArray arg) {
5290         LDKCVec_SignatureZ arg_constr;
5291         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5292         if (arg_constr.datalen > 0)
5293                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
5294         else
5295                 arg_constr.data = NULL;
5296         for (size_t i = 0; i < arg_constr.datalen; i++) {
5297                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, arg, i);
5298                 LDKSignature arr_conv_8_ref;
5299                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
5300                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
5301                 arg_constr.data[i] = arr_conv_8_ref;
5302         }
5303         CVec_SignatureZ_free(arg_constr);
5304 }
5305
5306 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SpendableOutputDescriptorZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5307         LDKCVec_SpendableOutputDescriptorZ arg_constr;
5308         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5309         if (arg_constr.datalen > 0)
5310                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKSpendableOutputDescriptor), "LDKCVec_SpendableOutputDescriptorZ Elements");
5311         else
5312                 arg_constr.data = NULL;
5313         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5314         for (size_t b = 0; b < arg_constr.datalen; b++) {
5315                 long arr_conv_27 = arg_vals[b];
5316                 LDKSpendableOutputDescriptor arr_conv_27_conv = *(LDKSpendableOutputDescriptor*)arr_conv_27;
5317                 FREE((void*)arr_conv_27);
5318                 arg_constr.data[b] = arr_conv_27_conv;
5319         }
5320         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5321         CVec_SpendableOutputDescriptorZ_free(arg_constr);
5322 }
5323
5324 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TransactionZ_1free(JNIEnv * _env, jclass _b, jobjectArray arg) {
5325         LDKCVec_TransactionZ arg_constr;
5326         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5327         if (arg_constr.datalen > 0)
5328                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKTransaction), "LDKCVec_TransactionZ Elements");
5329         else
5330                 arg_constr.data = NULL;
5331         for (size_t i = 0; i < arg_constr.datalen; i++) {
5332                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, arg, i);
5333                 LDKTransaction arr_conv_8_ref;
5334                 arr_conv_8_ref.datalen = (*_env)->GetArrayLength (_env, arr_conv_8);
5335                 arr_conv_8_ref.data = MALLOC(arr_conv_8_ref.datalen, "LDKTransaction Bytes");
5336                 (*_env)->GetByteArrayRegion(_env, arr_conv_8, 0, arr_conv_8_ref.datalen, arr_conv_8_ref.data);
5337                 arr_conv_8_ref.data_is_owned = true;
5338                 arg_constr.data[i] = arr_conv_8_ref;
5339         }
5340         CVec_TransactionZ_free(arg_constr);
5341 }
5342
5343 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TxOutZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5344         LDKCVec_TxOutZ arg_constr;
5345         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5346         if (arg_constr.datalen > 0)
5347                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKTxOut), "LDKCVec_TxOutZ Elements");
5348         else
5349                 arg_constr.data = NULL;
5350         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5351         for (size_t h = 0; h < arg_constr.datalen; h++) {
5352                 long arr_conv_7 = arg_vals[h];
5353                 LDKTxOut arr_conv_7_conv = *(LDKTxOut*)arr_conv_7;
5354                 FREE((void*)arr_conv_7);
5355                 arg_constr.data[h] = arr_conv_7_conv;
5356         }
5357         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5358         CVec_TxOutZ_free(arg_constr);
5359 }
5360
5361 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateAddHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5362         LDKCVec_UpdateAddHTLCZ arg_constr;
5363         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5364         if (arg_constr.datalen > 0)
5365                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
5366         else
5367                 arg_constr.data = NULL;
5368         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5369         for (size_t p = 0; p < arg_constr.datalen; p++) {
5370                 long arr_conv_15 = arg_vals[p];
5371                 LDKUpdateAddHTLC arr_conv_15_conv;
5372                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
5373                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
5374                 arg_constr.data[p] = arr_conv_15_conv;
5375         }
5376         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5377         CVec_UpdateAddHTLCZ_free(arg_constr);
5378 }
5379
5380 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5381         LDKCVec_UpdateFailHTLCZ arg_constr;
5382         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5383         if (arg_constr.datalen > 0)
5384                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
5385         else
5386                 arg_constr.data = NULL;
5387         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5388         for (size_t q = 0; q < arg_constr.datalen; q++) {
5389                 long arr_conv_16 = arg_vals[q];
5390                 LDKUpdateFailHTLC arr_conv_16_conv;
5391                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5392                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5393                 arg_constr.data[q] = arr_conv_16_conv;
5394         }
5395         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5396         CVec_UpdateFailHTLCZ_free(arg_constr);
5397 }
5398
5399 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailMalformedHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5400         LDKCVec_UpdateFailMalformedHTLCZ arg_constr;
5401         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5402         if (arg_constr.datalen > 0)
5403                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
5404         else
5405                 arg_constr.data = NULL;
5406         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5407         for (size_t z = 0; z < arg_constr.datalen; z++) {
5408                 long arr_conv_25 = arg_vals[z];
5409                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
5410                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
5411                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
5412                 arg_constr.data[z] = arr_conv_25_conv;
5413         }
5414         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5415         CVec_UpdateFailMalformedHTLCZ_free(arg_constr);
5416 }
5417
5418 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFulfillHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5419         LDKCVec_UpdateFulfillHTLCZ arg_constr;
5420         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5421         if (arg_constr.datalen > 0)
5422                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
5423         else
5424                 arg_constr.data = NULL;
5425         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5426         for (size_t t = 0; t < arg_constr.datalen; t++) {
5427                 long arr_conv_19 = arg_vals[t];
5428                 LDKUpdateFulfillHTLC arr_conv_19_conv;
5429                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
5430                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
5431                 arg_constr.data[t] = arr_conv_19_conv;
5432         }
5433         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5434         CVec_UpdateFulfillHTLCZ_free(arg_constr);
5435 }
5436
5437 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u64Z_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5438         LDKCVec_u64Z arg_constr;
5439         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5440         if (arg_constr.datalen > 0)
5441                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
5442         else
5443                 arg_constr.data = NULL;
5444         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5445         for (size_t g = 0; g < arg_constr.datalen; g++) {
5446                 long arr_conv_6 = arg_vals[g];
5447                 arg_constr.data[g] = arr_conv_6;
5448         }
5449         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5450         CVec_u64Z_free(arg_constr);
5451 }
5452
5453 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u8Z_1free(JNIEnv * _env, jclass _b, jbyteArray arg) {
5454         LDKCVec_u8Z arg_ref;
5455         arg_ref.datalen = (*_env)->GetArrayLength (_env, arg);
5456         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
5457         (*_env)->GetByteArrayRegion(_env, arg, 0, arg_ref.datalen, arg_ref.data);
5458         CVec_u8Z_free(arg_ref);
5459 }
5460
5461 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Transaction_1free(JNIEnv * _env, jclass _b, jbyteArray _res) {
5462         LDKTransaction _res_ref;
5463         _res_ref.datalen = (*_env)->GetArrayLength (_env, _res);
5464         _res_ref.data = MALLOC(_res_ref.datalen, "LDKTransaction Bytes");
5465         (*_env)->GetByteArrayRegion(_env, _res, 0, _res_ref.datalen, _res_ref.data);
5466         _res_ref.data_is_owned = true;
5467         Transaction_free(_res_ref);
5468 }
5469
5470 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxOut_1free(JNIEnv * _env, jclass _b, jlong _res) {
5471         LDKTxOut _res_conv = *(LDKTxOut*)_res;
5472         FREE((void*)_res);
5473         TxOut_free(_res_conv);
5474 }
5475
5476 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1new(JNIEnv * _env, jclass _b, jlong a, jbyteArray b) {
5477         LDKTransaction b_ref;
5478         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
5479         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
5480         (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data);
5481         b_ref.data_is_owned = true;
5482         LDKC2Tuple_usizeTransactionZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
5483         *ret_ref = C2Tuple_usizeTransactionZ_new(a, b_ref);
5484         return (long)ret_ref;
5485 }
5486
5487 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1ok(JNIEnv * _env, jclass _b) {
5488         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
5489         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_ok();
5490         return (long)ret_conv;
5491 }
5492
5493 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1ok(JNIEnv * _env, jclass _b) {
5494         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
5495         *ret_conv = CResult_NoneMonitorUpdateErrorZ_ok();
5496         return (long)ret_conv;
5497 }
5498
5499 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1new(JNIEnv * _env, jclass _b, jlong a, jbyteArray b) {
5500         LDKOutPoint a_conv;
5501         a_conv.inner = (void*)(a & (~1));
5502         a_conv.is_owned = (a & 1) || (a == 0);
5503         if (a_conv.inner != NULL)
5504                 a_conv = OutPoint_clone(&a_conv);
5505         LDKCVec_u8Z b_ref;
5506         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
5507         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
5508         (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data);
5509         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
5510         *ret_ref = C2Tuple_OutPointScriptZ_new(a_conv, b_ref);
5511         return (long)ret_ref;
5512 }
5513
5514 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1TxOutZZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jlongArray b) {
5515         LDKThirtyTwoBytes a_ref;
5516         CHECK((*_env)->GetArrayLength (_env, a) == 32);
5517         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
5518         LDKCVec_TxOutZ b_constr;
5519         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
5520         if (b_constr.datalen > 0)
5521                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKTxOut), "LDKCVec_TxOutZ Elements");
5522         else
5523                 b_constr.data = NULL;
5524         long* b_vals = (*_env)->GetLongArrayElements (_env, b, NULL);
5525         for (size_t h = 0; h < b_constr.datalen; h++) {
5526                 long arr_conv_7 = b_vals[h];
5527                 LDKTxOut arr_conv_7_conv = *(LDKTxOut*)arr_conv_7;
5528                 FREE((void*)arr_conv_7);
5529                 b_constr.data[h] = arr_conv_7_conv;
5530         }
5531         (*_env)->ReleaseLongArrayElements (_env, b, b_vals, 0);
5532         LDKC2Tuple_TxidCVec_TxOutZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_TxOutZZ), "LDKC2Tuple_TxidCVec_TxOutZZ");
5533         *ret_ref = C2Tuple_TxidCVec_TxOutZZ_new(a_ref, b_constr);
5534         return (long)ret_ref;
5535 }
5536
5537 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1new(JNIEnv * _env, jclass _b, jlong a, jlong b) {
5538         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
5539         *ret_ref = C2Tuple_u64u64Z_new(a, b);
5540         return (long)ret_ref;
5541 }
5542
5543 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jobjectArray b) {
5544         LDKSignature a_ref;
5545         CHECK((*_env)->GetArrayLength (_env, a) == 64);
5546         (*_env)->GetByteArrayRegion (_env, a, 0, 64, a_ref.compact_form);
5547         LDKCVec_SignatureZ b_constr;
5548         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
5549         if (b_constr.datalen > 0)
5550                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
5551         else
5552                 b_constr.data = NULL;
5553         for (size_t i = 0; i < b_constr.datalen; i++) {
5554                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, b, i);
5555                 LDKSignature arr_conv_8_ref;
5556                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
5557                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
5558                 b_constr.data[i] = arr_conv_8_ref;
5559         }
5560         LDKC2Tuple_SignatureCVec_SignatureZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
5561         *ret_ref = C2Tuple_SignatureCVec_SignatureZZ_new(a_ref, b_constr);
5562         return (long)ret_ref;
5563 }
5564
5565 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1err(JNIEnv * _env, jclass _b) {
5566         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
5567         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err();
5568         return (long)ret_conv;
5569 }
5570
5571 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1err(JNIEnv * _env, jclass _b) {
5572         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
5573         *ret_conv = CResult_SignatureNoneZ_err();
5574         return (long)ret_conv;
5575 }
5576
5577 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1err(JNIEnv * _env, jclass _b) {
5578         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
5579         *ret_conv = CResult_CVec_SignatureZNoneZ_err();
5580         return (long)ret_conv;
5581 }
5582
5583 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1ok(JNIEnv * _env, jclass _b) {
5584         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
5585         *ret_conv = CResult_NoneAPIErrorZ_ok();
5586         return (long)ret_conv;
5587 }
5588
5589 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1ok(JNIEnv * _env, jclass _b) {
5590         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
5591         *ret_conv = CResult_NonePaymentSendFailureZ_ok();
5592         return (long)ret_conv;
5593 }
5594
5595 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1new(JNIEnv * _env, jclass _b, jlong a, jlong b, jlong c) {
5596         LDKChannelAnnouncement a_conv;
5597         a_conv.inner = (void*)(a & (~1));
5598         a_conv.is_owned = (a & 1) || (a == 0);
5599         if (a_conv.inner != NULL)
5600                 a_conv = ChannelAnnouncement_clone(&a_conv);
5601         LDKChannelUpdate b_conv;
5602         b_conv.inner = (void*)(b & (~1));
5603         b_conv.is_owned = (b & 1) || (b == 0);
5604         if (b_conv.inner != NULL)
5605                 b_conv = ChannelUpdate_clone(&b_conv);
5606         LDKChannelUpdate c_conv;
5607         c_conv.inner = (void*)(c & (~1));
5608         c_conv.is_owned = (c & 1) || (c == 0);
5609         if (c_conv.inner != NULL)
5610                 c_conv = ChannelUpdate_clone(&c_conv);
5611         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
5612         *ret_ref = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(a_conv, b_conv, c_conv);
5613         return (long)ret_ref;
5614 }
5615
5616 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b) {
5617         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
5618         *ret_conv = CResult_NonePeerHandleErrorZ_ok();
5619         return (long)ret_conv;
5620 }
5621
5622 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1HTLCOutputInCommitmentSignatureZ_1new(JNIEnv * _env, jclass _b, jlong a, jbyteArray b) {
5623         LDKHTLCOutputInCommitment a_conv;
5624         a_conv.inner = (void*)(a & (~1));
5625         a_conv.is_owned = (a & 1) || (a == 0);
5626         if (a_conv.inner != NULL)
5627                 a_conv = HTLCOutputInCommitment_clone(&a_conv);
5628         LDKSignature b_ref;
5629         CHECK((*_env)->GetArrayLength (_env, b) == 64);
5630         (*_env)->GetByteArrayRegion (_env, b, 0, 64, b_ref.compact_form);
5631         LDKC2Tuple_HTLCOutputInCommitmentSignatureZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ), "LDKC2Tuple_HTLCOutputInCommitmentSignatureZ");
5632         *ret_ref = C2Tuple_HTLCOutputInCommitmentSignatureZ_new(a_conv, b_ref);
5633         return (long)ret_ref;
5634 }
5635
5636 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Event_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5637         LDKEvent this_ptr_conv = *(LDKEvent*)this_ptr;
5638         FREE((void*)this_ptr);
5639         Event_free(this_ptr_conv);
5640 }
5641
5642 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Event_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5643         LDKEvent* orig_conv = (LDKEvent*)orig;
5644         LDKEvent *ret_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
5645         *ret_copy = Event_clone(orig_conv);
5646         long ret_ref = (long)ret_copy;
5647         return ret_ref;
5648 }
5649
5650 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5651         LDKMessageSendEvent this_ptr_conv = *(LDKMessageSendEvent*)this_ptr;
5652         FREE((void*)this_ptr);
5653         MessageSendEvent_free(this_ptr_conv);
5654 }
5655
5656 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5657         LDKMessageSendEvent* orig_conv = (LDKMessageSendEvent*)orig;
5658         LDKMessageSendEvent *ret_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
5659         *ret_copy = MessageSendEvent_clone(orig_conv);
5660         long ret_ref = (long)ret_copy;
5661         return ret_ref;
5662 }
5663
5664 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5665         LDKMessageSendEventsProvider this_ptr_conv = *(LDKMessageSendEventsProvider*)this_ptr;
5666         FREE((void*)this_ptr);
5667         MessageSendEventsProvider_free(this_ptr_conv);
5668 }
5669
5670 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_EventsProvider_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5671         LDKEventsProvider this_ptr_conv = *(LDKEventsProvider*)this_ptr;
5672         FREE((void*)this_ptr);
5673         EventsProvider_free(this_ptr_conv);
5674 }
5675
5676 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_APIError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5677         LDKAPIError this_ptr_conv = *(LDKAPIError*)this_ptr;
5678         FREE((void*)this_ptr);
5679         APIError_free(this_ptr_conv);
5680 }
5681
5682 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_APIError_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5683         LDKAPIError* orig_conv = (LDKAPIError*)orig;
5684         LDKAPIError *ret_copy = MALLOC(sizeof(LDKAPIError), "LDKAPIError");
5685         *ret_copy = APIError_clone(orig_conv);
5686         long ret_ref = (long)ret_copy;
5687         return ret_ref;
5688 }
5689
5690 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5691         LDKLevel* orig_conv = (LDKLevel*)orig;
5692         jclass ret_conv = LDKLevel_to_java(_env, Level_clone(orig_conv));
5693         return ret_conv;
5694 }
5695
5696 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1max(JNIEnv * _env, jclass _b) {
5697         jclass ret_conv = LDKLevel_to_java(_env, Level_max());
5698         return ret_conv;
5699 }
5700
5701 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Logger_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5702         LDKLogger this_ptr_conv = *(LDKLogger*)this_ptr;
5703         FREE((void*)this_ptr);
5704         Logger_free(this_ptr_conv);
5705 }
5706
5707 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5708         LDKChannelHandshakeConfig 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         ChannelHandshakeConfig_free(this_ptr_conv);
5712 }
5713
5714 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5715         LDKChannelHandshakeConfig orig_conv;
5716         orig_conv.inner = (void*)(orig & (~1));
5717         orig_conv.is_owned = false;
5718         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_clone(&orig_conv);
5719         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5720         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5721         long ret_ref = (long)ret_var.inner;
5722         if (ret_var.is_owned) {
5723                 ret_ref |= 1;
5724         }
5725         return ret_ref;
5726 }
5727
5728 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
5729         LDKChannelHandshakeConfig this_ptr_conv;
5730         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5731         this_ptr_conv.is_owned = false;
5732         jint ret_val = ChannelHandshakeConfig_get_minimum_depth(&this_ptr_conv);
5733         return ret_val;
5734 }
5735
5736 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
5737         LDKChannelHandshakeConfig this_ptr_conv;
5738         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5739         this_ptr_conv.is_owned = false;
5740         ChannelHandshakeConfig_set_minimum_depth(&this_ptr_conv, val);
5741 }
5742
5743 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
5744         LDKChannelHandshakeConfig this_ptr_conv;
5745         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5746         this_ptr_conv.is_owned = false;
5747         jshort ret_val = ChannelHandshakeConfig_get_our_to_self_delay(&this_ptr_conv);
5748         return ret_val;
5749 }
5750
5751 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1our_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
5752         LDKChannelHandshakeConfig this_ptr_conv;
5753         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5754         this_ptr_conv.is_owned = false;
5755         ChannelHandshakeConfig_set_our_to_self_delay(&this_ptr_conv, val);
5756 }
5757
5758 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
5759         LDKChannelHandshakeConfig this_ptr_conv;
5760         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5761         this_ptr_conv.is_owned = false;
5762         jlong ret_val = ChannelHandshakeConfig_get_our_htlc_minimum_msat(&this_ptr_conv);
5763         return ret_val;
5764 }
5765
5766 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1our_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5767         LDKChannelHandshakeConfig this_ptr_conv;
5768         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5769         this_ptr_conv.is_owned = false;
5770         ChannelHandshakeConfig_set_our_htlc_minimum_msat(&this_ptr_conv, val);
5771 }
5772
5773 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) {
5774         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_new(minimum_depth_arg, our_to_self_delay_arg, our_htlc_minimum_msat_arg);
5775         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5776         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5777         long ret_ref = (long)ret_var.inner;
5778         if (ret_var.is_owned) {
5779                 ret_ref |= 1;
5780         }
5781         return ret_ref;
5782 }
5783
5784 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1default(JNIEnv * _env, jclass _b) {
5785         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_default();
5786         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5787         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5788         long ret_ref = (long)ret_var.inner;
5789         if (ret_var.is_owned) {
5790                 ret_ref |= 1;
5791         }
5792         return ret_ref;
5793 }
5794
5795 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5796         LDKChannelHandshakeLimits this_ptr_conv;
5797         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5798         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5799         ChannelHandshakeLimits_free(this_ptr_conv);
5800 }
5801
5802 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5803         LDKChannelHandshakeLimits orig_conv;
5804         orig_conv.inner = (void*)(orig & (~1));
5805         orig_conv.is_owned = false;
5806         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_clone(&orig_conv);
5807         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5808         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5809         long ret_ref = (long)ret_var.inner;
5810         if (ret_var.is_owned) {
5811                 ret_ref |= 1;
5812         }
5813         return ret_ref;
5814 }
5815
5816 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
5817         LDKChannelHandshakeLimits this_ptr_conv;
5818         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5819         this_ptr_conv.is_owned = false;
5820         jlong ret_val = ChannelHandshakeLimits_get_min_funding_satoshis(&this_ptr_conv);
5821         return ret_val;
5822 }
5823
5824 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5825         LDKChannelHandshakeLimits this_ptr_conv;
5826         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5827         this_ptr_conv.is_owned = false;
5828         ChannelHandshakeLimits_set_min_funding_satoshis(&this_ptr_conv, val);
5829 }
5830
5831 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
5832         LDKChannelHandshakeLimits this_ptr_conv;
5833         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5834         this_ptr_conv.is_owned = false;
5835         jlong ret_val = ChannelHandshakeLimits_get_max_htlc_minimum_msat(&this_ptr_conv);
5836         return ret_val;
5837 }
5838
5839 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5840         LDKChannelHandshakeLimits this_ptr_conv;
5841         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5842         this_ptr_conv.is_owned = false;
5843         ChannelHandshakeLimits_set_max_htlc_minimum_msat(&this_ptr_conv, val);
5844 }
5845
5846 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
5847         LDKChannelHandshakeLimits this_ptr_conv;
5848         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5849         this_ptr_conv.is_owned = false;
5850         jlong ret_val = ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(&this_ptr_conv);
5851         return ret_val;
5852 }
5853
5854 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) {
5855         LDKChannelHandshakeLimits this_ptr_conv;
5856         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5857         this_ptr_conv.is_owned = false;
5858         ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
5859 }
5860
5861 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
5862         LDKChannelHandshakeLimits this_ptr_conv;
5863         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5864         this_ptr_conv.is_owned = false;
5865         jlong ret_val = ChannelHandshakeLimits_get_max_channel_reserve_satoshis(&this_ptr_conv);
5866         return ret_val;
5867 }
5868
5869 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5870         LDKChannelHandshakeLimits this_ptr_conv;
5871         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5872         this_ptr_conv.is_owned = false;
5873         ChannelHandshakeLimits_set_max_channel_reserve_satoshis(&this_ptr_conv, val);
5874 }
5875
5876 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
5877         LDKChannelHandshakeLimits this_ptr_conv;
5878         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5879         this_ptr_conv.is_owned = false;
5880         jshort ret_val = ChannelHandshakeLimits_get_min_max_accepted_htlcs(&this_ptr_conv);
5881         return ret_val;
5882 }
5883
5884 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
5885         LDKChannelHandshakeLimits this_ptr_conv;
5886         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5887         this_ptr_conv.is_owned = false;
5888         ChannelHandshakeLimits_set_min_max_accepted_htlcs(&this_ptr_conv, val);
5889 }
5890
5891 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
5892         LDKChannelHandshakeLimits this_ptr_conv;
5893         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5894         this_ptr_conv.is_owned = false;
5895         jlong ret_val = ChannelHandshakeLimits_get_min_dust_limit_satoshis(&this_ptr_conv);
5896         return ret_val;
5897 }
5898
5899 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5900         LDKChannelHandshakeLimits this_ptr_conv;
5901         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5902         this_ptr_conv.is_owned = false;
5903         ChannelHandshakeLimits_set_min_dust_limit_satoshis(&this_ptr_conv, val);
5904 }
5905
5906 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
5907         LDKChannelHandshakeLimits this_ptr_conv;
5908         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5909         this_ptr_conv.is_owned = false;
5910         jlong ret_val = ChannelHandshakeLimits_get_max_dust_limit_satoshis(&this_ptr_conv);
5911         return ret_val;
5912 }
5913
5914 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5915         LDKChannelHandshakeLimits this_ptr_conv;
5916         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5917         this_ptr_conv.is_owned = false;
5918         ChannelHandshakeLimits_set_max_dust_limit_satoshis(&this_ptr_conv, val);
5919 }
5920
5921 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
5922         LDKChannelHandshakeLimits this_ptr_conv;
5923         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5924         this_ptr_conv.is_owned = false;
5925         jint ret_val = ChannelHandshakeLimits_get_max_minimum_depth(&this_ptr_conv);
5926         return ret_val;
5927 }
5928
5929 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
5930         LDKChannelHandshakeLimits this_ptr_conv;
5931         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5932         this_ptr_conv.is_owned = false;
5933         ChannelHandshakeLimits_set_max_minimum_depth(&this_ptr_conv, val);
5934 }
5935
5936 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1force_1announced_1channel_1preference(JNIEnv * _env, jclass _b, jlong this_ptr) {
5937         LDKChannelHandshakeLimits this_ptr_conv;
5938         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5939         this_ptr_conv.is_owned = false;
5940         jboolean ret_val = ChannelHandshakeLimits_get_force_announced_channel_preference(&this_ptr_conv);
5941         return ret_val;
5942 }
5943
5944 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1force_1announced_1channel_1preference(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
5945         LDKChannelHandshakeLimits this_ptr_conv;
5946         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5947         this_ptr_conv.is_owned = false;
5948         ChannelHandshakeLimits_set_force_announced_channel_preference(&this_ptr_conv, val);
5949 }
5950
5951 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1their_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
5952         LDKChannelHandshakeLimits this_ptr_conv;
5953         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5954         this_ptr_conv.is_owned = false;
5955         jshort ret_val = ChannelHandshakeLimits_get_their_to_self_delay(&this_ptr_conv);
5956         return ret_val;
5957 }
5958
5959 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1their_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
5960         LDKChannelHandshakeLimits this_ptr_conv;
5961         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5962         this_ptr_conv.is_owned = false;
5963         ChannelHandshakeLimits_set_their_to_self_delay(&this_ptr_conv, val);
5964 }
5965
5966 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) {
5967         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);
5968         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5969         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5970         long ret_ref = (long)ret_var.inner;
5971         if (ret_var.is_owned) {
5972                 ret_ref |= 1;
5973         }
5974         return ret_ref;
5975 }
5976
5977 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1default(JNIEnv * _env, jclass _b) {
5978         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_default();
5979         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5980         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5981         long ret_ref = (long)ret_var.inner;
5982         if (ret_var.is_owned) {
5983                 ret_ref |= 1;
5984         }
5985         return ret_ref;
5986 }
5987
5988 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5989         LDKChannelConfig this_ptr_conv;
5990         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5991         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5992         ChannelConfig_free(this_ptr_conv);
5993 }
5994
5995 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5996         LDKChannelConfig orig_conv;
5997         orig_conv.inner = (void*)(orig & (~1));
5998         orig_conv.is_owned = false;
5999         LDKChannelConfig ret_var = ChannelConfig_clone(&orig_conv);
6000         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6001         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6002         long ret_ref = (long)ret_var.inner;
6003         if (ret_var.is_owned) {
6004                 ret_ref |= 1;
6005         }
6006         return ret_ref;
6007 }
6008
6009 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
6010         LDKChannelConfig this_ptr_conv;
6011         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6012         this_ptr_conv.is_owned = false;
6013         jint ret_val = ChannelConfig_get_fee_proportional_millionths(&this_ptr_conv);
6014         return ret_val;
6015 }
6016
6017 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
6018         LDKChannelConfig this_ptr_conv;
6019         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6020         this_ptr_conv.is_owned = false;
6021         ChannelConfig_set_fee_proportional_millionths(&this_ptr_conv, val);
6022 }
6023
6024 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1announced_1channel(JNIEnv * _env, jclass _b, jlong this_ptr) {
6025         LDKChannelConfig this_ptr_conv;
6026         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6027         this_ptr_conv.is_owned = false;
6028         jboolean ret_val = ChannelConfig_get_announced_channel(&this_ptr_conv);
6029         return ret_val;
6030 }
6031
6032 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1announced_1channel(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
6033         LDKChannelConfig this_ptr_conv;
6034         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6035         this_ptr_conv.is_owned = false;
6036         ChannelConfig_set_announced_channel(&this_ptr_conv, val);
6037 }
6038
6039 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1commit_1upfront_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
6040         LDKChannelConfig this_ptr_conv;
6041         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6042         this_ptr_conv.is_owned = false;
6043         jboolean ret_val = ChannelConfig_get_commit_upfront_shutdown_pubkey(&this_ptr_conv);
6044         return ret_val;
6045 }
6046
6047 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1commit_1upfront_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
6048         LDKChannelConfig this_ptr_conv;
6049         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6050         this_ptr_conv.is_owned = false;
6051         ChannelConfig_set_commit_upfront_shutdown_pubkey(&this_ptr_conv, val);
6052 }
6053
6054 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) {
6055         LDKChannelConfig ret_var = ChannelConfig_new(fee_proportional_millionths_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
6056         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6057         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6058         long ret_ref = (long)ret_var.inner;
6059         if (ret_var.is_owned) {
6060                 ret_ref |= 1;
6061         }
6062         return ret_ref;
6063 }
6064
6065 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1default(JNIEnv * _env, jclass _b) {
6066         LDKChannelConfig ret_var = ChannelConfig_default();
6067         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6068         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6069         long ret_ref = (long)ret_var.inner;
6070         if (ret_var.is_owned) {
6071                 ret_ref |= 1;
6072         }
6073         return ret_ref;
6074 }
6075
6076 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1write(JNIEnv * _env, jclass _b, jlong obj) {
6077         LDKChannelConfig obj_conv;
6078         obj_conv.inner = (void*)(obj & (~1));
6079         obj_conv.is_owned = false;
6080         LDKCVec_u8Z arg_var = ChannelConfig_write(&obj_conv);
6081         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
6082         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
6083         CVec_u8Z_free(arg_var);
6084         return arg_arr;
6085 }
6086
6087 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
6088         LDKu8slice ser_ref;
6089         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
6090         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
6091         LDKChannelConfig ret_var = ChannelConfig_read(ser_ref);
6092         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6093         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6094         long ret_ref = (long)ret_var.inner;
6095         if (ret_var.is_owned) {
6096                 ret_ref |= 1;
6097         }
6098         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
6099         return ret_ref;
6100 }
6101
6102 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6103         LDKUserConfig this_ptr_conv;
6104         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6105         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6106         UserConfig_free(this_ptr_conv);
6107 }
6108
6109 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6110         LDKUserConfig orig_conv;
6111         orig_conv.inner = (void*)(orig & (~1));
6112         orig_conv.is_owned = false;
6113         LDKUserConfig ret_var = UserConfig_clone(&orig_conv);
6114         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6115         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6116         long ret_ref = (long)ret_var.inner;
6117         if (ret_var.is_owned) {
6118                 ret_ref |= 1;
6119         }
6120         return ret_ref;
6121 }
6122
6123 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1own_1channel_1config(JNIEnv * _env, jclass _b, jlong this_ptr) {
6124         LDKUserConfig this_ptr_conv;
6125         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6126         this_ptr_conv.is_owned = false;
6127         LDKChannelHandshakeConfig ret_var = UserConfig_get_own_channel_config(&this_ptr_conv);
6128         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6129         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6130         long ret_ref = (long)ret_var.inner;
6131         if (ret_var.is_owned) {
6132                 ret_ref |= 1;
6133         }
6134         return ret_ref;
6135 }
6136
6137 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1own_1channel_1config(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
6138         LDKUserConfig this_ptr_conv;
6139         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6140         this_ptr_conv.is_owned = false;
6141         LDKChannelHandshakeConfig val_conv;
6142         val_conv.inner = (void*)(val & (~1));
6143         val_conv.is_owned = (val & 1) || (val == 0);
6144         if (val_conv.inner != NULL)
6145                 val_conv = ChannelHandshakeConfig_clone(&val_conv);
6146         UserConfig_set_own_channel_config(&this_ptr_conv, val_conv);
6147 }
6148
6149 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1peer_1channel_1config_1limits(JNIEnv * _env, jclass _b, jlong this_ptr) {
6150         LDKUserConfig this_ptr_conv;
6151         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6152         this_ptr_conv.is_owned = false;
6153         LDKChannelHandshakeLimits ret_var = UserConfig_get_peer_channel_config_limits(&this_ptr_conv);
6154         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6155         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6156         long ret_ref = (long)ret_var.inner;
6157         if (ret_var.is_owned) {
6158                 ret_ref |= 1;
6159         }
6160         return ret_ref;
6161 }
6162
6163 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1peer_1channel_1config_1limits(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
6164         LDKUserConfig this_ptr_conv;
6165         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6166         this_ptr_conv.is_owned = false;
6167         LDKChannelHandshakeLimits val_conv;
6168         val_conv.inner = (void*)(val & (~1));
6169         val_conv.is_owned = (val & 1) || (val == 0);
6170         if (val_conv.inner != NULL)
6171                 val_conv = ChannelHandshakeLimits_clone(&val_conv);
6172         UserConfig_set_peer_channel_config_limits(&this_ptr_conv, val_conv);
6173 }
6174
6175 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1channel_1options(JNIEnv * _env, jclass _b, jlong this_ptr) {
6176         LDKUserConfig this_ptr_conv;
6177         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6178         this_ptr_conv.is_owned = false;
6179         LDKChannelConfig ret_var = UserConfig_get_channel_options(&this_ptr_conv);
6180         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6181         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6182         long ret_ref = (long)ret_var.inner;
6183         if (ret_var.is_owned) {
6184                 ret_ref |= 1;
6185         }
6186         return ret_ref;
6187 }
6188
6189 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1channel_1options(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
6190         LDKUserConfig this_ptr_conv;
6191         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6192         this_ptr_conv.is_owned = false;
6193         LDKChannelConfig val_conv;
6194         val_conv.inner = (void*)(val & (~1));
6195         val_conv.is_owned = (val & 1) || (val == 0);
6196         if (val_conv.inner != NULL)
6197                 val_conv = ChannelConfig_clone(&val_conv);
6198         UserConfig_set_channel_options(&this_ptr_conv, val_conv);
6199 }
6200
6201 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) {
6202         LDKChannelHandshakeConfig own_channel_config_arg_conv;
6203         own_channel_config_arg_conv.inner = (void*)(own_channel_config_arg & (~1));
6204         own_channel_config_arg_conv.is_owned = (own_channel_config_arg & 1) || (own_channel_config_arg == 0);
6205         if (own_channel_config_arg_conv.inner != NULL)
6206                 own_channel_config_arg_conv = ChannelHandshakeConfig_clone(&own_channel_config_arg_conv);
6207         LDKChannelHandshakeLimits peer_channel_config_limits_arg_conv;
6208         peer_channel_config_limits_arg_conv.inner = (void*)(peer_channel_config_limits_arg & (~1));
6209         peer_channel_config_limits_arg_conv.is_owned = (peer_channel_config_limits_arg & 1) || (peer_channel_config_limits_arg == 0);
6210         if (peer_channel_config_limits_arg_conv.inner != NULL)
6211                 peer_channel_config_limits_arg_conv = ChannelHandshakeLimits_clone(&peer_channel_config_limits_arg_conv);
6212         LDKChannelConfig channel_options_arg_conv;
6213         channel_options_arg_conv.inner = (void*)(channel_options_arg & (~1));
6214         channel_options_arg_conv.is_owned = (channel_options_arg & 1) || (channel_options_arg == 0);
6215         if (channel_options_arg_conv.inner != NULL)
6216                 channel_options_arg_conv = ChannelConfig_clone(&channel_options_arg_conv);
6217         LDKUserConfig ret_var = UserConfig_new(own_channel_config_arg_conv, peer_channel_config_limits_arg_conv, channel_options_arg_conv);
6218         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6219         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6220         long ret_ref = (long)ret_var.inner;
6221         if (ret_var.is_owned) {
6222                 ret_ref |= 1;
6223         }
6224         return ret_ref;
6225 }
6226
6227 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1default(JNIEnv * _env, jclass _b) {
6228         LDKUserConfig ret_var = UserConfig_default();
6229         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6230         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6231         long ret_ref = (long)ret_var.inner;
6232         if (ret_var.is_owned) {
6233                 ret_ref |= 1;
6234         }
6235         return ret_ref;
6236 }
6237
6238 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_AccessError_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6239         LDKAccessError* orig_conv = (LDKAccessError*)orig;
6240         jclass ret_conv = LDKAccessError_to_java(_env, AccessError_clone(orig_conv));
6241         return ret_conv;
6242 }
6243
6244 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Access_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6245         LDKAccess this_ptr_conv = *(LDKAccess*)this_ptr;
6246         FREE((void*)this_ptr);
6247         Access_free(this_ptr_conv);
6248 }
6249
6250 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Watch_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6251         LDKWatch this_ptr_conv = *(LDKWatch*)this_ptr;
6252         FREE((void*)this_ptr);
6253         Watch_free(this_ptr_conv);
6254 }
6255
6256 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6257         LDKFilter this_ptr_conv = *(LDKFilter*)this_ptr;
6258         FREE((void*)this_ptr);
6259         Filter_free(this_ptr_conv);
6260 }
6261
6262 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6263         LDKBroadcasterInterface this_ptr_conv = *(LDKBroadcasterInterface*)this_ptr;
6264         FREE((void*)this_ptr);
6265         BroadcasterInterface_free(this_ptr_conv);
6266 }
6267
6268 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ConfirmationTarget_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6269         LDKConfirmationTarget* orig_conv = (LDKConfirmationTarget*)orig;
6270         jclass ret_conv = LDKConfirmationTarget_to_java(_env, ConfirmationTarget_clone(orig_conv));
6271         return ret_conv;
6272 }
6273
6274 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FeeEstimator_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6275         LDKFeeEstimator this_ptr_conv = *(LDKFeeEstimator*)this_ptr;
6276         FREE((void*)this_ptr);
6277         FeeEstimator_free(this_ptr_conv);
6278 }
6279
6280 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6281         LDKChainMonitor this_ptr_conv;
6282         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6283         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6284         ChainMonitor_free(this_ptr_conv);
6285 }
6286
6287 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1block_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jlongArray txdata, jint height) {
6288         LDKChainMonitor this_arg_conv;
6289         this_arg_conv.inner = (void*)(this_arg & (~1));
6290         this_arg_conv.is_owned = false;
6291         unsigned char header_arr[80];
6292         CHECK((*_env)->GetArrayLength (_env, header) == 80);
6293         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
6294         unsigned char (*header_ref)[80] = &header_arr;
6295         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
6296         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
6297         if (txdata_constr.datalen > 0)
6298                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
6299         else
6300                 txdata_constr.data = NULL;
6301         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
6302         for (size_t y = 0; y < txdata_constr.datalen; y++) {
6303                 long arr_conv_24 = txdata_vals[y];
6304                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
6305                 FREE((void*)arr_conv_24);
6306                 txdata_constr.data[y] = arr_conv_24_conv;
6307         }
6308         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
6309         ChainMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
6310 }
6311
6312 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1block_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jint disconnected_height) {
6313         LDKChainMonitor this_arg_conv;
6314         this_arg_conv.inner = (void*)(this_arg & (~1));
6315         this_arg_conv.is_owned = false;
6316         unsigned char header_arr[80];
6317         CHECK((*_env)->GetArrayLength (_env, header) == 80);
6318         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
6319         unsigned char (*header_ref)[80] = &header_arr;
6320         ChainMonitor_block_disconnected(&this_arg_conv, header_ref, disconnected_height);
6321 }
6322
6323 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1new(JNIEnv * _env, jclass _b, jlong chain_source, jlong broadcaster, jlong logger, jlong feeest) {
6324         LDKFilter* chain_source_conv = (LDKFilter*)chain_source;
6325         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
6326         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
6327                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6328                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
6329         }
6330         LDKLogger logger_conv = *(LDKLogger*)logger;
6331         if (logger_conv.free == LDKLogger_JCalls_free) {
6332                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6333                 LDKLogger_JCalls_clone(logger_conv.this_arg);
6334         }
6335         LDKFeeEstimator feeest_conv = *(LDKFeeEstimator*)feeest;
6336         if (feeest_conv.free == LDKFeeEstimator_JCalls_free) {
6337                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6338                 LDKFeeEstimator_JCalls_clone(feeest_conv.this_arg);
6339         }
6340         LDKChainMonitor ret_var = ChainMonitor_new(chain_source_conv, broadcaster_conv, logger_conv, feeest_conv);
6341         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6342         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6343         long ret_ref = (long)ret_var.inner;
6344         if (ret_var.is_owned) {
6345                 ret_ref |= 1;
6346         }
6347         return ret_ref;
6348 }
6349
6350 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1Watch(JNIEnv * _env, jclass _b, jlong this_arg) {
6351         LDKChainMonitor this_arg_conv;
6352         this_arg_conv.inner = (void*)(this_arg & (~1));
6353         this_arg_conv.is_owned = false;
6354         LDKWatch* ret = MALLOC(sizeof(LDKWatch), "LDKWatch");
6355         *ret = ChainMonitor_as_Watch(&this_arg_conv);
6356         return (long)ret;
6357 }
6358
6359 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1EventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
6360         LDKChainMonitor this_arg_conv;
6361         this_arg_conv.inner = (void*)(this_arg & (~1));
6362         this_arg_conv.is_owned = false;
6363         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
6364         *ret = ChainMonitor_as_EventsProvider(&this_arg_conv);
6365         return (long)ret;
6366 }
6367
6368 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6369         LDKChannelMonitorUpdate this_ptr_conv;
6370         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6371         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6372         ChannelMonitorUpdate_free(this_ptr_conv);
6373 }
6374
6375 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6376         LDKChannelMonitorUpdate orig_conv;
6377         orig_conv.inner = (void*)(orig & (~1));
6378         orig_conv.is_owned = false;
6379         LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_clone(&orig_conv);
6380         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6381         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6382         long ret_ref = (long)ret_var.inner;
6383         if (ret_var.is_owned) {
6384                 ret_ref |= 1;
6385         }
6386         return ret_ref;
6387 }
6388
6389 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1get_1update_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
6390         LDKChannelMonitorUpdate this_ptr_conv;
6391         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6392         this_ptr_conv.is_owned = false;
6393         jlong ret_val = ChannelMonitorUpdate_get_update_id(&this_ptr_conv);
6394         return ret_val;
6395 }
6396
6397 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1set_1update_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
6398         LDKChannelMonitorUpdate this_ptr_conv;
6399         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6400         this_ptr_conv.is_owned = false;
6401         ChannelMonitorUpdate_set_update_id(&this_ptr_conv, val);
6402 }
6403
6404 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
6405         LDKChannelMonitorUpdate obj_conv;
6406         obj_conv.inner = (void*)(obj & (~1));
6407         obj_conv.is_owned = false;
6408         LDKCVec_u8Z arg_var = ChannelMonitorUpdate_write(&obj_conv);
6409         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
6410         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
6411         CVec_u8Z_free(arg_var);
6412         return arg_arr;
6413 }
6414
6415 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
6416         LDKu8slice ser_ref;
6417         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
6418         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
6419         LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_read(ser_ref);
6420         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6421         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6422         long ret_ref = (long)ret_var.inner;
6423         if (ret_var.is_owned) {
6424                 ret_ref |= 1;
6425         }
6426         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
6427         return ret_ref;
6428 }
6429
6430 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdateErr_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6431         LDKChannelMonitorUpdateErr* orig_conv = (LDKChannelMonitorUpdateErr*)orig;
6432         jclass ret_conv = LDKChannelMonitorUpdateErr_to_java(_env, ChannelMonitorUpdateErr_clone(orig_conv));
6433         return ret_conv;
6434 }
6435
6436 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorUpdateError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6437         LDKMonitorUpdateError this_ptr_conv;
6438         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6439         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6440         MonitorUpdateError_free(this_ptr_conv);
6441 }
6442
6443 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6444         LDKMonitorEvent this_ptr_conv;
6445         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6446         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6447         MonitorEvent_free(this_ptr_conv);
6448 }
6449
6450 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6451         LDKMonitorEvent orig_conv;
6452         orig_conv.inner = (void*)(orig & (~1));
6453         orig_conv.is_owned = false;
6454         LDKMonitorEvent ret_var = MonitorEvent_clone(&orig_conv);
6455         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6456         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6457         long ret_ref = (long)ret_var.inner;
6458         if (ret_var.is_owned) {
6459                 ret_ref |= 1;
6460         }
6461         return ret_ref;
6462 }
6463
6464 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6465         LDKHTLCUpdate this_ptr_conv;
6466         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6467         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6468         HTLCUpdate_free(this_ptr_conv);
6469 }
6470
6471 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6472         LDKHTLCUpdate orig_conv;
6473         orig_conv.inner = (void*)(orig & (~1));
6474         orig_conv.is_owned = false;
6475         LDKHTLCUpdate ret_var = HTLCUpdate_clone(&orig_conv);
6476         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6477         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6478         long ret_ref = (long)ret_var.inner;
6479         if (ret_var.is_owned) {
6480                 ret_ref |= 1;
6481         }
6482         return ret_ref;
6483 }
6484
6485 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
6486         LDKHTLCUpdate obj_conv;
6487         obj_conv.inner = (void*)(obj & (~1));
6488         obj_conv.is_owned = false;
6489         LDKCVec_u8Z arg_var = HTLCUpdate_write(&obj_conv);
6490         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
6491         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
6492         CVec_u8Z_free(arg_var);
6493         return arg_arr;
6494 }
6495
6496 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
6497         LDKu8slice ser_ref;
6498         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
6499         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
6500         LDKHTLCUpdate ret_var = HTLCUpdate_read(ser_ref);
6501         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6502         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6503         long ret_ref = (long)ret_var.inner;
6504         if (ret_var.is_owned) {
6505                 ret_ref |= 1;
6506         }
6507         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
6508         return ret_ref;
6509 }
6510
6511 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6512         LDKChannelMonitor this_ptr_conv;
6513         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6514         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6515         ChannelMonitor_free(this_ptr_conv);
6516 }
6517
6518 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1update_1monitor(JNIEnv * _env, jclass _b, jlong this_arg, jlong updates, jlong broadcaster, jlong logger) {
6519         LDKChannelMonitor this_arg_conv;
6520         this_arg_conv.inner = (void*)(this_arg & (~1));
6521         this_arg_conv.is_owned = false;
6522         LDKChannelMonitorUpdate updates_conv;
6523         updates_conv.inner = (void*)(updates & (~1));
6524         updates_conv.is_owned = (updates & 1) || (updates == 0);
6525         if (updates_conv.inner != NULL)
6526                 updates_conv = ChannelMonitorUpdate_clone(&updates_conv);
6527         LDKBroadcasterInterface* broadcaster_conv = (LDKBroadcasterInterface*)broadcaster;
6528         LDKLogger* logger_conv = (LDKLogger*)logger;
6529         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
6530         *ret_conv = ChannelMonitor_update_monitor(&this_arg_conv, updates_conv, broadcaster_conv, logger_conv);
6531         return (long)ret_conv;
6532 }
6533
6534 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1update_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
6535         LDKChannelMonitor this_arg_conv;
6536         this_arg_conv.inner = (void*)(this_arg & (~1));
6537         this_arg_conv.is_owned = false;
6538         jlong ret_val = ChannelMonitor_get_latest_update_id(&this_arg_conv);
6539         return ret_val;
6540 }
6541
6542 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1funding_1txo(JNIEnv * _env, jclass _b, jlong this_arg) {
6543         LDKChannelMonitor this_arg_conv;
6544         this_arg_conv.inner = (void*)(this_arg & (~1));
6545         this_arg_conv.is_owned = false;
6546         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
6547         *ret_ref = ChannelMonitor_get_funding_txo(&this_arg_conv);
6548         return (long)ret_ref;
6549 }
6550
6551 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1monitor_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
6552         LDKChannelMonitor this_arg_conv;
6553         this_arg_conv.inner = (void*)(this_arg & (~1));
6554         this_arg_conv.is_owned = false;
6555         LDKCVec_MonitorEventZ ret_var = ChannelMonitor_get_and_clear_pending_monitor_events(&this_arg_conv);
6556         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
6557         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
6558         for (size_t o = 0; o < ret_var.datalen; o++) {
6559                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
6560                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6561                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6562                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
6563                 if (arr_conv_14_var.is_owned) {
6564                         arr_conv_14_ref |= 1;
6565                 }
6566                 ret_arr_ptr[o] = arr_conv_14_ref;
6567         }
6568         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
6569         FREE(ret_var.data);
6570         return ret_arr;
6571 }
6572
6573 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
6574         LDKChannelMonitor this_arg_conv;
6575         this_arg_conv.inner = (void*)(this_arg & (~1));
6576         this_arg_conv.is_owned = false;
6577         LDKCVec_EventZ ret_var = ChannelMonitor_get_and_clear_pending_events(&this_arg_conv);
6578         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
6579         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
6580         for (size_t h = 0; h < ret_var.datalen; h++) {
6581                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
6582                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
6583                 long arr_conv_7_ref = (long)arr_conv_7_copy;
6584                 ret_arr_ptr[h] = arr_conv_7_ref;
6585         }
6586         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
6587         CVec_EventZ_free(ret_var);
6588         return ret_arr;
6589 }
6590
6591 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1holder_1commitment_1txn(JNIEnv * _env, jclass _b, jlong this_arg, jlong logger) {
6592         LDKChannelMonitor this_arg_conv;
6593         this_arg_conv.inner = (void*)(this_arg & (~1));
6594         this_arg_conv.is_owned = false;
6595         LDKLogger* logger_conv = (LDKLogger*)logger;
6596         LDKCVec_TransactionZ ret_var = ChannelMonitor_get_latest_holder_commitment_txn(&this_arg_conv, logger_conv);
6597         jobjectArray ret_arr = (*_env)->NewObjectArray(_env, ret_var.datalen, arr_of_B_clz, NULL);
6598         for (size_t i = 0; i < ret_var.datalen; i++) {
6599                 LDKTransaction arr_conv_8_var = ret_var.data[i];
6600                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, arr_conv_8_var.datalen);
6601                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, arr_conv_8_var.datalen, arr_conv_8_var.data);
6602                 Transaction_free(arr_conv_8_var);
6603                 (*_env)->SetObjectArrayElement(_env, ret_arr, i, arr_conv_8_arr);
6604         }
6605         CVec_TransactionZ_free(ret_var);
6606         return ret_arr;
6607 }
6608
6609 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) {
6610         LDKChannelMonitor this_arg_conv;
6611         this_arg_conv.inner = (void*)(this_arg & (~1));
6612         this_arg_conv.is_owned = false;
6613         unsigned char header_arr[80];
6614         CHECK((*_env)->GetArrayLength (_env, header) == 80);
6615         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
6616         unsigned char (*header_ref)[80] = &header_arr;
6617         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
6618         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
6619         if (txdata_constr.datalen > 0)
6620                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
6621         else
6622                 txdata_constr.data = NULL;
6623         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
6624         for (size_t y = 0; y < txdata_constr.datalen; y++) {
6625                 long arr_conv_24 = txdata_vals[y];
6626                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
6627                 FREE((void*)arr_conv_24);
6628                 txdata_constr.data[y] = arr_conv_24_conv;
6629         }
6630         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
6631         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
6632         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
6633                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6634                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
6635         }
6636         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
6637         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
6638                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6639                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
6640         }
6641         LDKLogger logger_conv = *(LDKLogger*)logger;
6642         if (logger_conv.free == LDKLogger_JCalls_free) {
6643                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6644                 LDKLogger_JCalls_clone(logger_conv.this_arg);
6645         }
6646         LDKCVec_C2Tuple_TxidCVec_TxOutZZZ ret_var = ChannelMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height, broadcaster_conv, fee_estimator_conv, logger_conv);
6647         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
6648         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
6649         for (size_t b = 0; b < ret_var.datalen; b++) {
6650                 LDKC2Tuple_TxidCVec_TxOutZZ* arr_conv_27_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_TxOutZZ), "LDKC2Tuple_TxidCVec_TxOutZZ");
6651                 *arr_conv_27_ref = ret_var.data[b];
6652                 ret_arr_ptr[b] = (long)arr_conv_27_ref;
6653         }
6654         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
6655         CVec_C2Tuple_TxidCVec_TxOutZZZ_free(ret_var);
6656         return ret_arr;
6657 }
6658
6659 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) {
6660         LDKChannelMonitor this_arg_conv;
6661         this_arg_conv.inner = (void*)(this_arg & (~1));
6662         this_arg_conv.is_owned = false;
6663         unsigned char header_arr[80];
6664         CHECK((*_env)->GetArrayLength (_env, header) == 80);
6665         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
6666         unsigned char (*header_ref)[80] = &header_arr;
6667         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
6668         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
6669                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6670                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
6671         }
6672         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
6673         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
6674                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6675                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
6676         }
6677         LDKLogger logger_conv = *(LDKLogger*)logger;
6678         if (logger_conv.free == LDKLogger_JCalls_free) {
6679                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6680                 LDKLogger_JCalls_clone(logger_conv.this_arg);
6681         }
6682         ChannelMonitor_block_disconnected(&this_arg_conv, header_ref, height, broadcaster_conv, fee_estimator_conv, logger_conv);
6683 }
6684
6685 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6686         LDKOutPoint this_ptr_conv;
6687         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6688         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6689         OutPoint_free(this_ptr_conv);
6690 }
6691
6692 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6693         LDKOutPoint orig_conv;
6694         orig_conv.inner = (void*)(orig & (~1));
6695         orig_conv.is_owned = false;
6696         LDKOutPoint ret_var = OutPoint_clone(&orig_conv);
6697         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6698         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6699         long ret_ref = (long)ret_var.inner;
6700         if (ret_var.is_owned) {
6701                 ret_ref |= 1;
6702         }
6703         return ret_ref;
6704 }
6705
6706 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1txid(JNIEnv * _env, jclass _b, jlong this_ptr) {
6707         LDKOutPoint this_ptr_conv;
6708         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6709         this_ptr_conv.is_owned = false;
6710         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6711         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OutPoint_get_txid(&this_ptr_conv));
6712         return ret_arr;
6713 }
6714
6715 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1txid(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6716         LDKOutPoint this_ptr_conv;
6717         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6718         this_ptr_conv.is_owned = false;
6719         LDKThirtyTwoBytes val_ref;
6720         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6721         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
6722         OutPoint_set_txid(&this_ptr_conv, val_ref);
6723 }
6724
6725 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1index(JNIEnv * _env, jclass _b, jlong this_ptr) {
6726         LDKOutPoint this_ptr_conv;
6727         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6728         this_ptr_conv.is_owned = false;
6729         jshort ret_val = OutPoint_get_index(&this_ptr_conv);
6730         return ret_val;
6731 }
6732
6733 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1index(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
6734         LDKOutPoint this_ptr_conv;
6735         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6736         this_ptr_conv.is_owned = false;
6737         OutPoint_set_index(&this_ptr_conv, val);
6738 }
6739
6740 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1new(JNIEnv * _env, jclass _b, jbyteArray txid_arg, jshort index_arg) {
6741         LDKThirtyTwoBytes txid_arg_ref;
6742         CHECK((*_env)->GetArrayLength (_env, txid_arg) == 32);
6743         (*_env)->GetByteArrayRegion (_env, txid_arg, 0, 32, txid_arg_ref.data);
6744         LDKOutPoint ret_var = OutPoint_new(txid_arg_ref, index_arg);
6745         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6746         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6747         long ret_ref = (long)ret_var.inner;
6748         if (ret_var.is_owned) {
6749                 ret_ref |= 1;
6750         }
6751         return ret_ref;
6752 }
6753
6754 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1to_1channel_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
6755         LDKOutPoint this_arg_conv;
6756         this_arg_conv.inner = (void*)(this_arg & (~1));
6757         this_arg_conv.is_owned = false;
6758         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
6759         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, OutPoint_to_channel_id(&this_arg_conv).data);
6760         return arg_arr;
6761 }
6762
6763 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1write(JNIEnv * _env, jclass _b, jlong obj) {
6764         LDKOutPoint obj_conv;
6765         obj_conv.inner = (void*)(obj & (~1));
6766         obj_conv.is_owned = false;
6767         LDKCVec_u8Z arg_var = OutPoint_write(&obj_conv);
6768         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
6769         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
6770         CVec_u8Z_free(arg_var);
6771         return arg_arr;
6772 }
6773
6774 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
6775         LDKu8slice ser_ref;
6776         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
6777         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
6778         LDKOutPoint ret_var = OutPoint_read(ser_ref);
6779         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6780         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6781         long ret_ref = (long)ret_var.inner;
6782         if (ret_var.is_owned) {
6783                 ret_ref |= 1;
6784         }
6785         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
6786         return ret_ref;
6787 }
6788
6789 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6790         LDKSpendableOutputDescriptor this_ptr_conv = *(LDKSpendableOutputDescriptor*)this_ptr;
6791         FREE((void*)this_ptr);
6792         SpendableOutputDescriptor_free(this_ptr_conv);
6793 }
6794
6795 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6796         LDKSpendableOutputDescriptor* orig_conv = (LDKSpendableOutputDescriptor*)orig;
6797         LDKSpendableOutputDescriptor *ret_copy = MALLOC(sizeof(LDKSpendableOutputDescriptor), "LDKSpendableOutputDescriptor");
6798         *ret_copy = SpendableOutputDescriptor_clone(orig_conv);
6799         long ret_ref = (long)ret_copy;
6800         return ret_ref;
6801 }
6802
6803 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6804         LDKChannelKeys this_ptr_conv = *(LDKChannelKeys*)this_ptr;
6805         FREE((void*)this_ptr);
6806         ChannelKeys_free(this_ptr_conv);
6807 }
6808
6809 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysInterface_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6810         LDKKeysInterface this_ptr_conv = *(LDKKeysInterface*)this_ptr;
6811         FREE((void*)this_ptr);
6812         KeysInterface_free(this_ptr_conv);
6813 }
6814
6815 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6816         LDKInMemoryChannelKeys this_ptr_conv;
6817         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6818         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6819         InMemoryChannelKeys_free(this_ptr_conv);
6820 }
6821
6822 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6823         LDKInMemoryChannelKeys orig_conv;
6824         orig_conv.inner = (void*)(orig & (~1));
6825         orig_conv.is_owned = false;
6826         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_clone(&orig_conv);
6827         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6828         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6829         long ret_ref = (long)ret_var.inner;
6830         if (ret_var.is_owned) {
6831                 ret_ref |= 1;
6832         }
6833         return ret_ref;
6834 }
6835
6836 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1funding_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6837         LDKInMemoryChannelKeys this_ptr_conv;
6838         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6839         this_ptr_conv.is_owned = false;
6840         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6841         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_funding_key(&this_ptr_conv));
6842         return ret_arr;
6843 }
6844
6845 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1funding_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6846         LDKInMemoryChannelKeys this_ptr_conv;
6847         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6848         this_ptr_conv.is_owned = false;
6849         LDKSecretKey val_ref;
6850         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6851         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6852         InMemoryChannelKeys_set_funding_key(&this_ptr_conv, val_ref);
6853 }
6854
6855 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1revocation_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6856         LDKInMemoryChannelKeys this_ptr_conv;
6857         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6858         this_ptr_conv.is_owned = false;
6859         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6860         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_revocation_base_key(&this_ptr_conv));
6861         return ret_arr;
6862 }
6863
6864 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1revocation_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6865         LDKInMemoryChannelKeys this_ptr_conv;
6866         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6867         this_ptr_conv.is_owned = false;
6868         LDKSecretKey val_ref;
6869         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6870         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6871         InMemoryChannelKeys_set_revocation_base_key(&this_ptr_conv, val_ref);
6872 }
6873
6874 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6875         LDKInMemoryChannelKeys this_ptr_conv;
6876         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6877         this_ptr_conv.is_owned = false;
6878         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6879         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_payment_key(&this_ptr_conv));
6880         return ret_arr;
6881 }
6882
6883 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6884         LDKInMemoryChannelKeys this_ptr_conv;
6885         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6886         this_ptr_conv.is_owned = false;
6887         LDKSecretKey val_ref;
6888         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6889         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6890         InMemoryChannelKeys_set_payment_key(&this_ptr_conv, val_ref);
6891 }
6892
6893 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1delayed_1payment_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6894         LDKInMemoryChannelKeys this_ptr_conv;
6895         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6896         this_ptr_conv.is_owned = false;
6897         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6898         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_delayed_payment_base_key(&this_ptr_conv));
6899         return ret_arr;
6900 }
6901
6902 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1delayed_1payment_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6903         LDKInMemoryChannelKeys this_ptr_conv;
6904         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6905         this_ptr_conv.is_owned = false;
6906         LDKSecretKey val_ref;
6907         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6908         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6909         InMemoryChannelKeys_set_delayed_payment_base_key(&this_ptr_conv, val_ref);
6910 }
6911
6912 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1htlc_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6913         LDKInMemoryChannelKeys this_ptr_conv;
6914         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6915         this_ptr_conv.is_owned = false;
6916         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6917         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_htlc_base_key(&this_ptr_conv));
6918         return ret_arr;
6919 }
6920
6921 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1htlc_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6922         LDKInMemoryChannelKeys this_ptr_conv;
6923         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6924         this_ptr_conv.is_owned = false;
6925         LDKSecretKey val_ref;
6926         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6927         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6928         InMemoryChannelKeys_set_htlc_base_key(&this_ptr_conv, val_ref);
6929 }
6930
6931 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1commitment_1seed(JNIEnv * _env, jclass _b, jlong this_ptr) {
6932         LDKInMemoryChannelKeys this_ptr_conv;
6933         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6934         this_ptr_conv.is_owned = false;
6935         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6936         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_commitment_seed(&this_ptr_conv));
6937         return ret_arr;
6938 }
6939
6940 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1commitment_1seed(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6941         LDKInMemoryChannelKeys this_ptr_conv;
6942         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6943         this_ptr_conv.is_owned = false;
6944         LDKThirtyTwoBytes val_ref;
6945         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6946         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
6947         InMemoryChannelKeys_set_commitment_seed(&this_ptr_conv, val_ref);
6948 }
6949
6950 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) {
6951         LDKSecretKey funding_key_ref;
6952         CHECK((*_env)->GetArrayLength (_env, funding_key) == 32);
6953         (*_env)->GetByteArrayRegion (_env, funding_key, 0, 32, funding_key_ref.bytes);
6954         LDKSecretKey revocation_base_key_ref;
6955         CHECK((*_env)->GetArrayLength (_env, revocation_base_key) == 32);
6956         (*_env)->GetByteArrayRegion (_env, revocation_base_key, 0, 32, revocation_base_key_ref.bytes);
6957         LDKSecretKey payment_key_ref;
6958         CHECK((*_env)->GetArrayLength (_env, payment_key) == 32);
6959         (*_env)->GetByteArrayRegion (_env, payment_key, 0, 32, payment_key_ref.bytes);
6960         LDKSecretKey delayed_payment_base_key_ref;
6961         CHECK((*_env)->GetArrayLength (_env, delayed_payment_base_key) == 32);
6962         (*_env)->GetByteArrayRegion (_env, delayed_payment_base_key, 0, 32, delayed_payment_base_key_ref.bytes);
6963         LDKSecretKey htlc_base_key_ref;
6964         CHECK((*_env)->GetArrayLength (_env, htlc_base_key) == 32);
6965         (*_env)->GetByteArrayRegion (_env, htlc_base_key, 0, 32, htlc_base_key_ref.bytes);
6966         LDKThirtyTwoBytes commitment_seed_ref;
6967         CHECK((*_env)->GetArrayLength (_env, commitment_seed) == 32);
6968         (*_env)->GetByteArrayRegion (_env, commitment_seed, 0, 32, commitment_seed_ref.data);
6969         LDKC2Tuple_u64u64Z key_derivation_params_conv = *(LDKC2Tuple_u64u64Z*)key_derivation_params;
6970         FREE((void*)key_derivation_params);
6971         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);
6972         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6973         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6974         long ret_ref = (long)ret_var.inner;
6975         if (ret_var.is_owned) {
6976                 ret_ref |= 1;
6977         }
6978         return ret_ref;
6979 }
6980
6981 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
6982         LDKInMemoryChannelKeys this_arg_conv;
6983         this_arg_conv.inner = (void*)(this_arg & (~1));
6984         this_arg_conv.is_owned = false;
6985         LDKChannelPublicKeys ret_var = InMemoryChannelKeys_counterparty_pubkeys(&this_arg_conv);
6986         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6987         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6988         long ret_ref = (long)ret_var.inner;
6989         if (ret_var.is_owned) {
6990                 ret_ref |= 1;
6991         }
6992         return ret_ref;
6993 }
6994
6995 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_arg) {
6996         LDKInMemoryChannelKeys this_arg_conv;
6997         this_arg_conv.inner = (void*)(this_arg & (~1));
6998         this_arg_conv.is_owned = false;
6999         jshort ret_val = InMemoryChannelKeys_counterparty_selected_contest_delay(&this_arg_conv);
7000         return ret_val;
7001 }
7002
7003 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1holder_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_arg) {
7004         LDKInMemoryChannelKeys this_arg_conv;
7005         this_arg_conv.inner = (void*)(this_arg & (~1));
7006         this_arg_conv.is_owned = false;
7007         jshort ret_val = InMemoryChannelKeys_holder_selected_contest_delay(&this_arg_conv);
7008         return ret_val;
7009 }
7010
7011 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1as_1ChannelKeys(JNIEnv * _env, jclass _b, jlong this_arg) {
7012         LDKInMemoryChannelKeys this_arg_conv;
7013         this_arg_conv.inner = (void*)(this_arg & (~1));
7014         this_arg_conv.is_owned = false;
7015         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
7016         *ret = InMemoryChannelKeys_as_ChannelKeys(&this_arg_conv);
7017         return (long)ret;
7018 }
7019
7020 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
7021         LDKInMemoryChannelKeys obj_conv;
7022         obj_conv.inner = (void*)(obj & (~1));
7023         obj_conv.is_owned = false;
7024         LDKCVec_u8Z arg_var = InMemoryChannelKeys_write(&obj_conv);
7025         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
7026         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
7027         CVec_u8Z_free(arg_var);
7028         return arg_arr;
7029 }
7030
7031 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
7032         LDKu8slice ser_ref;
7033         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
7034         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
7035         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_read(ser_ref);
7036         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7037         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7038         long ret_ref = (long)ret_var.inner;
7039         if (ret_var.is_owned) {
7040                 ret_ref |= 1;
7041         }
7042         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
7043         return ret_ref;
7044 }
7045
7046 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7047         LDKKeysManager this_ptr_conv;
7048         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7049         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7050         KeysManager_free(this_ptr_conv);
7051 }
7052
7053 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) {
7054         unsigned char seed_arr[32];
7055         CHECK((*_env)->GetArrayLength (_env, seed) == 32);
7056         (*_env)->GetByteArrayRegion (_env, seed, 0, 32, seed_arr);
7057         unsigned char (*seed_ref)[32] = &seed_arr;
7058         LDKNetwork network_conv = LDKNetwork_from_java(_env, network);
7059         LDKKeysManager ret_var = KeysManager_new(seed_ref, network_conv, starting_time_secs, starting_time_nanos);
7060         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7061         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7062         long ret_ref = (long)ret_var.inner;
7063         if (ret_var.is_owned) {
7064                 ret_ref |= 1;
7065         }
7066         return ret_ref;
7067 }
7068
7069 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) {
7070         LDKKeysManager this_arg_conv;
7071         this_arg_conv.inner = (void*)(this_arg & (~1));
7072         this_arg_conv.is_owned = false;
7073         LDKInMemoryChannelKeys ret_var = KeysManager_derive_channel_keys(&this_arg_conv, channel_value_satoshis, params_1, params_2);
7074         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7075         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7076         long ret_ref = (long)ret_var.inner;
7077         if (ret_var.is_owned) {
7078                 ret_ref |= 1;
7079         }
7080         return ret_ref;
7081 }
7082
7083 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_KeysManager_1as_1KeysInterface(JNIEnv * _env, jclass _b, jlong this_arg) {
7084         LDKKeysManager this_arg_conv;
7085         this_arg_conv.inner = (void*)(this_arg & (~1));
7086         this_arg_conv.is_owned = false;
7087         LDKKeysInterface* ret = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
7088         *ret = KeysManager_as_KeysInterface(&this_arg_conv);
7089         return (long)ret;
7090 }
7091
7092 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7093         LDKChannelManager this_ptr_conv;
7094         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7095         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7096         ChannelManager_free(this_ptr_conv);
7097 }
7098
7099 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7100         LDKChannelDetails this_ptr_conv;
7101         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7102         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7103         ChannelDetails_free(this_ptr_conv);
7104 }
7105
7106 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7107         LDKChannelDetails orig_conv;
7108         orig_conv.inner = (void*)(orig & (~1));
7109         orig_conv.is_owned = false;
7110         LDKChannelDetails ret_var = ChannelDetails_clone(&orig_conv);
7111         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7112         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7113         long ret_ref = (long)ret_var.inner;
7114         if (ret_var.is_owned) {
7115                 ret_ref |= 1;
7116         }
7117         return ret_ref;
7118 }
7119
7120 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
7121         LDKChannelDetails this_ptr_conv;
7122         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7123         this_ptr_conv.is_owned = false;
7124         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
7125         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ChannelDetails_get_channel_id(&this_ptr_conv));
7126         return ret_arr;
7127 }
7128
7129 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7130         LDKChannelDetails this_ptr_conv;
7131         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7132         this_ptr_conv.is_owned = false;
7133         LDKThirtyTwoBytes val_ref;
7134         CHECK((*_env)->GetArrayLength (_env, val) == 32);
7135         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
7136         ChannelDetails_set_channel_id(&this_ptr_conv, val_ref);
7137 }
7138
7139 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1remote_1network_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
7140         LDKChannelDetails this_ptr_conv;
7141         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7142         this_ptr_conv.is_owned = false;
7143         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
7144         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelDetails_get_remote_network_id(&this_ptr_conv).compressed_form);
7145         return arg_arr;
7146 }
7147
7148 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1remote_1network_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7149         LDKChannelDetails this_ptr_conv;
7150         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7151         this_ptr_conv.is_owned = false;
7152         LDKPublicKey val_ref;
7153         CHECK((*_env)->GetArrayLength (_env, val) == 33);
7154         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
7155         ChannelDetails_set_remote_network_id(&this_ptr_conv, val_ref);
7156 }
7157
7158 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1counterparty_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
7159         LDKChannelDetails this_ptr_conv;
7160         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7161         this_ptr_conv.is_owned = false;
7162         LDKInitFeatures ret_var = ChannelDetails_get_counterparty_features(&this_ptr_conv);
7163         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7164         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7165         long ret_ref = (long)ret_var.inner;
7166         if (ret_var.is_owned) {
7167                 ret_ref |= 1;
7168         }
7169         return ret_ref;
7170 }
7171
7172 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1counterparty_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7173         LDKChannelDetails this_ptr_conv;
7174         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7175         this_ptr_conv.is_owned = false;
7176         LDKInitFeatures val_conv;
7177         val_conv.inner = (void*)(val & (~1));
7178         val_conv.is_owned = (val & 1) || (val == 0);
7179         // Warning: we may need a move here but can't clone!
7180         ChannelDetails_set_counterparty_features(&this_ptr_conv, val_conv);
7181 }
7182
7183 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1value_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7184         LDKChannelDetails this_ptr_conv;
7185         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7186         this_ptr_conv.is_owned = false;
7187         jlong ret_val = ChannelDetails_get_channel_value_satoshis(&this_ptr_conv);
7188         return ret_val;
7189 }
7190
7191 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1value_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7192         LDKChannelDetails this_ptr_conv;
7193         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7194         this_ptr_conv.is_owned = false;
7195         ChannelDetails_set_channel_value_satoshis(&this_ptr_conv, val);
7196 }
7197
7198 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1user_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
7199         LDKChannelDetails this_ptr_conv;
7200         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7201         this_ptr_conv.is_owned = false;
7202         jlong ret_val = ChannelDetails_get_user_id(&this_ptr_conv);
7203         return ret_val;
7204 }
7205
7206 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1user_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7207         LDKChannelDetails this_ptr_conv;
7208         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7209         this_ptr_conv.is_owned = false;
7210         ChannelDetails_set_user_id(&this_ptr_conv, val);
7211 }
7212
7213 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1outbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7214         LDKChannelDetails this_ptr_conv;
7215         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7216         this_ptr_conv.is_owned = false;
7217         jlong ret_val = ChannelDetails_get_outbound_capacity_msat(&this_ptr_conv);
7218         return ret_val;
7219 }
7220
7221 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1outbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7222         LDKChannelDetails this_ptr_conv;
7223         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7224         this_ptr_conv.is_owned = false;
7225         ChannelDetails_set_outbound_capacity_msat(&this_ptr_conv, val);
7226 }
7227
7228 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1inbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7229         LDKChannelDetails this_ptr_conv;
7230         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7231         this_ptr_conv.is_owned = false;
7232         jlong ret_val = ChannelDetails_get_inbound_capacity_msat(&this_ptr_conv);
7233         return ret_val;
7234 }
7235
7236 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1inbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7237         LDKChannelDetails this_ptr_conv;
7238         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7239         this_ptr_conv.is_owned = false;
7240         ChannelDetails_set_inbound_capacity_msat(&this_ptr_conv, val);
7241 }
7242
7243 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1is_1live(JNIEnv * _env, jclass _b, jlong this_ptr) {
7244         LDKChannelDetails this_ptr_conv;
7245         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7246         this_ptr_conv.is_owned = false;
7247         jboolean ret_val = ChannelDetails_get_is_live(&this_ptr_conv);
7248         return ret_val;
7249 }
7250
7251 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1is_1live(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
7252         LDKChannelDetails this_ptr_conv;
7253         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7254         this_ptr_conv.is_owned = false;
7255         ChannelDetails_set_is_live(&this_ptr_conv, val);
7256 }
7257
7258 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PaymentSendFailure_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7259         LDKPaymentSendFailure this_ptr_conv;
7260         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7261         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7262         PaymentSendFailure_free(this_ptr_conv);
7263 }
7264
7265 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) {
7266         LDKNetwork network_conv = LDKNetwork_from_java(_env, network);
7267         LDKFeeEstimator fee_est_conv = *(LDKFeeEstimator*)fee_est;
7268         if (fee_est_conv.free == LDKFeeEstimator_JCalls_free) {
7269                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7270                 LDKFeeEstimator_JCalls_clone(fee_est_conv.this_arg);
7271         }
7272         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
7273         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
7274                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7275                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
7276         }
7277         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
7278         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
7279                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7280                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
7281         }
7282         LDKLogger logger_conv = *(LDKLogger*)logger;
7283         if (logger_conv.free == LDKLogger_JCalls_free) {
7284                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7285                 LDKLogger_JCalls_clone(logger_conv.this_arg);
7286         }
7287         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
7288         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
7289                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7290                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
7291         }
7292         LDKUserConfig config_conv;
7293         config_conv.inner = (void*)(config & (~1));
7294         config_conv.is_owned = (config & 1) || (config == 0);
7295         if (config_conv.inner != NULL)
7296                 config_conv = UserConfig_clone(&config_conv);
7297         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);
7298         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7299         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7300         long ret_ref = (long)ret_var.inner;
7301         if (ret_var.is_owned) {
7302                 ret_ref |= 1;
7303         }
7304         return ret_ref;
7305 }
7306
7307 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) {
7308         LDKChannelManager this_arg_conv;
7309         this_arg_conv.inner = (void*)(this_arg & (~1));
7310         this_arg_conv.is_owned = false;
7311         LDKPublicKey their_network_key_ref;
7312         CHECK((*_env)->GetArrayLength (_env, their_network_key) == 33);
7313         (*_env)->GetByteArrayRegion (_env, their_network_key, 0, 33, their_network_key_ref.compressed_form);
7314         LDKUserConfig override_config_conv;
7315         override_config_conv.inner = (void*)(override_config & (~1));
7316         override_config_conv.is_owned = (override_config & 1) || (override_config == 0);
7317         if (override_config_conv.inner != NULL)
7318                 override_config_conv = UserConfig_clone(&override_config_conv);
7319         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
7320         *ret_conv = ChannelManager_create_channel(&this_arg_conv, their_network_key_ref, channel_value_satoshis, push_msat, user_id, override_config_conv);
7321         return (long)ret_conv;
7322 }
7323
7324 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
7325         LDKChannelManager this_arg_conv;
7326         this_arg_conv.inner = (void*)(this_arg & (~1));
7327         this_arg_conv.is_owned = false;
7328         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_channels(&this_arg_conv);
7329         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
7330         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
7331         for (size_t q = 0; q < ret_var.datalen; q++) {
7332                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
7333                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7334                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7335                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
7336                 if (arr_conv_16_var.is_owned) {
7337                         arr_conv_16_ref |= 1;
7338                 }
7339                 ret_arr_ptr[q] = arr_conv_16_ref;
7340         }
7341         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
7342         FREE(ret_var.data);
7343         return ret_arr;
7344 }
7345
7346 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1usable_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
7347         LDKChannelManager this_arg_conv;
7348         this_arg_conv.inner = (void*)(this_arg & (~1));
7349         this_arg_conv.is_owned = false;
7350         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_usable_channels(&this_arg_conv);
7351         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
7352         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
7353         for (size_t q = 0; q < ret_var.datalen; q++) {
7354                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
7355                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7356                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7357                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
7358                 if (arr_conv_16_var.is_owned) {
7359                         arr_conv_16_ref |= 1;
7360                 }
7361                 ret_arr_ptr[q] = arr_conv_16_ref;
7362         }
7363         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
7364         FREE(ret_var.data);
7365         return ret_arr;
7366 }
7367
7368 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1close_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray channel_id) {
7369         LDKChannelManager this_arg_conv;
7370         this_arg_conv.inner = (void*)(this_arg & (~1));
7371         this_arg_conv.is_owned = false;
7372         unsigned char channel_id_arr[32];
7373         CHECK((*_env)->GetArrayLength (_env, channel_id) == 32);
7374         (*_env)->GetByteArrayRegion (_env, channel_id, 0, 32, channel_id_arr);
7375         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
7376         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
7377         *ret_conv = ChannelManager_close_channel(&this_arg_conv, channel_id_ref);
7378         return (long)ret_conv;
7379 }
7380
7381 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray channel_id) {
7382         LDKChannelManager this_arg_conv;
7383         this_arg_conv.inner = (void*)(this_arg & (~1));
7384         this_arg_conv.is_owned = false;
7385         unsigned char channel_id_arr[32];
7386         CHECK((*_env)->GetArrayLength (_env, channel_id) == 32);
7387         (*_env)->GetByteArrayRegion (_env, channel_id, 0, 32, channel_id_arr);
7388         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
7389         ChannelManager_force_close_channel(&this_arg_conv, channel_id_ref);
7390 }
7391
7392 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1all_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
7393         LDKChannelManager this_arg_conv;
7394         this_arg_conv.inner = (void*)(this_arg & (~1));
7395         this_arg_conv.is_owned = false;
7396         ChannelManager_force_close_all_channels(&this_arg_conv);
7397 }
7398
7399 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) {
7400         LDKChannelManager this_arg_conv;
7401         this_arg_conv.inner = (void*)(this_arg & (~1));
7402         this_arg_conv.is_owned = false;
7403         LDKRoute route_conv;
7404         route_conv.inner = (void*)(route & (~1));
7405         route_conv.is_owned = false;
7406         LDKThirtyTwoBytes payment_hash_ref;
7407         CHECK((*_env)->GetArrayLength (_env, payment_hash) == 32);
7408         (*_env)->GetByteArrayRegion (_env, payment_hash, 0, 32, payment_hash_ref.data);
7409         LDKThirtyTwoBytes payment_secret_ref;
7410         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
7411         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
7412         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
7413         *ret_conv = ChannelManager_send_payment(&this_arg_conv, &route_conv, payment_hash_ref, payment_secret_ref);
7414         return (long)ret_conv;
7415 }
7416
7417 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) {
7418         LDKChannelManager this_arg_conv;
7419         this_arg_conv.inner = (void*)(this_arg & (~1));
7420         this_arg_conv.is_owned = false;
7421         unsigned char temporary_channel_id_arr[32];
7422         CHECK((*_env)->GetArrayLength (_env, temporary_channel_id) == 32);
7423         (*_env)->GetByteArrayRegion (_env, temporary_channel_id, 0, 32, temporary_channel_id_arr);
7424         unsigned char (*temporary_channel_id_ref)[32] = &temporary_channel_id_arr;
7425         LDKOutPoint funding_txo_conv;
7426         funding_txo_conv.inner = (void*)(funding_txo & (~1));
7427         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
7428         if (funding_txo_conv.inner != NULL)
7429                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
7430         ChannelManager_funding_transaction_generated(&this_arg_conv, temporary_channel_id_ref, funding_txo_conv);
7431 }
7432
7433 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) {
7434         LDKChannelManager this_arg_conv;
7435         this_arg_conv.inner = (void*)(this_arg & (~1));
7436         this_arg_conv.is_owned = false;
7437         LDKThreeBytes rgb_ref;
7438         CHECK((*_env)->GetArrayLength (_env, rgb) == 3);
7439         (*_env)->GetByteArrayRegion (_env, rgb, 0, 3, rgb_ref.data);
7440         LDKThirtyTwoBytes alias_ref;
7441         CHECK((*_env)->GetArrayLength (_env, alias) == 32);
7442         (*_env)->GetByteArrayRegion (_env, alias, 0, 32, alias_ref.data);
7443         LDKCVec_NetAddressZ addresses_constr;
7444         addresses_constr.datalen = (*_env)->GetArrayLength (_env, addresses);
7445         if (addresses_constr.datalen > 0)
7446                 addresses_constr.data = MALLOC(addresses_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
7447         else
7448                 addresses_constr.data = NULL;
7449         long* addresses_vals = (*_env)->GetLongArrayElements (_env, addresses, NULL);
7450         for (size_t m = 0; m < addresses_constr.datalen; m++) {
7451                 long arr_conv_12 = addresses_vals[m];
7452                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
7453                 FREE((void*)arr_conv_12);
7454                 addresses_constr.data[m] = arr_conv_12_conv;
7455         }
7456         (*_env)->ReleaseLongArrayElements (_env, addresses, addresses_vals, 0);
7457         ChannelManager_broadcast_node_announcement(&this_arg_conv, rgb_ref, alias_ref, addresses_constr);
7458 }
7459
7460 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1process_1pending_1htlc_1forwards(JNIEnv * _env, jclass _b, jlong this_arg) {
7461         LDKChannelManager this_arg_conv;
7462         this_arg_conv.inner = (void*)(this_arg & (~1));
7463         this_arg_conv.is_owned = false;
7464         ChannelManager_process_pending_htlc_forwards(&this_arg_conv);
7465 }
7466
7467 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1timer_1chan_1freshness_1every_1min(JNIEnv * _env, jclass _b, jlong this_arg) {
7468         LDKChannelManager this_arg_conv;
7469         this_arg_conv.inner = (void*)(this_arg & (~1));
7470         this_arg_conv.is_owned = false;
7471         ChannelManager_timer_chan_freshness_every_min(&this_arg_conv);
7472 }
7473
7474 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) {
7475         LDKChannelManager this_arg_conv;
7476         this_arg_conv.inner = (void*)(this_arg & (~1));
7477         this_arg_conv.is_owned = false;
7478         unsigned char payment_hash_arr[32];
7479         CHECK((*_env)->GetArrayLength (_env, payment_hash) == 32);
7480         (*_env)->GetByteArrayRegion (_env, payment_hash, 0, 32, payment_hash_arr);
7481         unsigned char (*payment_hash_ref)[32] = &payment_hash_arr;
7482         LDKThirtyTwoBytes payment_secret_ref;
7483         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
7484         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
7485         jboolean ret_val = ChannelManager_fail_htlc_backwards(&this_arg_conv, payment_hash_ref, payment_secret_ref);
7486         return ret_val;
7487 }
7488
7489 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) {
7490         LDKChannelManager this_arg_conv;
7491         this_arg_conv.inner = (void*)(this_arg & (~1));
7492         this_arg_conv.is_owned = false;
7493         LDKThirtyTwoBytes payment_preimage_ref;
7494         CHECK((*_env)->GetArrayLength (_env, payment_preimage) == 32);
7495         (*_env)->GetByteArrayRegion (_env, payment_preimage, 0, 32, payment_preimage_ref.data);
7496         LDKThirtyTwoBytes payment_secret_ref;
7497         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
7498         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
7499         jboolean ret_val = ChannelManager_claim_funds(&this_arg_conv, payment_preimage_ref, payment_secret_ref, expected_amount);
7500         return ret_val;
7501 }
7502
7503 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1get_1our_1node_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
7504         LDKChannelManager this_arg_conv;
7505         this_arg_conv.inner = (void*)(this_arg & (~1));
7506         this_arg_conv.is_owned = false;
7507         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
7508         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelManager_get_our_node_id(&this_arg_conv).compressed_form);
7509         return arg_arr;
7510 }
7511
7512 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) {
7513         LDKChannelManager this_arg_conv;
7514         this_arg_conv.inner = (void*)(this_arg & (~1));
7515         this_arg_conv.is_owned = false;
7516         LDKOutPoint funding_txo_conv;
7517         funding_txo_conv.inner = (void*)(funding_txo & (~1));
7518         funding_txo_conv.is_owned = false;
7519         ChannelManager_channel_monitor_updated(&this_arg_conv, &funding_txo_conv, highest_applied_update_id);
7520 }
7521
7522 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1MessageSendEventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
7523         LDKChannelManager this_arg_conv;
7524         this_arg_conv.inner = (void*)(this_arg & (~1));
7525         this_arg_conv.is_owned = false;
7526         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
7527         *ret = ChannelManager_as_MessageSendEventsProvider(&this_arg_conv);
7528         return (long)ret;
7529 }
7530
7531 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1EventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
7532         LDKChannelManager this_arg_conv;
7533         this_arg_conv.inner = (void*)(this_arg & (~1));
7534         this_arg_conv.is_owned = false;
7535         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
7536         *ret = ChannelManager_as_EventsProvider(&this_arg_conv);
7537         return (long)ret;
7538 }
7539
7540 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jlongArray txdata, jint height) {
7541         LDKChannelManager this_arg_conv;
7542         this_arg_conv.inner = (void*)(this_arg & (~1));
7543         this_arg_conv.is_owned = false;
7544         unsigned char header_arr[80];
7545         CHECK((*_env)->GetArrayLength (_env, header) == 80);
7546         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
7547         unsigned char (*header_ref)[80] = &header_arr;
7548         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
7549         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
7550         if (txdata_constr.datalen > 0)
7551                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
7552         else
7553                 txdata_constr.data = NULL;
7554         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
7555         for (size_t y = 0; y < txdata_constr.datalen; y++) {
7556                 long arr_conv_24 = txdata_vals[y];
7557                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
7558                 FREE((void*)arr_conv_24);
7559                 txdata_constr.data[y] = arr_conv_24_conv;
7560         }
7561         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
7562         ChannelManager_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
7563 }
7564
7565 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header) {
7566         LDKChannelManager this_arg_conv;
7567         this_arg_conv.inner = (void*)(this_arg & (~1));
7568         this_arg_conv.is_owned = false;
7569         unsigned char header_arr[80];
7570         CHECK((*_env)->GetArrayLength (_env, header) == 80);
7571         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
7572         unsigned char (*header_ref)[80] = &header_arr;
7573         ChannelManager_block_disconnected(&this_arg_conv, header_ref);
7574 }
7575
7576 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1ChannelMessageHandler(JNIEnv * _env, jclass _b, jlong this_arg) {
7577         LDKChannelManager this_arg_conv;
7578         this_arg_conv.inner = (void*)(this_arg & (~1));
7579         this_arg_conv.is_owned = false;
7580         LDKChannelMessageHandler* ret = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
7581         *ret = ChannelManager_as_ChannelMessageHandler(&this_arg_conv);
7582         return (long)ret;
7583 }
7584
7585 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7586         LDKChannelManagerReadArgs this_ptr_conv;
7587         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7588         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7589         ChannelManagerReadArgs_free(this_ptr_conv);
7590 }
7591
7592 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1keys_1manager(JNIEnv * _env, jclass _b, jlong this_ptr) {
7593         LDKChannelManagerReadArgs this_ptr_conv;
7594         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7595         this_ptr_conv.is_owned = false;
7596         long ret_ret = (long)ChannelManagerReadArgs_get_keys_manager(&this_ptr_conv);
7597         return ret_ret;
7598 }
7599
7600 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1keys_1manager(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7601         LDKChannelManagerReadArgs this_ptr_conv;
7602         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7603         this_ptr_conv.is_owned = false;
7604         LDKKeysInterface val_conv = *(LDKKeysInterface*)val;
7605         if (val_conv.free == LDKKeysInterface_JCalls_free) {
7606                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7607                 LDKKeysInterface_JCalls_clone(val_conv.this_arg);
7608         }
7609         ChannelManagerReadArgs_set_keys_manager(&this_ptr_conv, val_conv);
7610 }
7611
7612 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1fee_1estimator(JNIEnv * _env, jclass _b, jlong this_ptr) {
7613         LDKChannelManagerReadArgs this_ptr_conv;
7614         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7615         this_ptr_conv.is_owned = false;
7616         long ret_ret = (long)ChannelManagerReadArgs_get_fee_estimator(&this_ptr_conv);
7617         return ret_ret;
7618 }
7619
7620 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1fee_1estimator(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7621         LDKChannelManagerReadArgs this_ptr_conv;
7622         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7623         this_ptr_conv.is_owned = false;
7624         LDKFeeEstimator val_conv = *(LDKFeeEstimator*)val;
7625         if (val_conv.free == LDKFeeEstimator_JCalls_free) {
7626                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7627                 LDKFeeEstimator_JCalls_clone(val_conv.this_arg);
7628         }
7629         ChannelManagerReadArgs_set_fee_estimator(&this_ptr_conv, val_conv);
7630 }
7631
7632 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1chain_1monitor(JNIEnv * _env, jclass _b, jlong this_ptr) {
7633         LDKChannelManagerReadArgs this_ptr_conv;
7634         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7635         this_ptr_conv.is_owned = false;
7636         long ret_ret = (long)ChannelManagerReadArgs_get_chain_monitor(&this_ptr_conv);
7637         return ret_ret;
7638 }
7639
7640 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1chain_1monitor(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7641         LDKChannelManagerReadArgs this_ptr_conv;
7642         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7643         this_ptr_conv.is_owned = false;
7644         LDKWatch val_conv = *(LDKWatch*)val;
7645         if (val_conv.free == LDKWatch_JCalls_free) {
7646                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7647                 LDKWatch_JCalls_clone(val_conv.this_arg);
7648         }
7649         ChannelManagerReadArgs_set_chain_monitor(&this_ptr_conv, val_conv);
7650 }
7651
7652 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1tx_1broadcaster(JNIEnv * _env, jclass _b, jlong this_ptr) {
7653         LDKChannelManagerReadArgs this_ptr_conv;
7654         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7655         this_ptr_conv.is_owned = false;
7656         long ret_ret = (long)ChannelManagerReadArgs_get_tx_broadcaster(&this_ptr_conv);
7657         return ret_ret;
7658 }
7659
7660 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1tx_1broadcaster(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7661         LDKChannelManagerReadArgs this_ptr_conv;
7662         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7663         this_ptr_conv.is_owned = false;
7664         LDKBroadcasterInterface val_conv = *(LDKBroadcasterInterface*)val;
7665         if (val_conv.free == LDKBroadcasterInterface_JCalls_free) {
7666                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7667                 LDKBroadcasterInterface_JCalls_clone(val_conv.this_arg);
7668         }
7669         ChannelManagerReadArgs_set_tx_broadcaster(&this_ptr_conv, val_conv);
7670 }
7671
7672 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1logger(JNIEnv * _env, jclass _b, jlong this_ptr) {
7673         LDKChannelManagerReadArgs this_ptr_conv;
7674         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7675         this_ptr_conv.is_owned = false;
7676         long ret_ret = (long)ChannelManagerReadArgs_get_logger(&this_ptr_conv);
7677         return ret_ret;
7678 }
7679
7680 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1logger(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7681         LDKChannelManagerReadArgs this_ptr_conv;
7682         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7683         this_ptr_conv.is_owned = false;
7684         LDKLogger val_conv = *(LDKLogger*)val;
7685         if (val_conv.free == LDKLogger_JCalls_free) {
7686                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7687                 LDKLogger_JCalls_clone(val_conv.this_arg);
7688         }
7689         ChannelManagerReadArgs_set_logger(&this_ptr_conv, val_conv);
7690 }
7691
7692 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1default_1config(JNIEnv * _env, jclass _b, jlong this_ptr) {
7693         LDKChannelManagerReadArgs this_ptr_conv;
7694         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7695         this_ptr_conv.is_owned = false;
7696         LDKUserConfig ret_var = ChannelManagerReadArgs_get_default_config(&this_ptr_conv);
7697         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7698         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7699         long ret_ref = (long)ret_var.inner;
7700         if (ret_var.is_owned) {
7701                 ret_ref |= 1;
7702         }
7703         return ret_ref;
7704 }
7705
7706 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1default_1config(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7707         LDKChannelManagerReadArgs this_ptr_conv;
7708         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7709         this_ptr_conv.is_owned = false;
7710         LDKUserConfig val_conv;
7711         val_conv.inner = (void*)(val & (~1));
7712         val_conv.is_owned = (val & 1) || (val == 0);
7713         if (val_conv.inner != NULL)
7714                 val_conv = UserConfig_clone(&val_conv);
7715         ChannelManagerReadArgs_set_default_config(&this_ptr_conv, val_conv);
7716 }
7717
7718 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) {
7719         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
7720         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
7721                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7722                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
7723         }
7724         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
7725         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
7726                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7727                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
7728         }
7729         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
7730         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
7731                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7732                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
7733         }
7734         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
7735         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
7736                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7737                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
7738         }
7739         LDKLogger logger_conv = *(LDKLogger*)logger;
7740         if (logger_conv.free == LDKLogger_JCalls_free) {
7741                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7742                 LDKLogger_JCalls_clone(logger_conv.this_arg);
7743         }
7744         LDKUserConfig default_config_conv;
7745         default_config_conv.inner = (void*)(default_config & (~1));
7746         default_config_conv.is_owned = (default_config & 1) || (default_config == 0);
7747         if (default_config_conv.inner != NULL)
7748                 default_config_conv = UserConfig_clone(&default_config_conv);
7749         LDKCVec_ChannelMonitorZ channel_monitors_constr;
7750         channel_monitors_constr.datalen = (*_env)->GetArrayLength (_env, channel_monitors);
7751         if (channel_monitors_constr.datalen > 0)
7752                 channel_monitors_constr.data = MALLOC(channel_monitors_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
7753         else
7754                 channel_monitors_constr.data = NULL;
7755         long* channel_monitors_vals = (*_env)->GetLongArrayElements (_env, channel_monitors, NULL);
7756         for (size_t q = 0; q < channel_monitors_constr.datalen; q++) {
7757                 long arr_conv_16 = channel_monitors_vals[q];
7758                 LDKChannelMonitor arr_conv_16_conv;
7759                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
7760                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
7761                 channel_monitors_constr.data[q] = arr_conv_16_conv;
7762         }
7763         (*_env)->ReleaseLongArrayElements (_env, channel_monitors, channel_monitors_vals, 0);
7764         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);
7765         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7766         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7767         long ret_ref = (long)ret_var.inner;
7768         if (ret_var.is_owned) {
7769                 ret_ref |= 1;
7770         }
7771         return ret_ref;
7772 }
7773
7774 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DecodeError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7775         LDKDecodeError this_ptr_conv;
7776         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7777         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7778         DecodeError_free(this_ptr_conv);
7779 }
7780
7781 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Init_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7782         LDKInit this_ptr_conv;
7783         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7784         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7785         Init_free(this_ptr_conv);
7786 }
7787
7788 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Init_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7789         LDKInit orig_conv;
7790         orig_conv.inner = (void*)(orig & (~1));
7791         orig_conv.is_owned = false;
7792         LDKInit ret_var = Init_clone(&orig_conv);
7793         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7794         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7795         long ret_ref = (long)ret_var.inner;
7796         if (ret_var.is_owned) {
7797                 ret_ref |= 1;
7798         }
7799         return ret_ref;
7800 }
7801
7802 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7803         LDKErrorMessage this_ptr_conv;
7804         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7805         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7806         ErrorMessage_free(this_ptr_conv);
7807 }
7808
7809 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7810         LDKErrorMessage orig_conv;
7811         orig_conv.inner = (void*)(orig & (~1));
7812         orig_conv.is_owned = false;
7813         LDKErrorMessage ret_var = ErrorMessage_clone(&orig_conv);
7814         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7815         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7816         long ret_ref = (long)ret_var.inner;
7817         if (ret_var.is_owned) {
7818                 ret_ref |= 1;
7819         }
7820         return ret_ref;
7821 }
7822
7823 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
7824         LDKErrorMessage this_ptr_conv;
7825         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7826         this_ptr_conv.is_owned = false;
7827         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
7828         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ErrorMessage_get_channel_id(&this_ptr_conv));
7829         return ret_arr;
7830 }
7831
7832 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7833         LDKErrorMessage this_ptr_conv;
7834         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7835         this_ptr_conv.is_owned = false;
7836         LDKThirtyTwoBytes val_ref;
7837         CHECK((*_env)->GetArrayLength (_env, val) == 32);
7838         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
7839         ErrorMessage_set_channel_id(&this_ptr_conv, val_ref);
7840 }
7841
7842 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1data(JNIEnv * _env, jclass _b, jlong this_ptr) {
7843         LDKErrorMessage this_ptr_conv;
7844         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7845         this_ptr_conv.is_owned = false;
7846         LDKStr _str = ErrorMessage_get_data(&this_ptr_conv);
7847         char* _buf = MALLOC(_str.len + 1, "str conv buf");
7848         memcpy(_buf, _str.chars, _str.len);
7849         _buf[_str.len] = 0;
7850         jstring _conv = (*_env)->NewStringUTF(_env, _str.chars);
7851         FREE(_buf);
7852         return _conv;
7853 }
7854
7855 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1data(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7856         LDKErrorMessage this_ptr_conv;
7857         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7858         this_ptr_conv.is_owned = false;
7859         LDKCVec_u8Z val_ref;
7860         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
7861         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
7862         (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data);
7863         ErrorMessage_set_data(&this_ptr_conv, val_ref);
7864 }
7865
7866 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray data_arg) {
7867         LDKThirtyTwoBytes channel_id_arg_ref;
7868         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
7869         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
7870         LDKCVec_u8Z data_arg_ref;
7871         data_arg_ref.datalen = (*_env)->GetArrayLength (_env, data_arg);
7872         data_arg_ref.data = MALLOC(data_arg_ref.datalen, "LDKCVec_u8Z Bytes");
7873         (*_env)->GetByteArrayRegion(_env, data_arg, 0, data_arg_ref.datalen, data_arg_ref.data);
7874         LDKErrorMessage ret_var = ErrorMessage_new(channel_id_arg_ref, data_arg_ref);
7875         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7876         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7877         long ret_ref = (long)ret_var.inner;
7878         if (ret_var.is_owned) {
7879                 ret_ref |= 1;
7880         }
7881         return ret_ref;
7882 }
7883
7884 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7885         LDKPing 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         Ping_free(this_ptr_conv);
7889 }
7890
7891 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7892         LDKPing orig_conv;
7893         orig_conv.inner = (void*)(orig & (~1));
7894         orig_conv.is_owned = false;
7895         LDKPing ret_var = Ping_clone(&orig_conv);
7896         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7897         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7898         long ret_ref = (long)ret_var.inner;
7899         if (ret_var.is_owned) {
7900                 ret_ref |= 1;
7901         }
7902         return ret_ref;
7903 }
7904
7905 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Ping_1get_1ponglen(JNIEnv * _env, jclass _b, jlong this_ptr) {
7906         LDKPing this_ptr_conv;
7907         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7908         this_ptr_conv.is_owned = false;
7909         jshort ret_val = Ping_get_ponglen(&this_ptr_conv);
7910         return ret_val;
7911 }
7912
7913 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1ponglen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7914         LDKPing this_ptr_conv;
7915         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7916         this_ptr_conv.is_owned = false;
7917         Ping_set_ponglen(&this_ptr_conv, val);
7918 }
7919
7920 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Ping_1get_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr) {
7921         LDKPing this_ptr_conv;
7922         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7923         this_ptr_conv.is_owned = false;
7924         jshort ret_val = Ping_get_byteslen(&this_ptr_conv);
7925         return ret_val;
7926 }
7927
7928 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7929         LDKPing this_ptr_conv;
7930         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7931         this_ptr_conv.is_owned = false;
7932         Ping_set_byteslen(&this_ptr_conv, val);
7933 }
7934
7935 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1new(JNIEnv * _env, jclass _b, jshort ponglen_arg, jshort byteslen_arg) {
7936         LDKPing ret_var = Ping_new(ponglen_arg, byteslen_arg);
7937         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7938         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7939         long ret_ref = (long)ret_var.inner;
7940         if (ret_var.is_owned) {
7941                 ret_ref |= 1;
7942         }
7943         return ret_ref;
7944 }
7945
7946 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7947         LDKPong this_ptr_conv;
7948         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7949         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7950         Pong_free(this_ptr_conv);
7951 }
7952
7953 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7954         LDKPong orig_conv;
7955         orig_conv.inner = (void*)(orig & (~1));
7956         orig_conv.is_owned = false;
7957         LDKPong ret_var = Pong_clone(&orig_conv);
7958         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7959         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7960         long ret_ref = (long)ret_var.inner;
7961         if (ret_var.is_owned) {
7962                 ret_ref |= 1;
7963         }
7964         return ret_ref;
7965 }
7966
7967 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Pong_1get_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr) {
7968         LDKPong this_ptr_conv;
7969         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7970         this_ptr_conv.is_owned = false;
7971         jshort ret_val = Pong_get_byteslen(&this_ptr_conv);
7972         return ret_val;
7973 }
7974
7975 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1set_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7976         LDKPong this_ptr_conv;
7977         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7978         this_ptr_conv.is_owned = false;
7979         Pong_set_byteslen(&this_ptr_conv, val);
7980 }
7981
7982 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1new(JNIEnv * _env, jclass _b, jshort byteslen_arg) {
7983         LDKPong ret_var = Pong_new(byteslen_arg);
7984         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7985         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7986         long ret_ref = (long)ret_var.inner;
7987         if (ret_var.is_owned) {
7988                 ret_ref |= 1;
7989         }
7990         return ret_ref;
7991 }
7992
7993 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7994         LDKOpenChannel this_ptr_conv;
7995         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7996         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7997         OpenChannel_free(this_ptr_conv);
7998 }
7999
8000 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8001         LDKOpenChannel orig_conv;
8002         orig_conv.inner = (void*)(orig & (~1));
8003         orig_conv.is_owned = false;
8004         LDKOpenChannel ret_var = OpenChannel_clone(&orig_conv);
8005         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8006         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8007         long ret_ref = (long)ret_var.inner;
8008         if (ret_var.is_owned) {
8009                 ret_ref |= 1;
8010         }
8011         return ret_ref;
8012 }
8013
8014 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
8015         LDKOpenChannel this_ptr_conv;
8016         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8017         this_ptr_conv.is_owned = false;
8018         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8019         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OpenChannel_get_chain_hash(&this_ptr_conv));
8020         return ret_arr;
8021 }
8022
8023 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8024         LDKOpenChannel this_ptr_conv;
8025         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8026         this_ptr_conv.is_owned = false;
8027         LDKThirtyTwoBytes val_ref;
8028         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8029         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8030         OpenChannel_set_chain_hash(&this_ptr_conv, val_ref);
8031 }
8032
8033 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8034         LDKOpenChannel this_ptr_conv;
8035         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8036         this_ptr_conv.is_owned = false;
8037         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8038         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OpenChannel_get_temporary_channel_id(&this_ptr_conv));
8039         return ret_arr;
8040 }
8041
8042 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8043         LDKOpenChannel this_ptr_conv;
8044         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8045         this_ptr_conv.is_owned = false;
8046         LDKThirtyTwoBytes val_ref;
8047         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8048         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8049         OpenChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
8050 }
8051
8052 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
8053         LDKOpenChannel this_ptr_conv;
8054         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8055         this_ptr_conv.is_owned = false;
8056         jlong ret_val = OpenChannel_get_funding_satoshis(&this_ptr_conv);
8057         return ret_val;
8058 }
8059
8060 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8061         LDKOpenChannel this_ptr_conv;
8062         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8063         this_ptr_conv.is_owned = false;
8064         OpenChannel_set_funding_satoshis(&this_ptr_conv, val);
8065 }
8066
8067 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1push_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
8068         LDKOpenChannel this_ptr_conv;
8069         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8070         this_ptr_conv.is_owned = false;
8071         jlong ret_val = OpenChannel_get_push_msat(&this_ptr_conv);
8072         return ret_val;
8073 }
8074
8075 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1push_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8076         LDKOpenChannel this_ptr_conv;
8077         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8078         this_ptr_conv.is_owned = false;
8079         OpenChannel_set_push_msat(&this_ptr_conv, val);
8080 }
8081
8082 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
8083         LDKOpenChannel this_ptr_conv;
8084         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8085         this_ptr_conv.is_owned = false;
8086         jlong ret_val = OpenChannel_get_dust_limit_satoshis(&this_ptr_conv);
8087         return ret_val;
8088 }
8089
8090 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8091         LDKOpenChannel this_ptr_conv;
8092         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8093         this_ptr_conv.is_owned = false;
8094         OpenChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
8095 }
8096
8097 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
8098         LDKOpenChannel this_ptr_conv;
8099         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8100         this_ptr_conv.is_owned = false;
8101         jlong ret_val = OpenChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
8102         return ret_val;
8103 }
8104
8105 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) {
8106         LDKOpenChannel this_ptr_conv;
8107         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8108         this_ptr_conv.is_owned = false;
8109         OpenChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
8110 }
8111
8112 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
8113         LDKOpenChannel this_ptr_conv;
8114         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8115         this_ptr_conv.is_owned = false;
8116         jlong ret_val = OpenChannel_get_channel_reserve_satoshis(&this_ptr_conv);
8117         return ret_val;
8118 }
8119
8120 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8121         LDKOpenChannel this_ptr_conv;
8122         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8123         this_ptr_conv.is_owned = false;
8124         OpenChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
8125 }
8126
8127 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
8128         LDKOpenChannel this_ptr_conv;
8129         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8130         this_ptr_conv.is_owned = false;
8131         jlong ret_val = OpenChannel_get_htlc_minimum_msat(&this_ptr_conv);
8132         return ret_val;
8133 }
8134
8135 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8136         LDKOpenChannel this_ptr_conv;
8137         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8138         this_ptr_conv.is_owned = false;
8139         OpenChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
8140 }
8141
8142 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr) {
8143         LDKOpenChannel this_ptr_conv;
8144         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8145         this_ptr_conv.is_owned = false;
8146         jint ret_val = OpenChannel_get_feerate_per_kw(&this_ptr_conv);
8147         return ret_val;
8148 }
8149
8150 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
8151         LDKOpenChannel this_ptr_conv;
8152         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8153         this_ptr_conv.is_owned = false;
8154         OpenChannel_set_feerate_per_kw(&this_ptr_conv, val);
8155 }
8156
8157 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
8158         LDKOpenChannel this_ptr_conv;
8159         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8160         this_ptr_conv.is_owned = false;
8161         jshort ret_val = OpenChannel_get_to_self_delay(&this_ptr_conv);
8162         return ret_val;
8163 }
8164
8165 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8166         LDKOpenChannel this_ptr_conv;
8167         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8168         this_ptr_conv.is_owned = false;
8169         OpenChannel_set_to_self_delay(&this_ptr_conv, val);
8170 }
8171
8172 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
8173         LDKOpenChannel this_ptr_conv;
8174         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8175         this_ptr_conv.is_owned = false;
8176         jshort ret_val = OpenChannel_get_max_accepted_htlcs(&this_ptr_conv);
8177         return ret_val;
8178 }
8179
8180 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8181         LDKOpenChannel this_ptr_conv;
8182         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8183         this_ptr_conv.is_owned = false;
8184         OpenChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
8185 }
8186
8187 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
8188         LDKOpenChannel this_ptr_conv;
8189         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8190         this_ptr_conv.is_owned = false;
8191         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8192         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
8193         return arg_arr;
8194 }
8195
8196 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8197         LDKOpenChannel this_ptr_conv;
8198         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8199         this_ptr_conv.is_owned = false;
8200         LDKPublicKey val_ref;
8201         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8202         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8203         OpenChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
8204 }
8205
8206 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8207         LDKOpenChannel this_ptr_conv;
8208         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8209         this_ptr_conv.is_owned = false;
8210         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8211         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
8212         return arg_arr;
8213 }
8214
8215 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8216         LDKOpenChannel this_ptr_conv;
8217         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8218         this_ptr_conv.is_owned = false;
8219         LDKPublicKey val_ref;
8220         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8221         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8222         OpenChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
8223 }
8224
8225 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
8226         LDKOpenChannel this_ptr_conv;
8227         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8228         this_ptr_conv.is_owned = false;
8229         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8230         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_payment_point(&this_ptr_conv).compressed_form);
8231         return arg_arr;
8232 }
8233
8234 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8235         LDKOpenChannel this_ptr_conv;
8236         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8237         this_ptr_conv.is_owned = false;
8238         LDKPublicKey val_ref;
8239         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8240         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8241         OpenChannel_set_payment_point(&this_ptr_conv, val_ref);
8242 }
8243
8244 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8245         LDKOpenChannel this_ptr_conv;
8246         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8247         this_ptr_conv.is_owned = false;
8248         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8249         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
8250         return arg_arr;
8251 }
8252
8253 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8254         LDKOpenChannel this_ptr_conv;
8255         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8256         this_ptr_conv.is_owned = false;
8257         LDKPublicKey val_ref;
8258         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8259         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8260         OpenChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
8261 }
8262
8263 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8264         LDKOpenChannel this_ptr_conv;
8265         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8266         this_ptr_conv.is_owned = false;
8267         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8268         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
8269         return arg_arr;
8270 }
8271
8272 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8273         LDKOpenChannel this_ptr_conv;
8274         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8275         this_ptr_conv.is_owned = false;
8276         LDKPublicKey val_ref;
8277         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8278         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8279         OpenChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
8280 }
8281
8282 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
8283         LDKOpenChannel this_ptr_conv;
8284         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8285         this_ptr_conv.is_owned = false;
8286         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8287         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
8288         return arg_arr;
8289 }
8290
8291 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8292         LDKOpenChannel this_ptr_conv;
8293         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8294         this_ptr_conv.is_owned = false;
8295         LDKPublicKey val_ref;
8296         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8297         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8298         OpenChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
8299 }
8300
8301 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1flags(JNIEnv * _env, jclass _b, jlong this_ptr) {
8302         LDKOpenChannel this_ptr_conv;
8303         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8304         this_ptr_conv.is_owned = false;
8305         jbyte ret_val = OpenChannel_get_channel_flags(&this_ptr_conv);
8306         return ret_val;
8307 }
8308
8309 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1flags(JNIEnv * _env, jclass _b, jlong this_ptr, jbyte val) {
8310         LDKOpenChannel this_ptr_conv;
8311         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8312         this_ptr_conv.is_owned = false;
8313         OpenChannel_set_channel_flags(&this_ptr_conv, val);
8314 }
8315
8316 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8317         LDKAcceptChannel this_ptr_conv;
8318         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8319         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8320         AcceptChannel_free(this_ptr_conv);
8321 }
8322
8323 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8324         LDKAcceptChannel orig_conv;
8325         orig_conv.inner = (void*)(orig & (~1));
8326         orig_conv.is_owned = false;
8327         LDKAcceptChannel ret_var = AcceptChannel_clone(&orig_conv);
8328         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8329         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8330         long ret_ref = (long)ret_var.inner;
8331         if (ret_var.is_owned) {
8332                 ret_ref |= 1;
8333         }
8334         return ret_ref;
8335 }
8336
8337 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8338         LDKAcceptChannel this_ptr_conv;
8339         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8340         this_ptr_conv.is_owned = false;
8341         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8342         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *AcceptChannel_get_temporary_channel_id(&this_ptr_conv));
8343         return ret_arr;
8344 }
8345
8346 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8347         LDKAcceptChannel this_ptr_conv;
8348         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8349         this_ptr_conv.is_owned = false;
8350         LDKThirtyTwoBytes val_ref;
8351         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8352         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8353         AcceptChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
8354 }
8355
8356 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
8357         LDKAcceptChannel this_ptr_conv;
8358         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8359         this_ptr_conv.is_owned = false;
8360         jlong ret_val = AcceptChannel_get_dust_limit_satoshis(&this_ptr_conv);
8361         return ret_val;
8362 }
8363
8364 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8365         LDKAcceptChannel this_ptr_conv;
8366         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8367         this_ptr_conv.is_owned = false;
8368         AcceptChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
8369 }
8370
8371 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
8372         LDKAcceptChannel this_ptr_conv;
8373         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8374         this_ptr_conv.is_owned = false;
8375         jlong ret_val = AcceptChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
8376         return ret_val;
8377 }
8378
8379 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) {
8380         LDKAcceptChannel this_ptr_conv;
8381         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8382         this_ptr_conv.is_owned = false;
8383         AcceptChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
8384 }
8385
8386 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
8387         LDKAcceptChannel this_ptr_conv;
8388         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8389         this_ptr_conv.is_owned = false;
8390         jlong ret_val = AcceptChannel_get_channel_reserve_satoshis(&this_ptr_conv);
8391         return ret_val;
8392 }
8393
8394 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8395         LDKAcceptChannel this_ptr_conv;
8396         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8397         this_ptr_conv.is_owned = false;
8398         AcceptChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
8399 }
8400
8401 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
8402         LDKAcceptChannel this_ptr_conv;
8403         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8404         this_ptr_conv.is_owned = false;
8405         jlong ret_val = AcceptChannel_get_htlc_minimum_msat(&this_ptr_conv);
8406         return ret_val;
8407 }
8408
8409 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8410         LDKAcceptChannel this_ptr_conv;
8411         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8412         this_ptr_conv.is_owned = false;
8413         AcceptChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
8414 }
8415
8416 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
8417         LDKAcceptChannel this_ptr_conv;
8418         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8419         this_ptr_conv.is_owned = false;
8420         jint ret_val = AcceptChannel_get_minimum_depth(&this_ptr_conv);
8421         return ret_val;
8422 }
8423
8424 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
8425         LDKAcceptChannel this_ptr_conv;
8426         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8427         this_ptr_conv.is_owned = false;
8428         AcceptChannel_set_minimum_depth(&this_ptr_conv, val);
8429 }
8430
8431 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
8432         LDKAcceptChannel this_ptr_conv;
8433         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8434         this_ptr_conv.is_owned = false;
8435         jshort ret_val = AcceptChannel_get_to_self_delay(&this_ptr_conv);
8436         return ret_val;
8437 }
8438
8439 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8440         LDKAcceptChannel this_ptr_conv;
8441         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8442         this_ptr_conv.is_owned = false;
8443         AcceptChannel_set_to_self_delay(&this_ptr_conv, val);
8444 }
8445
8446 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
8447         LDKAcceptChannel this_ptr_conv;
8448         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8449         this_ptr_conv.is_owned = false;
8450         jshort ret_val = AcceptChannel_get_max_accepted_htlcs(&this_ptr_conv);
8451         return ret_val;
8452 }
8453
8454 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8455         LDKAcceptChannel this_ptr_conv;
8456         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8457         this_ptr_conv.is_owned = false;
8458         AcceptChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
8459 }
8460
8461 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
8462         LDKAcceptChannel this_ptr_conv;
8463         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8464         this_ptr_conv.is_owned = false;
8465         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8466         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
8467         return arg_arr;
8468 }
8469
8470 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8471         LDKAcceptChannel this_ptr_conv;
8472         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8473         this_ptr_conv.is_owned = false;
8474         LDKPublicKey val_ref;
8475         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8476         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8477         AcceptChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
8478 }
8479
8480 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8481         LDKAcceptChannel this_ptr_conv;
8482         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8483         this_ptr_conv.is_owned = false;
8484         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8485         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
8486         return arg_arr;
8487 }
8488
8489 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8490         LDKAcceptChannel this_ptr_conv;
8491         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8492         this_ptr_conv.is_owned = false;
8493         LDKPublicKey val_ref;
8494         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8495         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8496         AcceptChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
8497 }
8498
8499 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
8500         LDKAcceptChannel this_ptr_conv;
8501         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8502         this_ptr_conv.is_owned = false;
8503         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8504         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_payment_point(&this_ptr_conv).compressed_form);
8505         return arg_arr;
8506 }
8507
8508 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8509         LDKAcceptChannel this_ptr_conv;
8510         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8511         this_ptr_conv.is_owned = false;
8512         LDKPublicKey val_ref;
8513         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8514         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8515         AcceptChannel_set_payment_point(&this_ptr_conv, val_ref);
8516 }
8517
8518 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8519         LDKAcceptChannel this_ptr_conv;
8520         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8521         this_ptr_conv.is_owned = false;
8522         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8523         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
8524         return arg_arr;
8525 }
8526
8527 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8528         LDKAcceptChannel this_ptr_conv;
8529         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8530         this_ptr_conv.is_owned = false;
8531         LDKPublicKey val_ref;
8532         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8533         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8534         AcceptChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
8535 }
8536
8537 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8538         LDKAcceptChannel this_ptr_conv;
8539         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8540         this_ptr_conv.is_owned = false;
8541         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8542         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
8543         return arg_arr;
8544 }
8545
8546 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8547         LDKAcceptChannel this_ptr_conv;
8548         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8549         this_ptr_conv.is_owned = false;
8550         LDKPublicKey val_ref;
8551         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8552         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8553         AcceptChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
8554 }
8555
8556 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
8557         LDKAcceptChannel this_ptr_conv;
8558         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8559         this_ptr_conv.is_owned = false;
8560         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8561         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
8562         return arg_arr;
8563 }
8564
8565 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8566         LDKAcceptChannel this_ptr_conv;
8567         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8568         this_ptr_conv.is_owned = false;
8569         LDKPublicKey val_ref;
8570         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8571         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8572         AcceptChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
8573 }
8574
8575 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8576         LDKFundingCreated this_ptr_conv;
8577         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8578         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8579         FundingCreated_free(this_ptr_conv);
8580 }
8581
8582 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingCreated_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8583         LDKFundingCreated orig_conv;
8584         orig_conv.inner = (void*)(orig & (~1));
8585         orig_conv.is_owned = false;
8586         LDKFundingCreated ret_var = FundingCreated_clone(&orig_conv);
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 jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8597         LDKFundingCreated this_ptr_conv;
8598         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8599         this_ptr_conv.is_owned = false;
8600         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8601         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingCreated_get_temporary_channel_id(&this_ptr_conv));
8602         return ret_arr;
8603 }
8604
8605 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8606         LDKFundingCreated this_ptr_conv;
8607         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8608         this_ptr_conv.is_owned = false;
8609         LDKThirtyTwoBytes val_ref;
8610         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8611         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8612         FundingCreated_set_temporary_channel_id(&this_ptr_conv, val_ref);
8613 }
8614
8615 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1txid(JNIEnv * _env, jclass _b, jlong this_ptr) {
8616         LDKFundingCreated this_ptr_conv;
8617         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8618         this_ptr_conv.is_owned = false;
8619         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8620         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingCreated_get_funding_txid(&this_ptr_conv));
8621         return ret_arr;
8622 }
8623
8624 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1txid(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8625         LDKFundingCreated this_ptr_conv;
8626         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8627         this_ptr_conv.is_owned = false;
8628         LDKThirtyTwoBytes val_ref;
8629         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8630         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8631         FundingCreated_set_funding_txid(&this_ptr_conv, val_ref);
8632 }
8633
8634 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1output_1index(JNIEnv * _env, jclass _b, jlong this_ptr) {
8635         LDKFundingCreated this_ptr_conv;
8636         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8637         this_ptr_conv.is_owned = false;
8638         jshort ret_val = FundingCreated_get_funding_output_index(&this_ptr_conv);
8639         return ret_val;
8640 }
8641
8642 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1output_1index(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8643         LDKFundingCreated this_ptr_conv;
8644         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8645         this_ptr_conv.is_owned = false;
8646         FundingCreated_set_funding_output_index(&this_ptr_conv, val);
8647 }
8648
8649 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
8650         LDKFundingCreated this_ptr_conv;
8651         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8652         this_ptr_conv.is_owned = false;
8653         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
8654         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, FundingCreated_get_signature(&this_ptr_conv).compact_form);
8655         return arg_arr;
8656 }
8657
8658 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8659         LDKFundingCreated this_ptr_conv;
8660         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8661         this_ptr_conv.is_owned = false;
8662         LDKSignature val_ref;
8663         CHECK((*_env)->GetArrayLength (_env, val) == 64);
8664         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
8665         FundingCreated_set_signature(&this_ptr_conv, val_ref);
8666 }
8667
8668 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) {
8669         LDKThirtyTwoBytes temporary_channel_id_arg_ref;
8670         CHECK((*_env)->GetArrayLength (_env, temporary_channel_id_arg) == 32);
8671         (*_env)->GetByteArrayRegion (_env, temporary_channel_id_arg, 0, 32, temporary_channel_id_arg_ref.data);
8672         LDKThirtyTwoBytes funding_txid_arg_ref;
8673         CHECK((*_env)->GetArrayLength (_env, funding_txid_arg) == 32);
8674         (*_env)->GetByteArrayRegion (_env, funding_txid_arg, 0, 32, funding_txid_arg_ref.data);
8675         LDKSignature signature_arg_ref;
8676         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
8677         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
8678         LDKFundingCreated ret_var = FundingCreated_new(temporary_channel_id_arg_ref, funding_txid_arg_ref, funding_output_index_arg, signature_arg_ref);
8679         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8680         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8681         long ret_ref = (long)ret_var.inner;
8682         if (ret_var.is_owned) {
8683                 ret_ref |= 1;
8684         }
8685         return ret_ref;
8686 }
8687
8688 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8689         LDKFundingSigned this_ptr_conv;
8690         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8691         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8692         FundingSigned_free(this_ptr_conv);
8693 }
8694
8695 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8696         LDKFundingSigned orig_conv;
8697         orig_conv.inner = (void*)(orig & (~1));
8698         orig_conv.is_owned = false;
8699         LDKFundingSigned ret_var = FundingSigned_clone(&orig_conv);
8700         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8701         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8702         long ret_ref = (long)ret_var.inner;
8703         if (ret_var.is_owned) {
8704                 ret_ref |= 1;
8705         }
8706         return ret_ref;
8707 }
8708
8709 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8710         LDKFundingSigned this_ptr_conv;
8711         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8712         this_ptr_conv.is_owned = false;
8713         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8714         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingSigned_get_channel_id(&this_ptr_conv));
8715         return ret_arr;
8716 }
8717
8718 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8719         LDKFundingSigned this_ptr_conv;
8720         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8721         this_ptr_conv.is_owned = false;
8722         LDKThirtyTwoBytes val_ref;
8723         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8724         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8725         FundingSigned_set_channel_id(&this_ptr_conv, val_ref);
8726 }
8727
8728 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
8729         LDKFundingSigned this_ptr_conv;
8730         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8731         this_ptr_conv.is_owned = false;
8732         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
8733         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, FundingSigned_get_signature(&this_ptr_conv).compact_form);
8734         return arg_arr;
8735 }
8736
8737 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8738         LDKFundingSigned this_ptr_conv;
8739         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8740         this_ptr_conv.is_owned = false;
8741         LDKSignature val_ref;
8742         CHECK((*_env)->GetArrayLength (_env, val) == 64);
8743         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
8744         FundingSigned_set_signature(&this_ptr_conv, val_ref);
8745 }
8746
8747 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray signature_arg) {
8748         LDKThirtyTwoBytes channel_id_arg_ref;
8749         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
8750         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
8751         LDKSignature signature_arg_ref;
8752         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
8753         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
8754         LDKFundingSigned ret_var = FundingSigned_new(channel_id_arg_ref, signature_arg_ref);
8755         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8756         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8757         long ret_ref = (long)ret_var.inner;
8758         if (ret_var.is_owned) {
8759                 ret_ref |= 1;
8760         }
8761         return ret_ref;
8762 }
8763
8764 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8765         LDKFundingLocked this_ptr_conv;
8766         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8767         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8768         FundingLocked_free(this_ptr_conv);
8769 }
8770
8771 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8772         LDKFundingLocked orig_conv;
8773         orig_conv.inner = (void*)(orig & (~1));
8774         orig_conv.is_owned = false;
8775         LDKFundingLocked ret_var = FundingLocked_clone(&orig_conv);
8776         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8777         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8778         long ret_ref = (long)ret_var.inner;
8779         if (ret_var.is_owned) {
8780                 ret_ref |= 1;
8781         }
8782         return ret_ref;
8783 }
8784
8785 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8786         LDKFundingLocked this_ptr_conv;
8787         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8788         this_ptr_conv.is_owned = false;
8789         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8790         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingLocked_get_channel_id(&this_ptr_conv));
8791         return ret_arr;
8792 }
8793
8794 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8795         LDKFundingLocked this_ptr_conv;
8796         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8797         this_ptr_conv.is_owned = false;
8798         LDKThirtyTwoBytes val_ref;
8799         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8800         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8801         FundingLocked_set_channel_id(&this_ptr_conv, val_ref);
8802 }
8803
8804 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
8805         LDKFundingLocked this_ptr_conv;
8806         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8807         this_ptr_conv.is_owned = false;
8808         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8809         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, FundingLocked_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
8810         return arg_arr;
8811 }
8812
8813 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1set_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8814         LDKFundingLocked this_ptr_conv;
8815         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8816         this_ptr_conv.is_owned = false;
8817         LDKPublicKey val_ref;
8818         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8819         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8820         FundingLocked_set_next_per_commitment_point(&this_ptr_conv, val_ref);
8821 }
8822
8823 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray next_per_commitment_point_arg) {
8824         LDKThirtyTwoBytes channel_id_arg_ref;
8825         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
8826         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
8827         LDKPublicKey next_per_commitment_point_arg_ref;
8828         CHECK((*_env)->GetArrayLength (_env, next_per_commitment_point_arg) == 33);
8829         (*_env)->GetByteArrayRegion (_env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
8830         LDKFundingLocked ret_var = FundingLocked_new(channel_id_arg_ref, next_per_commitment_point_arg_ref);
8831         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8832         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8833         long ret_ref = (long)ret_var.inner;
8834         if (ret_var.is_owned) {
8835                 ret_ref |= 1;
8836         }
8837         return ret_ref;
8838 }
8839
8840 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8841         LDKShutdown this_ptr_conv;
8842         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8843         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8844         Shutdown_free(this_ptr_conv);
8845 }
8846
8847 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8848         LDKShutdown orig_conv;
8849         orig_conv.inner = (void*)(orig & (~1));
8850         orig_conv.is_owned = false;
8851         LDKShutdown ret_var = Shutdown_clone(&orig_conv);
8852         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8853         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8854         long ret_ref = (long)ret_var.inner;
8855         if (ret_var.is_owned) {
8856                 ret_ref |= 1;
8857         }
8858         return ret_ref;
8859 }
8860
8861 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8862         LDKShutdown this_ptr_conv;
8863         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8864         this_ptr_conv.is_owned = false;
8865         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8866         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *Shutdown_get_channel_id(&this_ptr_conv));
8867         return ret_arr;
8868 }
8869
8870 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8871         LDKShutdown this_ptr_conv;
8872         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8873         this_ptr_conv.is_owned = false;
8874         LDKThirtyTwoBytes val_ref;
8875         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8876         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8877         Shutdown_set_channel_id(&this_ptr_conv, val_ref);
8878 }
8879
8880 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1scriptpubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
8881         LDKShutdown this_ptr_conv;
8882         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8883         this_ptr_conv.is_owned = false;
8884         LDKu8slice arg_var = Shutdown_get_scriptpubkey(&this_ptr_conv);
8885         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8886         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8887         return arg_arr;
8888 }
8889
8890 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1scriptpubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8891         LDKShutdown this_ptr_conv;
8892         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8893         this_ptr_conv.is_owned = false;
8894         LDKCVec_u8Z val_ref;
8895         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
8896         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
8897         (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data);
8898         Shutdown_set_scriptpubkey(&this_ptr_conv, val_ref);
8899 }
8900
8901 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray scriptpubkey_arg) {
8902         LDKThirtyTwoBytes channel_id_arg_ref;
8903         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
8904         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
8905         LDKCVec_u8Z scriptpubkey_arg_ref;
8906         scriptpubkey_arg_ref.datalen = (*_env)->GetArrayLength (_env, scriptpubkey_arg);
8907         scriptpubkey_arg_ref.data = MALLOC(scriptpubkey_arg_ref.datalen, "LDKCVec_u8Z Bytes");
8908         (*_env)->GetByteArrayRegion(_env, scriptpubkey_arg, 0, scriptpubkey_arg_ref.datalen, scriptpubkey_arg_ref.data);
8909         LDKShutdown ret_var = Shutdown_new(channel_id_arg_ref, scriptpubkey_arg_ref);
8910         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8911         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8912         long ret_ref = (long)ret_var.inner;
8913         if (ret_var.is_owned) {
8914                 ret_ref |= 1;
8915         }
8916         return ret_ref;
8917 }
8918
8919 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8920         LDKClosingSigned this_ptr_conv;
8921         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8922         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8923         ClosingSigned_free(this_ptr_conv);
8924 }
8925
8926 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8927         LDKClosingSigned orig_conv;
8928         orig_conv.inner = (void*)(orig & (~1));
8929         orig_conv.is_owned = false;
8930         LDKClosingSigned ret_var = ClosingSigned_clone(&orig_conv);
8931         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8932         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8933         long ret_ref = (long)ret_var.inner;
8934         if (ret_var.is_owned) {
8935                 ret_ref |= 1;
8936         }
8937         return ret_ref;
8938 }
8939
8940 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8941         LDKClosingSigned this_ptr_conv;
8942         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8943         this_ptr_conv.is_owned = false;
8944         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8945         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ClosingSigned_get_channel_id(&this_ptr_conv));
8946         return ret_arr;
8947 }
8948
8949 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8950         LDKClosingSigned this_ptr_conv;
8951         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8952         this_ptr_conv.is_owned = false;
8953         LDKThirtyTwoBytes val_ref;
8954         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8955         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8956         ClosingSigned_set_channel_id(&this_ptr_conv, val_ref);
8957 }
8958
8959 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1fee_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
8960         LDKClosingSigned this_ptr_conv;
8961         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8962         this_ptr_conv.is_owned = false;
8963         jlong ret_val = ClosingSigned_get_fee_satoshis(&this_ptr_conv);
8964         return ret_val;
8965 }
8966
8967 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1fee_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8968         LDKClosingSigned this_ptr_conv;
8969         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8970         this_ptr_conv.is_owned = false;
8971         ClosingSigned_set_fee_satoshis(&this_ptr_conv, val);
8972 }
8973
8974 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
8975         LDKClosingSigned this_ptr_conv;
8976         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8977         this_ptr_conv.is_owned = false;
8978         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
8979         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ClosingSigned_get_signature(&this_ptr_conv).compact_form);
8980         return arg_arr;
8981 }
8982
8983 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8984         LDKClosingSigned this_ptr_conv;
8985         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8986         this_ptr_conv.is_owned = false;
8987         LDKSignature val_ref;
8988         CHECK((*_env)->GetArrayLength (_env, val) == 64);
8989         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
8990         ClosingSigned_set_signature(&this_ptr_conv, val_ref);
8991 }
8992
8993 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) {
8994         LDKThirtyTwoBytes channel_id_arg_ref;
8995         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
8996         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
8997         LDKSignature signature_arg_ref;
8998         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
8999         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
9000         LDKClosingSigned ret_var = ClosingSigned_new(channel_id_arg_ref, fee_satoshis_arg, signature_arg_ref);
9001         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9002         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9003         long ret_ref = (long)ret_var.inner;
9004         if (ret_var.is_owned) {
9005                 ret_ref |= 1;
9006         }
9007         return ret_ref;
9008 }
9009
9010 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9011         LDKUpdateAddHTLC 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         UpdateAddHTLC_free(this_ptr_conv);
9015 }
9016
9017 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9018         LDKUpdateAddHTLC orig_conv;
9019         orig_conv.inner = (void*)(orig & (~1));
9020         orig_conv.is_owned = false;
9021         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_clone(&orig_conv);
9022         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9023         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9024         long ret_ref = (long)ret_var.inner;
9025         if (ret_var.is_owned) {
9026                 ret_ref |= 1;
9027         }
9028         return ret_ref;
9029 }
9030
9031 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9032         LDKUpdateAddHTLC this_ptr_conv;
9033         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9034         this_ptr_conv.is_owned = false;
9035         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9036         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateAddHTLC_get_channel_id(&this_ptr_conv));
9037         return ret_arr;
9038 }
9039
9040 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9041         LDKUpdateAddHTLC this_ptr_conv;
9042         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9043         this_ptr_conv.is_owned = false;
9044         LDKThirtyTwoBytes val_ref;
9045         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9046         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9047         UpdateAddHTLC_set_channel_id(&this_ptr_conv, val_ref);
9048 }
9049
9050 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9051         LDKUpdateAddHTLC this_ptr_conv;
9052         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9053         this_ptr_conv.is_owned = false;
9054         jlong ret_val = UpdateAddHTLC_get_htlc_id(&this_ptr_conv);
9055         return ret_val;
9056 }
9057
9058 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9059         LDKUpdateAddHTLC this_ptr_conv;
9060         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9061         this_ptr_conv.is_owned = false;
9062         UpdateAddHTLC_set_htlc_id(&this_ptr_conv, val);
9063 }
9064
9065 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
9066         LDKUpdateAddHTLC this_ptr_conv;
9067         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9068         this_ptr_conv.is_owned = false;
9069         jlong ret_val = UpdateAddHTLC_get_amount_msat(&this_ptr_conv);
9070         return ret_val;
9071 }
9072
9073 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9074         LDKUpdateAddHTLC this_ptr_conv;
9075         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9076         this_ptr_conv.is_owned = false;
9077         UpdateAddHTLC_set_amount_msat(&this_ptr_conv, val);
9078 }
9079
9080 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
9081         LDKUpdateAddHTLC this_ptr_conv;
9082         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9083         this_ptr_conv.is_owned = false;
9084         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9085         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateAddHTLC_get_payment_hash(&this_ptr_conv));
9086         return ret_arr;
9087 }
9088
9089 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9090         LDKUpdateAddHTLC this_ptr_conv;
9091         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9092         this_ptr_conv.is_owned = false;
9093         LDKThirtyTwoBytes val_ref;
9094         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9095         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9096         UpdateAddHTLC_set_payment_hash(&this_ptr_conv, val_ref);
9097 }
9098
9099 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr) {
9100         LDKUpdateAddHTLC this_ptr_conv;
9101         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9102         this_ptr_conv.is_owned = false;
9103         jint ret_val = UpdateAddHTLC_get_cltv_expiry(&this_ptr_conv);
9104         return ret_val;
9105 }
9106
9107 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
9108         LDKUpdateAddHTLC this_ptr_conv;
9109         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9110         this_ptr_conv.is_owned = false;
9111         UpdateAddHTLC_set_cltv_expiry(&this_ptr_conv, val);
9112 }
9113
9114 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9115         LDKUpdateFulfillHTLC this_ptr_conv;
9116         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9117         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9118         UpdateFulfillHTLC_free(this_ptr_conv);
9119 }
9120
9121 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9122         LDKUpdateFulfillHTLC orig_conv;
9123         orig_conv.inner = (void*)(orig & (~1));
9124         orig_conv.is_owned = false;
9125         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_clone(&orig_conv);
9126         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9127         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9128         long ret_ref = (long)ret_var.inner;
9129         if (ret_var.is_owned) {
9130                 ret_ref |= 1;
9131         }
9132         return ret_ref;
9133 }
9134
9135 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9136         LDKUpdateFulfillHTLC this_ptr_conv;
9137         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9138         this_ptr_conv.is_owned = false;
9139         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9140         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_channel_id(&this_ptr_conv));
9141         return ret_arr;
9142 }
9143
9144 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9145         LDKUpdateFulfillHTLC this_ptr_conv;
9146         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9147         this_ptr_conv.is_owned = false;
9148         LDKThirtyTwoBytes val_ref;
9149         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9150         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9151         UpdateFulfillHTLC_set_channel_id(&this_ptr_conv, val_ref);
9152 }
9153
9154 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9155         LDKUpdateFulfillHTLC this_ptr_conv;
9156         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9157         this_ptr_conv.is_owned = false;
9158         jlong ret_val = UpdateFulfillHTLC_get_htlc_id(&this_ptr_conv);
9159         return ret_val;
9160 }
9161
9162 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9163         LDKUpdateFulfillHTLC this_ptr_conv;
9164         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9165         this_ptr_conv.is_owned = false;
9166         UpdateFulfillHTLC_set_htlc_id(&this_ptr_conv, val);
9167 }
9168
9169 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1payment_1preimage(JNIEnv * _env, jclass _b, jlong this_ptr) {
9170         LDKUpdateFulfillHTLC this_ptr_conv;
9171         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9172         this_ptr_conv.is_owned = false;
9173         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9174         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_payment_preimage(&this_ptr_conv));
9175         return ret_arr;
9176 }
9177
9178 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1payment_1preimage(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9179         LDKUpdateFulfillHTLC this_ptr_conv;
9180         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9181         this_ptr_conv.is_owned = false;
9182         LDKThirtyTwoBytes val_ref;
9183         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9184         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9185         UpdateFulfillHTLC_set_payment_preimage(&this_ptr_conv, val_ref);
9186 }
9187
9188 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) {
9189         LDKThirtyTwoBytes channel_id_arg_ref;
9190         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9191         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9192         LDKThirtyTwoBytes payment_preimage_arg_ref;
9193         CHECK((*_env)->GetArrayLength (_env, payment_preimage_arg) == 32);
9194         (*_env)->GetByteArrayRegion (_env, payment_preimage_arg, 0, 32, payment_preimage_arg_ref.data);
9195         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_new(channel_id_arg_ref, htlc_id_arg, payment_preimage_arg_ref);
9196         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9197         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9198         long ret_ref = (long)ret_var.inner;
9199         if (ret_var.is_owned) {
9200                 ret_ref |= 1;
9201         }
9202         return ret_ref;
9203 }
9204
9205 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9206         LDKUpdateFailHTLC this_ptr_conv;
9207         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9208         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9209         UpdateFailHTLC_free(this_ptr_conv);
9210 }
9211
9212 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9213         LDKUpdateFailHTLC orig_conv;
9214         orig_conv.inner = (void*)(orig & (~1));
9215         orig_conv.is_owned = false;
9216         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_clone(&orig_conv);
9217         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9218         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9219         long ret_ref = (long)ret_var.inner;
9220         if (ret_var.is_owned) {
9221                 ret_ref |= 1;
9222         }
9223         return ret_ref;
9224 }
9225
9226 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9227         LDKUpdateFailHTLC this_ptr_conv;
9228         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9229         this_ptr_conv.is_owned = false;
9230         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9231         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFailHTLC_get_channel_id(&this_ptr_conv));
9232         return ret_arr;
9233 }
9234
9235 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9236         LDKUpdateFailHTLC this_ptr_conv;
9237         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9238         this_ptr_conv.is_owned = false;
9239         LDKThirtyTwoBytes val_ref;
9240         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9241         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9242         UpdateFailHTLC_set_channel_id(&this_ptr_conv, val_ref);
9243 }
9244
9245 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9246         LDKUpdateFailHTLC this_ptr_conv;
9247         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9248         this_ptr_conv.is_owned = false;
9249         jlong ret_val = UpdateFailHTLC_get_htlc_id(&this_ptr_conv);
9250         return ret_val;
9251 }
9252
9253 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9254         LDKUpdateFailHTLC this_ptr_conv;
9255         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9256         this_ptr_conv.is_owned = false;
9257         UpdateFailHTLC_set_htlc_id(&this_ptr_conv, val);
9258 }
9259
9260 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9261         LDKUpdateFailMalformedHTLC this_ptr_conv;
9262         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9263         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9264         UpdateFailMalformedHTLC_free(this_ptr_conv);
9265 }
9266
9267 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9268         LDKUpdateFailMalformedHTLC orig_conv;
9269         orig_conv.inner = (void*)(orig & (~1));
9270         orig_conv.is_owned = false;
9271         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_clone(&orig_conv);
9272         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9273         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9274         long ret_ref = (long)ret_var.inner;
9275         if (ret_var.is_owned) {
9276                 ret_ref |= 1;
9277         }
9278         return ret_ref;
9279 }
9280
9281 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9282         LDKUpdateFailMalformedHTLC this_ptr_conv;
9283         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9284         this_ptr_conv.is_owned = false;
9285         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9286         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFailMalformedHTLC_get_channel_id(&this_ptr_conv));
9287         return ret_arr;
9288 }
9289
9290 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9291         LDKUpdateFailMalformedHTLC this_ptr_conv;
9292         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9293         this_ptr_conv.is_owned = false;
9294         LDKThirtyTwoBytes val_ref;
9295         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9296         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9297         UpdateFailMalformedHTLC_set_channel_id(&this_ptr_conv, val_ref);
9298 }
9299
9300 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9301         LDKUpdateFailMalformedHTLC this_ptr_conv;
9302         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9303         this_ptr_conv.is_owned = false;
9304         jlong ret_val = UpdateFailMalformedHTLC_get_htlc_id(&this_ptr_conv);
9305         return ret_val;
9306 }
9307
9308 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9309         LDKUpdateFailMalformedHTLC this_ptr_conv;
9310         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9311         this_ptr_conv.is_owned = false;
9312         UpdateFailMalformedHTLC_set_htlc_id(&this_ptr_conv, val);
9313 }
9314
9315 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1failure_1code(JNIEnv * _env, jclass _b, jlong this_ptr) {
9316         LDKUpdateFailMalformedHTLC this_ptr_conv;
9317         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9318         this_ptr_conv.is_owned = false;
9319         jshort ret_val = UpdateFailMalformedHTLC_get_failure_code(&this_ptr_conv);
9320         return ret_val;
9321 }
9322
9323 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1failure_1code(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
9324         LDKUpdateFailMalformedHTLC this_ptr_conv;
9325         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9326         this_ptr_conv.is_owned = false;
9327         UpdateFailMalformedHTLC_set_failure_code(&this_ptr_conv, val);
9328 }
9329
9330 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9331         LDKCommitmentSigned 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         CommitmentSigned_free(this_ptr_conv);
9335 }
9336
9337 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9338         LDKCommitmentSigned orig_conv;
9339         orig_conv.inner = (void*)(orig & (~1));
9340         orig_conv.is_owned = false;
9341         LDKCommitmentSigned ret_var = CommitmentSigned_clone(&orig_conv);
9342         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9343         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9344         long ret_ref = (long)ret_var.inner;
9345         if (ret_var.is_owned) {
9346                 ret_ref |= 1;
9347         }
9348         return ret_ref;
9349 }
9350
9351 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9352         LDKCommitmentSigned this_ptr_conv;
9353         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9354         this_ptr_conv.is_owned = false;
9355         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9356         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *CommitmentSigned_get_channel_id(&this_ptr_conv));
9357         return ret_arr;
9358 }
9359
9360 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9361         LDKCommitmentSigned this_ptr_conv;
9362         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9363         this_ptr_conv.is_owned = false;
9364         LDKThirtyTwoBytes val_ref;
9365         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9366         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9367         CommitmentSigned_set_channel_id(&this_ptr_conv, val_ref);
9368 }
9369
9370 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
9371         LDKCommitmentSigned this_ptr_conv;
9372         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9373         this_ptr_conv.is_owned = false;
9374         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9375         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, CommitmentSigned_get_signature(&this_ptr_conv).compact_form);
9376         return arg_arr;
9377 }
9378
9379 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9380         LDKCommitmentSigned this_ptr_conv;
9381         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9382         this_ptr_conv.is_owned = false;
9383         LDKSignature val_ref;
9384         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9385         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9386         CommitmentSigned_set_signature(&this_ptr_conv, val_ref);
9387 }
9388
9389 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1htlc_1signatures(JNIEnv * _env, jclass _b, jlong this_ptr, jobjectArray val) {
9390         LDKCommitmentSigned this_ptr_conv;
9391         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9392         this_ptr_conv.is_owned = false;
9393         LDKCVec_SignatureZ val_constr;
9394         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
9395         if (val_constr.datalen > 0)
9396                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
9397         else
9398                 val_constr.data = NULL;
9399         for (size_t i = 0; i < val_constr.datalen; i++) {
9400                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, val, i);
9401                 LDKSignature arr_conv_8_ref;
9402                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
9403                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
9404                 val_constr.data[i] = arr_conv_8_ref;
9405         }
9406         CommitmentSigned_set_htlc_signatures(&this_ptr_conv, val_constr);
9407 }
9408
9409 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) {
9410         LDKThirtyTwoBytes channel_id_arg_ref;
9411         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9412         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9413         LDKSignature signature_arg_ref;
9414         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
9415         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
9416         LDKCVec_SignatureZ htlc_signatures_arg_constr;
9417         htlc_signatures_arg_constr.datalen = (*_env)->GetArrayLength (_env, htlc_signatures_arg);
9418         if (htlc_signatures_arg_constr.datalen > 0)
9419                 htlc_signatures_arg_constr.data = MALLOC(htlc_signatures_arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
9420         else
9421                 htlc_signatures_arg_constr.data = NULL;
9422         for (size_t i = 0; i < htlc_signatures_arg_constr.datalen; i++) {
9423                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, htlc_signatures_arg, i);
9424                 LDKSignature arr_conv_8_ref;
9425                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
9426                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
9427                 htlc_signatures_arg_constr.data[i] = arr_conv_8_ref;
9428         }
9429         LDKCommitmentSigned ret_var = CommitmentSigned_new(channel_id_arg_ref, signature_arg_ref, htlc_signatures_arg_constr);
9430         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9431         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9432         long ret_ref = (long)ret_var.inner;
9433         if (ret_var.is_owned) {
9434                 ret_ref |= 1;
9435         }
9436         return ret_ref;
9437 }
9438
9439 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9440         LDKRevokeAndACK this_ptr_conv;
9441         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9442         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9443         RevokeAndACK_free(this_ptr_conv);
9444 }
9445
9446 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9447         LDKRevokeAndACK orig_conv;
9448         orig_conv.inner = (void*)(orig & (~1));
9449         orig_conv.is_owned = false;
9450         LDKRevokeAndACK ret_var = RevokeAndACK_clone(&orig_conv);
9451         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9452         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9453         long ret_ref = (long)ret_var.inner;
9454         if (ret_var.is_owned) {
9455                 ret_ref |= 1;
9456         }
9457         return ret_ref;
9458 }
9459
9460 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9461         LDKRevokeAndACK this_ptr_conv;
9462         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9463         this_ptr_conv.is_owned = false;
9464         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9465         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *RevokeAndACK_get_channel_id(&this_ptr_conv));
9466         return ret_arr;
9467 }
9468
9469 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9470         LDKRevokeAndACK this_ptr_conv;
9471         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9472         this_ptr_conv.is_owned = false;
9473         LDKThirtyTwoBytes val_ref;
9474         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9475         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9476         RevokeAndACK_set_channel_id(&this_ptr_conv, val_ref);
9477 }
9478
9479 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr) {
9480         LDKRevokeAndACK this_ptr_conv;
9481         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9482         this_ptr_conv.is_owned = false;
9483         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9484         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *RevokeAndACK_get_per_commitment_secret(&this_ptr_conv));
9485         return ret_arr;
9486 }
9487
9488 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9489         LDKRevokeAndACK this_ptr_conv;
9490         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9491         this_ptr_conv.is_owned = false;
9492         LDKThirtyTwoBytes val_ref;
9493         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9494         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9495         RevokeAndACK_set_per_commitment_secret(&this_ptr_conv, val_ref);
9496 }
9497
9498 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
9499         LDKRevokeAndACK this_ptr_conv;
9500         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9501         this_ptr_conv.is_owned = false;
9502         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9503         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RevokeAndACK_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
9504         return arg_arr;
9505 }
9506
9507 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9508         LDKRevokeAndACK this_ptr_conv;
9509         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9510         this_ptr_conv.is_owned = false;
9511         LDKPublicKey val_ref;
9512         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9513         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9514         RevokeAndACK_set_next_per_commitment_point(&this_ptr_conv, val_ref);
9515 }
9516
9517 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) {
9518         LDKThirtyTwoBytes channel_id_arg_ref;
9519         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9520         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9521         LDKThirtyTwoBytes per_commitment_secret_arg_ref;
9522         CHECK((*_env)->GetArrayLength (_env, per_commitment_secret_arg) == 32);
9523         (*_env)->GetByteArrayRegion (_env, per_commitment_secret_arg, 0, 32, per_commitment_secret_arg_ref.data);
9524         LDKPublicKey next_per_commitment_point_arg_ref;
9525         CHECK((*_env)->GetArrayLength (_env, next_per_commitment_point_arg) == 33);
9526         (*_env)->GetByteArrayRegion (_env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
9527         LDKRevokeAndACK ret_var = RevokeAndACK_new(channel_id_arg_ref, per_commitment_secret_arg_ref, next_per_commitment_point_arg_ref);
9528         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9529         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9530         long ret_ref = (long)ret_var.inner;
9531         if (ret_var.is_owned) {
9532                 ret_ref |= 1;
9533         }
9534         return ret_ref;
9535 }
9536
9537 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9538         LDKUpdateFee this_ptr_conv;
9539         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9540         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9541         UpdateFee_free(this_ptr_conv);
9542 }
9543
9544 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9545         LDKUpdateFee orig_conv;
9546         orig_conv.inner = (void*)(orig & (~1));
9547         orig_conv.is_owned = false;
9548         LDKUpdateFee ret_var = UpdateFee_clone(&orig_conv);
9549         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9550         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9551         long ret_ref = (long)ret_var.inner;
9552         if (ret_var.is_owned) {
9553                 ret_ref |= 1;
9554         }
9555         return ret_ref;
9556 }
9557
9558 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9559         LDKUpdateFee this_ptr_conv;
9560         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9561         this_ptr_conv.is_owned = false;
9562         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9563         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFee_get_channel_id(&this_ptr_conv));
9564         return ret_arr;
9565 }
9566
9567 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9568         LDKUpdateFee this_ptr_conv;
9569         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9570         this_ptr_conv.is_owned = false;
9571         LDKThirtyTwoBytes val_ref;
9572         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9573         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9574         UpdateFee_set_channel_id(&this_ptr_conv, val_ref);
9575 }
9576
9577 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr) {
9578         LDKUpdateFee this_ptr_conv;
9579         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9580         this_ptr_conv.is_owned = false;
9581         jint ret_val = UpdateFee_get_feerate_per_kw(&this_ptr_conv);
9582         return ret_val;
9583 }
9584
9585 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
9586         LDKUpdateFee this_ptr_conv;
9587         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9588         this_ptr_conv.is_owned = false;
9589         UpdateFee_set_feerate_per_kw(&this_ptr_conv, val);
9590 }
9591
9592 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jint feerate_per_kw_arg) {
9593         LDKThirtyTwoBytes channel_id_arg_ref;
9594         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9595         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9596         LDKUpdateFee ret_var = UpdateFee_new(channel_id_arg_ref, feerate_per_kw_arg);
9597         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9598         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9599         long ret_ref = (long)ret_var.inner;
9600         if (ret_var.is_owned) {
9601                 ret_ref |= 1;
9602         }
9603         return ret_ref;
9604 }
9605
9606 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9607         LDKDataLossProtect this_ptr_conv;
9608         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9609         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9610         DataLossProtect_free(this_ptr_conv);
9611 }
9612
9613 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9614         LDKDataLossProtect orig_conv;
9615         orig_conv.inner = (void*)(orig & (~1));
9616         orig_conv.is_owned = false;
9617         LDKDataLossProtect ret_var = DataLossProtect_clone(&orig_conv);
9618         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9619         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9620         long ret_ref = (long)ret_var.inner;
9621         if (ret_var.is_owned) {
9622                 ret_ref |= 1;
9623         }
9624         return ret_ref;
9625 }
9626
9627 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1your_1last_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr) {
9628         LDKDataLossProtect this_ptr_conv;
9629         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9630         this_ptr_conv.is_owned = false;
9631         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9632         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *DataLossProtect_get_your_last_per_commitment_secret(&this_ptr_conv));
9633         return ret_arr;
9634 }
9635
9636 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1set_1your_1last_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9637         LDKDataLossProtect this_ptr_conv;
9638         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9639         this_ptr_conv.is_owned = false;
9640         LDKThirtyTwoBytes val_ref;
9641         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9642         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9643         DataLossProtect_set_your_last_per_commitment_secret(&this_ptr_conv, val_ref);
9644 }
9645
9646 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1my_1current_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
9647         LDKDataLossProtect this_ptr_conv;
9648         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9649         this_ptr_conv.is_owned = false;
9650         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9651         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, DataLossProtect_get_my_current_per_commitment_point(&this_ptr_conv).compressed_form);
9652         return arg_arr;
9653 }
9654
9655 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1set_1my_1current_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9656         LDKDataLossProtect this_ptr_conv;
9657         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9658         this_ptr_conv.is_owned = false;
9659         LDKPublicKey val_ref;
9660         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9661         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9662         DataLossProtect_set_my_current_per_commitment_point(&this_ptr_conv, val_ref);
9663 }
9664
9665 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) {
9666         LDKThirtyTwoBytes your_last_per_commitment_secret_arg_ref;
9667         CHECK((*_env)->GetArrayLength (_env, your_last_per_commitment_secret_arg) == 32);
9668         (*_env)->GetByteArrayRegion (_env, your_last_per_commitment_secret_arg, 0, 32, your_last_per_commitment_secret_arg_ref.data);
9669         LDKPublicKey my_current_per_commitment_point_arg_ref;
9670         CHECK((*_env)->GetArrayLength (_env, my_current_per_commitment_point_arg) == 33);
9671         (*_env)->GetByteArrayRegion (_env, my_current_per_commitment_point_arg, 0, 33, my_current_per_commitment_point_arg_ref.compressed_form);
9672         LDKDataLossProtect ret_var = DataLossProtect_new(your_last_per_commitment_secret_arg_ref, my_current_per_commitment_point_arg_ref);
9673         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9674         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9675         long ret_ref = (long)ret_var.inner;
9676         if (ret_var.is_owned) {
9677                 ret_ref |= 1;
9678         }
9679         return ret_ref;
9680 }
9681
9682 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9683         LDKChannelReestablish this_ptr_conv;
9684         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9685         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9686         ChannelReestablish_free(this_ptr_conv);
9687 }
9688
9689 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9690         LDKChannelReestablish orig_conv;
9691         orig_conv.inner = (void*)(orig & (~1));
9692         orig_conv.is_owned = false;
9693         LDKChannelReestablish ret_var = ChannelReestablish_clone(&orig_conv);
9694         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9695         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9696         long ret_ref = (long)ret_var.inner;
9697         if (ret_var.is_owned) {
9698                 ret_ref |= 1;
9699         }
9700         return ret_ref;
9701 }
9702
9703 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9704         LDKChannelReestablish this_ptr_conv;
9705         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9706         this_ptr_conv.is_owned = false;
9707         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9708         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ChannelReestablish_get_channel_id(&this_ptr_conv));
9709         return ret_arr;
9710 }
9711
9712 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9713         LDKChannelReestablish this_ptr_conv;
9714         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9715         this_ptr_conv.is_owned = false;
9716         LDKThirtyTwoBytes val_ref;
9717         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9718         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9719         ChannelReestablish_set_channel_id(&this_ptr_conv, val_ref);
9720 }
9721
9722 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1local_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr) {
9723         LDKChannelReestablish this_ptr_conv;
9724         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9725         this_ptr_conv.is_owned = false;
9726         jlong ret_val = ChannelReestablish_get_next_local_commitment_number(&this_ptr_conv);
9727         return ret_val;
9728 }
9729
9730 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1next_1local_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9731         LDKChannelReestablish this_ptr_conv;
9732         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9733         this_ptr_conv.is_owned = false;
9734         ChannelReestablish_set_next_local_commitment_number(&this_ptr_conv, val);
9735 }
9736
9737 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1remote_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr) {
9738         LDKChannelReestablish this_ptr_conv;
9739         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9740         this_ptr_conv.is_owned = false;
9741         jlong ret_val = ChannelReestablish_get_next_remote_commitment_number(&this_ptr_conv);
9742         return ret_val;
9743 }
9744
9745 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1next_1remote_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9746         LDKChannelReestablish this_ptr_conv;
9747         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9748         this_ptr_conv.is_owned = false;
9749         ChannelReestablish_set_next_remote_commitment_number(&this_ptr_conv, val);
9750 }
9751
9752 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9753         LDKAnnouncementSignatures this_ptr_conv;
9754         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9755         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9756         AnnouncementSignatures_free(this_ptr_conv);
9757 }
9758
9759 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9760         LDKAnnouncementSignatures orig_conv;
9761         orig_conv.inner = (void*)(orig & (~1));
9762         orig_conv.is_owned = false;
9763         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_clone(&orig_conv);
9764         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9765         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9766         long ret_ref = (long)ret_var.inner;
9767         if (ret_var.is_owned) {
9768                 ret_ref |= 1;
9769         }
9770         return ret_ref;
9771 }
9772
9773 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9774         LDKAnnouncementSignatures this_ptr_conv;
9775         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9776         this_ptr_conv.is_owned = false;
9777         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9778         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *AnnouncementSignatures_get_channel_id(&this_ptr_conv));
9779         return ret_arr;
9780 }
9781
9782 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9783         LDKAnnouncementSignatures this_ptr_conv;
9784         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9785         this_ptr_conv.is_owned = false;
9786         LDKThirtyTwoBytes val_ref;
9787         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9788         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9789         AnnouncementSignatures_set_channel_id(&this_ptr_conv, val_ref);
9790 }
9791
9792 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9793         LDKAnnouncementSignatures this_ptr_conv;
9794         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9795         this_ptr_conv.is_owned = false;
9796         jlong ret_val = AnnouncementSignatures_get_short_channel_id(&this_ptr_conv);
9797         return ret_val;
9798 }
9799
9800 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9801         LDKAnnouncementSignatures this_ptr_conv;
9802         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9803         this_ptr_conv.is_owned = false;
9804         AnnouncementSignatures_set_short_channel_id(&this_ptr_conv, val);
9805 }
9806
9807 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1node_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
9808         LDKAnnouncementSignatures this_ptr_conv;
9809         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9810         this_ptr_conv.is_owned = false;
9811         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9812         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, AnnouncementSignatures_get_node_signature(&this_ptr_conv).compact_form);
9813         return arg_arr;
9814 }
9815
9816 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1node_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9817         LDKAnnouncementSignatures this_ptr_conv;
9818         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9819         this_ptr_conv.is_owned = false;
9820         LDKSignature val_ref;
9821         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9822         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9823         AnnouncementSignatures_set_node_signature(&this_ptr_conv, val_ref);
9824 }
9825
9826 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1bitcoin_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
9827         LDKAnnouncementSignatures this_ptr_conv;
9828         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9829         this_ptr_conv.is_owned = false;
9830         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9831         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, AnnouncementSignatures_get_bitcoin_signature(&this_ptr_conv).compact_form);
9832         return arg_arr;
9833 }
9834
9835 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1bitcoin_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9836         LDKAnnouncementSignatures this_ptr_conv;
9837         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9838         this_ptr_conv.is_owned = false;
9839         LDKSignature val_ref;
9840         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9841         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9842         AnnouncementSignatures_set_bitcoin_signature(&this_ptr_conv, val_ref);
9843 }
9844
9845 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) {
9846         LDKThirtyTwoBytes channel_id_arg_ref;
9847         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9848         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9849         LDKSignature node_signature_arg_ref;
9850         CHECK((*_env)->GetArrayLength (_env, node_signature_arg) == 64);
9851         (*_env)->GetByteArrayRegion (_env, node_signature_arg, 0, 64, node_signature_arg_ref.compact_form);
9852         LDKSignature bitcoin_signature_arg_ref;
9853         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_arg) == 64);
9854         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_arg, 0, 64, bitcoin_signature_arg_ref.compact_form);
9855         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_new(channel_id_arg_ref, short_channel_id_arg, node_signature_arg_ref, bitcoin_signature_arg_ref);
9856         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9857         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9858         long ret_ref = (long)ret_var.inner;
9859         if (ret_var.is_owned) {
9860                 ret_ref |= 1;
9861         }
9862         return ret_ref;
9863 }
9864
9865 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetAddress_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9866         LDKNetAddress this_ptr_conv = *(LDKNetAddress*)this_ptr;
9867         FREE((void*)this_ptr);
9868         NetAddress_free(this_ptr_conv);
9869 }
9870
9871 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetAddress_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9872         LDKNetAddress* orig_conv = (LDKNetAddress*)orig;
9873         LDKNetAddress *ret_copy = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress");
9874         *ret_copy = NetAddress_clone(orig_conv);
9875         long ret_ref = (long)ret_copy;
9876         return ret_ref;
9877 }
9878
9879 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9880         LDKUnsignedNodeAnnouncement this_ptr_conv;
9881         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9882         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9883         UnsignedNodeAnnouncement_free(this_ptr_conv);
9884 }
9885
9886 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9887         LDKUnsignedNodeAnnouncement orig_conv;
9888         orig_conv.inner = (void*)(orig & (~1));
9889         orig_conv.is_owned = false;
9890         LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_clone(&orig_conv);
9891         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9892         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9893         long ret_ref = (long)ret_var.inner;
9894         if (ret_var.is_owned) {
9895                 ret_ref |= 1;
9896         }
9897         return ret_ref;
9898 }
9899
9900 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
9901         LDKUnsignedNodeAnnouncement this_ptr_conv;
9902         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9903         this_ptr_conv.is_owned = false;
9904         LDKNodeFeatures ret_var = UnsignedNodeAnnouncement_get_features(&this_ptr_conv);
9905         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9906         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9907         long ret_ref = (long)ret_var.inner;
9908         if (ret_var.is_owned) {
9909                 ret_ref |= 1;
9910         }
9911         return ret_ref;
9912 }
9913
9914 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9915         LDKUnsignedNodeAnnouncement this_ptr_conv;
9916         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9917         this_ptr_conv.is_owned = false;
9918         LDKNodeFeatures val_conv;
9919         val_conv.inner = (void*)(val & (~1));
9920         val_conv.is_owned = (val & 1) || (val == 0);
9921         // Warning: we may need a move here but can't clone!
9922         UnsignedNodeAnnouncement_set_features(&this_ptr_conv, val_conv);
9923 }
9924
9925 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
9926         LDKUnsignedNodeAnnouncement this_ptr_conv;
9927         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9928         this_ptr_conv.is_owned = false;
9929         jint ret_val = UnsignedNodeAnnouncement_get_timestamp(&this_ptr_conv);
9930         return ret_val;
9931 }
9932
9933 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
9934         LDKUnsignedNodeAnnouncement this_ptr_conv;
9935         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9936         this_ptr_conv.is_owned = false;
9937         UnsignedNodeAnnouncement_set_timestamp(&this_ptr_conv, val);
9938 }
9939
9940 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9941         LDKUnsignedNodeAnnouncement this_ptr_conv;
9942         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9943         this_ptr_conv.is_owned = false;
9944         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9945         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedNodeAnnouncement_get_node_id(&this_ptr_conv).compressed_form);
9946         return arg_arr;
9947 }
9948
9949 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9950         LDKUnsignedNodeAnnouncement this_ptr_conv;
9951         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9952         this_ptr_conv.is_owned = false;
9953         LDKPublicKey val_ref;
9954         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9955         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9956         UnsignedNodeAnnouncement_set_node_id(&this_ptr_conv, val_ref);
9957 }
9958
9959 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr) {
9960         LDKUnsignedNodeAnnouncement this_ptr_conv;
9961         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9962         this_ptr_conv.is_owned = false;
9963         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 3);
9964         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 3, *UnsignedNodeAnnouncement_get_rgb(&this_ptr_conv));
9965         return ret_arr;
9966 }
9967
9968 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9969         LDKUnsignedNodeAnnouncement this_ptr_conv;
9970         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9971         this_ptr_conv.is_owned = false;
9972         LDKThreeBytes val_ref;
9973         CHECK((*_env)->GetArrayLength (_env, val) == 3);
9974         (*_env)->GetByteArrayRegion (_env, val, 0, 3, val_ref.data);
9975         UnsignedNodeAnnouncement_set_rgb(&this_ptr_conv, val_ref);
9976 }
9977
9978 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1alias(JNIEnv * _env, jclass _b, jlong this_ptr) {
9979         LDKUnsignedNodeAnnouncement this_ptr_conv;
9980         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9981         this_ptr_conv.is_owned = false;
9982         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9983         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedNodeAnnouncement_get_alias(&this_ptr_conv));
9984         return ret_arr;
9985 }
9986
9987 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1alias(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9988         LDKUnsignedNodeAnnouncement this_ptr_conv;
9989         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9990         this_ptr_conv.is_owned = false;
9991         LDKThirtyTwoBytes val_ref;
9992         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9993         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9994         UnsignedNodeAnnouncement_set_alias(&this_ptr_conv, val_ref);
9995 }
9996
9997 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1addresses(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
9998         LDKUnsignedNodeAnnouncement this_ptr_conv;
9999         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10000         this_ptr_conv.is_owned = false;
10001         LDKCVec_NetAddressZ val_constr;
10002         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
10003         if (val_constr.datalen > 0)
10004                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
10005         else
10006                 val_constr.data = NULL;
10007         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
10008         for (size_t m = 0; m < val_constr.datalen; m++) {
10009                 long arr_conv_12 = val_vals[m];
10010                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
10011                 FREE((void*)arr_conv_12);
10012                 val_constr.data[m] = arr_conv_12_conv;
10013         }
10014         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
10015         UnsignedNodeAnnouncement_set_addresses(&this_ptr_conv, val_constr);
10016 }
10017
10018 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10019         LDKNodeAnnouncement this_ptr_conv;
10020         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10021         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10022         NodeAnnouncement_free(this_ptr_conv);
10023 }
10024
10025 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10026         LDKNodeAnnouncement orig_conv;
10027         orig_conv.inner = (void*)(orig & (~1));
10028         orig_conv.is_owned = false;
10029         LDKNodeAnnouncement ret_var = NodeAnnouncement_clone(&orig_conv);
10030         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10031         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10032         long ret_ref = (long)ret_var.inner;
10033         if (ret_var.is_owned) {
10034                 ret_ref |= 1;
10035         }
10036         return ret_ref;
10037 }
10038
10039 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
10040         LDKNodeAnnouncement this_ptr_conv;
10041         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10042         this_ptr_conv.is_owned = false;
10043         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10044         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, NodeAnnouncement_get_signature(&this_ptr_conv).compact_form);
10045         return arg_arr;
10046 }
10047
10048 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10049         LDKNodeAnnouncement this_ptr_conv;
10050         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10051         this_ptr_conv.is_owned = false;
10052         LDKSignature val_ref;
10053         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10054         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10055         NodeAnnouncement_set_signature(&this_ptr_conv, val_ref);
10056 }
10057
10058 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
10059         LDKNodeAnnouncement this_ptr_conv;
10060         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10061         this_ptr_conv.is_owned = false;
10062         LDKUnsignedNodeAnnouncement ret_var = NodeAnnouncement_get_contents(&this_ptr_conv);
10063         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10064         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10065         long ret_ref = (long)ret_var.inner;
10066         if (ret_var.is_owned) {
10067                 ret_ref |= 1;
10068         }
10069         return ret_ref;
10070 }
10071
10072 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10073         LDKNodeAnnouncement this_ptr_conv;
10074         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10075         this_ptr_conv.is_owned = false;
10076         LDKUnsignedNodeAnnouncement val_conv;
10077         val_conv.inner = (void*)(val & (~1));
10078         val_conv.is_owned = (val & 1) || (val == 0);
10079         if (val_conv.inner != NULL)
10080                 val_conv = UnsignedNodeAnnouncement_clone(&val_conv);
10081         NodeAnnouncement_set_contents(&this_ptr_conv, val_conv);
10082 }
10083
10084 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1new(JNIEnv * _env, jclass _b, jbyteArray signature_arg, jlong contents_arg) {
10085         LDKSignature signature_arg_ref;
10086         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
10087         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10088         LDKUnsignedNodeAnnouncement contents_arg_conv;
10089         contents_arg_conv.inner = (void*)(contents_arg & (~1));
10090         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
10091         if (contents_arg_conv.inner != NULL)
10092                 contents_arg_conv = UnsignedNodeAnnouncement_clone(&contents_arg_conv);
10093         LDKNodeAnnouncement ret_var = NodeAnnouncement_new(signature_arg_ref, contents_arg_conv);
10094         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10095         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10096         long ret_ref = (long)ret_var.inner;
10097         if (ret_var.is_owned) {
10098                 ret_ref |= 1;
10099         }
10100         return ret_ref;
10101 }
10102
10103 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10104         LDKUnsignedChannelAnnouncement this_ptr_conv;
10105         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10106         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10107         UnsignedChannelAnnouncement_free(this_ptr_conv);
10108 }
10109
10110 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10111         LDKUnsignedChannelAnnouncement orig_conv;
10112         orig_conv.inner = (void*)(orig & (~1));
10113         orig_conv.is_owned = false;
10114         LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_clone(&orig_conv);
10115         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10116         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10117         long ret_ref = (long)ret_var.inner;
10118         if (ret_var.is_owned) {
10119                 ret_ref |= 1;
10120         }
10121         return ret_ref;
10122 }
10123
10124 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
10125         LDKUnsignedChannelAnnouncement this_ptr_conv;
10126         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10127         this_ptr_conv.is_owned = false;
10128         LDKChannelFeatures ret_var = UnsignedChannelAnnouncement_get_features(&this_ptr_conv);
10129         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10130         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10131         long ret_ref = (long)ret_var.inner;
10132         if (ret_var.is_owned) {
10133                 ret_ref |= 1;
10134         }
10135         return ret_ref;
10136 }
10137
10138 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10139         LDKUnsignedChannelAnnouncement this_ptr_conv;
10140         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10141         this_ptr_conv.is_owned = false;
10142         LDKChannelFeatures val_conv;
10143         val_conv.inner = (void*)(val & (~1));
10144         val_conv.is_owned = (val & 1) || (val == 0);
10145         // Warning: we may need a move here but can't clone!
10146         UnsignedChannelAnnouncement_set_features(&this_ptr_conv, val_conv);
10147 }
10148
10149 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10150         LDKUnsignedChannelAnnouncement this_ptr_conv;
10151         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10152         this_ptr_conv.is_owned = false;
10153         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10154         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedChannelAnnouncement_get_chain_hash(&this_ptr_conv));
10155         return ret_arr;
10156 }
10157
10158 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10159         LDKUnsignedChannelAnnouncement this_ptr_conv;
10160         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10161         this_ptr_conv.is_owned = false;
10162         LDKThirtyTwoBytes val_ref;
10163         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10164         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10165         UnsignedChannelAnnouncement_set_chain_hash(&this_ptr_conv, val_ref);
10166 }
10167
10168 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10169         LDKUnsignedChannelAnnouncement this_ptr_conv;
10170         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10171         this_ptr_conv.is_owned = false;
10172         jlong ret_val = UnsignedChannelAnnouncement_get_short_channel_id(&this_ptr_conv);
10173         return ret_val;
10174 }
10175
10176 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10177         LDKUnsignedChannelAnnouncement this_ptr_conv;
10178         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10179         this_ptr_conv.is_owned = false;
10180         UnsignedChannelAnnouncement_set_short_channel_id(&this_ptr_conv, val);
10181 }
10182
10183 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
10184         LDKUnsignedChannelAnnouncement this_ptr_conv;
10185         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10186         this_ptr_conv.is_owned = false;
10187         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10188         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_1(&this_ptr_conv).compressed_form);
10189         return arg_arr;
10190 }
10191
10192 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10193         LDKUnsignedChannelAnnouncement this_ptr_conv;
10194         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10195         this_ptr_conv.is_owned = false;
10196         LDKPublicKey val_ref;
10197         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10198         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10199         UnsignedChannelAnnouncement_set_node_id_1(&this_ptr_conv, val_ref);
10200 }
10201
10202 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
10203         LDKUnsignedChannelAnnouncement this_ptr_conv;
10204         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10205         this_ptr_conv.is_owned = false;
10206         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10207         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_2(&this_ptr_conv).compressed_form);
10208         return arg_arr;
10209 }
10210
10211 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10212         LDKUnsignedChannelAnnouncement this_ptr_conv;
10213         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10214         this_ptr_conv.is_owned = false;
10215         LDKPublicKey val_ref;
10216         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10217         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10218         UnsignedChannelAnnouncement_set_node_id_2(&this_ptr_conv, val_ref);
10219 }
10220
10221 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
10222         LDKUnsignedChannelAnnouncement this_ptr_conv;
10223         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10224         this_ptr_conv.is_owned = false;
10225         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10226         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_1(&this_ptr_conv).compressed_form);
10227         return arg_arr;
10228 }
10229
10230 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10231         LDKUnsignedChannelAnnouncement this_ptr_conv;
10232         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10233         this_ptr_conv.is_owned = false;
10234         LDKPublicKey val_ref;
10235         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10236         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10237         UnsignedChannelAnnouncement_set_bitcoin_key_1(&this_ptr_conv, val_ref);
10238 }
10239
10240 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
10241         LDKUnsignedChannelAnnouncement this_ptr_conv;
10242         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10243         this_ptr_conv.is_owned = false;
10244         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10245         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_2(&this_ptr_conv).compressed_form);
10246         return arg_arr;
10247 }
10248
10249 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10250         LDKUnsignedChannelAnnouncement this_ptr_conv;
10251         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10252         this_ptr_conv.is_owned = false;
10253         LDKPublicKey val_ref;
10254         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10255         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10256         UnsignedChannelAnnouncement_set_bitcoin_key_2(&this_ptr_conv, val_ref);
10257 }
10258
10259 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10260         LDKChannelAnnouncement this_ptr_conv;
10261         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10262         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10263         ChannelAnnouncement_free(this_ptr_conv);
10264 }
10265
10266 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10267         LDKChannelAnnouncement orig_conv;
10268         orig_conv.inner = (void*)(orig & (~1));
10269         orig_conv.is_owned = false;
10270         LDKChannelAnnouncement ret_var = ChannelAnnouncement_clone(&orig_conv);
10271         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10272         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10273         long ret_ref = (long)ret_var.inner;
10274         if (ret_var.is_owned) {
10275                 ret_ref |= 1;
10276         }
10277         return ret_ref;
10278 }
10279
10280 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
10281         LDKChannelAnnouncement this_ptr_conv;
10282         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10283         this_ptr_conv.is_owned = false;
10284         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10285         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_1(&this_ptr_conv).compact_form);
10286         return arg_arr;
10287 }
10288
10289 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10290         LDKChannelAnnouncement this_ptr_conv;
10291         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10292         this_ptr_conv.is_owned = false;
10293         LDKSignature val_ref;
10294         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10295         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10296         ChannelAnnouncement_set_node_signature_1(&this_ptr_conv, val_ref);
10297 }
10298
10299 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
10300         LDKChannelAnnouncement this_ptr_conv;
10301         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10302         this_ptr_conv.is_owned = false;
10303         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10304         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_2(&this_ptr_conv).compact_form);
10305         return arg_arr;
10306 }
10307
10308 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10309         LDKChannelAnnouncement this_ptr_conv;
10310         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10311         this_ptr_conv.is_owned = false;
10312         LDKSignature val_ref;
10313         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10314         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10315         ChannelAnnouncement_set_node_signature_2(&this_ptr_conv, val_ref);
10316 }
10317
10318 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
10319         LDKChannelAnnouncement this_ptr_conv;
10320         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10321         this_ptr_conv.is_owned = false;
10322         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10323         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_1(&this_ptr_conv).compact_form);
10324         return arg_arr;
10325 }
10326
10327 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10328         LDKChannelAnnouncement this_ptr_conv;
10329         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10330         this_ptr_conv.is_owned = false;
10331         LDKSignature val_ref;
10332         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10333         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10334         ChannelAnnouncement_set_bitcoin_signature_1(&this_ptr_conv, val_ref);
10335 }
10336
10337 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
10338         LDKChannelAnnouncement this_ptr_conv;
10339         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10340         this_ptr_conv.is_owned = false;
10341         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10342         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_2(&this_ptr_conv).compact_form);
10343         return arg_arr;
10344 }
10345
10346 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10347         LDKChannelAnnouncement this_ptr_conv;
10348         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10349         this_ptr_conv.is_owned = false;
10350         LDKSignature val_ref;
10351         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10352         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10353         ChannelAnnouncement_set_bitcoin_signature_2(&this_ptr_conv, val_ref);
10354 }
10355
10356 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
10357         LDKChannelAnnouncement this_ptr_conv;
10358         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10359         this_ptr_conv.is_owned = false;
10360         LDKUnsignedChannelAnnouncement ret_var = ChannelAnnouncement_get_contents(&this_ptr_conv);
10361         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10362         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10363         long ret_ref = (long)ret_var.inner;
10364         if (ret_var.is_owned) {
10365                 ret_ref |= 1;
10366         }
10367         return ret_ref;
10368 }
10369
10370 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10371         LDKChannelAnnouncement this_ptr_conv;
10372         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10373         this_ptr_conv.is_owned = false;
10374         LDKUnsignedChannelAnnouncement val_conv;
10375         val_conv.inner = (void*)(val & (~1));
10376         val_conv.is_owned = (val & 1) || (val == 0);
10377         if (val_conv.inner != NULL)
10378                 val_conv = UnsignedChannelAnnouncement_clone(&val_conv);
10379         ChannelAnnouncement_set_contents(&this_ptr_conv, val_conv);
10380 }
10381
10382 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) {
10383         LDKSignature node_signature_1_arg_ref;
10384         CHECK((*_env)->GetArrayLength (_env, node_signature_1_arg) == 64);
10385         (*_env)->GetByteArrayRegion (_env, node_signature_1_arg, 0, 64, node_signature_1_arg_ref.compact_form);
10386         LDKSignature node_signature_2_arg_ref;
10387         CHECK((*_env)->GetArrayLength (_env, node_signature_2_arg) == 64);
10388         (*_env)->GetByteArrayRegion (_env, node_signature_2_arg, 0, 64, node_signature_2_arg_ref.compact_form);
10389         LDKSignature bitcoin_signature_1_arg_ref;
10390         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_1_arg) == 64);
10391         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_1_arg, 0, 64, bitcoin_signature_1_arg_ref.compact_form);
10392         LDKSignature bitcoin_signature_2_arg_ref;
10393         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_2_arg) == 64);
10394         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_2_arg, 0, 64, bitcoin_signature_2_arg_ref.compact_form);
10395         LDKUnsignedChannelAnnouncement contents_arg_conv;
10396         contents_arg_conv.inner = (void*)(contents_arg & (~1));
10397         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
10398         if (contents_arg_conv.inner != NULL)
10399                 contents_arg_conv = UnsignedChannelAnnouncement_clone(&contents_arg_conv);
10400         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);
10401         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10402         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10403         long ret_ref = (long)ret_var.inner;
10404         if (ret_var.is_owned) {
10405                 ret_ref |= 1;
10406         }
10407         return ret_ref;
10408 }
10409
10410 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10411         LDKUnsignedChannelUpdate this_ptr_conv;
10412         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10413         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10414         UnsignedChannelUpdate_free(this_ptr_conv);
10415 }
10416
10417 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10418         LDKUnsignedChannelUpdate orig_conv;
10419         orig_conv.inner = (void*)(orig & (~1));
10420         orig_conv.is_owned = false;
10421         LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_clone(&orig_conv);
10422         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10423         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10424         long ret_ref = (long)ret_var.inner;
10425         if (ret_var.is_owned) {
10426                 ret_ref |= 1;
10427         }
10428         return ret_ref;
10429 }
10430
10431 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10432         LDKUnsignedChannelUpdate this_ptr_conv;
10433         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10434         this_ptr_conv.is_owned = false;
10435         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10436         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedChannelUpdate_get_chain_hash(&this_ptr_conv));
10437         return ret_arr;
10438 }
10439
10440 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10441         LDKUnsignedChannelUpdate this_ptr_conv;
10442         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10443         this_ptr_conv.is_owned = false;
10444         LDKThirtyTwoBytes val_ref;
10445         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10446         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10447         UnsignedChannelUpdate_set_chain_hash(&this_ptr_conv, val_ref);
10448 }
10449
10450 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10451         LDKUnsignedChannelUpdate this_ptr_conv;
10452         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10453         this_ptr_conv.is_owned = false;
10454         jlong ret_val = UnsignedChannelUpdate_get_short_channel_id(&this_ptr_conv);
10455         return ret_val;
10456 }
10457
10458 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10459         LDKUnsignedChannelUpdate this_ptr_conv;
10460         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10461         this_ptr_conv.is_owned = false;
10462         UnsignedChannelUpdate_set_short_channel_id(&this_ptr_conv, val);
10463 }
10464
10465 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
10466         LDKUnsignedChannelUpdate this_ptr_conv;
10467         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10468         this_ptr_conv.is_owned = false;
10469         jint ret_val = UnsignedChannelUpdate_get_timestamp(&this_ptr_conv);
10470         return ret_val;
10471 }
10472
10473 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10474         LDKUnsignedChannelUpdate this_ptr_conv;
10475         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10476         this_ptr_conv.is_owned = false;
10477         UnsignedChannelUpdate_set_timestamp(&this_ptr_conv, val);
10478 }
10479
10480 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1flags(JNIEnv * _env, jclass _b, jlong this_ptr) {
10481         LDKUnsignedChannelUpdate this_ptr_conv;
10482         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10483         this_ptr_conv.is_owned = false;
10484         jbyte ret_val = UnsignedChannelUpdate_get_flags(&this_ptr_conv);
10485         return ret_val;
10486 }
10487
10488 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1flags(JNIEnv * _env, jclass _b, jlong this_ptr, jbyte val) {
10489         LDKUnsignedChannelUpdate this_ptr_conv;
10490         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10491         this_ptr_conv.is_owned = false;
10492         UnsignedChannelUpdate_set_flags(&this_ptr_conv, val);
10493 }
10494
10495 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
10496         LDKUnsignedChannelUpdate this_ptr_conv;
10497         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10498         this_ptr_conv.is_owned = false;
10499         jshort ret_val = UnsignedChannelUpdate_get_cltv_expiry_delta(&this_ptr_conv);
10500         return ret_val;
10501 }
10502
10503 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
10504         LDKUnsignedChannelUpdate this_ptr_conv;
10505         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10506         this_ptr_conv.is_owned = false;
10507         UnsignedChannelUpdate_set_cltv_expiry_delta(&this_ptr_conv, val);
10508 }
10509
10510 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10511         LDKUnsignedChannelUpdate this_ptr_conv;
10512         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10513         this_ptr_conv.is_owned = false;
10514         jlong ret_val = UnsignedChannelUpdate_get_htlc_minimum_msat(&this_ptr_conv);
10515         return ret_val;
10516 }
10517
10518 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10519         LDKUnsignedChannelUpdate this_ptr_conv;
10520         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10521         this_ptr_conv.is_owned = false;
10522         UnsignedChannelUpdate_set_htlc_minimum_msat(&this_ptr_conv, val);
10523 }
10524
10525 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10526         LDKUnsignedChannelUpdate this_ptr_conv;
10527         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10528         this_ptr_conv.is_owned = false;
10529         jint ret_val = UnsignedChannelUpdate_get_fee_base_msat(&this_ptr_conv);
10530         return ret_val;
10531 }
10532
10533 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10534         LDKUnsignedChannelUpdate this_ptr_conv;
10535         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10536         this_ptr_conv.is_owned = false;
10537         UnsignedChannelUpdate_set_fee_base_msat(&this_ptr_conv, val);
10538 }
10539
10540 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
10541         LDKUnsignedChannelUpdate this_ptr_conv;
10542         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10543         this_ptr_conv.is_owned = false;
10544         jint ret_val = UnsignedChannelUpdate_get_fee_proportional_millionths(&this_ptr_conv);
10545         return ret_val;
10546 }
10547
10548 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10549         LDKUnsignedChannelUpdate this_ptr_conv;
10550         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10551         this_ptr_conv.is_owned = false;
10552         UnsignedChannelUpdate_set_fee_proportional_millionths(&this_ptr_conv, val);
10553 }
10554
10555 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10556         LDKChannelUpdate this_ptr_conv;
10557         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10558         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10559         ChannelUpdate_free(this_ptr_conv);
10560 }
10561
10562 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10563         LDKChannelUpdate orig_conv;
10564         orig_conv.inner = (void*)(orig & (~1));
10565         orig_conv.is_owned = false;
10566         LDKChannelUpdate ret_var = ChannelUpdate_clone(&orig_conv);
10567         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10568         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10569         long ret_ref = (long)ret_var.inner;
10570         if (ret_var.is_owned) {
10571                 ret_ref |= 1;
10572         }
10573         return ret_ref;
10574 }
10575
10576 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
10577         LDKChannelUpdate this_ptr_conv;
10578         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10579         this_ptr_conv.is_owned = false;
10580         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10581         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelUpdate_get_signature(&this_ptr_conv).compact_form);
10582         return arg_arr;
10583 }
10584
10585 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10586         LDKChannelUpdate this_ptr_conv;
10587         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10588         this_ptr_conv.is_owned = false;
10589         LDKSignature val_ref;
10590         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10591         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10592         ChannelUpdate_set_signature(&this_ptr_conv, val_ref);
10593 }
10594
10595 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
10596         LDKChannelUpdate this_ptr_conv;
10597         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10598         this_ptr_conv.is_owned = false;
10599         LDKUnsignedChannelUpdate ret_var = ChannelUpdate_get_contents(&this_ptr_conv);
10600         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10601         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10602         long ret_ref = (long)ret_var.inner;
10603         if (ret_var.is_owned) {
10604                 ret_ref |= 1;
10605         }
10606         return ret_ref;
10607 }
10608
10609 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10610         LDKChannelUpdate this_ptr_conv;
10611         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10612         this_ptr_conv.is_owned = false;
10613         LDKUnsignedChannelUpdate val_conv;
10614         val_conv.inner = (void*)(val & (~1));
10615         val_conv.is_owned = (val & 1) || (val == 0);
10616         if (val_conv.inner != NULL)
10617                 val_conv = UnsignedChannelUpdate_clone(&val_conv);
10618         ChannelUpdate_set_contents(&this_ptr_conv, val_conv);
10619 }
10620
10621 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1new(JNIEnv * _env, jclass _b, jbyteArray signature_arg, jlong contents_arg) {
10622         LDKSignature signature_arg_ref;
10623         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
10624         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10625         LDKUnsignedChannelUpdate contents_arg_conv;
10626         contents_arg_conv.inner = (void*)(contents_arg & (~1));
10627         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
10628         if (contents_arg_conv.inner != NULL)
10629                 contents_arg_conv = UnsignedChannelUpdate_clone(&contents_arg_conv);
10630         LDKChannelUpdate ret_var = ChannelUpdate_new(signature_arg_ref, contents_arg_conv);
10631         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10632         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10633         long ret_ref = (long)ret_var.inner;
10634         if (ret_var.is_owned) {
10635                 ret_ref |= 1;
10636         }
10637         return ret_ref;
10638 }
10639
10640 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10641         LDKQueryChannelRange this_ptr_conv;
10642         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10643         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10644         QueryChannelRange_free(this_ptr_conv);
10645 }
10646
10647 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10648         LDKQueryChannelRange orig_conv;
10649         orig_conv.inner = (void*)(orig & (~1));
10650         orig_conv.is_owned = false;
10651         LDKQueryChannelRange ret_var = QueryChannelRange_clone(&orig_conv);
10652         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10653         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10654         long ret_ref = (long)ret_var.inner;
10655         if (ret_var.is_owned) {
10656                 ret_ref |= 1;
10657         }
10658         return ret_ref;
10659 }
10660
10661 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10662         LDKQueryChannelRange this_ptr_conv;
10663         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10664         this_ptr_conv.is_owned = false;
10665         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10666         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *QueryChannelRange_get_chain_hash(&this_ptr_conv));
10667         return ret_arr;
10668 }
10669
10670 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10671         LDKQueryChannelRange this_ptr_conv;
10672         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10673         this_ptr_conv.is_owned = false;
10674         LDKThirtyTwoBytes val_ref;
10675         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10676         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10677         QueryChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
10678 }
10679
10680 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr) {
10681         LDKQueryChannelRange this_ptr_conv;
10682         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10683         this_ptr_conv.is_owned = false;
10684         jint ret_val = QueryChannelRange_get_first_blocknum(&this_ptr_conv);
10685         return ret_val;
10686 }
10687
10688 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10689         LDKQueryChannelRange this_ptr_conv;
10690         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10691         this_ptr_conv.is_owned = false;
10692         QueryChannelRange_set_first_blocknum(&this_ptr_conv, val);
10693 }
10694
10695 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr) {
10696         LDKQueryChannelRange this_ptr_conv;
10697         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10698         this_ptr_conv.is_owned = false;
10699         jint ret_val = QueryChannelRange_get_number_of_blocks(&this_ptr_conv);
10700         return ret_val;
10701 }
10702
10703 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10704         LDKQueryChannelRange this_ptr_conv;
10705         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10706         this_ptr_conv.is_owned = false;
10707         QueryChannelRange_set_number_of_blocks(&this_ptr_conv, val);
10708 }
10709
10710 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) {
10711         LDKThirtyTwoBytes chain_hash_arg_ref;
10712         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10713         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10714         LDKQueryChannelRange ret_var = QueryChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg);
10715         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10716         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10717         long ret_ref = (long)ret_var.inner;
10718         if (ret_var.is_owned) {
10719                 ret_ref |= 1;
10720         }
10721         return ret_ref;
10722 }
10723
10724 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10725         LDKReplyChannelRange this_ptr_conv;
10726         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10727         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10728         ReplyChannelRange_free(this_ptr_conv);
10729 }
10730
10731 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10732         LDKReplyChannelRange orig_conv;
10733         orig_conv.inner = (void*)(orig & (~1));
10734         orig_conv.is_owned = false;
10735         LDKReplyChannelRange ret_var = ReplyChannelRange_clone(&orig_conv);
10736         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10737         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10738         long ret_ref = (long)ret_var.inner;
10739         if (ret_var.is_owned) {
10740                 ret_ref |= 1;
10741         }
10742         return ret_ref;
10743 }
10744
10745 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10746         LDKReplyChannelRange this_ptr_conv;
10747         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10748         this_ptr_conv.is_owned = false;
10749         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10750         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ReplyChannelRange_get_chain_hash(&this_ptr_conv));
10751         return ret_arr;
10752 }
10753
10754 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10755         LDKReplyChannelRange this_ptr_conv;
10756         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10757         this_ptr_conv.is_owned = false;
10758         LDKThirtyTwoBytes val_ref;
10759         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10760         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10761         ReplyChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
10762 }
10763
10764 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr) {
10765         LDKReplyChannelRange this_ptr_conv;
10766         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10767         this_ptr_conv.is_owned = false;
10768         jint ret_val = ReplyChannelRange_get_first_blocknum(&this_ptr_conv);
10769         return ret_val;
10770 }
10771
10772 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10773         LDKReplyChannelRange this_ptr_conv;
10774         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10775         this_ptr_conv.is_owned = false;
10776         ReplyChannelRange_set_first_blocknum(&this_ptr_conv, val);
10777 }
10778
10779 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr) {
10780         LDKReplyChannelRange this_ptr_conv;
10781         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10782         this_ptr_conv.is_owned = false;
10783         jint ret_val = ReplyChannelRange_get_number_of_blocks(&this_ptr_conv);
10784         return ret_val;
10785 }
10786
10787 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10788         LDKReplyChannelRange this_ptr_conv;
10789         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10790         this_ptr_conv.is_owned = false;
10791         ReplyChannelRange_set_number_of_blocks(&this_ptr_conv, val);
10792 }
10793
10794 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr) {
10795         LDKReplyChannelRange this_ptr_conv;
10796         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10797         this_ptr_conv.is_owned = false;
10798         jboolean ret_val = ReplyChannelRange_get_full_information(&this_ptr_conv);
10799         return ret_val;
10800 }
10801
10802 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
10803         LDKReplyChannelRange this_ptr_conv;
10804         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10805         this_ptr_conv.is_owned = false;
10806         ReplyChannelRange_set_full_information(&this_ptr_conv, val);
10807 }
10808
10809 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1short_1channel_1ids(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
10810         LDKReplyChannelRange this_ptr_conv;
10811         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10812         this_ptr_conv.is_owned = false;
10813         LDKCVec_u64Z val_constr;
10814         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
10815         if (val_constr.datalen > 0)
10816                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
10817         else
10818                 val_constr.data = NULL;
10819         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
10820         for (size_t g = 0; g < val_constr.datalen; g++) {
10821                 long arr_conv_6 = val_vals[g];
10822                 val_constr.data[g] = arr_conv_6;
10823         }
10824         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
10825         ReplyChannelRange_set_short_channel_ids(&this_ptr_conv, val_constr);
10826 }
10827
10828 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) {
10829         LDKThirtyTwoBytes chain_hash_arg_ref;
10830         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10831         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10832         LDKCVec_u64Z short_channel_ids_arg_constr;
10833         short_channel_ids_arg_constr.datalen = (*_env)->GetArrayLength (_env, short_channel_ids_arg);
10834         if (short_channel_ids_arg_constr.datalen > 0)
10835                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
10836         else
10837                 short_channel_ids_arg_constr.data = NULL;
10838         long* short_channel_ids_arg_vals = (*_env)->GetLongArrayElements (_env, short_channel_ids_arg, NULL);
10839         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
10840                 long arr_conv_6 = short_channel_ids_arg_vals[g];
10841                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
10842         }
10843         (*_env)->ReleaseLongArrayElements (_env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
10844         LDKReplyChannelRange ret_var = ReplyChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg, full_information_arg, short_channel_ids_arg_constr);
10845         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10846         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10847         long ret_ref = (long)ret_var.inner;
10848         if (ret_var.is_owned) {
10849                 ret_ref |= 1;
10850         }
10851         return ret_ref;
10852 }
10853
10854 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10855         LDKQueryShortChannelIds this_ptr_conv;
10856         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10857         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10858         QueryShortChannelIds_free(this_ptr_conv);
10859 }
10860
10861 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10862         LDKQueryShortChannelIds orig_conv;
10863         orig_conv.inner = (void*)(orig & (~1));
10864         orig_conv.is_owned = false;
10865         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_clone(&orig_conv);
10866         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10867         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10868         long ret_ref = (long)ret_var.inner;
10869         if (ret_var.is_owned) {
10870                 ret_ref |= 1;
10871         }
10872         return ret_ref;
10873 }
10874
10875 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10876         LDKQueryShortChannelIds this_ptr_conv;
10877         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10878         this_ptr_conv.is_owned = false;
10879         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10880         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *QueryShortChannelIds_get_chain_hash(&this_ptr_conv));
10881         return ret_arr;
10882 }
10883
10884 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10885         LDKQueryShortChannelIds this_ptr_conv;
10886         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10887         this_ptr_conv.is_owned = false;
10888         LDKThirtyTwoBytes val_ref;
10889         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10890         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10891         QueryShortChannelIds_set_chain_hash(&this_ptr_conv, val_ref);
10892 }
10893
10894 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1short_1channel_1ids(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
10895         LDKQueryShortChannelIds this_ptr_conv;
10896         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10897         this_ptr_conv.is_owned = false;
10898         LDKCVec_u64Z val_constr;
10899         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
10900         if (val_constr.datalen > 0)
10901                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
10902         else
10903                 val_constr.data = NULL;
10904         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
10905         for (size_t g = 0; g < val_constr.datalen; g++) {
10906                 long arr_conv_6 = val_vals[g];
10907                 val_constr.data[g] = arr_conv_6;
10908         }
10909         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
10910         QueryShortChannelIds_set_short_channel_ids(&this_ptr_conv, val_constr);
10911 }
10912
10913 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1new(JNIEnv * _env, jclass _b, jbyteArray chain_hash_arg, jlongArray short_channel_ids_arg) {
10914         LDKThirtyTwoBytes chain_hash_arg_ref;
10915         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10916         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10917         LDKCVec_u64Z short_channel_ids_arg_constr;
10918         short_channel_ids_arg_constr.datalen = (*_env)->GetArrayLength (_env, short_channel_ids_arg);
10919         if (short_channel_ids_arg_constr.datalen > 0)
10920                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
10921         else
10922                 short_channel_ids_arg_constr.data = NULL;
10923         long* short_channel_ids_arg_vals = (*_env)->GetLongArrayElements (_env, short_channel_ids_arg, NULL);
10924         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
10925                 long arr_conv_6 = short_channel_ids_arg_vals[g];
10926                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
10927         }
10928         (*_env)->ReleaseLongArrayElements (_env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
10929         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_new(chain_hash_arg_ref, short_channel_ids_arg_constr);
10930         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10931         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10932         long ret_ref = (long)ret_var.inner;
10933         if (ret_var.is_owned) {
10934                 ret_ref |= 1;
10935         }
10936         return ret_ref;
10937 }
10938
10939 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10940         LDKReplyShortChannelIdsEnd this_ptr_conv;
10941         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10942         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10943         ReplyShortChannelIdsEnd_free(this_ptr_conv);
10944 }
10945
10946 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10947         LDKReplyShortChannelIdsEnd orig_conv;
10948         orig_conv.inner = (void*)(orig & (~1));
10949         orig_conv.is_owned = false;
10950         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_clone(&orig_conv);
10951         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10952         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10953         long ret_ref = (long)ret_var.inner;
10954         if (ret_var.is_owned) {
10955                 ret_ref |= 1;
10956         }
10957         return ret_ref;
10958 }
10959
10960 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10961         LDKReplyShortChannelIdsEnd this_ptr_conv;
10962         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10963         this_ptr_conv.is_owned = false;
10964         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10965         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ReplyShortChannelIdsEnd_get_chain_hash(&this_ptr_conv));
10966         return ret_arr;
10967 }
10968
10969 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10970         LDKReplyShortChannelIdsEnd this_ptr_conv;
10971         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10972         this_ptr_conv.is_owned = false;
10973         LDKThirtyTwoBytes val_ref;
10974         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10975         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10976         ReplyShortChannelIdsEnd_set_chain_hash(&this_ptr_conv, val_ref);
10977 }
10978
10979 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr) {
10980         LDKReplyShortChannelIdsEnd this_ptr_conv;
10981         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10982         this_ptr_conv.is_owned = false;
10983         jboolean ret_val = ReplyShortChannelIdsEnd_get_full_information(&this_ptr_conv);
10984         return ret_val;
10985 }
10986
10987 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
10988         LDKReplyShortChannelIdsEnd this_ptr_conv;
10989         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10990         this_ptr_conv.is_owned = false;
10991         ReplyShortChannelIdsEnd_set_full_information(&this_ptr_conv, val);
10992 }
10993
10994 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1new(JNIEnv * _env, jclass _b, jbyteArray chain_hash_arg, jboolean full_information_arg) {
10995         LDKThirtyTwoBytes chain_hash_arg_ref;
10996         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10997         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10998         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_new(chain_hash_arg_ref, full_information_arg);
10999         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11000         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11001         long ret_ref = (long)ret_var.inner;
11002         if (ret_var.is_owned) {
11003                 ret_ref |= 1;
11004         }
11005         return ret_ref;
11006 }
11007
11008 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11009         LDKGossipTimestampFilter this_ptr_conv;
11010         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11011         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11012         GossipTimestampFilter_free(this_ptr_conv);
11013 }
11014
11015 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11016         LDKGossipTimestampFilter orig_conv;
11017         orig_conv.inner = (void*)(orig & (~1));
11018         orig_conv.is_owned = false;
11019         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_clone(&orig_conv);
11020         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11021         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11022         long ret_ref = (long)ret_var.inner;
11023         if (ret_var.is_owned) {
11024                 ret_ref |= 1;
11025         }
11026         return ret_ref;
11027 }
11028
11029 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
11030         LDKGossipTimestampFilter this_ptr_conv;
11031         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11032         this_ptr_conv.is_owned = false;
11033         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11034         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *GossipTimestampFilter_get_chain_hash(&this_ptr_conv));
11035         return ret_arr;
11036 }
11037
11038 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11039         LDKGossipTimestampFilter this_ptr_conv;
11040         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11041         this_ptr_conv.is_owned = false;
11042         LDKThirtyTwoBytes val_ref;
11043         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11044         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11045         GossipTimestampFilter_set_chain_hash(&this_ptr_conv, val_ref);
11046 }
11047
11048 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1first_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
11049         LDKGossipTimestampFilter this_ptr_conv;
11050         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11051         this_ptr_conv.is_owned = false;
11052         jint ret_val = GossipTimestampFilter_get_first_timestamp(&this_ptr_conv);
11053         return ret_val;
11054 }
11055
11056 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1first_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
11057         LDKGossipTimestampFilter this_ptr_conv;
11058         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11059         this_ptr_conv.is_owned = false;
11060         GossipTimestampFilter_set_first_timestamp(&this_ptr_conv, val);
11061 }
11062
11063 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1timestamp_1range(JNIEnv * _env, jclass _b, jlong this_ptr) {
11064         LDKGossipTimestampFilter this_ptr_conv;
11065         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11066         this_ptr_conv.is_owned = false;
11067         jint ret_val = GossipTimestampFilter_get_timestamp_range(&this_ptr_conv);
11068         return ret_val;
11069 }
11070
11071 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1timestamp_1range(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
11072         LDKGossipTimestampFilter this_ptr_conv;
11073         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11074         this_ptr_conv.is_owned = false;
11075         GossipTimestampFilter_set_timestamp_range(&this_ptr_conv, val);
11076 }
11077
11078 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) {
11079         LDKThirtyTwoBytes chain_hash_arg_ref;
11080         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
11081         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
11082         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_new(chain_hash_arg_ref, first_timestamp_arg, timestamp_range_arg);
11083         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11084         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11085         long ret_ref = (long)ret_var.inner;
11086         if (ret_var.is_owned) {
11087                 ret_ref |= 1;
11088         }
11089         return ret_ref;
11090 }
11091
11092 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorAction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11093         LDKErrorAction this_ptr_conv = *(LDKErrorAction*)this_ptr;
11094         FREE((void*)this_ptr);
11095         ErrorAction_free(this_ptr_conv);
11096 }
11097
11098 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorAction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11099         LDKErrorAction* orig_conv = (LDKErrorAction*)orig;
11100         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
11101         *ret_copy = ErrorAction_clone(orig_conv);
11102         long ret_ref = (long)ret_copy;
11103         return ret_ref;
11104 }
11105
11106 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11107         LDKLightningError this_ptr_conv;
11108         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11109         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11110         LightningError_free(this_ptr_conv);
11111 }
11112
11113 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1err(JNIEnv * _env, jclass _b, jlong this_ptr) {
11114         LDKLightningError this_ptr_conv;
11115         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11116         this_ptr_conv.is_owned = false;
11117         LDKStr _str = LightningError_get_err(&this_ptr_conv);
11118         char* _buf = MALLOC(_str.len + 1, "str conv buf");
11119         memcpy(_buf, _str.chars, _str.len);
11120         _buf[_str.len] = 0;
11121         jstring _conv = (*_env)->NewStringUTF(_env, _str.chars);
11122         FREE(_buf);
11123         return _conv;
11124 }
11125
11126 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1err(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11127         LDKLightningError this_ptr_conv;
11128         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11129         this_ptr_conv.is_owned = false;
11130         LDKCVec_u8Z val_ref;
11131         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
11132         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
11133         (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data);
11134         LightningError_set_err(&this_ptr_conv, val_ref);
11135 }
11136
11137 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1action(JNIEnv * _env, jclass _b, jlong this_ptr) {
11138         LDKLightningError this_ptr_conv;
11139         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11140         this_ptr_conv.is_owned = false;
11141         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
11142         *ret_copy = LightningError_get_action(&this_ptr_conv);
11143         long ret_ref = (long)ret_copy;
11144         return ret_ref;
11145 }
11146
11147 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1action(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11148         LDKLightningError this_ptr_conv;
11149         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11150         this_ptr_conv.is_owned = false;
11151         LDKErrorAction val_conv = *(LDKErrorAction*)val;
11152         FREE((void*)val);
11153         LightningError_set_action(&this_ptr_conv, val_conv);
11154 }
11155
11156 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LightningError_1new(JNIEnv * _env, jclass _b, jbyteArray err_arg, jlong action_arg) {
11157         LDKCVec_u8Z err_arg_ref;
11158         err_arg_ref.datalen = (*_env)->GetArrayLength (_env, err_arg);
11159         err_arg_ref.data = MALLOC(err_arg_ref.datalen, "LDKCVec_u8Z Bytes");
11160         (*_env)->GetByteArrayRegion(_env, err_arg, 0, err_arg_ref.datalen, err_arg_ref.data);
11161         LDKErrorAction action_arg_conv = *(LDKErrorAction*)action_arg;
11162         FREE((void*)action_arg);
11163         LDKLightningError ret_var = LightningError_new(err_arg_ref, action_arg_conv);
11164         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11165         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11166         long ret_ref = (long)ret_var.inner;
11167         if (ret_var.is_owned) {
11168                 ret_ref |= 1;
11169         }
11170         return ret_ref;
11171 }
11172
11173 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11174         LDKCommitmentUpdate this_ptr_conv;
11175         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11176         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11177         CommitmentUpdate_free(this_ptr_conv);
11178 }
11179
11180 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11181         LDKCommitmentUpdate orig_conv;
11182         orig_conv.inner = (void*)(orig & (~1));
11183         orig_conv.is_owned = false;
11184         LDKCommitmentUpdate ret_var = CommitmentUpdate_clone(&orig_conv);
11185         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11186         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11187         long ret_ref = (long)ret_var.inner;
11188         if (ret_var.is_owned) {
11189                 ret_ref |= 1;
11190         }
11191         return ret_ref;
11192 }
11193
11194 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1add_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
11195         LDKCommitmentUpdate this_ptr_conv;
11196         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11197         this_ptr_conv.is_owned = false;
11198         LDKCVec_UpdateAddHTLCZ val_constr;
11199         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
11200         if (val_constr.datalen > 0)
11201                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
11202         else
11203                 val_constr.data = NULL;
11204         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
11205         for (size_t p = 0; p < val_constr.datalen; p++) {
11206                 long arr_conv_15 = val_vals[p];
11207                 LDKUpdateAddHTLC arr_conv_15_conv;
11208                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
11209                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
11210                 if (arr_conv_15_conv.inner != NULL)
11211                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
11212                 val_constr.data[p] = arr_conv_15_conv;
11213         }
11214         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
11215         CommitmentUpdate_set_update_add_htlcs(&this_ptr_conv, val_constr);
11216 }
11217
11218 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fulfill_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
11219         LDKCommitmentUpdate this_ptr_conv;
11220         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11221         this_ptr_conv.is_owned = false;
11222         LDKCVec_UpdateFulfillHTLCZ val_constr;
11223         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
11224         if (val_constr.datalen > 0)
11225                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
11226         else
11227                 val_constr.data = NULL;
11228         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
11229         for (size_t t = 0; t < val_constr.datalen; t++) {
11230                 long arr_conv_19 = val_vals[t];
11231                 LDKUpdateFulfillHTLC arr_conv_19_conv;
11232                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
11233                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
11234                 if (arr_conv_19_conv.inner != NULL)
11235                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
11236                 val_constr.data[t] = arr_conv_19_conv;
11237         }
11238         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
11239         CommitmentUpdate_set_update_fulfill_htlcs(&this_ptr_conv, val_constr);
11240 }
11241
11242 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fail_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
11243         LDKCommitmentUpdate this_ptr_conv;
11244         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11245         this_ptr_conv.is_owned = false;
11246         LDKCVec_UpdateFailHTLCZ val_constr;
11247         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
11248         if (val_constr.datalen > 0)
11249                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
11250         else
11251                 val_constr.data = NULL;
11252         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
11253         for (size_t q = 0; q < val_constr.datalen; q++) {
11254                 long arr_conv_16 = val_vals[q];
11255                 LDKUpdateFailHTLC arr_conv_16_conv;
11256                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
11257                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
11258                 if (arr_conv_16_conv.inner != NULL)
11259                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
11260                 val_constr.data[q] = arr_conv_16_conv;
11261         }
11262         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
11263         CommitmentUpdate_set_update_fail_htlcs(&this_ptr_conv, val_constr);
11264 }
11265
11266 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fail_1malformed_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
11267         LDKCommitmentUpdate this_ptr_conv;
11268         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11269         this_ptr_conv.is_owned = false;
11270         LDKCVec_UpdateFailMalformedHTLCZ val_constr;
11271         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
11272         if (val_constr.datalen > 0)
11273                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
11274         else
11275                 val_constr.data = NULL;
11276         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
11277         for (size_t z = 0; z < val_constr.datalen; z++) {
11278                 long arr_conv_25 = val_vals[z];
11279                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
11280                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
11281                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
11282                 if (arr_conv_25_conv.inner != NULL)
11283                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
11284                 val_constr.data[z] = arr_conv_25_conv;
11285         }
11286         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
11287         CommitmentUpdate_set_update_fail_malformed_htlcs(&this_ptr_conv, val_constr);
11288 }
11289
11290 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1update_1fee(JNIEnv * _env, jclass _b, jlong this_ptr) {
11291         LDKCommitmentUpdate this_ptr_conv;
11292         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11293         this_ptr_conv.is_owned = false;
11294         LDKUpdateFee ret_var = CommitmentUpdate_get_update_fee(&this_ptr_conv);
11295         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11296         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11297         long ret_ref = (long)ret_var.inner;
11298         if (ret_var.is_owned) {
11299                 ret_ref |= 1;
11300         }
11301         return ret_ref;
11302 }
11303
11304 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fee(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11305         LDKCommitmentUpdate this_ptr_conv;
11306         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11307         this_ptr_conv.is_owned = false;
11308         LDKUpdateFee val_conv;
11309         val_conv.inner = (void*)(val & (~1));
11310         val_conv.is_owned = (val & 1) || (val == 0);
11311         if (val_conv.inner != NULL)
11312                 val_conv = UpdateFee_clone(&val_conv);
11313         CommitmentUpdate_set_update_fee(&this_ptr_conv, val_conv);
11314 }
11315
11316 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1commitment_1signed(JNIEnv * _env, jclass _b, jlong this_ptr) {
11317         LDKCommitmentUpdate this_ptr_conv;
11318         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11319         this_ptr_conv.is_owned = false;
11320         LDKCommitmentSigned ret_var = CommitmentUpdate_get_commitment_signed(&this_ptr_conv);
11321         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11322         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11323         long ret_ref = (long)ret_var.inner;
11324         if (ret_var.is_owned) {
11325                 ret_ref |= 1;
11326         }
11327         return ret_ref;
11328 }
11329
11330 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1commitment_1signed(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11331         LDKCommitmentUpdate this_ptr_conv;
11332         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11333         this_ptr_conv.is_owned = false;
11334         LDKCommitmentSigned val_conv;
11335         val_conv.inner = (void*)(val & (~1));
11336         val_conv.is_owned = (val & 1) || (val == 0);
11337         if (val_conv.inner != NULL)
11338                 val_conv = CommitmentSigned_clone(&val_conv);
11339         CommitmentUpdate_set_commitment_signed(&this_ptr_conv, val_conv);
11340 }
11341
11342 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) {
11343         LDKCVec_UpdateAddHTLCZ update_add_htlcs_arg_constr;
11344         update_add_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_add_htlcs_arg);
11345         if (update_add_htlcs_arg_constr.datalen > 0)
11346                 update_add_htlcs_arg_constr.data = MALLOC(update_add_htlcs_arg_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
11347         else
11348                 update_add_htlcs_arg_constr.data = NULL;
11349         long* update_add_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_add_htlcs_arg, NULL);
11350         for (size_t p = 0; p < update_add_htlcs_arg_constr.datalen; p++) {
11351                 long arr_conv_15 = update_add_htlcs_arg_vals[p];
11352                 LDKUpdateAddHTLC arr_conv_15_conv;
11353                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
11354                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
11355                 if (arr_conv_15_conv.inner != NULL)
11356                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
11357                 update_add_htlcs_arg_constr.data[p] = arr_conv_15_conv;
11358         }
11359         (*_env)->ReleaseLongArrayElements (_env, update_add_htlcs_arg, update_add_htlcs_arg_vals, 0);
11360         LDKCVec_UpdateFulfillHTLCZ update_fulfill_htlcs_arg_constr;
11361         update_fulfill_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fulfill_htlcs_arg);
11362         if (update_fulfill_htlcs_arg_constr.datalen > 0)
11363                 update_fulfill_htlcs_arg_constr.data = MALLOC(update_fulfill_htlcs_arg_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
11364         else
11365                 update_fulfill_htlcs_arg_constr.data = NULL;
11366         long* update_fulfill_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fulfill_htlcs_arg, NULL);
11367         for (size_t t = 0; t < update_fulfill_htlcs_arg_constr.datalen; t++) {
11368                 long arr_conv_19 = update_fulfill_htlcs_arg_vals[t];
11369                 LDKUpdateFulfillHTLC arr_conv_19_conv;
11370                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
11371                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
11372                 if (arr_conv_19_conv.inner != NULL)
11373                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
11374                 update_fulfill_htlcs_arg_constr.data[t] = arr_conv_19_conv;
11375         }
11376         (*_env)->ReleaseLongArrayElements (_env, update_fulfill_htlcs_arg, update_fulfill_htlcs_arg_vals, 0);
11377         LDKCVec_UpdateFailHTLCZ update_fail_htlcs_arg_constr;
11378         update_fail_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fail_htlcs_arg);
11379         if (update_fail_htlcs_arg_constr.datalen > 0)
11380                 update_fail_htlcs_arg_constr.data = MALLOC(update_fail_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
11381         else
11382                 update_fail_htlcs_arg_constr.data = NULL;
11383         long* update_fail_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fail_htlcs_arg, NULL);
11384         for (size_t q = 0; q < update_fail_htlcs_arg_constr.datalen; q++) {
11385                 long arr_conv_16 = update_fail_htlcs_arg_vals[q];
11386                 LDKUpdateFailHTLC arr_conv_16_conv;
11387                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
11388                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
11389                 if (arr_conv_16_conv.inner != NULL)
11390                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
11391                 update_fail_htlcs_arg_constr.data[q] = arr_conv_16_conv;
11392         }
11393         (*_env)->ReleaseLongArrayElements (_env, update_fail_htlcs_arg, update_fail_htlcs_arg_vals, 0);
11394         LDKCVec_UpdateFailMalformedHTLCZ update_fail_malformed_htlcs_arg_constr;
11395         update_fail_malformed_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fail_malformed_htlcs_arg);
11396         if (update_fail_malformed_htlcs_arg_constr.datalen > 0)
11397                 update_fail_malformed_htlcs_arg_constr.data = MALLOC(update_fail_malformed_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
11398         else
11399                 update_fail_malformed_htlcs_arg_constr.data = NULL;
11400         long* update_fail_malformed_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fail_malformed_htlcs_arg, NULL);
11401         for (size_t z = 0; z < update_fail_malformed_htlcs_arg_constr.datalen; z++) {
11402                 long arr_conv_25 = update_fail_malformed_htlcs_arg_vals[z];
11403                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
11404                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
11405                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
11406                 if (arr_conv_25_conv.inner != NULL)
11407                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
11408                 update_fail_malformed_htlcs_arg_constr.data[z] = arr_conv_25_conv;
11409         }
11410         (*_env)->ReleaseLongArrayElements (_env, update_fail_malformed_htlcs_arg, update_fail_malformed_htlcs_arg_vals, 0);
11411         LDKUpdateFee update_fee_arg_conv;
11412         update_fee_arg_conv.inner = (void*)(update_fee_arg & (~1));
11413         update_fee_arg_conv.is_owned = (update_fee_arg & 1) || (update_fee_arg == 0);
11414         if (update_fee_arg_conv.inner != NULL)
11415                 update_fee_arg_conv = UpdateFee_clone(&update_fee_arg_conv);
11416         LDKCommitmentSigned commitment_signed_arg_conv;
11417         commitment_signed_arg_conv.inner = (void*)(commitment_signed_arg & (~1));
11418         commitment_signed_arg_conv.is_owned = (commitment_signed_arg & 1) || (commitment_signed_arg == 0);
11419         if (commitment_signed_arg_conv.inner != NULL)
11420                 commitment_signed_arg_conv = CommitmentSigned_clone(&commitment_signed_arg_conv);
11421         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);
11422         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11423         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11424         long ret_ref = (long)ret_var.inner;
11425         if (ret_var.is_owned) {
11426                 ret_ref |= 1;
11427         }
11428         return ret_ref;
11429 }
11430
11431 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11432         LDKHTLCFailChannelUpdate this_ptr_conv = *(LDKHTLCFailChannelUpdate*)this_ptr;
11433         FREE((void*)this_ptr);
11434         HTLCFailChannelUpdate_free(this_ptr_conv);
11435 }
11436
11437 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11438         LDKHTLCFailChannelUpdate* orig_conv = (LDKHTLCFailChannelUpdate*)orig;
11439         LDKHTLCFailChannelUpdate *ret_copy = MALLOC(sizeof(LDKHTLCFailChannelUpdate), "LDKHTLCFailChannelUpdate");
11440         *ret_copy = HTLCFailChannelUpdate_clone(orig_conv);
11441         long ret_ref = (long)ret_copy;
11442         return ret_ref;
11443 }
11444
11445 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11446         LDKChannelMessageHandler this_ptr_conv = *(LDKChannelMessageHandler*)this_ptr;
11447         FREE((void*)this_ptr);
11448         ChannelMessageHandler_free(this_ptr_conv);
11449 }
11450
11451 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11452         LDKRoutingMessageHandler this_ptr_conv = *(LDKRoutingMessageHandler*)this_ptr;
11453         FREE((void*)this_ptr);
11454         RoutingMessageHandler_free(this_ptr_conv);
11455 }
11456
11457 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1write(JNIEnv * _env, jclass _b, jlong obj) {
11458         LDKAcceptChannel obj_conv;
11459         obj_conv.inner = (void*)(obj & (~1));
11460         obj_conv.is_owned = false;
11461         LDKCVec_u8Z arg_var = AcceptChannel_write(&obj_conv);
11462         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11463         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11464         CVec_u8Z_free(arg_var);
11465         return arg_arr;
11466 }
11467
11468 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11469         LDKu8slice ser_ref;
11470         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11471         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11472         LDKAcceptChannel ret_var = AcceptChannel_read(ser_ref);
11473         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11474         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11475         long ret_ref = (long)ret_var.inner;
11476         if (ret_var.is_owned) {
11477                 ret_ref |= 1;
11478         }
11479         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11480         return ret_ref;
11481 }
11482
11483 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1write(JNIEnv * _env, jclass _b, jlong obj) {
11484         LDKAnnouncementSignatures obj_conv;
11485         obj_conv.inner = (void*)(obj & (~1));
11486         obj_conv.is_owned = false;
11487         LDKCVec_u8Z arg_var = AnnouncementSignatures_write(&obj_conv);
11488         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11489         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11490         CVec_u8Z_free(arg_var);
11491         return arg_arr;
11492 }
11493
11494 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11495         LDKu8slice ser_ref;
11496         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11497         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11498         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_read(ser_ref);
11499         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11500         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11501         long ret_ref = (long)ret_var.inner;
11502         if (ret_var.is_owned) {
11503                 ret_ref |= 1;
11504         }
11505         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11506         return ret_ref;
11507 }
11508
11509 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1write(JNIEnv * _env, jclass _b, jlong obj) {
11510         LDKChannelReestablish obj_conv;
11511         obj_conv.inner = (void*)(obj & (~1));
11512         obj_conv.is_owned = false;
11513         LDKCVec_u8Z arg_var = ChannelReestablish_write(&obj_conv);
11514         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11515         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11516         CVec_u8Z_free(arg_var);
11517         return arg_arr;
11518 }
11519
11520 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11521         LDKu8slice ser_ref;
11522         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11523         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11524         LDKChannelReestablish ret_var = ChannelReestablish_read(ser_ref);
11525         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11526         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11527         long ret_ref = (long)ret_var.inner;
11528         if (ret_var.is_owned) {
11529                 ret_ref |= 1;
11530         }
11531         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11532         return ret_ref;
11533 }
11534
11535 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
11536         LDKClosingSigned obj_conv;
11537         obj_conv.inner = (void*)(obj & (~1));
11538         obj_conv.is_owned = false;
11539         LDKCVec_u8Z arg_var = ClosingSigned_write(&obj_conv);
11540         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11541         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11542         CVec_u8Z_free(arg_var);
11543         return arg_arr;
11544 }
11545
11546 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11547         LDKu8slice ser_ref;
11548         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11549         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11550         LDKClosingSigned ret_var = ClosingSigned_read(ser_ref);
11551         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11552         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11553         long ret_ref = (long)ret_var.inner;
11554         if (ret_var.is_owned) {
11555                 ret_ref |= 1;
11556         }
11557         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11558         return ret_ref;
11559 }
11560
11561 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
11562         LDKCommitmentSigned obj_conv;
11563         obj_conv.inner = (void*)(obj & (~1));
11564         obj_conv.is_owned = false;
11565         LDKCVec_u8Z arg_var = CommitmentSigned_write(&obj_conv);
11566         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11567         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11568         CVec_u8Z_free(arg_var);
11569         return arg_arr;
11570 }
11571
11572 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11573         LDKu8slice ser_ref;
11574         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11575         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11576         LDKCommitmentSigned ret_var = CommitmentSigned_read(ser_ref);
11577         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11578         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11579         long ret_ref = (long)ret_var.inner;
11580         if (ret_var.is_owned) {
11581                 ret_ref |= 1;
11582         }
11583         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11584         return ret_ref;
11585 }
11586
11587 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1write(JNIEnv * _env, jclass _b, jlong obj) {
11588         LDKFundingCreated obj_conv;
11589         obj_conv.inner = (void*)(obj & (~1));
11590         obj_conv.is_owned = false;
11591         LDKCVec_u8Z arg_var = FundingCreated_write(&obj_conv);
11592         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11593         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11594         CVec_u8Z_free(arg_var);
11595         return arg_arr;
11596 }
11597
11598 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingCreated_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11599         LDKu8slice ser_ref;
11600         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11601         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11602         LDKFundingCreated ret_var = FundingCreated_read(ser_ref);
11603         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11604         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11605         long ret_ref = (long)ret_var.inner;
11606         if (ret_var.is_owned) {
11607                 ret_ref |= 1;
11608         }
11609         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11610         return ret_ref;
11611 }
11612
11613 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
11614         LDKFundingSigned obj_conv;
11615         obj_conv.inner = (void*)(obj & (~1));
11616         obj_conv.is_owned = false;
11617         LDKCVec_u8Z arg_var = FundingSigned_write(&obj_conv);
11618         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11619         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11620         CVec_u8Z_free(arg_var);
11621         return arg_arr;
11622 }
11623
11624 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11625         LDKu8slice ser_ref;
11626         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11627         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11628         LDKFundingSigned ret_var = FundingSigned_read(ser_ref);
11629         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11630         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11631         long ret_ref = (long)ret_var.inner;
11632         if (ret_var.is_owned) {
11633                 ret_ref |= 1;
11634         }
11635         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11636         return ret_ref;
11637 }
11638
11639 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1write(JNIEnv * _env, jclass _b, jlong obj) {
11640         LDKFundingLocked obj_conv;
11641         obj_conv.inner = (void*)(obj & (~1));
11642         obj_conv.is_owned = false;
11643         LDKCVec_u8Z arg_var = FundingLocked_write(&obj_conv);
11644         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11645         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11646         CVec_u8Z_free(arg_var);
11647         return arg_arr;
11648 }
11649
11650 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11651         LDKu8slice ser_ref;
11652         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11653         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11654         LDKFundingLocked ret_var = FundingLocked_read(ser_ref);
11655         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11656         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11657         long ret_ref = (long)ret_var.inner;
11658         if (ret_var.is_owned) {
11659                 ret_ref |= 1;
11660         }
11661         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11662         return ret_ref;
11663 }
11664
11665 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Init_1write(JNIEnv * _env, jclass _b, jlong obj) {
11666         LDKInit obj_conv;
11667         obj_conv.inner = (void*)(obj & (~1));
11668         obj_conv.is_owned = false;
11669         LDKCVec_u8Z arg_var = Init_write(&obj_conv);
11670         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11671         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11672         CVec_u8Z_free(arg_var);
11673         return arg_arr;
11674 }
11675
11676 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Init_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11677         LDKu8slice ser_ref;
11678         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11679         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11680         LDKInit ret_var = Init_read(ser_ref);
11681         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11682         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11683         long ret_ref = (long)ret_var.inner;
11684         if (ret_var.is_owned) {
11685                 ret_ref |= 1;
11686         }
11687         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11688         return ret_ref;
11689 }
11690
11691 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1write(JNIEnv * _env, jclass _b, jlong obj) {
11692         LDKOpenChannel obj_conv;
11693         obj_conv.inner = (void*)(obj & (~1));
11694         obj_conv.is_owned = false;
11695         LDKCVec_u8Z arg_var = OpenChannel_write(&obj_conv);
11696         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11697         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11698         CVec_u8Z_free(arg_var);
11699         return arg_arr;
11700 }
11701
11702 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11703         LDKu8slice ser_ref;
11704         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11705         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11706         LDKOpenChannel ret_var = OpenChannel_read(ser_ref);
11707         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11708         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11709         long ret_ref = (long)ret_var.inner;
11710         if (ret_var.is_owned) {
11711                 ret_ref |= 1;
11712         }
11713         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11714         return ret_ref;
11715 }
11716
11717 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1write(JNIEnv * _env, jclass _b, jlong obj) {
11718         LDKRevokeAndACK obj_conv;
11719         obj_conv.inner = (void*)(obj & (~1));
11720         obj_conv.is_owned = false;
11721         LDKCVec_u8Z arg_var = RevokeAndACK_write(&obj_conv);
11722         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11723         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11724         CVec_u8Z_free(arg_var);
11725         return arg_arr;
11726 }
11727
11728 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11729         LDKu8slice ser_ref;
11730         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11731         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11732         LDKRevokeAndACK ret_var = RevokeAndACK_read(ser_ref);
11733         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11734         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11735         long ret_ref = (long)ret_var.inner;
11736         if (ret_var.is_owned) {
11737                 ret_ref |= 1;
11738         }
11739         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11740         return ret_ref;
11741 }
11742
11743 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1write(JNIEnv * _env, jclass _b, jlong obj) {
11744         LDKShutdown obj_conv;
11745         obj_conv.inner = (void*)(obj & (~1));
11746         obj_conv.is_owned = false;
11747         LDKCVec_u8Z arg_var = Shutdown_write(&obj_conv);
11748         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11749         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11750         CVec_u8Z_free(arg_var);
11751         return arg_arr;
11752 }
11753
11754 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11755         LDKu8slice ser_ref;
11756         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11757         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11758         LDKShutdown ret_var = Shutdown_read(ser_ref);
11759         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11760         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11761         long ret_ref = (long)ret_var.inner;
11762         if (ret_var.is_owned) {
11763                 ret_ref |= 1;
11764         }
11765         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11766         return ret_ref;
11767 }
11768
11769 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
11770         LDKUpdateFailHTLC obj_conv;
11771         obj_conv.inner = (void*)(obj & (~1));
11772         obj_conv.is_owned = false;
11773         LDKCVec_u8Z arg_var = UpdateFailHTLC_write(&obj_conv);
11774         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11775         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11776         CVec_u8Z_free(arg_var);
11777         return arg_arr;
11778 }
11779
11780 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11781         LDKu8slice ser_ref;
11782         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11783         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11784         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_read(ser_ref);
11785         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11786         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11787         long ret_ref = (long)ret_var.inner;
11788         if (ret_var.is_owned) {
11789                 ret_ref |= 1;
11790         }
11791         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11792         return ret_ref;
11793 }
11794
11795 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
11796         LDKUpdateFailMalformedHTLC obj_conv;
11797         obj_conv.inner = (void*)(obj & (~1));
11798         obj_conv.is_owned = false;
11799         LDKCVec_u8Z arg_var = UpdateFailMalformedHTLC_write(&obj_conv);
11800         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11801         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11802         CVec_u8Z_free(arg_var);
11803         return arg_arr;
11804 }
11805
11806 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11807         LDKu8slice ser_ref;
11808         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11809         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11810         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_read(ser_ref);
11811         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11812         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11813         long ret_ref = (long)ret_var.inner;
11814         if (ret_var.is_owned) {
11815                 ret_ref |= 1;
11816         }
11817         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11818         return ret_ref;
11819 }
11820
11821 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1write(JNIEnv * _env, jclass _b, jlong obj) {
11822         LDKUpdateFee obj_conv;
11823         obj_conv.inner = (void*)(obj & (~1));
11824         obj_conv.is_owned = false;
11825         LDKCVec_u8Z arg_var = UpdateFee_write(&obj_conv);
11826         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11827         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11828         CVec_u8Z_free(arg_var);
11829         return arg_arr;
11830 }
11831
11832 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11833         LDKu8slice ser_ref;
11834         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11835         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11836         LDKUpdateFee ret_var = UpdateFee_read(ser_ref);
11837         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11838         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11839         long ret_ref = (long)ret_var.inner;
11840         if (ret_var.is_owned) {
11841                 ret_ref |= 1;
11842         }
11843         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11844         return ret_ref;
11845 }
11846
11847 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
11848         LDKUpdateFulfillHTLC obj_conv;
11849         obj_conv.inner = (void*)(obj & (~1));
11850         obj_conv.is_owned = false;
11851         LDKCVec_u8Z arg_var = UpdateFulfillHTLC_write(&obj_conv);
11852         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11853         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11854         CVec_u8Z_free(arg_var);
11855         return arg_arr;
11856 }
11857
11858 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11859         LDKu8slice ser_ref;
11860         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11861         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11862         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_read(ser_ref);
11863         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11864         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11865         long ret_ref = (long)ret_var.inner;
11866         if (ret_var.is_owned) {
11867                 ret_ref |= 1;
11868         }
11869         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11870         return ret_ref;
11871 }
11872
11873 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
11874         LDKUpdateAddHTLC obj_conv;
11875         obj_conv.inner = (void*)(obj & (~1));
11876         obj_conv.is_owned = false;
11877         LDKCVec_u8Z arg_var = UpdateAddHTLC_write(&obj_conv);
11878         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11879         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11880         CVec_u8Z_free(arg_var);
11881         return arg_arr;
11882 }
11883
11884 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11885         LDKu8slice ser_ref;
11886         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11887         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11888         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_read(ser_ref);
11889         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11890         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11891         long ret_ref = (long)ret_var.inner;
11892         if (ret_var.is_owned) {
11893                 ret_ref |= 1;
11894         }
11895         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11896         return ret_ref;
11897 }
11898
11899 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Ping_1write(JNIEnv * _env, jclass _b, jlong obj) {
11900         LDKPing obj_conv;
11901         obj_conv.inner = (void*)(obj & (~1));
11902         obj_conv.is_owned = false;
11903         LDKCVec_u8Z arg_var = Ping_write(&obj_conv);
11904         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11905         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11906         CVec_u8Z_free(arg_var);
11907         return arg_arr;
11908 }
11909
11910 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11911         LDKu8slice ser_ref;
11912         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11913         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11914         LDKPing ret_var = Ping_read(ser_ref);
11915         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11916         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11917         long ret_ref = (long)ret_var.inner;
11918         if (ret_var.is_owned) {
11919                 ret_ref |= 1;
11920         }
11921         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11922         return ret_ref;
11923 }
11924
11925 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Pong_1write(JNIEnv * _env, jclass _b, jlong obj) {
11926         LDKPong obj_conv;
11927         obj_conv.inner = (void*)(obj & (~1));
11928         obj_conv.is_owned = false;
11929         LDKCVec_u8Z arg_var = Pong_write(&obj_conv);
11930         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11931         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11932         CVec_u8Z_free(arg_var);
11933         return arg_arr;
11934 }
11935
11936 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11937         LDKu8slice ser_ref;
11938         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11939         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11940         LDKPong ret_var = Pong_read(ser_ref);
11941         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11942         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11943         long ret_ref = (long)ret_var.inner;
11944         if (ret_var.is_owned) {
11945                 ret_ref |= 1;
11946         }
11947         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11948         return ret_ref;
11949 }
11950
11951 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
11952         LDKUnsignedChannelAnnouncement obj_conv;
11953         obj_conv.inner = (void*)(obj & (~1));
11954         obj_conv.is_owned = false;
11955         LDKCVec_u8Z arg_var = UnsignedChannelAnnouncement_write(&obj_conv);
11956         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11957         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11958         CVec_u8Z_free(arg_var);
11959         return arg_arr;
11960 }
11961
11962 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11963         LDKu8slice ser_ref;
11964         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11965         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11966         LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_read(ser_ref);
11967         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11968         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11969         long ret_ref = (long)ret_var.inner;
11970         if (ret_var.is_owned) {
11971                 ret_ref |= 1;
11972         }
11973         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11974         return ret_ref;
11975 }
11976
11977 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
11978         LDKChannelAnnouncement obj_conv;
11979         obj_conv.inner = (void*)(obj & (~1));
11980         obj_conv.is_owned = false;
11981         LDKCVec_u8Z arg_var = ChannelAnnouncement_write(&obj_conv);
11982         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11983         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11984         CVec_u8Z_free(arg_var);
11985         return arg_arr;
11986 }
11987
11988 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11989         LDKu8slice ser_ref;
11990         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11991         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11992         LDKChannelAnnouncement ret_var = ChannelAnnouncement_read(ser_ref);
11993         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11994         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11995         long ret_ref = (long)ret_var.inner;
11996         if (ret_var.is_owned) {
11997                 ret_ref |= 1;
11998         }
11999         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12000         return ret_ref;
12001 }
12002
12003 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
12004         LDKUnsignedChannelUpdate obj_conv;
12005         obj_conv.inner = (void*)(obj & (~1));
12006         obj_conv.is_owned = false;
12007         LDKCVec_u8Z arg_var = UnsignedChannelUpdate_write(&obj_conv);
12008         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12009         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12010         CVec_u8Z_free(arg_var);
12011         return arg_arr;
12012 }
12013
12014 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12015         LDKu8slice ser_ref;
12016         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12017         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12018         LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_read(ser_ref);
12019         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12020         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12021         long ret_ref = (long)ret_var.inner;
12022         if (ret_var.is_owned) {
12023                 ret_ref |= 1;
12024         }
12025         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12026         return ret_ref;
12027 }
12028
12029 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
12030         LDKChannelUpdate obj_conv;
12031         obj_conv.inner = (void*)(obj & (~1));
12032         obj_conv.is_owned = false;
12033         LDKCVec_u8Z arg_var = ChannelUpdate_write(&obj_conv);
12034         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12035         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12036         CVec_u8Z_free(arg_var);
12037         return arg_arr;
12038 }
12039
12040 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12041         LDKu8slice ser_ref;
12042         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12043         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12044         LDKChannelUpdate ret_var = ChannelUpdate_read(ser_ref);
12045         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12046         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12047         long ret_ref = (long)ret_var.inner;
12048         if (ret_var.is_owned) {
12049                 ret_ref |= 1;
12050         }
12051         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12052         return ret_ref;
12053 }
12054
12055 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1write(JNIEnv * _env, jclass _b, jlong obj) {
12056         LDKErrorMessage obj_conv;
12057         obj_conv.inner = (void*)(obj & (~1));
12058         obj_conv.is_owned = false;
12059         LDKCVec_u8Z arg_var = ErrorMessage_write(&obj_conv);
12060         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12061         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12062         CVec_u8Z_free(arg_var);
12063         return arg_arr;
12064 }
12065
12066 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12067         LDKu8slice ser_ref;
12068         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12069         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12070         LDKErrorMessage ret_var = ErrorMessage_read(ser_ref);
12071         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12072         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12073         long ret_ref = (long)ret_var.inner;
12074         if (ret_var.is_owned) {
12075                 ret_ref |= 1;
12076         }
12077         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12078         return ret_ref;
12079 }
12080
12081 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
12082         LDKUnsignedNodeAnnouncement obj_conv;
12083         obj_conv.inner = (void*)(obj & (~1));
12084         obj_conv.is_owned = false;
12085         LDKCVec_u8Z arg_var = UnsignedNodeAnnouncement_write(&obj_conv);
12086         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12087         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12088         CVec_u8Z_free(arg_var);
12089         return arg_arr;
12090 }
12091
12092 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12093         LDKu8slice ser_ref;
12094         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12095         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12096         LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_read(ser_ref);
12097         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12098         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12099         long ret_ref = (long)ret_var.inner;
12100         if (ret_var.is_owned) {
12101                 ret_ref |= 1;
12102         }
12103         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12104         return ret_ref;
12105 }
12106
12107 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
12108         LDKNodeAnnouncement obj_conv;
12109         obj_conv.inner = (void*)(obj & (~1));
12110         obj_conv.is_owned = false;
12111         LDKCVec_u8Z arg_var = NodeAnnouncement_write(&obj_conv);
12112         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12113         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12114         CVec_u8Z_free(arg_var);
12115         return arg_arr;
12116 }
12117
12118 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12119         LDKu8slice ser_ref;
12120         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12121         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12122         LDKNodeAnnouncement ret_var = NodeAnnouncement_read(ser_ref);
12123         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12124         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12125         long ret_ref = (long)ret_var.inner;
12126         if (ret_var.is_owned) {
12127                 ret_ref |= 1;
12128         }
12129         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12130         return ret_ref;
12131 }
12132
12133 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12134         LDKu8slice ser_ref;
12135         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12136         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12137         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_read(ser_ref);
12138         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12139         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12140         long ret_ref = (long)ret_var.inner;
12141         if (ret_var.is_owned) {
12142                 ret_ref |= 1;
12143         }
12144         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12145         return ret_ref;
12146 }
12147
12148 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1write(JNIEnv * _env, jclass _b, jlong obj) {
12149         LDKQueryShortChannelIds obj_conv;
12150         obj_conv.inner = (void*)(obj & (~1));
12151         obj_conv.is_owned = false;
12152         LDKCVec_u8Z arg_var = QueryShortChannelIds_write(&obj_conv);
12153         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12154         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12155         CVec_u8Z_free(arg_var);
12156         return arg_arr;
12157 }
12158
12159 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12160         LDKu8slice ser_ref;
12161         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12162         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12163         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_read(ser_ref);
12164         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12165         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12166         long ret_ref = (long)ret_var.inner;
12167         if (ret_var.is_owned) {
12168                 ret_ref |= 1;
12169         }
12170         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12171         return ret_ref;
12172 }
12173
12174 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1write(JNIEnv * _env, jclass _b, jlong obj) {
12175         LDKReplyShortChannelIdsEnd obj_conv;
12176         obj_conv.inner = (void*)(obj & (~1));
12177         obj_conv.is_owned = false;
12178         LDKCVec_u8Z arg_var = ReplyShortChannelIdsEnd_write(&obj_conv);
12179         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12180         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12181         CVec_u8Z_free(arg_var);
12182         return arg_arr;
12183 }
12184
12185 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12186         LDKu8slice ser_ref;
12187         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12188         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12189         LDKQueryChannelRange ret_var = QueryChannelRange_read(ser_ref);
12190         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12191         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12192         long ret_ref = (long)ret_var.inner;
12193         if (ret_var.is_owned) {
12194                 ret_ref |= 1;
12195         }
12196         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12197         return ret_ref;
12198 }
12199
12200 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1write(JNIEnv * _env, jclass _b, jlong obj) {
12201         LDKQueryChannelRange obj_conv;
12202         obj_conv.inner = (void*)(obj & (~1));
12203         obj_conv.is_owned = false;
12204         LDKCVec_u8Z arg_var = QueryChannelRange_write(&obj_conv);
12205         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12206         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12207         CVec_u8Z_free(arg_var);
12208         return arg_arr;
12209 }
12210
12211 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12212         LDKu8slice ser_ref;
12213         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12214         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12215         LDKReplyChannelRange ret_var = ReplyChannelRange_read(ser_ref);
12216         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12217         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12218         long ret_ref = (long)ret_var.inner;
12219         if (ret_var.is_owned) {
12220                 ret_ref |= 1;
12221         }
12222         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12223         return ret_ref;
12224 }
12225
12226 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1write(JNIEnv * _env, jclass _b, jlong obj) {
12227         LDKReplyChannelRange obj_conv;
12228         obj_conv.inner = (void*)(obj & (~1));
12229         obj_conv.is_owned = false;
12230         LDKCVec_u8Z arg_var = ReplyChannelRange_write(&obj_conv);
12231         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12232         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12233         CVec_u8Z_free(arg_var);
12234         return arg_arr;
12235 }
12236
12237 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12238         LDKu8slice ser_ref;
12239         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12240         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12241         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_read(ser_ref);
12242         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12243         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12244         long ret_ref = (long)ret_var.inner;
12245         if (ret_var.is_owned) {
12246                 ret_ref |= 1;
12247         }
12248         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12249         return ret_ref;
12250 }
12251
12252 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1write(JNIEnv * _env, jclass _b, jlong obj) {
12253         LDKGossipTimestampFilter obj_conv;
12254         obj_conv.inner = (void*)(obj & (~1));
12255         obj_conv.is_owned = false;
12256         LDKCVec_u8Z arg_var = GossipTimestampFilter_write(&obj_conv);
12257         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12258         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12259         CVec_u8Z_free(arg_var);
12260         return arg_arr;
12261 }
12262
12263 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12264         LDKMessageHandler this_ptr_conv;
12265         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12266         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12267         MessageHandler_free(this_ptr_conv);
12268 }
12269
12270 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1chan_1handler(JNIEnv * _env, jclass _b, jlong this_ptr) {
12271         LDKMessageHandler this_ptr_conv;
12272         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12273         this_ptr_conv.is_owned = false;
12274         long ret_ret = (long)MessageHandler_get_chan_handler(&this_ptr_conv);
12275         return ret_ret;
12276 }
12277
12278 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1chan_1handler(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12279         LDKMessageHandler this_ptr_conv;
12280         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12281         this_ptr_conv.is_owned = false;
12282         LDKChannelMessageHandler val_conv = *(LDKChannelMessageHandler*)val;
12283         if (val_conv.free == LDKChannelMessageHandler_JCalls_free) {
12284                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12285                 LDKChannelMessageHandler_JCalls_clone(val_conv.this_arg);
12286         }
12287         MessageHandler_set_chan_handler(&this_ptr_conv, val_conv);
12288 }
12289
12290 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1route_1handler(JNIEnv * _env, jclass _b, jlong this_ptr) {
12291         LDKMessageHandler this_ptr_conv;
12292         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12293         this_ptr_conv.is_owned = false;
12294         long ret_ret = (long)MessageHandler_get_route_handler(&this_ptr_conv);
12295         return ret_ret;
12296 }
12297
12298 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1route_1handler(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12299         LDKMessageHandler this_ptr_conv;
12300         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12301         this_ptr_conv.is_owned = false;
12302         LDKRoutingMessageHandler val_conv = *(LDKRoutingMessageHandler*)val;
12303         if (val_conv.free == LDKRoutingMessageHandler_JCalls_free) {
12304                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12305                 LDKRoutingMessageHandler_JCalls_clone(val_conv.this_arg);
12306         }
12307         MessageHandler_set_route_handler(&this_ptr_conv, val_conv);
12308 }
12309
12310 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1new(JNIEnv * _env, jclass _b, jlong chan_handler_arg, jlong route_handler_arg) {
12311         LDKChannelMessageHandler chan_handler_arg_conv = *(LDKChannelMessageHandler*)chan_handler_arg;
12312         if (chan_handler_arg_conv.free == LDKChannelMessageHandler_JCalls_free) {
12313                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12314                 LDKChannelMessageHandler_JCalls_clone(chan_handler_arg_conv.this_arg);
12315         }
12316         LDKRoutingMessageHandler route_handler_arg_conv = *(LDKRoutingMessageHandler*)route_handler_arg;
12317         if (route_handler_arg_conv.free == LDKRoutingMessageHandler_JCalls_free) {
12318                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12319                 LDKRoutingMessageHandler_JCalls_clone(route_handler_arg_conv.this_arg);
12320         }
12321         LDKMessageHandler ret_var = MessageHandler_new(chan_handler_arg_conv, route_handler_arg_conv);
12322         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12323         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12324         long ret_ref = (long)ret_var.inner;
12325         if (ret_var.is_owned) {
12326                 ret_ref |= 1;
12327         }
12328         return ret_ref;
12329 }
12330
12331 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12332         LDKSocketDescriptor this_ptr_conv = *(LDKSocketDescriptor*)this_ptr;
12333         FREE((void*)this_ptr);
12334         SocketDescriptor_free(this_ptr_conv);
12335 }
12336
12337 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12338         LDKPeerHandleError this_ptr_conv;
12339         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12340         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12341         PeerHandleError_free(this_ptr_conv);
12342 }
12343
12344 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1get_1no_1connection_1possible(JNIEnv * _env, jclass _b, jlong this_ptr) {
12345         LDKPeerHandleError this_ptr_conv;
12346         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12347         this_ptr_conv.is_owned = false;
12348         jboolean ret_val = PeerHandleError_get_no_connection_possible(&this_ptr_conv);
12349         return ret_val;
12350 }
12351
12352 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1set_1no_1connection_1possible(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
12353         LDKPeerHandleError this_ptr_conv;
12354         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12355         this_ptr_conv.is_owned = false;
12356         PeerHandleError_set_no_connection_possible(&this_ptr_conv, val);
12357 }
12358
12359 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1new(JNIEnv * _env, jclass _b, jboolean no_connection_possible_arg) {
12360         LDKPeerHandleError ret_var = PeerHandleError_new(no_connection_possible_arg);
12361         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12362         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12363         long ret_ref = (long)ret_var.inner;
12364         if (ret_var.is_owned) {
12365                 ret_ref |= 1;
12366         }
12367         return ret_ref;
12368 }
12369
12370 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12371         LDKPeerManager this_ptr_conv;
12372         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12373         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12374         PeerManager_free(this_ptr_conv);
12375 }
12376
12377 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) {
12378         LDKMessageHandler message_handler_conv;
12379         message_handler_conv.inner = (void*)(message_handler & (~1));
12380         message_handler_conv.is_owned = (message_handler & 1) || (message_handler == 0);
12381         // Warning: we may need a move here but can't clone!
12382         LDKSecretKey our_node_secret_ref;
12383         CHECK((*_env)->GetArrayLength (_env, our_node_secret) == 32);
12384         (*_env)->GetByteArrayRegion (_env, our_node_secret, 0, 32, our_node_secret_ref.bytes);
12385         unsigned char ephemeral_random_data_arr[32];
12386         CHECK((*_env)->GetArrayLength (_env, ephemeral_random_data) == 32);
12387         (*_env)->GetByteArrayRegion (_env, ephemeral_random_data, 0, 32, ephemeral_random_data_arr);
12388         unsigned char (*ephemeral_random_data_ref)[32] = &ephemeral_random_data_arr;
12389         LDKLogger logger_conv = *(LDKLogger*)logger;
12390         if (logger_conv.free == LDKLogger_JCalls_free) {
12391                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12392                 LDKLogger_JCalls_clone(logger_conv.this_arg);
12393         }
12394         LDKPeerManager ret_var = PeerManager_new(message_handler_conv, our_node_secret_ref, ephemeral_random_data_ref, logger_conv);
12395         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12396         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12397         long ret_ref = (long)ret_var.inner;
12398         if (ret_var.is_owned) {
12399                 ret_ref |= 1;
12400         }
12401         return ret_ref;
12402 }
12403
12404 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_PeerManager_1get_1peer_1node_1ids(JNIEnv * _env, jclass _b, jlong this_arg) {
12405         LDKPeerManager this_arg_conv;
12406         this_arg_conv.inner = (void*)(this_arg & (~1));
12407         this_arg_conv.is_owned = false;
12408         LDKCVec_PublicKeyZ ret_var = PeerManager_get_peer_node_ids(&this_arg_conv);
12409         jobjectArray ret_arr = (*_env)->NewObjectArray(_env, ret_var.datalen, arr_of_B_clz, NULL);
12410         for (size_t i = 0; i < ret_var.datalen; i++) {
12411                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 33);
12412                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 33, ret_var.data[i].compressed_form);
12413                 (*_env)->SetObjectArrayElement(_env, ret_arr, i, arr_conv_8_arr);
12414         }
12415         CVec_PublicKeyZ_free(ret_var);
12416         return ret_arr;
12417 }
12418
12419 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) {
12420         LDKPeerManager this_arg_conv;
12421         this_arg_conv.inner = (void*)(this_arg & (~1));
12422         this_arg_conv.is_owned = false;
12423         LDKPublicKey their_node_id_ref;
12424         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
12425         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
12426         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
12427         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
12428                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12429                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
12430         }
12431         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
12432         *ret_conv = PeerManager_new_outbound_connection(&this_arg_conv, their_node_id_ref, descriptor_conv);
12433         return (long)ret_conv;
12434 }
12435
12436 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1new_1inbound_1connection(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
12437         LDKPeerManager this_arg_conv;
12438         this_arg_conv.inner = (void*)(this_arg & (~1));
12439         this_arg_conv.is_owned = false;
12440         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
12441         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
12442                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12443                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
12444         }
12445         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
12446         *ret_conv = PeerManager_new_inbound_connection(&this_arg_conv, descriptor_conv);
12447         return (long)ret_conv;
12448 }
12449
12450 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1write_1buffer_1space_1avail(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
12451         LDKPeerManager this_arg_conv;
12452         this_arg_conv.inner = (void*)(this_arg & (~1));
12453         this_arg_conv.is_owned = false;
12454         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
12455         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
12456         *ret_conv = PeerManager_write_buffer_space_avail(&this_arg_conv, descriptor_conv);
12457         return (long)ret_conv;
12458 }
12459
12460 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1read_1event(JNIEnv * _env, jclass _b, jlong this_arg, jlong peer_descriptor, jbyteArray data) {
12461         LDKPeerManager this_arg_conv;
12462         this_arg_conv.inner = (void*)(this_arg & (~1));
12463         this_arg_conv.is_owned = false;
12464         LDKSocketDescriptor* peer_descriptor_conv = (LDKSocketDescriptor*)peer_descriptor;
12465         LDKu8slice data_ref;
12466         data_ref.datalen = (*_env)->GetArrayLength (_env, data);
12467         data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL);
12468         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
12469         *ret_conv = PeerManager_read_event(&this_arg_conv, peer_descriptor_conv, data_ref);
12470         (*_env)->ReleaseByteArrayElements(_env, data, (int8_t*)data_ref.data, 0);
12471         return (long)ret_conv;
12472 }
12473
12474 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1process_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
12475         LDKPeerManager this_arg_conv;
12476         this_arg_conv.inner = (void*)(this_arg & (~1));
12477         this_arg_conv.is_owned = false;
12478         PeerManager_process_events(&this_arg_conv);
12479 }
12480
12481 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1socket_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
12482         LDKPeerManager this_arg_conv;
12483         this_arg_conv.inner = (void*)(this_arg & (~1));
12484         this_arg_conv.is_owned = false;
12485         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
12486         PeerManager_socket_disconnected(&this_arg_conv, descriptor_conv);
12487 }
12488
12489 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1timer_1tick_1occured(JNIEnv * _env, jclass _b, jlong this_arg) {
12490         LDKPeerManager this_arg_conv;
12491         this_arg_conv.inner = (void*)(this_arg & (~1));
12492         this_arg_conv.is_owned = false;
12493         PeerManager_timer_tick_occured(&this_arg_conv);
12494 }
12495
12496 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_build_1commitment_1secret(JNIEnv * _env, jclass _b, jbyteArray commitment_seed, jlong idx) {
12497         unsigned char commitment_seed_arr[32];
12498         CHECK((*_env)->GetArrayLength (_env, commitment_seed) == 32);
12499         (*_env)->GetByteArrayRegion (_env, commitment_seed, 0, 32, commitment_seed_arr);
12500         unsigned char (*commitment_seed_ref)[32] = &commitment_seed_arr;
12501         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
12502         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, build_commitment_secret(commitment_seed_ref, idx).data);
12503         return arg_arr;
12504 }
12505
12506 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_derive_1private_1key(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jbyteArray base_secret) {
12507         LDKPublicKey per_commitment_point_ref;
12508         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
12509         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
12510         unsigned char base_secret_arr[32];
12511         CHECK((*_env)->GetArrayLength (_env, base_secret) == 32);
12512         (*_env)->GetByteArrayRegion (_env, base_secret, 0, 32, base_secret_arr);
12513         unsigned char (*base_secret_ref)[32] = &base_secret_arr;
12514         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
12515         *ret_conv = derive_private_key(per_commitment_point_ref, base_secret_ref);
12516         return (long)ret_conv;
12517 }
12518
12519 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_derive_1public_1key(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jbyteArray base_point) {
12520         LDKPublicKey per_commitment_point_ref;
12521         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
12522         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
12523         LDKPublicKey base_point_ref;
12524         CHECK((*_env)->GetArrayLength (_env, base_point) == 33);
12525         (*_env)->GetByteArrayRegion (_env, base_point, 0, 33, base_point_ref.compressed_form);
12526         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
12527         *ret_conv = derive_public_key(per_commitment_point_ref, base_point_ref);
12528         return (long)ret_conv;
12529 }
12530
12531 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) {
12532         unsigned char per_commitment_secret_arr[32];
12533         CHECK((*_env)->GetArrayLength (_env, per_commitment_secret) == 32);
12534         (*_env)->GetByteArrayRegion (_env, per_commitment_secret, 0, 32, per_commitment_secret_arr);
12535         unsigned char (*per_commitment_secret_ref)[32] = &per_commitment_secret_arr;
12536         unsigned char countersignatory_revocation_base_secret_arr[32];
12537         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base_secret) == 32);
12538         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base_secret, 0, 32, countersignatory_revocation_base_secret_arr);
12539         unsigned char (*countersignatory_revocation_base_secret_ref)[32] = &countersignatory_revocation_base_secret_arr;
12540         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
12541         *ret_conv = derive_private_revocation_key(per_commitment_secret_ref, countersignatory_revocation_base_secret_ref);
12542         return (long)ret_conv;
12543 }
12544
12545 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) {
12546         LDKPublicKey per_commitment_point_ref;
12547         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
12548         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
12549         LDKPublicKey countersignatory_revocation_base_point_ref;
12550         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base_point) == 33);
12551         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base_point, 0, 33, countersignatory_revocation_base_point_ref.compressed_form);
12552         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
12553         *ret_conv = derive_public_revocation_key(per_commitment_point_ref, countersignatory_revocation_base_point_ref);
12554         return (long)ret_conv;
12555 }
12556
12557 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12558         LDKTxCreationKeys 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         TxCreationKeys_free(this_ptr_conv);
12562 }
12563
12564 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12565         LDKTxCreationKeys orig_conv;
12566         orig_conv.inner = (void*)(orig & (~1));
12567         orig_conv.is_owned = false;
12568         LDKTxCreationKeys ret_var = TxCreationKeys_clone(&orig_conv);
12569         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12570         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12571         long ret_ref = (long)ret_var.inner;
12572         if (ret_var.is_owned) {
12573                 ret_ref |= 1;
12574         }
12575         return ret_ref;
12576 }
12577
12578 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
12579         LDKTxCreationKeys this_ptr_conv;
12580         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12581         this_ptr_conv.is_owned = false;
12582         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12583         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_per_commitment_point(&this_ptr_conv).compressed_form);
12584         return arg_arr;
12585 }
12586
12587 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12588         LDKTxCreationKeys this_ptr_conv;
12589         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12590         this_ptr_conv.is_owned = false;
12591         LDKPublicKey val_ref;
12592         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12593         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12594         TxCreationKeys_set_per_commitment_point(&this_ptr_conv, val_ref);
12595 }
12596
12597 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1revocation_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
12598         LDKTxCreationKeys this_ptr_conv;
12599         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12600         this_ptr_conv.is_owned = false;
12601         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12602         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_revocation_key(&this_ptr_conv).compressed_form);
12603         return arg_arr;
12604 }
12605
12606 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1revocation_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12607         LDKTxCreationKeys this_ptr_conv;
12608         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12609         this_ptr_conv.is_owned = false;
12610         LDKPublicKey val_ref;
12611         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12612         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12613         TxCreationKeys_set_revocation_key(&this_ptr_conv, val_ref);
12614 }
12615
12616 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
12617         LDKTxCreationKeys this_ptr_conv;
12618         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12619         this_ptr_conv.is_owned = false;
12620         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12621         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_htlc_key(&this_ptr_conv).compressed_form);
12622         return arg_arr;
12623 }
12624
12625 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1broadcaster_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12626         LDKTxCreationKeys this_ptr_conv;
12627         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12628         this_ptr_conv.is_owned = false;
12629         LDKPublicKey val_ref;
12630         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12631         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12632         TxCreationKeys_set_broadcaster_htlc_key(&this_ptr_conv, val_ref);
12633 }
12634
12635 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1countersignatory_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
12636         LDKTxCreationKeys this_ptr_conv;
12637         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12638         this_ptr_conv.is_owned = false;
12639         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12640         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_countersignatory_htlc_key(&this_ptr_conv).compressed_form);
12641         return arg_arr;
12642 }
12643
12644 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1countersignatory_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12645         LDKTxCreationKeys this_ptr_conv;
12646         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12647         this_ptr_conv.is_owned = false;
12648         LDKPublicKey val_ref;
12649         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12650         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12651         TxCreationKeys_set_countersignatory_htlc_key(&this_ptr_conv, val_ref);
12652 }
12653
12654 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1delayed_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
12655         LDKTxCreationKeys this_ptr_conv;
12656         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12657         this_ptr_conv.is_owned = false;
12658         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12659         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_delayed_payment_key(&this_ptr_conv).compressed_form);
12660         return arg_arr;
12661 }
12662
12663 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1broadcaster_1delayed_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12664         LDKTxCreationKeys this_ptr_conv;
12665         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12666         this_ptr_conv.is_owned = false;
12667         LDKPublicKey val_ref;
12668         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12669         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12670         TxCreationKeys_set_broadcaster_delayed_payment_key(&this_ptr_conv, val_ref);
12671 }
12672
12673 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) {
12674         LDKPublicKey per_commitment_point_arg_ref;
12675         CHECK((*_env)->GetArrayLength (_env, per_commitment_point_arg) == 33);
12676         (*_env)->GetByteArrayRegion (_env, per_commitment_point_arg, 0, 33, per_commitment_point_arg_ref.compressed_form);
12677         LDKPublicKey revocation_key_arg_ref;
12678         CHECK((*_env)->GetArrayLength (_env, revocation_key_arg) == 33);
12679         (*_env)->GetByteArrayRegion (_env, revocation_key_arg, 0, 33, revocation_key_arg_ref.compressed_form);
12680         LDKPublicKey broadcaster_htlc_key_arg_ref;
12681         CHECK((*_env)->GetArrayLength (_env, broadcaster_htlc_key_arg) == 33);
12682         (*_env)->GetByteArrayRegion (_env, broadcaster_htlc_key_arg, 0, 33, broadcaster_htlc_key_arg_ref.compressed_form);
12683         LDKPublicKey countersignatory_htlc_key_arg_ref;
12684         CHECK((*_env)->GetArrayLength (_env, countersignatory_htlc_key_arg) == 33);
12685         (*_env)->GetByteArrayRegion (_env, countersignatory_htlc_key_arg, 0, 33, countersignatory_htlc_key_arg_ref.compressed_form);
12686         LDKPublicKey broadcaster_delayed_payment_key_arg_ref;
12687         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key_arg) == 33);
12688         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key_arg, 0, 33, broadcaster_delayed_payment_key_arg_ref.compressed_form);
12689         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);
12690         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12691         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12692         long ret_ref = (long)ret_var.inner;
12693         if (ret_var.is_owned) {
12694                 ret_ref |= 1;
12695         }
12696         return ret_ref;
12697 }
12698
12699 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
12700         LDKTxCreationKeys obj_conv;
12701         obj_conv.inner = (void*)(obj & (~1));
12702         obj_conv.is_owned = false;
12703         LDKCVec_u8Z arg_var = TxCreationKeys_write(&obj_conv);
12704         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12705         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12706         CVec_u8Z_free(arg_var);
12707         return arg_arr;
12708 }
12709
12710 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12711         LDKu8slice ser_ref;
12712         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12713         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12714         LDKTxCreationKeys ret_var = TxCreationKeys_read(ser_ref);
12715         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12716         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12717         long ret_ref = (long)ret_var.inner;
12718         if (ret_var.is_owned) {
12719                 ret_ref |= 1;
12720         }
12721         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12722         return ret_ref;
12723 }
12724
12725 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12726         LDKPreCalculatedTxCreationKeys this_ptr_conv;
12727         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12728         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12729         PreCalculatedTxCreationKeys_free(this_ptr_conv);
12730 }
12731
12732 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12733         LDKPreCalculatedTxCreationKeys orig_conv;
12734         orig_conv.inner = (void*)(orig & (~1));
12735         orig_conv.is_owned = false;
12736         LDKPreCalculatedTxCreationKeys ret_var = PreCalculatedTxCreationKeys_clone(&orig_conv);
12737         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12738         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12739         long ret_ref = (long)ret_var.inner;
12740         if (ret_var.is_owned) {
12741                 ret_ref |= 1;
12742         }
12743         return ret_ref;
12744 }
12745
12746 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1new(JNIEnv * _env, jclass _b, jlong keys) {
12747         LDKTxCreationKeys keys_conv;
12748         keys_conv.inner = (void*)(keys & (~1));
12749         keys_conv.is_owned = (keys & 1) || (keys == 0);
12750         if (keys_conv.inner != NULL)
12751                 keys_conv = TxCreationKeys_clone(&keys_conv);
12752         LDKPreCalculatedTxCreationKeys ret_var = PreCalculatedTxCreationKeys_new(keys_conv);
12753         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12754         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12755         long ret_ref = (long)ret_var.inner;
12756         if (ret_var.is_owned) {
12757                 ret_ref |= 1;
12758         }
12759         return ret_ref;
12760 }
12761
12762 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1trust_1key_1derivation(JNIEnv * _env, jclass _b, jlong this_arg) {
12763         LDKPreCalculatedTxCreationKeys this_arg_conv;
12764         this_arg_conv.inner = (void*)(this_arg & (~1));
12765         this_arg_conv.is_owned = false;
12766         LDKTxCreationKeys ret_var = PreCalculatedTxCreationKeys_trust_key_derivation(&this_arg_conv);
12767         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12768         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12769         long ret_ref = (long)ret_var.inner;
12770         if (ret_var.is_owned) {
12771                 ret_ref |= 1;
12772         }
12773         return ret_ref;
12774 }
12775
12776 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_arg) {
12777         LDKPreCalculatedTxCreationKeys this_arg_conv;
12778         this_arg_conv.inner = (void*)(this_arg & (~1));
12779         this_arg_conv.is_owned = false;
12780         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12781         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, PreCalculatedTxCreationKeys_per_commitment_point(&this_arg_conv).compressed_form);
12782         return arg_arr;
12783 }
12784
12785 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12786         LDKChannelPublicKeys this_ptr_conv;
12787         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12788         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12789         ChannelPublicKeys_free(this_ptr_conv);
12790 }
12791
12792 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12793         LDKChannelPublicKeys orig_conv;
12794         orig_conv.inner = (void*)(orig & (~1));
12795         orig_conv.is_owned = false;
12796         LDKChannelPublicKeys ret_var = ChannelPublicKeys_clone(&orig_conv);
12797         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12798         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12799         long ret_ref = (long)ret_var.inner;
12800         if (ret_var.is_owned) {
12801                 ret_ref |= 1;
12802         }
12803         return ret_ref;
12804 }
12805
12806 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
12807         LDKChannelPublicKeys this_ptr_conv;
12808         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12809         this_ptr_conv.is_owned = false;
12810         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12811         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_funding_pubkey(&this_ptr_conv).compressed_form);
12812         return arg_arr;
12813 }
12814
12815 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12816         LDKChannelPublicKeys this_ptr_conv;
12817         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12818         this_ptr_conv.is_owned = false;
12819         LDKPublicKey val_ref;
12820         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12821         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12822         ChannelPublicKeys_set_funding_pubkey(&this_ptr_conv, val_ref);
12823 }
12824
12825 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
12826         LDKChannelPublicKeys this_ptr_conv;
12827         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12828         this_ptr_conv.is_owned = false;
12829         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12830         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_revocation_basepoint(&this_ptr_conv).compressed_form);
12831         return arg_arr;
12832 }
12833
12834 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12835         LDKChannelPublicKeys this_ptr_conv;
12836         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12837         this_ptr_conv.is_owned = false;
12838         LDKPublicKey val_ref;
12839         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12840         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12841         ChannelPublicKeys_set_revocation_basepoint(&this_ptr_conv, val_ref);
12842 }
12843
12844 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
12845         LDKChannelPublicKeys this_ptr_conv;
12846         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12847         this_ptr_conv.is_owned = false;
12848         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12849         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_payment_point(&this_ptr_conv).compressed_form);
12850         return arg_arr;
12851 }
12852
12853 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12854         LDKChannelPublicKeys this_ptr_conv;
12855         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12856         this_ptr_conv.is_owned = false;
12857         LDKPublicKey val_ref;
12858         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12859         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12860         ChannelPublicKeys_set_payment_point(&this_ptr_conv, val_ref);
12861 }
12862
12863 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
12864         LDKChannelPublicKeys this_ptr_conv;
12865         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12866         this_ptr_conv.is_owned = false;
12867         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12868         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
12869         return arg_arr;
12870 }
12871
12872 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12873         LDKChannelPublicKeys this_ptr_conv;
12874         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12875         this_ptr_conv.is_owned = false;
12876         LDKPublicKey val_ref;
12877         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12878         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12879         ChannelPublicKeys_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
12880 }
12881
12882 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
12883         LDKChannelPublicKeys this_ptr_conv;
12884         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12885         this_ptr_conv.is_owned = false;
12886         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12887         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_htlc_basepoint(&this_ptr_conv).compressed_form);
12888         return arg_arr;
12889 }
12890
12891 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12892         LDKChannelPublicKeys this_ptr_conv;
12893         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12894         this_ptr_conv.is_owned = false;
12895         LDKPublicKey val_ref;
12896         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12897         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12898         ChannelPublicKeys_set_htlc_basepoint(&this_ptr_conv, val_ref);
12899 }
12900
12901 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) {
12902         LDKPublicKey funding_pubkey_arg_ref;
12903         CHECK((*_env)->GetArrayLength (_env, funding_pubkey_arg) == 33);
12904         (*_env)->GetByteArrayRegion (_env, funding_pubkey_arg, 0, 33, funding_pubkey_arg_ref.compressed_form);
12905         LDKPublicKey revocation_basepoint_arg_ref;
12906         CHECK((*_env)->GetArrayLength (_env, revocation_basepoint_arg) == 33);
12907         (*_env)->GetByteArrayRegion (_env, revocation_basepoint_arg, 0, 33, revocation_basepoint_arg_ref.compressed_form);
12908         LDKPublicKey payment_point_arg_ref;
12909         CHECK((*_env)->GetArrayLength (_env, payment_point_arg) == 33);
12910         (*_env)->GetByteArrayRegion (_env, payment_point_arg, 0, 33, payment_point_arg_ref.compressed_form);
12911         LDKPublicKey delayed_payment_basepoint_arg_ref;
12912         CHECK((*_env)->GetArrayLength (_env, delayed_payment_basepoint_arg) == 33);
12913         (*_env)->GetByteArrayRegion (_env, delayed_payment_basepoint_arg, 0, 33, delayed_payment_basepoint_arg_ref.compressed_form);
12914         LDKPublicKey htlc_basepoint_arg_ref;
12915         CHECK((*_env)->GetArrayLength (_env, htlc_basepoint_arg) == 33);
12916         (*_env)->GetByteArrayRegion (_env, htlc_basepoint_arg, 0, 33, htlc_basepoint_arg_ref.compressed_form);
12917         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);
12918         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12919         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12920         long ret_ref = (long)ret_var.inner;
12921         if (ret_var.is_owned) {
12922                 ret_ref |= 1;
12923         }
12924         return ret_ref;
12925 }
12926
12927 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
12928         LDKChannelPublicKeys obj_conv;
12929         obj_conv.inner = (void*)(obj & (~1));
12930         obj_conv.is_owned = false;
12931         LDKCVec_u8Z arg_var = ChannelPublicKeys_write(&obj_conv);
12932         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12933         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12934         CVec_u8Z_free(arg_var);
12935         return arg_arr;
12936 }
12937
12938 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12939         LDKu8slice ser_ref;
12940         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12941         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12942         LDKChannelPublicKeys ret_var = ChannelPublicKeys_read(ser_ref);
12943         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12944         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12945         long ret_ref = (long)ret_var.inner;
12946         if (ret_var.is_owned) {
12947                 ret_ref |= 1;
12948         }
12949         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12950         return ret_ref;
12951 }
12952
12953 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) {
12954         LDKPublicKey per_commitment_point_ref;
12955         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
12956         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
12957         LDKPublicKey broadcaster_delayed_payment_base_ref;
12958         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_base) == 33);
12959         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_base, 0, 33, broadcaster_delayed_payment_base_ref.compressed_form);
12960         LDKPublicKey broadcaster_htlc_base_ref;
12961         CHECK((*_env)->GetArrayLength (_env, broadcaster_htlc_base) == 33);
12962         (*_env)->GetByteArrayRegion (_env, broadcaster_htlc_base, 0, 33, broadcaster_htlc_base_ref.compressed_form);
12963         LDKPublicKey countersignatory_revocation_base_ref;
12964         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base) == 33);
12965         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base, 0, 33, countersignatory_revocation_base_ref.compressed_form);
12966         LDKPublicKey countersignatory_htlc_base_ref;
12967         CHECK((*_env)->GetArrayLength (_env, countersignatory_htlc_base) == 33);
12968         (*_env)->GetByteArrayRegion (_env, countersignatory_htlc_base, 0, 33, countersignatory_htlc_base_ref.compressed_form);
12969         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
12970         *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);
12971         return (long)ret_conv;
12972 }
12973
12974 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) {
12975         LDKPublicKey revocation_key_ref;
12976         CHECK((*_env)->GetArrayLength (_env, revocation_key) == 33);
12977         (*_env)->GetByteArrayRegion (_env, revocation_key, 0, 33, revocation_key_ref.compressed_form);
12978         LDKPublicKey broadcaster_delayed_payment_key_ref;
12979         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key) == 33);
12980         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
12981         LDKCVec_u8Z arg_var = get_revokeable_redeemscript(revocation_key_ref, contest_delay, broadcaster_delayed_payment_key_ref);
12982         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12983         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12984         CVec_u8Z_free(arg_var);
12985         return arg_arr;
12986 }
12987
12988 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12989         LDKHTLCOutputInCommitment this_ptr_conv;
12990         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12991         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12992         HTLCOutputInCommitment_free(this_ptr_conv);
12993 }
12994
12995 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12996         LDKHTLCOutputInCommitment orig_conv;
12997         orig_conv.inner = (void*)(orig & (~1));
12998         orig_conv.is_owned = false;
12999         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_clone(&orig_conv);
13000         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13001         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13002         long ret_ref = (long)ret_var.inner;
13003         if (ret_var.is_owned) {
13004                 ret_ref |= 1;
13005         }
13006         return ret_ref;
13007 }
13008
13009 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1offered(JNIEnv * _env, jclass _b, jlong this_ptr) {
13010         LDKHTLCOutputInCommitment this_ptr_conv;
13011         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13012         this_ptr_conv.is_owned = false;
13013         jboolean ret_val = HTLCOutputInCommitment_get_offered(&this_ptr_conv);
13014         return ret_val;
13015 }
13016
13017 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1offered(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
13018         LDKHTLCOutputInCommitment this_ptr_conv;
13019         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13020         this_ptr_conv.is_owned = false;
13021         HTLCOutputInCommitment_set_offered(&this_ptr_conv, val);
13022 }
13023
13024 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
13025         LDKHTLCOutputInCommitment this_ptr_conv;
13026         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13027         this_ptr_conv.is_owned = false;
13028         jlong ret_val = HTLCOutputInCommitment_get_amount_msat(&this_ptr_conv);
13029         return ret_val;
13030 }
13031
13032 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13033         LDKHTLCOutputInCommitment this_ptr_conv;
13034         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13035         this_ptr_conv.is_owned = false;
13036         HTLCOutputInCommitment_set_amount_msat(&this_ptr_conv, val);
13037 }
13038
13039 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr) {
13040         LDKHTLCOutputInCommitment this_ptr_conv;
13041         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13042         this_ptr_conv.is_owned = false;
13043         jint ret_val = HTLCOutputInCommitment_get_cltv_expiry(&this_ptr_conv);
13044         return ret_val;
13045 }
13046
13047 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13048         LDKHTLCOutputInCommitment this_ptr_conv;
13049         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13050         this_ptr_conv.is_owned = false;
13051         HTLCOutputInCommitment_set_cltv_expiry(&this_ptr_conv, val);
13052 }
13053
13054 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
13055         LDKHTLCOutputInCommitment this_ptr_conv;
13056         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13057         this_ptr_conv.is_owned = false;
13058         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
13059         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *HTLCOutputInCommitment_get_payment_hash(&this_ptr_conv));
13060         return ret_arr;
13061 }
13062
13063 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13064         LDKHTLCOutputInCommitment this_ptr_conv;
13065         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13066         this_ptr_conv.is_owned = false;
13067         LDKThirtyTwoBytes val_ref;
13068         CHECK((*_env)->GetArrayLength (_env, val) == 32);
13069         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
13070         HTLCOutputInCommitment_set_payment_hash(&this_ptr_conv, val_ref);
13071 }
13072
13073 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1write(JNIEnv * _env, jclass _b, jlong obj) {
13074         LDKHTLCOutputInCommitment obj_conv;
13075         obj_conv.inner = (void*)(obj & (~1));
13076         obj_conv.is_owned = false;
13077         LDKCVec_u8Z arg_var = HTLCOutputInCommitment_write(&obj_conv);
13078         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13079         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13080         CVec_u8Z_free(arg_var);
13081         return arg_arr;
13082 }
13083
13084 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13085         LDKu8slice ser_ref;
13086         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13087         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13088         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_read(ser_ref);
13089         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13090         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13091         long ret_ref = (long)ret_var.inner;
13092         if (ret_var.is_owned) {
13093                 ret_ref |= 1;
13094         }
13095         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13096         return ret_ref;
13097 }
13098
13099 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_get_1htlc_1redeemscript(JNIEnv * _env, jclass _b, jlong htlc, jlong keys) {
13100         LDKHTLCOutputInCommitment htlc_conv;
13101         htlc_conv.inner = (void*)(htlc & (~1));
13102         htlc_conv.is_owned = false;
13103         LDKTxCreationKeys keys_conv;
13104         keys_conv.inner = (void*)(keys & (~1));
13105         keys_conv.is_owned = false;
13106         LDKCVec_u8Z arg_var = get_htlc_redeemscript(&htlc_conv, &keys_conv);
13107         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13108         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13109         CVec_u8Z_free(arg_var);
13110         return arg_arr;
13111 }
13112
13113 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_make_1funding_1redeemscript(JNIEnv * _env, jclass _b, jbyteArray broadcaster, jbyteArray countersignatory) {
13114         LDKPublicKey broadcaster_ref;
13115         CHECK((*_env)->GetArrayLength (_env, broadcaster) == 33);
13116         (*_env)->GetByteArrayRegion (_env, broadcaster, 0, 33, broadcaster_ref.compressed_form);
13117         LDKPublicKey countersignatory_ref;
13118         CHECK((*_env)->GetArrayLength (_env, countersignatory) == 33);
13119         (*_env)->GetByteArrayRegion (_env, countersignatory, 0, 33, countersignatory_ref.compressed_form);
13120         LDKCVec_u8Z arg_var = make_funding_redeemscript(broadcaster_ref, countersignatory_ref);
13121         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13122         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13123         CVec_u8Z_free(arg_var);
13124         return arg_arr;
13125 }
13126
13127 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_build_1htlc_1transaction(JNIEnv * _env, jclass _b, jbyteArray prev_hash, jint feerate_per_kw, jshort contest_delay, jlong htlc, jbyteArray broadcaster_delayed_payment_key, jbyteArray revocation_key) {
13128         unsigned char prev_hash_arr[32];
13129         CHECK((*_env)->GetArrayLength (_env, prev_hash) == 32);
13130         (*_env)->GetByteArrayRegion (_env, prev_hash, 0, 32, prev_hash_arr);
13131         unsigned char (*prev_hash_ref)[32] = &prev_hash_arr;
13132         LDKHTLCOutputInCommitment htlc_conv;
13133         htlc_conv.inner = (void*)(htlc & (~1));
13134         htlc_conv.is_owned = false;
13135         LDKPublicKey broadcaster_delayed_payment_key_ref;
13136         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key) == 33);
13137         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
13138         LDKPublicKey revocation_key_ref;
13139         CHECK((*_env)->GetArrayLength (_env, revocation_key) == 33);
13140         (*_env)->GetByteArrayRegion (_env, revocation_key, 0, 33, revocation_key_ref.compressed_form);
13141         LDKTransaction arg_var = build_htlc_transaction(prev_hash_ref, feerate_per_kw, contest_delay, &htlc_conv, broadcaster_delayed_payment_key_ref, revocation_key_ref);
13142         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13143         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13144         Transaction_free(arg_var);
13145         return arg_arr;
13146 }
13147
13148 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13149         LDKHolderCommitmentTransaction this_ptr_conv;
13150         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13151         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13152         HolderCommitmentTransaction_free(this_ptr_conv);
13153 }
13154
13155 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13156         LDKHolderCommitmentTransaction orig_conv;
13157         orig_conv.inner = (void*)(orig & (~1));
13158         orig_conv.is_owned = false;
13159         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_clone(&orig_conv);
13160         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13161         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13162         long ret_ref = (long)ret_var.inner;
13163         if (ret_var.is_owned) {
13164                 ret_ref |= 1;
13165         }
13166         return ret_ref;
13167 }
13168
13169 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1unsigned_1tx(JNIEnv * _env, jclass _b, jlong this_ptr) {
13170         LDKHolderCommitmentTransaction this_ptr_conv;
13171         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13172         this_ptr_conv.is_owned = false;
13173         LDKTransaction arg_var = HolderCommitmentTransaction_get_unsigned_tx(&this_ptr_conv);
13174         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13175         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13176         Transaction_free(arg_var);
13177         return arg_arr;
13178 }
13179
13180 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1unsigned_1tx(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13181         LDKHolderCommitmentTransaction this_ptr_conv;
13182         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13183         this_ptr_conv.is_owned = false;
13184         LDKTransaction val_ref;
13185         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
13186         val_ref.data = MALLOC(val_ref.datalen, "LDKTransaction Bytes");
13187         (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data);
13188         val_ref.data_is_owned = true;
13189         HolderCommitmentTransaction_set_unsigned_tx(&this_ptr_conv, val_ref);
13190 }
13191
13192 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1counterparty_1sig(JNIEnv * _env, jclass _b, jlong this_ptr) {
13193         LDKHolderCommitmentTransaction this_ptr_conv;
13194         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13195         this_ptr_conv.is_owned = false;
13196         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
13197         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, HolderCommitmentTransaction_get_counterparty_sig(&this_ptr_conv).compact_form);
13198         return arg_arr;
13199 }
13200
13201 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1counterparty_1sig(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13202         LDKHolderCommitmentTransaction this_ptr_conv;
13203         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13204         this_ptr_conv.is_owned = false;
13205         LDKSignature val_ref;
13206         CHECK((*_env)->GetArrayLength (_env, val) == 64);
13207         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
13208         HolderCommitmentTransaction_set_counterparty_sig(&this_ptr_conv, val_ref);
13209 }
13210
13211 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr) {
13212         LDKHolderCommitmentTransaction this_ptr_conv;
13213         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13214         this_ptr_conv.is_owned = false;
13215         jint ret_val = HolderCommitmentTransaction_get_feerate_per_kw(&this_ptr_conv);
13216         return ret_val;
13217 }
13218
13219 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13220         LDKHolderCommitmentTransaction this_ptr_conv;
13221         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13222         this_ptr_conv.is_owned = false;
13223         HolderCommitmentTransaction_set_feerate_per_kw(&this_ptr_conv, val);
13224 }
13225
13226 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1per_1htlc(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
13227         LDKHolderCommitmentTransaction this_ptr_conv;
13228         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13229         this_ptr_conv.is_owned = false;
13230         LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ val_constr;
13231         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
13232         if (val_constr.datalen > 0)
13233                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ), "LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ Elements");
13234         else
13235                 val_constr.data = NULL;
13236         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
13237         for (size_t q = 0; q < val_constr.datalen; q++) {
13238                 long arr_conv_42 = val_vals[q];
13239                 LDKC2Tuple_HTLCOutputInCommitmentSignatureZ arr_conv_42_conv = *(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ*)arr_conv_42;
13240                 FREE((void*)arr_conv_42);
13241                 val_constr.data[q] = arr_conv_42_conv;
13242         }
13243         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
13244         HolderCommitmentTransaction_set_per_htlc(&this_ptr_conv, val_constr);
13245 }
13246
13247 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1new_1missing_1holder_1sig(JNIEnv * _env, jclass _b, jbyteArray unsigned_tx, jbyteArray counterparty_sig, jbyteArray holder_funding_key, jbyteArray counterparty_funding_key, jlong keys, jint feerate_per_kw, jlongArray htlc_data) {
13248         LDKTransaction unsigned_tx_ref;
13249         unsigned_tx_ref.datalen = (*_env)->GetArrayLength (_env, unsigned_tx);
13250         unsigned_tx_ref.data = MALLOC(unsigned_tx_ref.datalen, "LDKTransaction Bytes");
13251         (*_env)->GetByteArrayRegion(_env, unsigned_tx, 0, unsigned_tx_ref.datalen, unsigned_tx_ref.data);
13252         unsigned_tx_ref.data_is_owned = true;
13253         LDKSignature counterparty_sig_ref;
13254         CHECK((*_env)->GetArrayLength (_env, counterparty_sig) == 64);
13255         (*_env)->GetByteArrayRegion (_env, counterparty_sig, 0, 64, counterparty_sig_ref.compact_form);
13256         LDKPublicKey holder_funding_key_ref;
13257         CHECK((*_env)->GetArrayLength (_env, holder_funding_key) == 33);
13258         (*_env)->GetByteArrayRegion (_env, holder_funding_key, 0, 33, holder_funding_key_ref.compressed_form);
13259         LDKPublicKey counterparty_funding_key_ref;
13260         CHECK((*_env)->GetArrayLength (_env, counterparty_funding_key) == 33);
13261         (*_env)->GetByteArrayRegion (_env, counterparty_funding_key, 0, 33, counterparty_funding_key_ref.compressed_form);
13262         LDKTxCreationKeys keys_conv;
13263         keys_conv.inner = (void*)(keys & (~1));
13264         keys_conv.is_owned = (keys & 1) || (keys == 0);
13265         if (keys_conv.inner != NULL)
13266                 keys_conv = TxCreationKeys_clone(&keys_conv);
13267         LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ htlc_data_constr;
13268         htlc_data_constr.datalen = (*_env)->GetArrayLength (_env, htlc_data);
13269         if (htlc_data_constr.datalen > 0)
13270                 htlc_data_constr.data = MALLOC(htlc_data_constr.datalen * sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ), "LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ Elements");
13271         else
13272                 htlc_data_constr.data = NULL;
13273         long* htlc_data_vals = (*_env)->GetLongArrayElements (_env, htlc_data, NULL);
13274         for (size_t q = 0; q < htlc_data_constr.datalen; q++) {
13275                 long arr_conv_42 = htlc_data_vals[q];
13276                 LDKC2Tuple_HTLCOutputInCommitmentSignatureZ arr_conv_42_conv = *(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ*)arr_conv_42;
13277                 FREE((void*)arr_conv_42);
13278                 htlc_data_constr.data[q] = arr_conv_42_conv;
13279         }
13280         (*_env)->ReleaseLongArrayElements (_env, htlc_data, htlc_data_vals, 0);
13281         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_new_missing_holder_sig(unsigned_tx_ref, counterparty_sig_ref, holder_funding_key_ref, counterparty_funding_key_ref, keys_conv, feerate_per_kw, htlc_data_constr);
13282         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13283         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13284         long ret_ref = (long)ret_var.inner;
13285         if (ret_var.is_owned) {
13286                 ret_ref |= 1;
13287         }
13288         return ret_ref;
13289 }
13290
13291 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1trust_1key_1derivation(JNIEnv * _env, jclass _b, jlong this_arg) {
13292         LDKHolderCommitmentTransaction this_arg_conv;
13293         this_arg_conv.inner = (void*)(this_arg & (~1));
13294         this_arg_conv.is_owned = false;
13295         LDKTxCreationKeys ret_var = HolderCommitmentTransaction_trust_key_derivation(&this_arg_conv);
13296         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13297         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13298         long ret_ref = (long)ret_var.inner;
13299         if (ret_var.is_owned) {
13300                 ret_ref |= 1;
13301         }
13302         return ret_ref;
13303 }
13304
13305 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1txid(JNIEnv * _env, jclass _b, jlong this_arg) {
13306         LDKHolderCommitmentTransaction this_arg_conv;
13307         this_arg_conv.inner = (void*)(this_arg & (~1));
13308         this_arg_conv.is_owned = false;
13309         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
13310         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, HolderCommitmentTransaction_txid(&this_arg_conv).data);
13311         return arg_arr;
13312 }
13313
13314 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) {
13315         LDKHolderCommitmentTransaction this_arg_conv;
13316         this_arg_conv.inner = (void*)(this_arg & (~1));
13317         this_arg_conv.is_owned = false;
13318         unsigned char funding_key_arr[32];
13319         CHECK((*_env)->GetArrayLength (_env, funding_key) == 32);
13320         (*_env)->GetByteArrayRegion (_env, funding_key, 0, 32, funding_key_arr);
13321         unsigned char (*funding_key_ref)[32] = &funding_key_arr;
13322         LDKu8slice funding_redeemscript_ref;
13323         funding_redeemscript_ref.datalen = (*_env)->GetArrayLength (_env, funding_redeemscript);
13324         funding_redeemscript_ref.data = (*_env)->GetByteArrayElements (_env, funding_redeemscript, NULL);
13325         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
13326         (*_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);
13327         (*_env)->ReleaseByteArrayElements(_env, funding_redeemscript, (int8_t*)funding_redeemscript_ref.data, 0);
13328         return arg_arr;
13329 }
13330
13331 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) {
13332         LDKHolderCommitmentTransaction this_arg_conv;
13333         this_arg_conv.inner = (void*)(this_arg & (~1));
13334         this_arg_conv.is_owned = false;
13335         unsigned char htlc_base_key_arr[32];
13336         CHECK((*_env)->GetArrayLength (_env, htlc_base_key) == 32);
13337         (*_env)->GetByteArrayRegion (_env, htlc_base_key, 0, 32, htlc_base_key_arr);
13338         unsigned char (*htlc_base_key_ref)[32] = &htlc_base_key_arr;
13339         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
13340         *ret_conv = HolderCommitmentTransaction_get_htlc_sigs(&this_arg_conv, htlc_base_key_ref, counterparty_selected_contest_delay);
13341         return (long)ret_conv;
13342 }
13343
13344 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1write(JNIEnv * _env, jclass _b, jlong obj) {
13345         LDKHolderCommitmentTransaction obj_conv;
13346         obj_conv.inner = (void*)(obj & (~1));
13347         obj_conv.is_owned = false;
13348         LDKCVec_u8Z arg_var = HolderCommitmentTransaction_write(&obj_conv);
13349         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13350         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13351         CVec_u8Z_free(arg_var);
13352         return arg_arr;
13353 }
13354
13355 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13356         LDKu8slice ser_ref;
13357         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13358         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13359         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_read(ser_ref);
13360         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13361         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13362         long ret_ref = (long)ret_var.inner;
13363         if (ret_var.is_owned) {
13364                 ret_ref |= 1;
13365         }
13366         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13367         return ret_ref;
13368 }
13369
13370 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InitFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13371         LDKInitFeatures this_ptr_conv;
13372         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13373         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13374         InitFeatures_free(this_ptr_conv);
13375 }
13376
13377 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13378         LDKNodeFeatures 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         NodeFeatures_free(this_ptr_conv);
13382 }
13383
13384 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13385         LDKChannelFeatures this_ptr_conv;
13386         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13387         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13388         ChannelFeatures_free(this_ptr_conv);
13389 }
13390
13391 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13392         LDKRouteHop this_ptr_conv;
13393         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13394         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13395         RouteHop_free(this_ptr_conv);
13396 }
13397
13398 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13399         LDKRouteHop orig_conv;
13400         orig_conv.inner = (void*)(orig & (~1));
13401         orig_conv.is_owned = false;
13402         LDKRouteHop ret_var = RouteHop_clone(&orig_conv);
13403         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13404         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13405         long ret_ref = (long)ret_var.inner;
13406         if (ret_var.is_owned) {
13407                 ret_ref |= 1;
13408         }
13409         return ret_ref;
13410 }
13411
13412 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
13413         LDKRouteHop this_ptr_conv;
13414         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13415         this_ptr_conv.is_owned = false;
13416         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
13417         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RouteHop_get_pubkey(&this_ptr_conv).compressed_form);
13418         return arg_arr;
13419 }
13420
13421 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13422         LDKRouteHop this_ptr_conv;
13423         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13424         this_ptr_conv.is_owned = false;
13425         LDKPublicKey val_ref;
13426         CHECK((*_env)->GetArrayLength (_env, val) == 33);
13427         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
13428         RouteHop_set_pubkey(&this_ptr_conv, val_ref);
13429 }
13430
13431 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1node_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
13432         LDKRouteHop this_ptr_conv;
13433         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13434         this_ptr_conv.is_owned = false;
13435         LDKNodeFeatures ret_var = RouteHop_get_node_features(&this_ptr_conv);
13436         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13437         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13438         long ret_ref = (long)ret_var.inner;
13439         if (ret_var.is_owned) {
13440                 ret_ref |= 1;
13441         }
13442         return ret_ref;
13443 }
13444
13445 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1node_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13446         LDKRouteHop this_ptr_conv;
13447         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13448         this_ptr_conv.is_owned = false;
13449         LDKNodeFeatures val_conv;
13450         val_conv.inner = (void*)(val & (~1));
13451         val_conv.is_owned = (val & 1) || (val == 0);
13452         // Warning: we may need a move here but can't clone!
13453         RouteHop_set_node_features(&this_ptr_conv, val_conv);
13454 }
13455
13456 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
13457         LDKRouteHop this_ptr_conv;
13458         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13459         this_ptr_conv.is_owned = false;
13460         jlong ret_val = RouteHop_get_short_channel_id(&this_ptr_conv);
13461         return ret_val;
13462 }
13463
13464 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13465         LDKRouteHop this_ptr_conv;
13466         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13467         this_ptr_conv.is_owned = false;
13468         RouteHop_set_short_channel_id(&this_ptr_conv, val);
13469 }
13470
13471 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1channel_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
13472         LDKRouteHop this_ptr_conv;
13473         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13474         this_ptr_conv.is_owned = false;
13475         LDKChannelFeatures ret_var = RouteHop_get_channel_features(&this_ptr_conv);
13476         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13477         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13478         long ret_ref = (long)ret_var.inner;
13479         if (ret_var.is_owned) {
13480                 ret_ref |= 1;
13481         }
13482         return ret_ref;
13483 }
13484
13485 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1channel_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13486         LDKRouteHop this_ptr_conv;
13487         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13488         this_ptr_conv.is_owned = false;
13489         LDKChannelFeatures val_conv;
13490         val_conv.inner = (void*)(val & (~1));
13491         val_conv.is_owned = (val & 1) || (val == 0);
13492         // Warning: we may need a move here but can't clone!
13493         RouteHop_set_channel_features(&this_ptr_conv, val_conv);
13494 }
13495
13496 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1fee_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
13497         LDKRouteHop this_ptr_conv;
13498         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13499         this_ptr_conv.is_owned = false;
13500         jlong ret_val = RouteHop_get_fee_msat(&this_ptr_conv);
13501         return ret_val;
13502 }
13503
13504 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1fee_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13505         LDKRouteHop this_ptr_conv;
13506         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13507         this_ptr_conv.is_owned = false;
13508         RouteHop_set_fee_msat(&this_ptr_conv, val);
13509 }
13510
13511 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
13512         LDKRouteHop this_ptr_conv;
13513         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13514         this_ptr_conv.is_owned = false;
13515         jint ret_val = RouteHop_get_cltv_expiry_delta(&this_ptr_conv);
13516         return ret_val;
13517 }
13518
13519 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13520         LDKRouteHop this_ptr_conv;
13521         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13522         this_ptr_conv.is_owned = false;
13523         RouteHop_set_cltv_expiry_delta(&this_ptr_conv, val);
13524 }
13525
13526 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) {
13527         LDKPublicKey pubkey_arg_ref;
13528         CHECK((*_env)->GetArrayLength (_env, pubkey_arg) == 33);
13529         (*_env)->GetByteArrayRegion (_env, pubkey_arg, 0, 33, pubkey_arg_ref.compressed_form);
13530         LDKNodeFeatures node_features_arg_conv;
13531         node_features_arg_conv.inner = (void*)(node_features_arg & (~1));
13532         node_features_arg_conv.is_owned = (node_features_arg & 1) || (node_features_arg == 0);
13533         // Warning: we may need a move here but can't clone!
13534         LDKChannelFeatures channel_features_arg_conv;
13535         channel_features_arg_conv.inner = (void*)(channel_features_arg & (~1));
13536         channel_features_arg_conv.is_owned = (channel_features_arg & 1) || (channel_features_arg == 0);
13537         // Warning: we may need a move here but can't clone!
13538         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);
13539         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13540         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13541         long ret_ref = (long)ret_var.inner;
13542         if (ret_var.is_owned) {
13543                 ret_ref |= 1;
13544         }
13545         return ret_ref;
13546 }
13547
13548 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13549         LDKRoute this_ptr_conv;
13550         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13551         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13552         Route_free(this_ptr_conv);
13553 }
13554
13555 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13556         LDKRoute orig_conv;
13557         orig_conv.inner = (void*)(orig & (~1));
13558         orig_conv.is_owned = false;
13559         LDKRoute ret_var = Route_clone(&orig_conv);
13560         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13561         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13562         long ret_ref = (long)ret_var.inner;
13563         if (ret_var.is_owned) {
13564                 ret_ref |= 1;
13565         }
13566         return ret_ref;
13567 }
13568
13569 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1set_1paths(JNIEnv * _env, jclass _b, jlong this_ptr, jobjectArray val) {
13570         LDKRoute this_ptr_conv;
13571         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13572         this_ptr_conv.is_owned = false;
13573         LDKCVec_CVec_RouteHopZZ val_constr;
13574         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
13575         if (val_constr.datalen > 0)
13576                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
13577         else
13578                 val_constr.data = NULL;
13579         for (size_t m = 0; m < val_constr.datalen; m++) {
13580                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, val, m);
13581                 LDKCVec_RouteHopZ arr_conv_12_constr;
13582                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
13583                 if (arr_conv_12_constr.datalen > 0)
13584                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
13585                 else
13586                         arr_conv_12_constr.data = NULL;
13587                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
13588                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
13589                         long arr_conv_10 = arr_conv_12_vals[k];
13590                         LDKRouteHop arr_conv_10_conv;
13591                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
13592                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
13593                         if (arr_conv_10_conv.inner != NULL)
13594                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
13595                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
13596                 }
13597                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
13598                 val_constr.data[m] = arr_conv_12_constr;
13599         }
13600         Route_set_paths(&this_ptr_conv, val_constr);
13601 }
13602
13603 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1new(JNIEnv * _env, jclass _b, jobjectArray paths_arg) {
13604         LDKCVec_CVec_RouteHopZZ paths_arg_constr;
13605         paths_arg_constr.datalen = (*_env)->GetArrayLength (_env, paths_arg);
13606         if (paths_arg_constr.datalen > 0)
13607                 paths_arg_constr.data = MALLOC(paths_arg_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
13608         else
13609                 paths_arg_constr.data = NULL;
13610         for (size_t m = 0; m < paths_arg_constr.datalen; m++) {
13611                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, paths_arg, m);
13612                 LDKCVec_RouteHopZ arr_conv_12_constr;
13613                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
13614                 if (arr_conv_12_constr.datalen > 0)
13615                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
13616                 else
13617                         arr_conv_12_constr.data = NULL;
13618                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
13619                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
13620                         long arr_conv_10 = arr_conv_12_vals[k];
13621                         LDKRouteHop arr_conv_10_conv;
13622                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
13623                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
13624                         if (arr_conv_10_conv.inner != NULL)
13625                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
13626                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
13627                 }
13628                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
13629                 paths_arg_constr.data[m] = arr_conv_12_constr;
13630         }
13631         LDKRoute ret_var = Route_new(paths_arg_constr);
13632         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13633         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13634         long ret_ref = (long)ret_var.inner;
13635         if (ret_var.is_owned) {
13636                 ret_ref |= 1;
13637         }
13638         return ret_ref;
13639 }
13640
13641 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Route_1write(JNIEnv * _env, jclass _b, jlong obj) {
13642         LDKRoute obj_conv;
13643         obj_conv.inner = (void*)(obj & (~1));
13644         obj_conv.is_owned = false;
13645         LDKCVec_u8Z arg_var = Route_write(&obj_conv);
13646         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13647         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13648         CVec_u8Z_free(arg_var);
13649         return arg_arr;
13650 }
13651
13652 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13653         LDKu8slice ser_ref;
13654         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13655         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13656         LDKRoute ret_var = Route_read(ser_ref);
13657         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13658         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13659         long ret_ref = (long)ret_var.inner;
13660         if (ret_var.is_owned) {
13661                 ret_ref |= 1;
13662         }
13663         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13664         return ret_ref;
13665 }
13666
13667 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13668         LDKRouteHint this_ptr_conv;
13669         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13670         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13671         RouteHint_free(this_ptr_conv);
13672 }
13673
13674 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13675         LDKRouteHint orig_conv;
13676         orig_conv.inner = (void*)(orig & (~1));
13677         orig_conv.is_owned = false;
13678         LDKRouteHint ret_var = RouteHint_clone(&orig_conv);
13679         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13680         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13681         long ret_ref = (long)ret_var.inner;
13682         if (ret_var.is_owned) {
13683                 ret_ref |= 1;
13684         }
13685         return ret_ref;
13686 }
13687
13688 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1src_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
13689         LDKRouteHint this_ptr_conv;
13690         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13691         this_ptr_conv.is_owned = false;
13692         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
13693         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RouteHint_get_src_node_id(&this_ptr_conv).compressed_form);
13694         return arg_arr;
13695 }
13696
13697 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1src_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13698         LDKRouteHint this_ptr_conv;
13699         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13700         this_ptr_conv.is_owned = false;
13701         LDKPublicKey val_ref;
13702         CHECK((*_env)->GetArrayLength (_env, val) == 33);
13703         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
13704         RouteHint_set_src_node_id(&this_ptr_conv, val_ref);
13705 }
13706
13707 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
13708         LDKRouteHint this_ptr_conv;
13709         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13710         this_ptr_conv.is_owned = false;
13711         jlong ret_val = RouteHint_get_short_channel_id(&this_ptr_conv);
13712         return ret_val;
13713 }
13714
13715 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13716         LDKRouteHint this_ptr_conv;
13717         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13718         this_ptr_conv.is_owned = false;
13719         RouteHint_set_short_channel_id(&this_ptr_conv, val);
13720 }
13721
13722 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1fees(JNIEnv * _env, jclass _b, jlong this_ptr) {
13723         LDKRouteHint this_ptr_conv;
13724         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13725         this_ptr_conv.is_owned = false;
13726         LDKRoutingFees ret_var = RouteHint_get_fees(&this_ptr_conv);
13727         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13728         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13729         long ret_ref = (long)ret_var.inner;
13730         if (ret_var.is_owned) {
13731                 ret_ref |= 1;
13732         }
13733         return ret_ref;
13734 }
13735
13736 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1fees(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13737         LDKRouteHint this_ptr_conv;
13738         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13739         this_ptr_conv.is_owned = false;
13740         LDKRoutingFees val_conv;
13741         val_conv.inner = (void*)(val & (~1));
13742         val_conv.is_owned = (val & 1) || (val == 0);
13743         if (val_conv.inner != NULL)
13744                 val_conv = RoutingFees_clone(&val_conv);
13745         RouteHint_set_fees(&this_ptr_conv, val_conv);
13746 }
13747
13748 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
13749         LDKRouteHint this_ptr_conv;
13750         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13751         this_ptr_conv.is_owned = false;
13752         jshort ret_val = RouteHint_get_cltv_expiry_delta(&this_ptr_conv);
13753         return ret_val;
13754 }
13755
13756 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
13757         LDKRouteHint this_ptr_conv;
13758         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13759         this_ptr_conv.is_owned = false;
13760         RouteHint_set_cltv_expiry_delta(&this_ptr_conv, val);
13761 }
13762
13763 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
13764         LDKRouteHint this_ptr_conv;
13765         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13766         this_ptr_conv.is_owned = false;
13767         jlong ret_val = RouteHint_get_htlc_minimum_msat(&this_ptr_conv);
13768         return ret_val;
13769 }
13770
13771 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13772         LDKRouteHint this_ptr_conv;
13773         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13774         this_ptr_conv.is_owned = false;
13775         RouteHint_set_htlc_minimum_msat(&this_ptr_conv, val);
13776 }
13777
13778 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) {
13779         LDKPublicKey src_node_id_arg_ref;
13780         CHECK((*_env)->GetArrayLength (_env, src_node_id_arg) == 33);
13781         (*_env)->GetByteArrayRegion (_env, src_node_id_arg, 0, 33, src_node_id_arg_ref.compressed_form);
13782         LDKRoutingFees fees_arg_conv;
13783         fees_arg_conv.inner = (void*)(fees_arg & (~1));
13784         fees_arg_conv.is_owned = (fees_arg & 1) || (fees_arg == 0);
13785         if (fees_arg_conv.inner != NULL)
13786                 fees_arg_conv = RoutingFees_clone(&fees_arg_conv);
13787         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);
13788         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13789         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13790         long ret_ref = (long)ret_var.inner;
13791         if (ret_var.is_owned) {
13792                 ret_ref |= 1;
13793         }
13794         return ret_ref;
13795 }
13796
13797 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) {
13798         LDKPublicKey our_node_id_ref;
13799         CHECK((*_env)->GetArrayLength (_env, our_node_id) == 33);
13800         (*_env)->GetByteArrayRegion (_env, our_node_id, 0, 33, our_node_id_ref.compressed_form);
13801         LDKNetworkGraph network_conv;
13802         network_conv.inner = (void*)(network & (~1));
13803         network_conv.is_owned = false;
13804         LDKPublicKey target_ref;
13805         CHECK((*_env)->GetArrayLength (_env, target) == 33);
13806         (*_env)->GetByteArrayRegion (_env, target, 0, 33, target_ref.compressed_form);
13807         LDKCVec_ChannelDetailsZ first_hops_constr;
13808         first_hops_constr.datalen = (*_env)->GetArrayLength (_env, first_hops);
13809         if (first_hops_constr.datalen > 0)
13810                 first_hops_constr.data = MALLOC(first_hops_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
13811         else
13812                 first_hops_constr.data = NULL;
13813         long* first_hops_vals = (*_env)->GetLongArrayElements (_env, first_hops, NULL);
13814         for (size_t q = 0; q < first_hops_constr.datalen; q++) {
13815                 long arr_conv_16 = first_hops_vals[q];
13816                 LDKChannelDetails arr_conv_16_conv;
13817                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
13818                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
13819                 first_hops_constr.data[q] = arr_conv_16_conv;
13820         }
13821         (*_env)->ReleaseLongArrayElements (_env, first_hops, first_hops_vals, 0);
13822         LDKCVec_RouteHintZ last_hops_constr;
13823         last_hops_constr.datalen = (*_env)->GetArrayLength (_env, last_hops);
13824         if (last_hops_constr.datalen > 0)
13825                 last_hops_constr.data = MALLOC(last_hops_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
13826         else
13827                 last_hops_constr.data = NULL;
13828         long* last_hops_vals = (*_env)->GetLongArrayElements (_env, last_hops, NULL);
13829         for (size_t l = 0; l < last_hops_constr.datalen; l++) {
13830                 long arr_conv_11 = last_hops_vals[l];
13831                 LDKRouteHint arr_conv_11_conv;
13832                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
13833                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
13834                 if (arr_conv_11_conv.inner != NULL)
13835                         arr_conv_11_conv = RouteHint_clone(&arr_conv_11_conv);
13836                 last_hops_constr.data[l] = arr_conv_11_conv;
13837         }
13838         (*_env)->ReleaseLongArrayElements (_env, last_hops, last_hops_vals, 0);
13839         LDKLogger logger_conv = *(LDKLogger*)logger;
13840         if (logger_conv.free == LDKLogger_JCalls_free) {
13841                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
13842                 LDKLogger_JCalls_clone(logger_conv.this_arg);
13843         }
13844         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
13845         *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);
13846         FREE(first_hops_constr.data);
13847         return (long)ret_conv;
13848 }
13849
13850 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13851         LDKNetworkGraph this_ptr_conv;
13852         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13853         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13854         NetworkGraph_free(this_ptr_conv);
13855 }
13856
13857 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13858         LDKLockedNetworkGraph this_ptr_conv;
13859         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13860         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13861         LockedNetworkGraph_free(this_ptr_conv);
13862 }
13863
13864 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13865         LDKNetGraphMsgHandler this_ptr_conv;
13866         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13867         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13868         NetGraphMsgHandler_free(this_ptr_conv);
13869 }
13870
13871 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1new(JNIEnv * _env, jclass _b, jlong chain_access, jlong logger) {
13872         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
13873         LDKLogger logger_conv = *(LDKLogger*)logger;
13874         if (logger_conv.free == LDKLogger_JCalls_free) {
13875                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
13876                 LDKLogger_JCalls_clone(logger_conv.this_arg);
13877         }
13878         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_new(chain_access_conv, logger_conv);
13879         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13880         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13881         long ret_ref = (long)ret_var.inner;
13882         if (ret_var.is_owned) {
13883                 ret_ref |= 1;
13884         }
13885         return ret_ref;
13886 }
13887
13888 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1from_1net_1graph(JNIEnv * _env, jclass _b, jlong chain_access, jlong logger, jlong network_graph) {
13889         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
13890         LDKLogger logger_conv = *(LDKLogger*)logger;
13891         if (logger_conv.free == LDKLogger_JCalls_free) {
13892                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
13893                 LDKLogger_JCalls_clone(logger_conv.this_arg);
13894         }
13895         LDKNetworkGraph network_graph_conv;
13896         network_graph_conv.inner = (void*)(network_graph & (~1));
13897         network_graph_conv.is_owned = (network_graph & 1) || (network_graph == 0);
13898         // Warning: we may need a move here but can't clone!
13899         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_from_net_graph(chain_access_conv, logger_conv, network_graph_conv);
13900         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13901         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13902         long ret_ref = (long)ret_var.inner;
13903         if (ret_var.is_owned) {
13904                 ret_ref |= 1;
13905         }
13906         return ret_ref;
13907 }
13908
13909 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1read_1locked_1graph(JNIEnv * _env, jclass _b, jlong this_arg) {
13910         LDKNetGraphMsgHandler this_arg_conv;
13911         this_arg_conv.inner = (void*)(this_arg & (~1));
13912         this_arg_conv.is_owned = false;
13913         LDKLockedNetworkGraph ret_var = NetGraphMsgHandler_read_locked_graph(&this_arg_conv);
13914         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13915         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13916         long ret_ref = (long)ret_var.inner;
13917         if (ret_var.is_owned) {
13918                 ret_ref |= 1;
13919         }
13920         return ret_ref;
13921 }
13922
13923 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1graph(JNIEnv * _env, jclass _b, jlong this_arg) {
13924         LDKLockedNetworkGraph this_arg_conv;
13925         this_arg_conv.inner = (void*)(this_arg & (~1));
13926         this_arg_conv.is_owned = false;
13927         LDKNetworkGraph ret_var = LockedNetworkGraph_graph(&this_arg_conv);
13928         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13929         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13930         long ret_ref = (long)ret_var.inner;
13931         if (ret_var.is_owned) {
13932                 ret_ref |= 1;
13933         }
13934         return ret_ref;
13935 }
13936
13937 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1as_1RoutingMessageHandler(JNIEnv * _env, jclass _b, jlong this_arg) {
13938         LDKNetGraphMsgHandler this_arg_conv;
13939         this_arg_conv.inner = (void*)(this_arg & (~1));
13940         this_arg_conv.is_owned = false;
13941         LDKRoutingMessageHandler* ret = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
13942         *ret = NetGraphMsgHandler_as_RoutingMessageHandler(&this_arg_conv);
13943         return (long)ret;
13944 }
13945
13946 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13947         LDKDirectionalChannelInfo this_ptr_conv;
13948         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13949         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13950         DirectionalChannelInfo_free(this_ptr_conv);
13951 }
13952
13953 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr) {
13954         LDKDirectionalChannelInfo this_ptr_conv;
13955         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13956         this_ptr_conv.is_owned = false;
13957         jint ret_val = DirectionalChannelInfo_get_last_update(&this_ptr_conv);
13958         return ret_val;
13959 }
13960
13961 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13962         LDKDirectionalChannelInfo this_ptr_conv;
13963         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13964         this_ptr_conv.is_owned = false;
13965         DirectionalChannelInfo_set_last_update(&this_ptr_conv, val);
13966 }
13967
13968 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1enabled(JNIEnv * _env, jclass _b, jlong this_ptr) {
13969         LDKDirectionalChannelInfo this_ptr_conv;
13970         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13971         this_ptr_conv.is_owned = false;
13972         jboolean ret_val = DirectionalChannelInfo_get_enabled(&this_ptr_conv);
13973         return ret_val;
13974 }
13975
13976 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1enabled(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
13977         LDKDirectionalChannelInfo this_ptr_conv;
13978         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13979         this_ptr_conv.is_owned = false;
13980         DirectionalChannelInfo_set_enabled(&this_ptr_conv, val);
13981 }
13982
13983 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
13984         LDKDirectionalChannelInfo this_ptr_conv;
13985         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13986         this_ptr_conv.is_owned = false;
13987         jshort ret_val = DirectionalChannelInfo_get_cltv_expiry_delta(&this_ptr_conv);
13988         return ret_val;
13989 }
13990
13991 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
13992         LDKDirectionalChannelInfo this_ptr_conv;
13993         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13994         this_ptr_conv.is_owned = false;
13995         DirectionalChannelInfo_set_cltv_expiry_delta(&this_ptr_conv, val);
13996 }
13997
13998 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
13999         LDKDirectionalChannelInfo this_ptr_conv;
14000         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14001         this_ptr_conv.is_owned = false;
14002         jlong ret_val = DirectionalChannelInfo_get_htlc_minimum_msat(&this_ptr_conv);
14003         return ret_val;
14004 }
14005
14006 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14007         LDKDirectionalChannelInfo this_ptr_conv;
14008         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14009         this_ptr_conv.is_owned = false;
14010         DirectionalChannelInfo_set_htlc_minimum_msat(&this_ptr_conv, val);
14011 }
14012
14013 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
14014         LDKDirectionalChannelInfo this_ptr_conv;
14015         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14016         this_ptr_conv.is_owned = false;
14017         LDKChannelUpdate ret_var = DirectionalChannelInfo_get_last_update_message(&this_ptr_conv);
14018         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14019         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14020         long ret_ref = (long)ret_var.inner;
14021         if (ret_var.is_owned) {
14022                 ret_ref |= 1;
14023         }
14024         return ret_ref;
14025 }
14026
14027 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14028         LDKDirectionalChannelInfo this_ptr_conv;
14029         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14030         this_ptr_conv.is_owned = false;
14031         LDKChannelUpdate val_conv;
14032         val_conv.inner = (void*)(val & (~1));
14033         val_conv.is_owned = (val & 1) || (val == 0);
14034         if (val_conv.inner != NULL)
14035                 val_conv = ChannelUpdate_clone(&val_conv);
14036         DirectionalChannelInfo_set_last_update_message(&this_ptr_conv, val_conv);
14037 }
14038
14039 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
14040         LDKDirectionalChannelInfo obj_conv;
14041         obj_conv.inner = (void*)(obj & (~1));
14042         obj_conv.is_owned = false;
14043         LDKCVec_u8Z arg_var = DirectionalChannelInfo_write(&obj_conv);
14044         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14045         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14046         CVec_u8Z_free(arg_var);
14047         return arg_arr;
14048 }
14049
14050 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14051         LDKu8slice ser_ref;
14052         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14053         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14054         LDKDirectionalChannelInfo ret_var = DirectionalChannelInfo_read(ser_ref);
14055         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14056         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14057         long ret_ref = (long)ret_var.inner;
14058         if (ret_var.is_owned) {
14059                 ret_ref |= 1;
14060         }
14061         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14062         return ret_ref;
14063 }
14064
14065 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14066         LDKChannelInfo this_ptr_conv;
14067         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14068         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14069         ChannelInfo_free(this_ptr_conv);
14070 }
14071
14072 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
14073         LDKChannelInfo this_ptr_conv;
14074         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14075         this_ptr_conv.is_owned = false;
14076         LDKChannelFeatures ret_var = ChannelInfo_get_features(&this_ptr_conv);
14077         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14078         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14079         long ret_ref = (long)ret_var.inner;
14080         if (ret_var.is_owned) {
14081                 ret_ref |= 1;
14082         }
14083         return ret_ref;
14084 }
14085
14086 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14087         LDKChannelInfo this_ptr_conv;
14088         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14089         this_ptr_conv.is_owned = false;
14090         LDKChannelFeatures val_conv;
14091         val_conv.inner = (void*)(val & (~1));
14092         val_conv.is_owned = (val & 1) || (val == 0);
14093         // Warning: we may need a move here but can't clone!
14094         ChannelInfo_set_features(&this_ptr_conv, val_conv);
14095 }
14096
14097 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1one(JNIEnv * _env, jclass _b, jlong this_ptr) {
14098         LDKChannelInfo this_ptr_conv;
14099         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14100         this_ptr_conv.is_owned = false;
14101         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14102         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelInfo_get_node_one(&this_ptr_conv).compressed_form);
14103         return arg_arr;
14104 }
14105
14106 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1one(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14107         LDKChannelInfo this_ptr_conv;
14108         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14109         this_ptr_conv.is_owned = false;
14110         LDKPublicKey val_ref;
14111         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14112         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14113         ChannelInfo_set_node_one(&this_ptr_conv, val_ref);
14114 }
14115
14116 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1one_1to_1two(JNIEnv * _env, jclass _b, jlong this_ptr) {
14117         LDKChannelInfo this_ptr_conv;
14118         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14119         this_ptr_conv.is_owned = false;
14120         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_one_to_two(&this_ptr_conv);
14121         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14122         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14123         long ret_ref = (long)ret_var.inner;
14124         if (ret_var.is_owned) {
14125                 ret_ref |= 1;
14126         }
14127         return ret_ref;
14128 }
14129
14130 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1one_1to_1two(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14131         LDKChannelInfo this_ptr_conv;
14132         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14133         this_ptr_conv.is_owned = false;
14134         LDKDirectionalChannelInfo val_conv;
14135         val_conv.inner = (void*)(val & (~1));
14136         val_conv.is_owned = (val & 1) || (val == 0);
14137         // Warning: we may need a move here but can't clone!
14138         ChannelInfo_set_one_to_two(&this_ptr_conv, val_conv);
14139 }
14140
14141 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1two(JNIEnv * _env, jclass _b, jlong this_ptr) {
14142         LDKChannelInfo this_ptr_conv;
14143         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14144         this_ptr_conv.is_owned = false;
14145         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14146         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelInfo_get_node_two(&this_ptr_conv).compressed_form);
14147         return arg_arr;
14148 }
14149
14150 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1two(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14151         LDKChannelInfo this_ptr_conv;
14152         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14153         this_ptr_conv.is_owned = false;
14154         LDKPublicKey val_ref;
14155         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14156         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14157         ChannelInfo_set_node_two(&this_ptr_conv, val_ref);
14158 }
14159
14160 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1two_1to_1one(JNIEnv * _env, jclass _b, jlong this_ptr) {
14161         LDKChannelInfo this_ptr_conv;
14162         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14163         this_ptr_conv.is_owned = false;
14164         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_two_to_one(&this_ptr_conv);
14165         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14166         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14167         long ret_ref = (long)ret_var.inner;
14168         if (ret_var.is_owned) {
14169                 ret_ref |= 1;
14170         }
14171         return ret_ref;
14172 }
14173
14174 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1two_1to_1one(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14175         LDKChannelInfo this_ptr_conv;
14176         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14177         this_ptr_conv.is_owned = false;
14178         LDKDirectionalChannelInfo val_conv;
14179         val_conv.inner = (void*)(val & (~1));
14180         val_conv.is_owned = (val & 1) || (val == 0);
14181         // Warning: we may need a move here but can't clone!
14182         ChannelInfo_set_two_to_one(&this_ptr_conv, val_conv);
14183 }
14184
14185 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
14186         LDKChannelInfo this_ptr_conv;
14187         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14188         this_ptr_conv.is_owned = false;
14189         LDKChannelAnnouncement ret_var = ChannelInfo_get_announcement_message(&this_ptr_conv);
14190         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14191         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14192         long ret_ref = (long)ret_var.inner;
14193         if (ret_var.is_owned) {
14194                 ret_ref |= 1;
14195         }
14196         return ret_ref;
14197 }
14198
14199 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14200         LDKChannelInfo this_ptr_conv;
14201         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14202         this_ptr_conv.is_owned = false;
14203         LDKChannelAnnouncement val_conv;
14204         val_conv.inner = (void*)(val & (~1));
14205         val_conv.is_owned = (val & 1) || (val == 0);
14206         if (val_conv.inner != NULL)
14207                 val_conv = ChannelAnnouncement_clone(&val_conv);
14208         ChannelInfo_set_announcement_message(&this_ptr_conv, val_conv);
14209 }
14210
14211 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
14212         LDKChannelInfo obj_conv;
14213         obj_conv.inner = (void*)(obj & (~1));
14214         obj_conv.is_owned = false;
14215         LDKCVec_u8Z arg_var = ChannelInfo_write(&obj_conv);
14216         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14217         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14218         CVec_u8Z_free(arg_var);
14219         return arg_arr;
14220 }
14221
14222 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14223         LDKu8slice ser_ref;
14224         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14225         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14226         LDKChannelInfo ret_var = ChannelInfo_read(ser_ref);
14227         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14228         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14229         long ret_ref = (long)ret_var.inner;
14230         if (ret_var.is_owned) {
14231                 ret_ref |= 1;
14232         }
14233         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14234         return ret_ref;
14235 }
14236
14237 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14238         LDKRoutingFees this_ptr_conv;
14239         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14240         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14241         RoutingFees_free(this_ptr_conv);
14242 }
14243
14244 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1clone(JNIEnv * _env, jclass _b, jlong orig) {
14245         LDKRoutingFees orig_conv;
14246         orig_conv.inner = (void*)(orig & (~1));
14247         orig_conv.is_owned = false;
14248         LDKRoutingFees ret_var = RoutingFees_clone(&orig_conv);
14249         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14250         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14251         long ret_ref = (long)ret_var.inner;
14252         if (ret_var.is_owned) {
14253                 ret_ref |= 1;
14254         }
14255         return ret_ref;
14256 }
14257
14258 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
14259         LDKRoutingFees this_ptr_conv;
14260         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14261         this_ptr_conv.is_owned = false;
14262         jint ret_val = RoutingFees_get_base_msat(&this_ptr_conv);
14263         return ret_val;
14264 }
14265
14266 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
14267         LDKRoutingFees this_ptr_conv;
14268         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14269         this_ptr_conv.is_owned = false;
14270         RoutingFees_set_base_msat(&this_ptr_conv, val);
14271 }
14272
14273 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
14274         LDKRoutingFees this_ptr_conv;
14275         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14276         this_ptr_conv.is_owned = false;
14277         jint ret_val = RoutingFees_get_proportional_millionths(&this_ptr_conv);
14278         return ret_val;
14279 }
14280
14281 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
14282         LDKRoutingFees this_ptr_conv;
14283         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14284         this_ptr_conv.is_owned = false;
14285         RoutingFees_set_proportional_millionths(&this_ptr_conv, val);
14286 }
14287
14288 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1new(JNIEnv * _env, jclass _b, jint base_msat_arg, jint proportional_millionths_arg) {
14289         LDKRoutingFees ret_var = RoutingFees_new(base_msat_arg, proportional_millionths_arg);
14290         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14291         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14292         long ret_ref = (long)ret_var.inner;
14293         if (ret_var.is_owned) {
14294                 ret_ref |= 1;
14295         }
14296         return ret_ref;
14297 }
14298
14299 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14300         LDKu8slice ser_ref;
14301         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14302         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14303         LDKRoutingFees ret_var = RoutingFees_read(ser_ref);
14304         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14305         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14306         long ret_ref = (long)ret_var.inner;
14307         if (ret_var.is_owned) {
14308                 ret_ref |= 1;
14309         }
14310         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14311         return ret_ref;
14312 }
14313
14314 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RoutingFees_1write(JNIEnv * _env, jclass _b, jlong obj) {
14315         LDKRoutingFees obj_conv;
14316         obj_conv.inner = (void*)(obj & (~1));
14317         obj_conv.is_owned = false;
14318         LDKCVec_u8Z arg_var = RoutingFees_write(&obj_conv);
14319         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14320         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14321         CVec_u8Z_free(arg_var);
14322         return arg_arr;
14323 }
14324
14325 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14326         LDKNodeAnnouncementInfo this_ptr_conv;
14327         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14328         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14329         NodeAnnouncementInfo_free(this_ptr_conv);
14330 }
14331
14332 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
14333         LDKNodeAnnouncementInfo this_ptr_conv;
14334         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14335         this_ptr_conv.is_owned = false;
14336         LDKNodeFeatures ret_var = NodeAnnouncementInfo_get_features(&this_ptr_conv);
14337         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14338         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14339         long ret_ref = (long)ret_var.inner;
14340         if (ret_var.is_owned) {
14341                 ret_ref |= 1;
14342         }
14343         return ret_ref;
14344 }
14345
14346 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14347         LDKNodeAnnouncementInfo this_ptr_conv;
14348         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14349         this_ptr_conv.is_owned = false;
14350         LDKNodeFeatures val_conv;
14351         val_conv.inner = (void*)(val & (~1));
14352         val_conv.is_owned = (val & 1) || (val == 0);
14353         // Warning: we may need a move here but can't clone!
14354         NodeAnnouncementInfo_set_features(&this_ptr_conv, val_conv);
14355 }
14356
14357 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr) {
14358         LDKNodeAnnouncementInfo this_ptr_conv;
14359         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14360         this_ptr_conv.is_owned = false;
14361         jint ret_val = NodeAnnouncementInfo_get_last_update(&this_ptr_conv);
14362         return ret_val;
14363 }
14364
14365 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
14366         LDKNodeAnnouncementInfo this_ptr_conv;
14367         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14368         this_ptr_conv.is_owned = false;
14369         NodeAnnouncementInfo_set_last_update(&this_ptr_conv, val);
14370 }
14371
14372 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr) {
14373         LDKNodeAnnouncementInfo this_ptr_conv;
14374         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14375         this_ptr_conv.is_owned = false;
14376         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 3);
14377         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 3, *NodeAnnouncementInfo_get_rgb(&this_ptr_conv));
14378         return ret_arr;
14379 }
14380
14381 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14382         LDKNodeAnnouncementInfo this_ptr_conv;
14383         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14384         this_ptr_conv.is_owned = false;
14385         LDKThreeBytes val_ref;
14386         CHECK((*_env)->GetArrayLength (_env, val) == 3);
14387         (*_env)->GetByteArrayRegion (_env, val, 0, 3, val_ref.data);
14388         NodeAnnouncementInfo_set_rgb(&this_ptr_conv, val_ref);
14389 }
14390
14391 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1alias(JNIEnv * _env, jclass _b, jlong this_ptr) {
14392         LDKNodeAnnouncementInfo this_ptr_conv;
14393         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14394         this_ptr_conv.is_owned = false;
14395         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
14396         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *NodeAnnouncementInfo_get_alias(&this_ptr_conv));
14397         return ret_arr;
14398 }
14399
14400 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1alias(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14401         LDKNodeAnnouncementInfo this_ptr_conv;
14402         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14403         this_ptr_conv.is_owned = false;
14404         LDKThirtyTwoBytes val_ref;
14405         CHECK((*_env)->GetArrayLength (_env, val) == 32);
14406         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
14407         NodeAnnouncementInfo_set_alias(&this_ptr_conv, val_ref);
14408 }
14409
14410 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1addresses(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
14411         LDKNodeAnnouncementInfo this_ptr_conv;
14412         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14413         this_ptr_conv.is_owned = false;
14414         LDKCVec_NetAddressZ val_constr;
14415         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
14416         if (val_constr.datalen > 0)
14417                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
14418         else
14419                 val_constr.data = NULL;
14420         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
14421         for (size_t m = 0; m < val_constr.datalen; m++) {
14422                 long arr_conv_12 = val_vals[m];
14423                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
14424                 FREE((void*)arr_conv_12);
14425                 val_constr.data[m] = arr_conv_12_conv;
14426         }
14427         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
14428         NodeAnnouncementInfo_set_addresses(&this_ptr_conv, val_constr);
14429 }
14430
14431 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
14432         LDKNodeAnnouncementInfo this_ptr_conv;
14433         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14434         this_ptr_conv.is_owned = false;
14435         LDKNodeAnnouncement ret_var = NodeAnnouncementInfo_get_announcement_message(&this_ptr_conv);
14436         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14437         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14438         long ret_ref = (long)ret_var.inner;
14439         if (ret_var.is_owned) {
14440                 ret_ref |= 1;
14441         }
14442         return ret_ref;
14443 }
14444
14445 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14446         LDKNodeAnnouncementInfo this_ptr_conv;
14447         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14448         this_ptr_conv.is_owned = false;
14449         LDKNodeAnnouncement val_conv;
14450         val_conv.inner = (void*)(val & (~1));
14451         val_conv.is_owned = (val & 1) || (val == 0);
14452         if (val_conv.inner != NULL)
14453                 val_conv = NodeAnnouncement_clone(&val_conv);
14454         NodeAnnouncementInfo_set_announcement_message(&this_ptr_conv, val_conv);
14455 }
14456
14457 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) {
14458         LDKNodeFeatures features_arg_conv;
14459         features_arg_conv.inner = (void*)(features_arg & (~1));
14460         features_arg_conv.is_owned = (features_arg & 1) || (features_arg == 0);
14461         // Warning: we may need a move here but can't clone!
14462         LDKThreeBytes rgb_arg_ref;
14463         CHECK((*_env)->GetArrayLength (_env, rgb_arg) == 3);
14464         (*_env)->GetByteArrayRegion (_env, rgb_arg, 0, 3, rgb_arg_ref.data);
14465         LDKThirtyTwoBytes alias_arg_ref;
14466         CHECK((*_env)->GetArrayLength (_env, alias_arg) == 32);
14467         (*_env)->GetByteArrayRegion (_env, alias_arg, 0, 32, alias_arg_ref.data);
14468         LDKCVec_NetAddressZ addresses_arg_constr;
14469         addresses_arg_constr.datalen = (*_env)->GetArrayLength (_env, addresses_arg);
14470         if (addresses_arg_constr.datalen > 0)
14471                 addresses_arg_constr.data = MALLOC(addresses_arg_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
14472         else
14473                 addresses_arg_constr.data = NULL;
14474         long* addresses_arg_vals = (*_env)->GetLongArrayElements (_env, addresses_arg, NULL);
14475         for (size_t m = 0; m < addresses_arg_constr.datalen; m++) {
14476                 long arr_conv_12 = addresses_arg_vals[m];
14477                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
14478                 FREE((void*)arr_conv_12);
14479                 addresses_arg_constr.data[m] = arr_conv_12_conv;
14480         }
14481         (*_env)->ReleaseLongArrayElements (_env, addresses_arg, addresses_arg_vals, 0);
14482         LDKNodeAnnouncement announcement_message_arg_conv;
14483         announcement_message_arg_conv.inner = (void*)(announcement_message_arg & (~1));
14484         announcement_message_arg_conv.is_owned = (announcement_message_arg & 1) || (announcement_message_arg == 0);
14485         if (announcement_message_arg_conv.inner != NULL)
14486                 announcement_message_arg_conv = NodeAnnouncement_clone(&announcement_message_arg_conv);
14487         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_new(features_arg_conv, last_update_arg, rgb_arg_ref, alias_arg_ref, addresses_arg_constr, announcement_message_arg_conv);
14488         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14489         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14490         long ret_ref = (long)ret_var.inner;
14491         if (ret_var.is_owned) {
14492                 ret_ref |= 1;
14493         }
14494         return ret_ref;
14495 }
14496
14497 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
14498         LDKNodeAnnouncementInfo obj_conv;
14499         obj_conv.inner = (void*)(obj & (~1));
14500         obj_conv.is_owned = false;
14501         LDKCVec_u8Z arg_var = NodeAnnouncementInfo_write(&obj_conv);
14502         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14503         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14504         CVec_u8Z_free(arg_var);
14505         return arg_arr;
14506 }
14507
14508 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14509         LDKu8slice ser_ref;
14510         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14511         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14512         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_read(ser_ref);
14513         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14514         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14515         long ret_ref = (long)ret_var.inner;
14516         if (ret_var.is_owned) {
14517                 ret_ref |= 1;
14518         }
14519         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14520         return ret_ref;
14521 }
14522
14523 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14524         LDKNodeInfo this_ptr_conv;
14525         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14526         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14527         NodeInfo_free(this_ptr_conv);
14528 }
14529
14530 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1channels(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
14531         LDKNodeInfo this_ptr_conv;
14532         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14533         this_ptr_conv.is_owned = false;
14534         LDKCVec_u64Z val_constr;
14535         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
14536         if (val_constr.datalen > 0)
14537                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
14538         else
14539                 val_constr.data = NULL;
14540         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
14541         for (size_t g = 0; g < val_constr.datalen; g++) {
14542                 long arr_conv_6 = val_vals[g];
14543                 val_constr.data[g] = arr_conv_6;
14544         }
14545         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
14546         NodeInfo_set_channels(&this_ptr_conv, val_constr);
14547 }
14548
14549 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1lowest_1inbound_1channel_1fees(JNIEnv * _env, jclass _b, jlong this_ptr) {
14550         LDKNodeInfo this_ptr_conv;
14551         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14552         this_ptr_conv.is_owned = false;
14553         LDKRoutingFees ret_var = NodeInfo_get_lowest_inbound_channel_fees(&this_ptr_conv);
14554         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14555         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14556         long ret_ref = (long)ret_var.inner;
14557         if (ret_var.is_owned) {
14558                 ret_ref |= 1;
14559         }
14560         return ret_ref;
14561 }
14562
14563 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1lowest_1inbound_1channel_1fees(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14564         LDKNodeInfo this_ptr_conv;
14565         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14566         this_ptr_conv.is_owned = false;
14567         LDKRoutingFees val_conv;
14568         val_conv.inner = (void*)(val & (~1));
14569         val_conv.is_owned = (val & 1) || (val == 0);
14570         if (val_conv.inner != NULL)
14571                 val_conv = RoutingFees_clone(&val_conv);
14572         NodeInfo_set_lowest_inbound_channel_fees(&this_ptr_conv, val_conv);
14573 }
14574
14575 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1announcement_1info(JNIEnv * _env, jclass _b, jlong this_ptr) {
14576         LDKNodeInfo this_ptr_conv;
14577         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14578         this_ptr_conv.is_owned = false;
14579         LDKNodeAnnouncementInfo ret_var = NodeInfo_get_announcement_info(&this_ptr_conv);
14580         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14581         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14582         long ret_ref = (long)ret_var.inner;
14583         if (ret_var.is_owned) {
14584                 ret_ref |= 1;
14585         }
14586         return ret_ref;
14587 }
14588
14589 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1announcement_1info(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14590         LDKNodeInfo this_ptr_conv;
14591         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14592         this_ptr_conv.is_owned = false;
14593         LDKNodeAnnouncementInfo val_conv;
14594         val_conv.inner = (void*)(val & (~1));
14595         val_conv.is_owned = (val & 1) || (val == 0);
14596         // Warning: we may need a move here but can't clone!
14597         NodeInfo_set_announcement_info(&this_ptr_conv, val_conv);
14598 }
14599
14600 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) {
14601         LDKCVec_u64Z channels_arg_constr;
14602         channels_arg_constr.datalen = (*_env)->GetArrayLength (_env, channels_arg);
14603         if (channels_arg_constr.datalen > 0)
14604                 channels_arg_constr.data = MALLOC(channels_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
14605         else
14606                 channels_arg_constr.data = NULL;
14607         long* channels_arg_vals = (*_env)->GetLongArrayElements (_env, channels_arg, NULL);
14608         for (size_t g = 0; g < channels_arg_constr.datalen; g++) {
14609                 long arr_conv_6 = channels_arg_vals[g];
14610                 channels_arg_constr.data[g] = arr_conv_6;
14611         }
14612         (*_env)->ReleaseLongArrayElements (_env, channels_arg, channels_arg_vals, 0);
14613         LDKRoutingFees lowest_inbound_channel_fees_arg_conv;
14614         lowest_inbound_channel_fees_arg_conv.inner = (void*)(lowest_inbound_channel_fees_arg & (~1));
14615         lowest_inbound_channel_fees_arg_conv.is_owned = (lowest_inbound_channel_fees_arg & 1) || (lowest_inbound_channel_fees_arg == 0);
14616         if (lowest_inbound_channel_fees_arg_conv.inner != NULL)
14617                 lowest_inbound_channel_fees_arg_conv = RoutingFees_clone(&lowest_inbound_channel_fees_arg_conv);
14618         LDKNodeAnnouncementInfo announcement_info_arg_conv;
14619         announcement_info_arg_conv.inner = (void*)(announcement_info_arg & (~1));
14620         announcement_info_arg_conv.is_owned = (announcement_info_arg & 1) || (announcement_info_arg == 0);
14621         // Warning: we may need a move here but can't clone!
14622         LDKNodeInfo ret_var = NodeInfo_new(channels_arg_constr, lowest_inbound_channel_fees_arg_conv, announcement_info_arg_conv);
14623         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14624         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14625         long ret_ref = (long)ret_var.inner;
14626         if (ret_var.is_owned) {
14627                 ret_ref |= 1;
14628         }
14629         return ret_ref;
14630 }
14631
14632 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
14633         LDKNodeInfo obj_conv;
14634         obj_conv.inner = (void*)(obj & (~1));
14635         obj_conv.is_owned = false;
14636         LDKCVec_u8Z arg_var = NodeInfo_write(&obj_conv);
14637         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14638         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14639         CVec_u8Z_free(arg_var);
14640         return arg_arr;
14641 }
14642
14643 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14644         LDKu8slice ser_ref;
14645         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14646         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14647         LDKNodeInfo ret_var = NodeInfo_read(ser_ref);
14648         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14649         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14650         long ret_ref = (long)ret_var.inner;
14651         if (ret_var.is_owned) {
14652                 ret_ref |= 1;
14653         }
14654         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14655         return ret_ref;
14656 }
14657
14658 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1write(JNIEnv * _env, jclass _b, jlong obj) {
14659         LDKNetworkGraph obj_conv;
14660         obj_conv.inner = (void*)(obj & (~1));
14661         obj_conv.is_owned = false;
14662         LDKCVec_u8Z arg_var = NetworkGraph_write(&obj_conv);
14663         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14664         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14665         CVec_u8Z_free(arg_var);
14666         return arg_arr;
14667 }
14668
14669 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14670         LDKu8slice ser_ref;
14671         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14672         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14673         LDKNetworkGraph ret_var = NetworkGraph_read(ser_ref);
14674         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14675         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14676         long ret_ref = (long)ret_var.inner;
14677         if (ret_var.is_owned) {
14678                 ret_ref |= 1;
14679         }
14680         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14681         return ret_ref;
14682 }
14683
14684 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1new(JNIEnv * _env, jclass _b) {
14685         LDKNetworkGraph ret_var = NetworkGraph_new();
14686         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14687         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14688         long ret_ref = (long)ret_var.inner;
14689         if (ret_var.is_owned) {
14690                 ret_ref |= 1;
14691         }
14692         return ret_ref;
14693 }
14694
14695 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) {
14696         LDKNetworkGraph this_arg_conv;
14697         this_arg_conv.inner = (void*)(this_arg & (~1));
14698         this_arg_conv.is_owned = false;
14699         NetworkGraph_close_channel_from_update(&this_arg_conv, short_channel_id, is_permanent);
14700 }
14701