9c42cc38745a8489d1aea8e0d244f7051613175b
[ldk-java] / src / main / jni / bindings.c
1 #include "org_ldk_impl_bindings.h"
2 #include <rust_types.h>
3 #include <lightning.h>
4 #include <string.h>
5 #include <stdatomic.h>
6 #include <assert.h>
7 // Always run a, then assert it is true:
8 #define DO_ASSERT(a) do { bool _assert_val = (a); assert(_assert_val); } while(0)
9 // Assert a is true or do nothing
10 #define CHECK(a) DO_ASSERT(a)
11
12 // Running a leak check across all the allocations and frees of the JDK is a mess,
13 // so instead we implement our own naive leak checker here, relying on the -wrap
14 // linker option to wrap malloc/calloc/realloc/free, tracking everyhing allocated
15 // and free'd in Rust or C across the generated bindings shared library.
16 #include <threads.h>
17 #include <execinfo.h>
18 #include <unistd.h>
19 static mtx_t allocation_mtx;
20
21 void __attribute__((constructor)) init_mtx() {
22         DO_ASSERT(mtx_init(&allocation_mtx, mtx_plain) == thrd_success);
23 }
24
25 #define BT_MAX 128
26 typedef struct allocation {
27         struct allocation* next;
28         void* ptr;
29         const char* struct_name;
30         void* bt[BT_MAX];
31         int bt_len;
32 } allocation;
33 static allocation* allocation_ll = NULL;
34
35 void* __real_malloc(size_t len);
36 void* __real_calloc(size_t nmemb, size_t len);
37 static void new_allocation(void* res, const char* struct_name) {
38         allocation* new_alloc = __real_malloc(sizeof(allocation));
39         new_alloc->ptr = res;
40         new_alloc->struct_name = struct_name;
41         new_alloc->bt_len = backtrace(new_alloc->bt, BT_MAX);
42         DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
43         new_alloc->next = allocation_ll;
44         allocation_ll = new_alloc;
45         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
46 }
47 static void* MALLOC(size_t len, const char* struct_name) {
48         void* res = __real_malloc(len);
49         new_allocation(res, struct_name);
50         return res;
51 }
52 void __real_free(void* ptr);
53 static void alloc_freed(void* ptr) {
54         allocation* p = NULL;
55         DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
56         allocation* it = allocation_ll;
57         while (it->ptr != ptr) {
58                 p = it; it = it->next;
59                 if (it == NULL) {
60                         fprintf(stderr, "Tried to free unknown pointer %p at:\n", ptr);
61                         void* bt[BT_MAX];
62                         int bt_len = backtrace(bt, BT_MAX);
63                         backtrace_symbols_fd(bt, bt_len, STDERR_FILENO);
64                         fprintf(stderr, "\n\n");
65                         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
66                         return; // addrsan should catch malloc-unknown and print more info than we have
67                 }
68         }
69         if (p) { p->next = it->next; } else { allocation_ll = it->next; }
70         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
71         DO_ASSERT(it->ptr == ptr);
72         __real_free(it);
73 }
74 static void FREE(void* ptr) {
75         if ((long)ptr < 1024) return; // Rust loves to create pointers to the NULL page for dummys
76         alloc_freed(ptr);
77         __real_free(ptr);
78 }
79
80 void* __wrap_malloc(size_t len) {
81         void* res = __real_malloc(len);
82         new_allocation(res, "malloc call");
83         return res;
84 }
85 void* __wrap_calloc(size_t nmemb, size_t len) {
86         void* res = __real_calloc(nmemb, len);
87         new_allocation(res, "calloc call");
88         return res;
89 }
90 void __wrap_free(void* ptr) {
91         if (ptr == NULL) return;
92         alloc_freed(ptr);
93         __real_free(ptr);
94 }
95
96 void* __real_realloc(void* ptr, size_t newlen);
97 void* __wrap_realloc(void* ptr, size_t len) {
98         if (ptr != NULL) alloc_freed(ptr);
99         void* res = __real_realloc(ptr, len);
100         new_allocation(res, "realloc call");
101         return res;
102 }
103 void __wrap_reallocarray(void* ptr, size_t new_sz) {
104         // Rust doesn't seem to use reallocarray currently
105         assert(false);
106 }
107
108 void __attribute__((destructor)) check_leaks() {
109         for (allocation* a = allocation_ll; a != NULL; a = a->next) {
110                 fprintf(stderr, "%s %p remains:\n", a->struct_name, a->ptr);
111                 backtrace_symbols_fd(a->bt, a->bt_len, STDERR_FILENO);
112                 fprintf(stderr, "\n\n");
113         }
114         DO_ASSERT(allocation_ll == NULL);
115 }
116 static jclass arr_of_B_clz = NULL;
117 JNIEXPORT void Java_org_ldk_impl_bindings_init_1class_1cache(JNIEnv * env, jclass _b) {
118         arr_of_B_clz = (*env)->FindClass(env, "[B");
119         CHECK(arr_of_B_clz != NULL);
120         arr_of_B_clz = (*env)->NewGlobalRef(env, arr_of_B_clz);
121 }
122 static inline struct LDKThirtyTwoBytes ThirtyTwoBytes_clone(const struct LDKThirtyTwoBytes *orig) { struct LDKThirtyTwoBytes ret; memcpy(ret.data, orig->data, 32); return ret; }
123
124 static jmethodID ordinal_meth = NULL;
125 static jmethodID slicedef_meth = NULL;
126 static jclass slicedef_cls = NULL;
127 JNIEXPORT void Java_org_ldk_impl_bindings_init(JNIEnv * env, jclass _b, jclass enum_class, jclass slicedef_class) {
128         ordinal_meth = (*env)->GetMethodID(env, enum_class, "ordinal", "()I");
129         CHECK(ordinal_meth != NULL);
130         slicedef_meth = (*env)->GetMethodID(env, slicedef_class, "<init>", "(JJJ)V");
131         CHECK(slicedef_meth != NULL);
132         slicedef_cls = (*env)->NewGlobalRef(env, slicedef_class);
133         CHECK(slicedef_cls != NULL);
134 }
135
136 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_deref_1bool (JNIEnv * env, jclass _a, jlong ptr) {
137         return *((bool*)ptr);
138 }
139 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_deref_1long (JNIEnv * env, jclass _a, jlong ptr) {
140         return *((long*)ptr);
141 }
142 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_free_1heap_1ptr (JNIEnv * env, jclass _a, jlong ptr) {
143         FREE((void*)ptr);
144 }
145 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_read_1bytes (JNIEnv * _env, jclass _b, jlong ptr, jlong len) {
146         jbyteArray ret_arr = (*_env)->NewByteArray(_env, len);
147         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, len, (unsigned char*)ptr);
148         return ret_arr;
149 }
150 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_get_1u8_1slice_1bytes (JNIEnv * _env, jclass _b, jlong slice_ptr) {
151         LDKu8slice *slice = (LDKu8slice*)slice_ptr;
152         jbyteArray ret_arr = (*_env)->NewByteArray(_env, slice->datalen);
153         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, slice->datalen, slice->data);
154         return ret_arr;
155 }
156 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec (JNIEnv * _env, jclass _b, jbyteArray bytes) {
157         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "LDKCVec_u8");
158         vec->datalen = (*_env)->GetArrayLength(_env, bytes);
159         vec->data = (uint8_t*)MALLOC(vec->datalen, "LDKCVec_u8Z Bytes");
160         (*_env)->GetByteArrayRegion (_env, bytes, 0, vec->datalen, vec->data);
161         return (long)vec;
162 }
163 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_txpointer_1get_1buffer (JNIEnv * env, jclass _b, jlong ptr) {
164         LDKTransaction *txdata = (LDKTransaction*)ptr;
165         LDKu8slice slice;
166         slice.data = txdata->data;
167         slice.datalen = txdata->datalen;
168         return Java_org_ldk_impl_bindings_get_1u8_1slice_1bytes(env, _b, (long)&slice);
169 }
170 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data (JNIEnv * env, jclass _b, jbyteArray bytes) {
171         LDKTransaction *txdata = (LDKTransaction*)MALLOC(sizeof(LDKTransaction), "LDKTransaction");
172         txdata->datalen = (*env)->GetArrayLength(env, bytes);
173         txdata->data = (uint8_t*)MALLOC(txdata->datalen, "Tx Data Bytes");
174         txdata->data_is_owned = false;
175         (*env)->GetByteArrayRegion (env, bytes, 0, txdata->datalen, txdata->data);
176         return (long)txdata;
177 }
178 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_txpointer_1free (JNIEnv * env, jclass _b, jlong ptr) {
179         LDKTransaction *tx = (LDKTransaction*)ptr;
180         tx->data_is_owned = true;
181         Transaction_free(*tx);
182         FREE((void*)ptr);
183 }
184 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) {
185         // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
186         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically");
187         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically");
188         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically");
189         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_C2Tuple_usizeTransactionZZ, datalen), "Vec<*> needs to be mapped identically");
190         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
191         return (long)vec->datalen;
192 }
193 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec (JNIEnv * _env, jclass _b) {
194         // Check sizes of a few Vec types are all consistent as we're meant to be generic across types
195         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_SignatureZ), "Vec<*> needs to be mapped identically");
196         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_MessageSendEventZ), "Vec<*> needs to be mapped identically");
197         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_EventZ), "Vec<*> needs to be mapped identically");
198         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "Vec<*> needs to be mapped identically");
199         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "Empty LDKCVec");
200         vec->data = NULL;
201         vec->datalen = 0;
202         return (long)vec;
203 }
204
205 // We assume that CVec_u8Z and u8slice are the same size and layout (and thus pointers to the two can be mixed)
206 _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKu8slice), "Vec<u8> and [u8] need to have been mapped identically");
207 _Static_assert(offsetof(LDKCVec_u8Z, data) == offsetof(LDKu8slice, data), "Vec<u8> and [u8] need to have been mapped identically");
208 _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen), "Vec<u8> and [u8] need to have been mapped identically");
209
210 static inline LDKAccessError LDKAccessError_from_java(JNIEnv *env, jclass val) {
211         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
212                 case 0: return LDKAccessError_UnknownChain;
213                 case 1: return LDKAccessError_UnknownTx;
214         }
215         abort();
216 }
217 static jclass LDKAccessError_class = NULL;
218 static jfieldID LDKAccessError_LDKAccessError_UnknownChain = NULL;
219 static jfieldID LDKAccessError_LDKAccessError_UnknownTx = NULL;
220 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKAccessError_init (JNIEnv * env, jclass clz) {
221         LDKAccessError_class = (*env)->NewGlobalRef(env, clz);
222         CHECK(LDKAccessError_class != NULL);
223         LDKAccessError_LDKAccessError_UnknownChain = (*env)->GetStaticFieldID(env, LDKAccessError_class, "LDKAccessError_UnknownChain", "Lorg/ldk/enums/LDKAccessError;");
224         CHECK(LDKAccessError_LDKAccessError_UnknownChain != NULL);
225         LDKAccessError_LDKAccessError_UnknownTx = (*env)->GetStaticFieldID(env, LDKAccessError_class, "LDKAccessError_UnknownTx", "Lorg/ldk/enums/LDKAccessError;");
226         CHECK(LDKAccessError_LDKAccessError_UnknownTx != NULL);
227 }
228 static inline jclass LDKAccessError_to_java(JNIEnv *env, LDKAccessError val) {
229         switch (val) {
230                 case LDKAccessError_UnknownChain:
231                         return (*env)->GetStaticObjectField(env, LDKAccessError_class, LDKAccessError_LDKAccessError_UnknownChain);
232                 case LDKAccessError_UnknownTx:
233                         return (*env)->GetStaticObjectField(env, LDKAccessError_class, LDKAccessError_LDKAccessError_UnknownTx);
234                 default: abort();
235         }
236 }
237
238 static inline LDKChannelMonitorUpdateErr LDKChannelMonitorUpdateErr_from_java(JNIEnv *env, jclass val) {
239         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
240                 case 0: return LDKChannelMonitorUpdateErr_TemporaryFailure;
241                 case 1: return LDKChannelMonitorUpdateErr_PermanentFailure;
242         }
243         abort();
244 }
245 static jclass LDKChannelMonitorUpdateErr_class = NULL;
246 static jfieldID LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure = NULL;
247 static jfieldID LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure = NULL;
248 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKChannelMonitorUpdateErr_init (JNIEnv * env, jclass clz) {
249         LDKChannelMonitorUpdateErr_class = (*env)->NewGlobalRef(env, clz);
250         CHECK(LDKChannelMonitorUpdateErr_class != NULL);
251         LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure = (*env)->GetStaticFieldID(env, LDKChannelMonitorUpdateErr_class, "LDKChannelMonitorUpdateErr_TemporaryFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
252         CHECK(LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure != NULL);
253         LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure = (*env)->GetStaticFieldID(env, LDKChannelMonitorUpdateErr_class, "LDKChannelMonitorUpdateErr_PermanentFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
254         CHECK(LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure != NULL);
255 }
256 static inline jclass LDKChannelMonitorUpdateErr_to_java(JNIEnv *env, LDKChannelMonitorUpdateErr val) {
257         switch (val) {
258                 case LDKChannelMonitorUpdateErr_TemporaryFailure:
259                         return (*env)->GetStaticObjectField(env, LDKChannelMonitorUpdateErr_class, LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure);
260                 case LDKChannelMonitorUpdateErr_PermanentFailure:
261                         return (*env)->GetStaticObjectField(env, LDKChannelMonitorUpdateErr_class, LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure);
262                 default: abort();
263         }
264 }
265
266 static inline LDKConfirmationTarget LDKConfirmationTarget_from_java(JNIEnv *env, jclass val) {
267         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
268                 case 0: return LDKConfirmationTarget_Background;
269                 case 1: return LDKConfirmationTarget_Normal;
270                 case 2: return LDKConfirmationTarget_HighPriority;
271         }
272         abort();
273 }
274 static jclass LDKConfirmationTarget_class = NULL;
275 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_Background = NULL;
276 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_Normal = NULL;
277 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_HighPriority = NULL;
278 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKConfirmationTarget_init (JNIEnv * env, jclass clz) {
279         LDKConfirmationTarget_class = (*env)->NewGlobalRef(env, clz);
280         CHECK(LDKConfirmationTarget_class != NULL);
281         LDKConfirmationTarget_LDKConfirmationTarget_Background = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_Background", "Lorg/ldk/enums/LDKConfirmationTarget;");
282         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_Background != NULL);
283         LDKConfirmationTarget_LDKConfirmationTarget_Normal = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_Normal", "Lorg/ldk/enums/LDKConfirmationTarget;");
284         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_Normal != NULL);
285         LDKConfirmationTarget_LDKConfirmationTarget_HighPriority = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_HighPriority", "Lorg/ldk/enums/LDKConfirmationTarget;");
286         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_HighPriority != NULL);
287 }
288 static inline jclass LDKConfirmationTarget_to_java(JNIEnv *env, LDKConfirmationTarget val) {
289         switch (val) {
290                 case LDKConfirmationTarget_Background:
291                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_Background);
292                 case LDKConfirmationTarget_Normal:
293                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_Normal);
294                 case LDKConfirmationTarget_HighPriority:
295                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_HighPriority);
296                 default: abort();
297         }
298 }
299
300 static inline LDKLevel LDKLevel_from_java(JNIEnv *env, jclass val) {
301         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
302                 case 0: return LDKLevel_Off;
303                 case 1: return LDKLevel_Error;
304                 case 2: return LDKLevel_Warn;
305                 case 3: return LDKLevel_Info;
306                 case 4: return LDKLevel_Debug;
307                 case 5: return LDKLevel_Trace;
308         }
309         abort();
310 }
311 static jclass LDKLevel_class = NULL;
312 static jfieldID LDKLevel_LDKLevel_Off = NULL;
313 static jfieldID LDKLevel_LDKLevel_Error = NULL;
314 static jfieldID LDKLevel_LDKLevel_Warn = NULL;
315 static jfieldID LDKLevel_LDKLevel_Info = NULL;
316 static jfieldID LDKLevel_LDKLevel_Debug = NULL;
317 static jfieldID LDKLevel_LDKLevel_Trace = NULL;
318 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKLevel_init (JNIEnv * env, jclass clz) {
319         LDKLevel_class = (*env)->NewGlobalRef(env, clz);
320         CHECK(LDKLevel_class != NULL);
321         LDKLevel_LDKLevel_Off = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Off", "Lorg/ldk/enums/LDKLevel;");
322         CHECK(LDKLevel_LDKLevel_Off != NULL);
323         LDKLevel_LDKLevel_Error = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Error", "Lorg/ldk/enums/LDKLevel;");
324         CHECK(LDKLevel_LDKLevel_Error != NULL);
325         LDKLevel_LDKLevel_Warn = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Warn", "Lorg/ldk/enums/LDKLevel;");
326         CHECK(LDKLevel_LDKLevel_Warn != NULL);
327         LDKLevel_LDKLevel_Info = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Info", "Lorg/ldk/enums/LDKLevel;");
328         CHECK(LDKLevel_LDKLevel_Info != NULL);
329         LDKLevel_LDKLevel_Debug = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Debug", "Lorg/ldk/enums/LDKLevel;");
330         CHECK(LDKLevel_LDKLevel_Debug != NULL);
331         LDKLevel_LDKLevel_Trace = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Trace", "Lorg/ldk/enums/LDKLevel;");
332         CHECK(LDKLevel_LDKLevel_Trace != NULL);
333 }
334 static inline jclass LDKLevel_to_java(JNIEnv *env, LDKLevel val) {
335         switch (val) {
336                 case LDKLevel_Off:
337                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Off);
338                 case LDKLevel_Error:
339                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Error);
340                 case LDKLevel_Warn:
341                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Warn);
342                 case LDKLevel_Info:
343                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Info);
344                 case LDKLevel_Debug:
345                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Debug);
346                 case LDKLevel_Trace:
347                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Trace);
348                 default: abort();
349         }
350 }
351
352 static inline LDKNetwork LDKNetwork_from_java(JNIEnv *env, jclass val) {
353         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
354                 case 0: return LDKNetwork_Bitcoin;
355                 case 1: return LDKNetwork_Testnet;
356                 case 2: return LDKNetwork_Regtest;
357         }
358         abort();
359 }
360 static jclass LDKNetwork_class = NULL;
361 static jfieldID LDKNetwork_LDKNetwork_Bitcoin = NULL;
362 static jfieldID LDKNetwork_LDKNetwork_Testnet = NULL;
363 static jfieldID LDKNetwork_LDKNetwork_Regtest = NULL;
364 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKNetwork_init (JNIEnv * env, jclass clz) {
365         LDKNetwork_class = (*env)->NewGlobalRef(env, clz);
366         CHECK(LDKNetwork_class != NULL);
367         LDKNetwork_LDKNetwork_Bitcoin = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Bitcoin", "Lorg/ldk/enums/LDKNetwork;");
368         CHECK(LDKNetwork_LDKNetwork_Bitcoin != NULL);
369         LDKNetwork_LDKNetwork_Testnet = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Testnet", "Lorg/ldk/enums/LDKNetwork;");
370         CHECK(LDKNetwork_LDKNetwork_Testnet != NULL);
371         LDKNetwork_LDKNetwork_Regtest = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Regtest", "Lorg/ldk/enums/LDKNetwork;");
372         CHECK(LDKNetwork_LDKNetwork_Regtest != NULL);
373 }
374 static inline jclass LDKNetwork_to_java(JNIEnv *env, LDKNetwork val) {
375         switch (val) {
376                 case LDKNetwork_Bitcoin:
377                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Bitcoin);
378                 case LDKNetwork_Testnet:
379                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Testnet);
380                 case LDKNetwork_Regtest:
381                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Regtest);
382                 default: abort();
383         }
384 }
385
386 static inline LDKSecp256k1Error LDKSecp256k1Error_from_java(JNIEnv *env, jclass val) {
387         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
388                 case 0: return LDKSecp256k1Error_IncorrectSignature;
389                 case 1: return LDKSecp256k1Error_InvalidMessage;
390                 case 2: return LDKSecp256k1Error_InvalidPublicKey;
391                 case 3: return LDKSecp256k1Error_InvalidSignature;
392                 case 4: return LDKSecp256k1Error_InvalidSecretKey;
393                 case 5: return LDKSecp256k1Error_InvalidRecoveryId;
394                 case 6: return LDKSecp256k1Error_InvalidTweak;
395                 case 7: return LDKSecp256k1Error_NotEnoughMemory;
396                 case 8: return LDKSecp256k1Error_CallbackPanicked;
397         }
398         abort();
399 }
400 static jclass LDKSecp256k1Error_class = NULL;
401 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature = NULL;
402 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage = NULL;
403 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey = NULL;
404 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature = NULL;
405 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey = NULL;
406 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId = NULL;
407 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak = NULL;
408 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory = NULL;
409 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked = NULL;
410 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKSecp256k1Error_init (JNIEnv * env, jclass clz) {
411         LDKSecp256k1Error_class = (*env)->NewGlobalRef(env, clz);
412         CHECK(LDKSecp256k1Error_class != NULL);
413         LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_IncorrectSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
414         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature != NULL);
415         LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidMessage", "Lorg/ldk/enums/LDKSecp256k1Error;");
416         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage != NULL);
417         LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidPublicKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
418         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey != NULL);
419         LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
420         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature != NULL);
421         LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidSecretKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
422         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey != NULL);
423         LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidRecoveryId", "Lorg/ldk/enums/LDKSecp256k1Error;");
424         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId != NULL);
425         LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidTweak", "Lorg/ldk/enums/LDKSecp256k1Error;");
426         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak != NULL);
427         LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_NotEnoughMemory", "Lorg/ldk/enums/LDKSecp256k1Error;");
428         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory != NULL);
429         LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_CallbackPanicked", "Lorg/ldk/enums/LDKSecp256k1Error;");
430         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked != NULL);
431 }
432 static inline jclass LDKSecp256k1Error_to_java(JNIEnv *env, LDKSecp256k1Error val) {
433         switch (val) {
434                 case LDKSecp256k1Error_IncorrectSignature:
435                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature);
436                 case LDKSecp256k1Error_InvalidMessage:
437                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage);
438                 case LDKSecp256k1Error_InvalidPublicKey:
439                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey);
440                 case LDKSecp256k1Error_InvalidSignature:
441                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature);
442                 case LDKSecp256k1Error_InvalidSecretKey:
443                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey);
444                 case LDKSecp256k1Error_InvalidRecoveryId:
445                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId);
446                 case LDKSecp256k1Error_InvalidTweak:
447                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak);
448                 case LDKSecp256k1Error_NotEnoughMemory:
449                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory);
450                 case LDKSecp256k1Error_CallbackPanicked:
451                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked);
452                 default: abort();
453         }
454 }
455
456 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1u8Z_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
457         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
458         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(uint8_t));
459 }
460 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1u8Z_1new(JNIEnv *env, jclass _b, jbyteArray elems){
461         LDKCVec_u8Z *ret = MALLOC(sizeof(LDKCVec_u8Z), "LDKCVec_u8Z");
462         ret->datalen = (*env)->GetArrayLength(env, elems);
463         if (ret->datalen == 0) {
464                 ret->data = NULL;
465         } else {
466                 ret->data = MALLOC(sizeof(uint8_t) * ret->datalen, "LDKCVec_u8Z Data");
467                 jbyte *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
468                 for (size_t i = 0; i < ret->datalen; i++) {
469                         ret->data[i] = java_elems[i];
470                 }
471                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
472         }
473         return (long)ret;
474 }
475 static inline LDKCVec_u8Z CVec_u8Z_clone(const LDKCVec_u8Z *orig) {
476         LDKCVec_u8Z ret = { .data = MALLOC(sizeof(jbyte) * orig->datalen, "LDKCVec_u8Z clone bytes"), .datalen = orig->datalen };
477         memcpy(ret.data, orig->data, sizeof(jbyte) * ret.datalen);
478         return ret;
479 }
480 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u64u64Z_1new(JNIEnv *_env, jclass _b, jlong a, jlong b) {
481         LDKC2Tuple_u64u64Z* ret = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
482         ret->a = a;
483         ret->b = b;
484         return (long)ret;
485 }
486 static inline LDKC2Tuple_u64u64Z C2Tuple_u64u64Z_clone(const LDKC2Tuple_u64u64Z *orig) {
487         LDKC2Tuple_u64u64Z ret = {
488                 .a = orig->a,
489                 .b = orig->b,
490         };
491         return ret;
492 }
493 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u64u64Z_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
494         LDKC2Tuple_u64u64Z *tuple = (LDKC2Tuple_u64u64Z*)ptr;
495         return tuple->a;
496 }
497 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u64u64Z_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
498         LDKC2Tuple_u64u64Z *tuple = (LDKC2Tuple_u64u64Z*)ptr;
499         return tuple->b;
500 }
501 static jclass LDKSpendableOutputDescriptor_StaticOutput_class = NULL;
502 static jmethodID LDKSpendableOutputDescriptor_StaticOutput_meth = NULL;
503 static jclass LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class = NULL;
504 static jmethodID LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = NULL;
505 static jclass LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class = NULL;
506 static jmethodID LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = NULL;
507 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKSpendableOutputDescriptor_init (JNIEnv * env, jclass _a) {
508         LDKSpendableOutputDescriptor_StaticOutput_class =
509                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$StaticOutput;"));
510         CHECK(LDKSpendableOutputDescriptor_StaticOutput_class != NULL);
511         LDKSpendableOutputDescriptor_StaticOutput_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_StaticOutput_class, "<init>", "(JJ)V");
512         CHECK(LDKSpendableOutputDescriptor_StaticOutput_meth != NULL);
513         LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class =
514                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$DynamicOutputP2WSH;"));
515         CHECK(LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class != NULL);
516         LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class, "<init>", "(J[BSJJ[B)V");
517         CHECK(LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth != NULL);
518         LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class =
519                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$StaticOutputCounterpartyPayment;"));
520         CHECK(LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class != NULL);
521         LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class, "<init>", "(JJJ)V");
522         CHECK(LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth != NULL);
523 }
524 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSpendableOutputDescriptor_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
525         LDKSpendableOutputDescriptor *obj = (LDKSpendableOutputDescriptor*)ptr;
526         switch(obj->tag) {
527                 case LDKSpendableOutputDescriptor_StaticOutput: {
528                         LDKOutPoint outpoint_var = obj->static_output.outpoint;
529                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
530                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
531                         long outpoint_ref = (long)outpoint_var.inner & ~1;
532                         long output_ref = (long)&obj->static_output.output;
533                         return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_StaticOutput_class, LDKSpendableOutputDescriptor_StaticOutput_meth, outpoint_ref, (long)output_ref);
534                 }
535                 case LDKSpendableOutputDescriptor_DynamicOutputP2WSH: {
536                         LDKOutPoint outpoint_var = obj->dynamic_output_p2wsh.outpoint;
537                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
538                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
539                         long outpoint_ref = (long)outpoint_var.inner & ~1;
540                         jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33);
541                         (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, obj->dynamic_output_p2wsh.per_commitment_point.compressed_form);
542                         long output_ref = (long)&obj->dynamic_output_p2wsh.output;
543                         long key_derivation_params_ref = (long)&obj->dynamic_output_p2wsh.key_derivation_params;
544                         jbyteArray revocation_pubkey_arr = (*_env)->NewByteArray(_env, 33);
545                         (*_env)->SetByteArrayRegion(_env, revocation_pubkey_arr, 0, 33, obj->dynamic_output_p2wsh.revocation_pubkey.compressed_form);
546                         return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth, outpoint_ref, per_commitment_point_arr, obj->dynamic_output_p2wsh.to_self_delay, (long)output_ref, key_derivation_params_ref, revocation_pubkey_arr);
547                 }
548                 case LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment: {
549                         LDKOutPoint outpoint_var = obj->static_output_counterparty_payment.outpoint;
550                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
551                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
552                         long outpoint_ref = (long)outpoint_var.inner & ~1;
553                         long output_ref = (long)&obj->static_output_counterparty_payment.output;
554                         long key_derivation_params_ref = (long)&obj->static_output_counterparty_payment.key_derivation_params;
555                         return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth, outpoint_ref, (long)output_ref, key_derivation_params_ref);
556                 }
557                 default: abort();
558         }
559 }
560 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1SpendableOutputDescriptorZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
561         LDKCVec_SpendableOutputDescriptorZ *vec = (LDKCVec_SpendableOutputDescriptorZ*)ptr;
562         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKSpendableOutputDescriptor));
563 }
564 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1SpendableOutputDescriptorZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
565         LDKCVec_SpendableOutputDescriptorZ *ret = MALLOC(sizeof(LDKCVec_SpendableOutputDescriptorZ), "LDKCVec_SpendableOutputDescriptorZ");
566         ret->datalen = (*env)->GetArrayLength(env, elems);
567         if (ret->datalen == 0) {
568                 ret->data = NULL;
569         } else {
570                 ret->data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * ret->datalen, "LDKCVec_SpendableOutputDescriptorZ Data");
571                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
572                 for (size_t i = 0; i < ret->datalen; i++) {
573                         jlong arr_elem = java_elems[i];
574                         LDKSpendableOutputDescriptor arr_elem_conv = *(LDKSpendableOutputDescriptor*)arr_elem;
575                         FREE((void*)arr_elem);
576                         ret->data[i] = arr_elem_conv;
577                 }
578                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
579         }
580         return (long)ret;
581 }
582 static inline LDKCVec_SpendableOutputDescriptorZ CVec_SpendableOutputDescriptorZ_clone(const LDKCVec_SpendableOutputDescriptorZ *orig) {
583         LDKCVec_SpendableOutputDescriptorZ ret = { .data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * orig->datalen, "LDKCVec_SpendableOutputDescriptorZ clone bytes"), .datalen = orig->datalen };
584         for (size_t i = 0; i < ret.datalen; i++) {
585                 ret.data[i] = SpendableOutputDescriptor_clone(&orig->data[i]);
586         }
587         return ret;
588 }
589 static jclass LDKErrorAction_DisconnectPeer_class = NULL;
590 static jmethodID LDKErrorAction_DisconnectPeer_meth = NULL;
591 static jclass LDKErrorAction_IgnoreError_class = NULL;
592 static jmethodID LDKErrorAction_IgnoreError_meth = NULL;
593 static jclass LDKErrorAction_SendErrorMessage_class = NULL;
594 static jmethodID LDKErrorAction_SendErrorMessage_meth = NULL;
595 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKErrorAction_init (JNIEnv * env, jclass _a) {
596         LDKErrorAction_DisconnectPeer_class =
597                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$DisconnectPeer;"));
598         CHECK(LDKErrorAction_DisconnectPeer_class != NULL);
599         LDKErrorAction_DisconnectPeer_meth = (*env)->GetMethodID(env, LDKErrorAction_DisconnectPeer_class, "<init>", "(J)V");
600         CHECK(LDKErrorAction_DisconnectPeer_meth != NULL);
601         LDKErrorAction_IgnoreError_class =
602                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$IgnoreError;"));
603         CHECK(LDKErrorAction_IgnoreError_class != NULL);
604         LDKErrorAction_IgnoreError_meth = (*env)->GetMethodID(env, LDKErrorAction_IgnoreError_class, "<init>", "()V");
605         CHECK(LDKErrorAction_IgnoreError_meth != NULL);
606         LDKErrorAction_SendErrorMessage_class =
607                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$SendErrorMessage;"));
608         CHECK(LDKErrorAction_SendErrorMessage_class != NULL);
609         LDKErrorAction_SendErrorMessage_meth = (*env)->GetMethodID(env, LDKErrorAction_SendErrorMessage_class, "<init>", "(J)V");
610         CHECK(LDKErrorAction_SendErrorMessage_meth != NULL);
611 }
612 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKErrorAction_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
613         LDKErrorAction *obj = (LDKErrorAction*)ptr;
614         switch(obj->tag) {
615                 case LDKErrorAction_DisconnectPeer: {
616                         LDKErrorMessage msg_var = obj->disconnect_peer.msg;
617                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
618                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
619                         long msg_ref = (long)msg_var.inner & ~1;
620                         return (*_env)->NewObject(_env, LDKErrorAction_DisconnectPeer_class, LDKErrorAction_DisconnectPeer_meth, msg_ref);
621                 }
622                 case LDKErrorAction_IgnoreError: {
623                         return (*_env)->NewObject(_env, LDKErrorAction_IgnoreError_class, LDKErrorAction_IgnoreError_meth);
624                 }
625                 case LDKErrorAction_SendErrorMessage: {
626                         LDKErrorMessage msg_var = obj->send_error_message.msg;
627                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
628                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
629                         long msg_ref = (long)msg_var.inner & ~1;
630                         return (*_env)->NewObject(_env, LDKErrorAction_SendErrorMessage_class, LDKErrorAction_SendErrorMessage_meth, msg_ref);
631                 }
632                 default: abort();
633         }
634 }
635 static jclass LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class = NULL;
636 static jmethodID LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = NULL;
637 static jclass LDKHTLCFailChannelUpdate_ChannelClosed_class = NULL;
638 static jmethodID LDKHTLCFailChannelUpdate_ChannelClosed_meth = NULL;
639 static jclass LDKHTLCFailChannelUpdate_NodeFailure_class = NULL;
640 static jmethodID LDKHTLCFailChannelUpdate_NodeFailure_meth = NULL;
641 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKHTLCFailChannelUpdate_init (JNIEnv * env, jclass _a) {
642         LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class =
643                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$ChannelUpdateMessage;"));
644         CHECK(LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class != NULL);
645         LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class, "<init>", "(J)V");
646         CHECK(LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth != NULL);
647         LDKHTLCFailChannelUpdate_ChannelClosed_class =
648                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$ChannelClosed;"));
649         CHECK(LDKHTLCFailChannelUpdate_ChannelClosed_class != NULL);
650         LDKHTLCFailChannelUpdate_ChannelClosed_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_ChannelClosed_class, "<init>", "(JZ)V");
651         CHECK(LDKHTLCFailChannelUpdate_ChannelClosed_meth != NULL);
652         LDKHTLCFailChannelUpdate_NodeFailure_class =
653                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$NodeFailure;"));
654         CHECK(LDKHTLCFailChannelUpdate_NodeFailure_class != NULL);
655         LDKHTLCFailChannelUpdate_NodeFailure_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_NodeFailure_class, "<init>", "([BZ)V");
656         CHECK(LDKHTLCFailChannelUpdate_NodeFailure_meth != NULL);
657 }
658 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKHTLCFailChannelUpdate_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
659         LDKHTLCFailChannelUpdate *obj = (LDKHTLCFailChannelUpdate*)ptr;
660         switch(obj->tag) {
661                 case LDKHTLCFailChannelUpdate_ChannelUpdateMessage: {
662                         LDKChannelUpdate msg_var = obj->channel_update_message.msg;
663                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
664                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
665                         long msg_ref = (long)msg_var.inner & ~1;
666                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth, msg_ref);
667                 }
668                 case LDKHTLCFailChannelUpdate_ChannelClosed: {
669                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_ChannelClosed_class, LDKHTLCFailChannelUpdate_ChannelClosed_meth, obj->channel_closed.short_channel_id, obj->channel_closed.is_permanent);
670                 }
671                 case LDKHTLCFailChannelUpdate_NodeFailure: {
672                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
673                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->node_failure.node_id.compressed_form);
674                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_NodeFailure_class, LDKHTLCFailChannelUpdate_NodeFailure_meth, node_id_arr, obj->node_failure.is_permanent);
675                 }
676                 default: abort();
677         }
678 }
679 static jclass LDKMessageSendEvent_SendAcceptChannel_class = NULL;
680 static jmethodID LDKMessageSendEvent_SendAcceptChannel_meth = NULL;
681 static jclass LDKMessageSendEvent_SendOpenChannel_class = NULL;
682 static jmethodID LDKMessageSendEvent_SendOpenChannel_meth = NULL;
683 static jclass LDKMessageSendEvent_SendFundingCreated_class = NULL;
684 static jmethodID LDKMessageSendEvent_SendFundingCreated_meth = NULL;
685 static jclass LDKMessageSendEvent_SendFundingSigned_class = NULL;
686 static jmethodID LDKMessageSendEvent_SendFundingSigned_meth = NULL;
687 static jclass LDKMessageSendEvent_SendFundingLocked_class = NULL;
688 static jmethodID LDKMessageSendEvent_SendFundingLocked_meth = NULL;
689 static jclass LDKMessageSendEvent_SendAnnouncementSignatures_class = NULL;
690 static jmethodID LDKMessageSendEvent_SendAnnouncementSignatures_meth = NULL;
691 static jclass LDKMessageSendEvent_UpdateHTLCs_class = NULL;
692 static jmethodID LDKMessageSendEvent_UpdateHTLCs_meth = NULL;
693 static jclass LDKMessageSendEvent_SendRevokeAndACK_class = NULL;
694 static jmethodID LDKMessageSendEvent_SendRevokeAndACK_meth = NULL;
695 static jclass LDKMessageSendEvent_SendClosingSigned_class = NULL;
696 static jmethodID LDKMessageSendEvent_SendClosingSigned_meth = NULL;
697 static jclass LDKMessageSendEvent_SendShutdown_class = NULL;
698 static jmethodID LDKMessageSendEvent_SendShutdown_meth = NULL;
699 static jclass LDKMessageSendEvent_SendChannelReestablish_class = NULL;
700 static jmethodID LDKMessageSendEvent_SendChannelReestablish_meth = NULL;
701 static jclass LDKMessageSendEvent_BroadcastChannelAnnouncement_class = NULL;
702 static jmethodID LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = NULL;
703 static jclass LDKMessageSendEvent_BroadcastNodeAnnouncement_class = NULL;
704 static jmethodID LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = NULL;
705 static jclass LDKMessageSendEvent_BroadcastChannelUpdate_class = NULL;
706 static jmethodID LDKMessageSendEvent_BroadcastChannelUpdate_meth = NULL;
707 static jclass LDKMessageSendEvent_HandleError_class = NULL;
708 static jmethodID LDKMessageSendEvent_HandleError_meth = NULL;
709 static jclass LDKMessageSendEvent_PaymentFailureNetworkUpdate_class = NULL;
710 static jmethodID LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = NULL;
711 static jclass LDKMessageSendEvent_SendChannelRangeQuery_class = NULL;
712 static jmethodID LDKMessageSendEvent_SendChannelRangeQuery_meth = NULL;
713 static jclass LDKMessageSendEvent_SendShortIdsQuery_class = NULL;
714 static jmethodID LDKMessageSendEvent_SendShortIdsQuery_meth = NULL;
715 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKMessageSendEvent_init (JNIEnv * env, jclass _a) {
716         LDKMessageSendEvent_SendAcceptChannel_class =
717                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendAcceptChannel;"));
718         CHECK(LDKMessageSendEvent_SendAcceptChannel_class != NULL);
719         LDKMessageSendEvent_SendAcceptChannel_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendAcceptChannel_class, "<init>", "([BJ)V");
720         CHECK(LDKMessageSendEvent_SendAcceptChannel_meth != NULL);
721         LDKMessageSendEvent_SendOpenChannel_class =
722                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendOpenChannel;"));
723         CHECK(LDKMessageSendEvent_SendOpenChannel_class != NULL);
724         LDKMessageSendEvent_SendOpenChannel_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendOpenChannel_class, "<init>", "([BJ)V");
725         CHECK(LDKMessageSendEvent_SendOpenChannel_meth != NULL);
726         LDKMessageSendEvent_SendFundingCreated_class =
727                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingCreated;"));
728         CHECK(LDKMessageSendEvent_SendFundingCreated_class != NULL);
729         LDKMessageSendEvent_SendFundingCreated_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingCreated_class, "<init>", "([BJ)V");
730         CHECK(LDKMessageSendEvent_SendFundingCreated_meth != NULL);
731         LDKMessageSendEvent_SendFundingSigned_class =
732                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingSigned;"));
733         CHECK(LDKMessageSendEvent_SendFundingSigned_class != NULL);
734         LDKMessageSendEvent_SendFundingSigned_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingSigned_class, "<init>", "([BJ)V");
735         CHECK(LDKMessageSendEvent_SendFundingSigned_meth != NULL);
736         LDKMessageSendEvent_SendFundingLocked_class =
737                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingLocked;"));
738         CHECK(LDKMessageSendEvent_SendFundingLocked_class != NULL);
739         LDKMessageSendEvent_SendFundingLocked_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingLocked_class, "<init>", "([BJ)V");
740         CHECK(LDKMessageSendEvent_SendFundingLocked_meth != NULL);
741         LDKMessageSendEvent_SendAnnouncementSignatures_class =
742                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendAnnouncementSignatures;"));
743         CHECK(LDKMessageSendEvent_SendAnnouncementSignatures_class != NULL);
744         LDKMessageSendEvent_SendAnnouncementSignatures_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendAnnouncementSignatures_class, "<init>", "([BJ)V");
745         CHECK(LDKMessageSendEvent_SendAnnouncementSignatures_meth != NULL);
746         LDKMessageSendEvent_UpdateHTLCs_class =
747                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$UpdateHTLCs;"));
748         CHECK(LDKMessageSendEvent_UpdateHTLCs_class != NULL);
749         LDKMessageSendEvent_UpdateHTLCs_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_UpdateHTLCs_class, "<init>", "([BJ)V");
750         CHECK(LDKMessageSendEvent_UpdateHTLCs_meth != NULL);
751         LDKMessageSendEvent_SendRevokeAndACK_class =
752                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendRevokeAndACK;"));
753         CHECK(LDKMessageSendEvent_SendRevokeAndACK_class != NULL);
754         LDKMessageSendEvent_SendRevokeAndACK_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendRevokeAndACK_class, "<init>", "([BJ)V");
755         CHECK(LDKMessageSendEvent_SendRevokeAndACK_meth != NULL);
756         LDKMessageSendEvent_SendClosingSigned_class =
757                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendClosingSigned;"));
758         CHECK(LDKMessageSendEvent_SendClosingSigned_class != NULL);
759         LDKMessageSendEvent_SendClosingSigned_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendClosingSigned_class, "<init>", "([BJ)V");
760         CHECK(LDKMessageSendEvent_SendClosingSigned_meth != NULL);
761         LDKMessageSendEvent_SendShutdown_class =
762                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendShutdown;"));
763         CHECK(LDKMessageSendEvent_SendShutdown_class != NULL);
764         LDKMessageSendEvent_SendShutdown_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendShutdown_class, "<init>", "([BJ)V");
765         CHECK(LDKMessageSendEvent_SendShutdown_meth != NULL);
766         LDKMessageSendEvent_SendChannelReestablish_class =
767                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendChannelReestablish;"));
768         CHECK(LDKMessageSendEvent_SendChannelReestablish_class != NULL);
769         LDKMessageSendEvent_SendChannelReestablish_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendChannelReestablish_class, "<init>", "([BJ)V");
770         CHECK(LDKMessageSendEvent_SendChannelReestablish_meth != NULL);
771         LDKMessageSendEvent_BroadcastChannelAnnouncement_class =
772                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastChannelAnnouncement;"));
773         CHECK(LDKMessageSendEvent_BroadcastChannelAnnouncement_class != NULL);
774         LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastChannelAnnouncement_class, "<init>", "(JJ)V");
775         CHECK(LDKMessageSendEvent_BroadcastChannelAnnouncement_meth != NULL);
776         LDKMessageSendEvent_BroadcastNodeAnnouncement_class =
777                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastNodeAnnouncement;"));
778         CHECK(LDKMessageSendEvent_BroadcastNodeAnnouncement_class != NULL);
779         LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastNodeAnnouncement_class, "<init>", "(J)V");
780         CHECK(LDKMessageSendEvent_BroadcastNodeAnnouncement_meth != NULL);
781         LDKMessageSendEvent_BroadcastChannelUpdate_class =
782                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastChannelUpdate;"));
783         CHECK(LDKMessageSendEvent_BroadcastChannelUpdate_class != NULL);
784         LDKMessageSendEvent_BroadcastChannelUpdate_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastChannelUpdate_class, "<init>", "(J)V");
785         CHECK(LDKMessageSendEvent_BroadcastChannelUpdate_meth != NULL);
786         LDKMessageSendEvent_HandleError_class =
787                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$HandleError;"));
788         CHECK(LDKMessageSendEvent_HandleError_class != NULL);
789         LDKMessageSendEvent_HandleError_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_HandleError_class, "<init>", "([BJ)V");
790         CHECK(LDKMessageSendEvent_HandleError_meth != NULL);
791         LDKMessageSendEvent_PaymentFailureNetworkUpdate_class =
792                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$PaymentFailureNetworkUpdate;"));
793         CHECK(LDKMessageSendEvent_PaymentFailureNetworkUpdate_class != NULL);
794         LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_PaymentFailureNetworkUpdate_class, "<init>", "(J)V");
795         CHECK(LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth != NULL);
796         LDKMessageSendEvent_SendChannelRangeQuery_class =
797                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendChannelRangeQuery;"));
798         CHECK(LDKMessageSendEvent_SendChannelRangeQuery_class != NULL);
799         LDKMessageSendEvent_SendChannelRangeQuery_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendChannelRangeQuery_class, "<init>", "([BJ)V");
800         CHECK(LDKMessageSendEvent_SendChannelRangeQuery_meth != NULL);
801         LDKMessageSendEvent_SendShortIdsQuery_class =
802                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendShortIdsQuery;"));
803         CHECK(LDKMessageSendEvent_SendShortIdsQuery_class != NULL);
804         LDKMessageSendEvent_SendShortIdsQuery_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendShortIdsQuery_class, "<init>", "([BJ)V");
805         CHECK(LDKMessageSendEvent_SendShortIdsQuery_meth != NULL);
806 }
807 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
808         LDKMessageSendEvent *obj = (LDKMessageSendEvent*)ptr;
809         switch(obj->tag) {
810                 case LDKMessageSendEvent_SendAcceptChannel: {
811                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
812                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_accept_channel.node_id.compressed_form);
813                         LDKAcceptChannel msg_var = obj->send_accept_channel.msg;
814                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
815                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
816                         long msg_ref = (long)msg_var.inner & ~1;
817                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendAcceptChannel_class, LDKMessageSendEvent_SendAcceptChannel_meth, node_id_arr, msg_ref);
818                 }
819                 case LDKMessageSendEvent_SendOpenChannel: {
820                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
821                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_open_channel.node_id.compressed_form);
822                         LDKOpenChannel msg_var = obj->send_open_channel.msg;
823                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
824                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
825                         long msg_ref = (long)msg_var.inner & ~1;
826                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendOpenChannel_class, LDKMessageSendEvent_SendOpenChannel_meth, node_id_arr, msg_ref);
827                 }
828                 case LDKMessageSendEvent_SendFundingCreated: {
829                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
830                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_created.node_id.compressed_form);
831                         LDKFundingCreated msg_var = obj->send_funding_created.msg;
832                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
833                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
834                         long msg_ref = (long)msg_var.inner & ~1;
835                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingCreated_class, LDKMessageSendEvent_SendFundingCreated_meth, node_id_arr, msg_ref);
836                 }
837                 case LDKMessageSendEvent_SendFundingSigned: {
838                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
839                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_signed.node_id.compressed_form);
840                         LDKFundingSigned msg_var = obj->send_funding_signed.msg;
841                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
842                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
843                         long msg_ref = (long)msg_var.inner & ~1;
844                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingSigned_class, LDKMessageSendEvent_SendFundingSigned_meth, node_id_arr, msg_ref);
845                 }
846                 case LDKMessageSendEvent_SendFundingLocked: {
847                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
848                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_locked.node_id.compressed_form);
849                         LDKFundingLocked msg_var = obj->send_funding_locked.msg;
850                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
851                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
852                         long msg_ref = (long)msg_var.inner & ~1;
853                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingLocked_class, LDKMessageSendEvent_SendFundingLocked_meth, node_id_arr, msg_ref);
854                 }
855                 case LDKMessageSendEvent_SendAnnouncementSignatures: {
856                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
857                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_announcement_signatures.node_id.compressed_form);
858                         LDKAnnouncementSignatures msg_var = obj->send_announcement_signatures.msg;
859                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
860                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
861                         long msg_ref = (long)msg_var.inner & ~1;
862                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendAnnouncementSignatures_class, LDKMessageSendEvent_SendAnnouncementSignatures_meth, node_id_arr, msg_ref);
863                 }
864                 case LDKMessageSendEvent_UpdateHTLCs: {
865                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
866                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->update_htl_cs.node_id.compressed_form);
867                         LDKCommitmentUpdate updates_var = obj->update_htl_cs.updates;
868                         CHECK((((long)updates_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
869                         CHECK((((long)&updates_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
870                         long updates_ref = (long)updates_var.inner & ~1;
871                         return (*_env)->NewObject(_env, LDKMessageSendEvent_UpdateHTLCs_class, LDKMessageSendEvent_UpdateHTLCs_meth, node_id_arr, updates_ref);
872                 }
873                 case LDKMessageSendEvent_SendRevokeAndACK: {
874                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
875                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_revoke_and_ack.node_id.compressed_form);
876                         LDKRevokeAndACK msg_var = obj->send_revoke_and_ack.msg;
877                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
878                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
879                         long msg_ref = (long)msg_var.inner & ~1;
880                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendRevokeAndACK_class, LDKMessageSendEvent_SendRevokeAndACK_meth, node_id_arr, msg_ref);
881                 }
882                 case LDKMessageSendEvent_SendClosingSigned: {
883                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
884                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_closing_signed.node_id.compressed_form);
885                         LDKClosingSigned msg_var = obj->send_closing_signed.msg;
886                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
887                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
888                         long msg_ref = (long)msg_var.inner & ~1;
889                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendClosingSigned_class, LDKMessageSendEvent_SendClosingSigned_meth, node_id_arr, msg_ref);
890                 }
891                 case LDKMessageSendEvent_SendShutdown: {
892                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
893                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_shutdown.node_id.compressed_form);
894                         LDKShutdown msg_var = obj->send_shutdown.msg;
895                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
896                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
897                         long msg_ref = (long)msg_var.inner & ~1;
898                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendShutdown_class, LDKMessageSendEvent_SendShutdown_meth, node_id_arr, msg_ref);
899                 }
900                 case LDKMessageSendEvent_SendChannelReestablish: {
901                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
902                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_channel_reestablish.node_id.compressed_form);
903                         LDKChannelReestablish msg_var = obj->send_channel_reestablish.msg;
904                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
905                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
906                         long msg_ref = (long)msg_var.inner & ~1;
907                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendChannelReestablish_class, LDKMessageSendEvent_SendChannelReestablish_meth, node_id_arr, msg_ref);
908                 }
909                 case LDKMessageSendEvent_BroadcastChannelAnnouncement: {
910                         LDKChannelAnnouncement msg_var = obj->broadcast_channel_announcement.msg;
911                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
912                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
913                         long msg_ref = (long)msg_var.inner & ~1;
914                         LDKChannelUpdate update_msg_var = obj->broadcast_channel_announcement.update_msg;
915                         CHECK((((long)update_msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
916                         CHECK((((long)&update_msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
917                         long update_msg_ref = (long)update_msg_var.inner & ~1;
918                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastChannelAnnouncement_class, LDKMessageSendEvent_BroadcastChannelAnnouncement_meth, msg_ref, update_msg_ref);
919                 }
920                 case LDKMessageSendEvent_BroadcastNodeAnnouncement: {
921                         LDKNodeAnnouncement msg_var = obj->broadcast_node_announcement.msg;
922                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
923                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
924                         long msg_ref = (long)msg_var.inner & ~1;
925                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastNodeAnnouncement_class, LDKMessageSendEvent_BroadcastNodeAnnouncement_meth, msg_ref);
926                 }
927                 case LDKMessageSendEvent_BroadcastChannelUpdate: {
928                         LDKChannelUpdate msg_var = obj->broadcast_channel_update.msg;
929                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
930                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
931                         long msg_ref = (long)msg_var.inner & ~1;
932                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastChannelUpdate_class, LDKMessageSendEvent_BroadcastChannelUpdate_meth, msg_ref);
933                 }
934                 case LDKMessageSendEvent_HandleError: {
935                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
936                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->handle_error.node_id.compressed_form);
937                         long action_ref = (long)&obj->handle_error.action;
938                         return (*_env)->NewObject(_env, LDKMessageSendEvent_HandleError_class, LDKMessageSendEvent_HandleError_meth, node_id_arr, action_ref);
939                 }
940                 case LDKMessageSendEvent_PaymentFailureNetworkUpdate: {
941                         long update_ref = (long)&obj->payment_failure_network_update.update;
942                         return (*_env)->NewObject(_env, LDKMessageSendEvent_PaymentFailureNetworkUpdate_class, LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth, update_ref);
943                 }
944                 case LDKMessageSendEvent_SendChannelRangeQuery: {
945                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
946                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_channel_range_query.node_id.compressed_form);
947                         LDKQueryChannelRange msg_var = obj->send_channel_range_query.msg;
948                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
949                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
950                         long msg_ref = (long)msg_var.inner & ~1;
951                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendChannelRangeQuery_class, LDKMessageSendEvent_SendChannelRangeQuery_meth, node_id_arr, msg_ref);
952                 }
953                 case LDKMessageSendEvent_SendShortIdsQuery: {
954                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
955                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_short_ids_query.node_id.compressed_form);
956                         LDKQueryShortChannelIds msg_var = obj->send_short_ids_query.msg;
957                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
958                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
959                         long msg_ref = (long)msg_var.inner & ~1;
960                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendShortIdsQuery_class, LDKMessageSendEvent_SendShortIdsQuery_meth, node_id_arr, msg_ref);
961                 }
962                 default: abort();
963         }
964 }
965 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1MessageSendEventZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
966         LDKCVec_MessageSendEventZ *vec = (LDKCVec_MessageSendEventZ*)ptr;
967         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKMessageSendEvent));
968 }
969 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1MessageSendEventZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
970         LDKCVec_MessageSendEventZ *ret = MALLOC(sizeof(LDKCVec_MessageSendEventZ), "LDKCVec_MessageSendEventZ");
971         ret->datalen = (*env)->GetArrayLength(env, elems);
972         if (ret->datalen == 0) {
973                 ret->data = NULL;
974         } else {
975                 ret->data = MALLOC(sizeof(LDKMessageSendEvent) * ret->datalen, "LDKCVec_MessageSendEventZ Data");
976                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
977                 for (size_t i = 0; i < ret->datalen; i++) {
978                         jlong arr_elem = java_elems[i];
979                         LDKMessageSendEvent arr_elem_conv = *(LDKMessageSendEvent*)arr_elem;
980                         FREE((void*)arr_elem);
981                         ret->data[i] = arr_elem_conv;
982                 }
983                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
984         }
985         return (long)ret;
986 }
987 static inline LDKCVec_MessageSendEventZ CVec_MessageSendEventZ_clone(const LDKCVec_MessageSendEventZ *orig) {
988         LDKCVec_MessageSendEventZ ret = { .data = MALLOC(sizeof(LDKMessageSendEvent) * orig->datalen, "LDKCVec_MessageSendEventZ clone bytes"), .datalen = orig->datalen };
989         for (size_t i = 0; i < ret.datalen; i++) {
990                 ret.data[i] = MessageSendEvent_clone(&orig->data[i]);
991         }
992         return ret;
993 }
994 static jclass LDKEvent_FundingGenerationReady_class = NULL;
995 static jmethodID LDKEvent_FundingGenerationReady_meth = NULL;
996 static jclass LDKEvent_FundingBroadcastSafe_class = NULL;
997 static jmethodID LDKEvent_FundingBroadcastSafe_meth = NULL;
998 static jclass LDKEvent_PaymentReceived_class = NULL;
999 static jmethodID LDKEvent_PaymentReceived_meth = NULL;
1000 static jclass LDKEvent_PaymentSent_class = NULL;
1001 static jmethodID LDKEvent_PaymentSent_meth = NULL;
1002 static jclass LDKEvent_PaymentFailed_class = NULL;
1003 static jmethodID LDKEvent_PaymentFailed_meth = NULL;
1004 static jclass LDKEvent_PendingHTLCsForwardable_class = NULL;
1005 static jmethodID LDKEvent_PendingHTLCsForwardable_meth = NULL;
1006 static jclass LDKEvent_SpendableOutputs_class = NULL;
1007 static jmethodID LDKEvent_SpendableOutputs_meth = NULL;
1008 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKEvent_init (JNIEnv * env, jclass _a) {
1009         LDKEvent_FundingGenerationReady_class =
1010                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$FundingGenerationReady;"));
1011         CHECK(LDKEvent_FundingGenerationReady_class != NULL);
1012         LDKEvent_FundingGenerationReady_meth = (*env)->GetMethodID(env, LDKEvent_FundingGenerationReady_class, "<init>", "([BJ[BJ)V");
1013         CHECK(LDKEvent_FundingGenerationReady_meth != NULL);
1014         LDKEvent_FundingBroadcastSafe_class =
1015                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$FundingBroadcastSafe;"));
1016         CHECK(LDKEvent_FundingBroadcastSafe_class != NULL);
1017         LDKEvent_FundingBroadcastSafe_meth = (*env)->GetMethodID(env, LDKEvent_FundingBroadcastSafe_class, "<init>", "(JJ)V");
1018         CHECK(LDKEvent_FundingBroadcastSafe_meth != NULL);
1019         LDKEvent_PaymentReceived_class =
1020                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentReceived;"));
1021         CHECK(LDKEvent_PaymentReceived_class != NULL);
1022         LDKEvent_PaymentReceived_meth = (*env)->GetMethodID(env, LDKEvent_PaymentReceived_class, "<init>", "([B[BJ)V");
1023         CHECK(LDKEvent_PaymentReceived_meth != NULL);
1024         LDKEvent_PaymentSent_class =
1025                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentSent;"));
1026         CHECK(LDKEvent_PaymentSent_class != NULL);
1027         LDKEvent_PaymentSent_meth = (*env)->GetMethodID(env, LDKEvent_PaymentSent_class, "<init>", "([B)V");
1028         CHECK(LDKEvent_PaymentSent_meth != NULL);
1029         LDKEvent_PaymentFailed_class =
1030                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentFailed;"));
1031         CHECK(LDKEvent_PaymentFailed_class != NULL);
1032         LDKEvent_PaymentFailed_meth = (*env)->GetMethodID(env, LDKEvent_PaymentFailed_class, "<init>", "([BZ)V");
1033         CHECK(LDKEvent_PaymentFailed_meth != NULL);
1034         LDKEvent_PendingHTLCsForwardable_class =
1035                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PendingHTLCsForwardable;"));
1036         CHECK(LDKEvent_PendingHTLCsForwardable_class != NULL);
1037         LDKEvent_PendingHTLCsForwardable_meth = (*env)->GetMethodID(env, LDKEvent_PendingHTLCsForwardable_class, "<init>", "(J)V");
1038         CHECK(LDKEvent_PendingHTLCsForwardable_meth != NULL);
1039         LDKEvent_SpendableOutputs_class =
1040                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$SpendableOutputs;"));
1041         CHECK(LDKEvent_SpendableOutputs_class != NULL);
1042         LDKEvent_SpendableOutputs_meth = (*env)->GetMethodID(env, LDKEvent_SpendableOutputs_class, "<init>", "([J)V");
1043         CHECK(LDKEvent_SpendableOutputs_meth != NULL);
1044 }
1045 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEvent_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
1046         LDKEvent *obj = (LDKEvent*)ptr;
1047         switch(obj->tag) {
1048                 case LDKEvent_FundingGenerationReady: {
1049                         jbyteArray temporary_channel_id_arr = (*_env)->NewByteArray(_env, 32);
1050                         (*_env)->SetByteArrayRegion(_env, temporary_channel_id_arr, 0, 32, obj->funding_generation_ready.temporary_channel_id.data);
1051                         LDKCVec_u8Z output_script_var = obj->funding_generation_ready.output_script;
1052                         jbyteArray output_script_arr = (*_env)->NewByteArray(_env, output_script_var.datalen);
1053                         (*_env)->SetByteArrayRegion(_env, output_script_arr, 0, output_script_var.datalen, output_script_var.data);
1054                         return (*_env)->NewObject(_env, LDKEvent_FundingGenerationReady_class, LDKEvent_FundingGenerationReady_meth, temporary_channel_id_arr, obj->funding_generation_ready.channel_value_satoshis, output_script_arr, obj->funding_generation_ready.user_channel_id);
1055                 }
1056                 case LDKEvent_FundingBroadcastSafe: {
1057                         LDKOutPoint funding_txo_var = obj->funding_broadcast_safe.funding_txo;
1058                         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1059                         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1060                         long funding_txo_ref = (long)funding_txo_var.inner & ~1;
1061                         return (*_env)->NewObject(_env, LDKEvent_FundingBroadcastSafe_class, LDKEvent_FundingBroadcastSafe_meth, funding_txo_ref, obj->funding_broadcast_safe.user_channel_id);
1062                 }
1063                 case LDKEvent_PaymentReceived: {
1064                         jbyteArray payment_hash_arr = (*_env)->NewByteArray(_env, 32);
1065                         (*_env)->SetByteArrayRegion(_env, payment_hash_arr, 0, 32, obj->payment_received.payment_hash.data);
1066                         jbyteArray payment_secret_arr = (*_env)->NewByteArray(_env, 32);
1067                         (*_env)->SetByteArrayRegion(_env, payment_secret_arr, 0, 32, obj->payment_received.payment_secret.data);
1068                         return (*_env)->NewObject(_env, LDKEvent_PaymentReceived_class, LDKEvent_PaymentReceived_meth, payment_hash_arr, payment_secret_arr, obj->payment_received.amt);
1069                 }
1070                 case LDKEvent_PaymentSent: {
1071                         jbyteArray payment_preimage_arr = (*_env)->NewByteArray(_env, 32);
1072                         (*_env)->SetByteArrayRegion(_env, payment_preimage_arr, 0, 32, obj->payment_sent.payment_preimage.data);
1073                         return (*_env)->NewObject(_env, LDKEvent_PaymentSent_class, LDKEvent_PaymentSent_meth, payment_preimage_arr);
1074                 }
1075                 case LDKEvent_PaymentFailed: {
1076                         jbyteArray payment_hash_arr = (*_env)->NewByteArray(_env, 32);
1077                         (*_env)->SetByteArrayRegion(_env, payment_hash_arr, 0, 32, obj->payment_failed.payment_hash.data);
1078                         return (*_env)->NewObject(_env, LDKEvent_PaymentFailed_class, LDKEvent_PaymentFailed_meth, payment_hash_arr, obj->payment_failed.rejected_by_dest);
1079                 }
1080                 case LDKEvent_PendingHTLCsForwardable: {
1081                         return (*_env)->NewObject(_env, LDKEvent_PendingHTLCsForwardable_class, LDKEvent_PendingHTLCsForwardable_meth, obj->pending_htl_cs_forwardable.time_forwardable);
1082                 }
1083                 case LDKEvent_SpendableOutputs: {
1084                         LDKCVec_SpendableOutputDescriptorZ outputs_var = obj->spendable_outputs.outputs;
1085                         jlongArray outputs_arr = (*_env)->NewLongArray(_env, outputs_var.datalen);
1086                         jlong *outputs_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, outputs_arr, NULL);
1087                         for (size_t b = 0; b < outputs_var.datalen; b++) {
1088                                 long arr_conv_27_ref = (long)&outputs_var.data[b];
1089                                 outputs_arr_ptr[b] = arr_conv_27_ref;
1090                         }
1091                         (*_env)->ReleasePrimitiveArrayCritical(_env, outputs_arr, outputs_arr_ptr, 0);
1092                         return (*_env)->NewObject(_env, LDKEvent_SpendableOutputs_class, LDKEvent_SpendableOutputs_meth, outputs_arr);
1093                 }
1094                 default: abort();
1095         }
1096 }
1097 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1EventZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1098         LDKCVec_EventZ *vec = (LDKCVec_EventZ*)ptr;
1099         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKEvent));
1100 }
1101 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1EventZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
1102         LDKCVec_EventZ *ret = MALLOC(sizeof(LDKCVec_EventZ), "LDKCVec_EventZ");
1103         ret->datalen = (*env)->GetArrayLength(env, elems);
1104         if (ret->datalen == 0) {
1105                 ret->data = NULL;
1106         } else {
1107                 ret->data = MALLOC(sizeof(LDKEvent) * ret->datalen, "LDKCVec_EventZ Data");
1108                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1109                 for (size_t i = 0; i < ret->datalen; i++) {
1110                         jlong arr_elem = java_elems[i];
1111                         LDKEvent arr_elem_conv = *(LDKEvent*)arr_elem;
1112                         FREE((void*)arr_elem);
1113                         ret->data[i] = arr_elem_conv;
1114                 }
1115                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1116         }
1117         return (long)ret;
1118 }
1119 static inline LDKCVec_EventZ CVec_EventZ_clone(const LDKCVec_EventZ *orig) {
1120         LDKCVec_EventZ ret = { .data = MALLOC(sizeof(LDKEvent) * orig->datalen, "LDKCVec_EventZ clone bytes"), .datalen = orig->datalen };
1121         for (size_t i = 0; i < ret.datalen; i++) {
1122                 ret.data[i] = Event_clone(&orig->data[i]);
1123         }
1124         return ret;
1125 }
1126 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) {
1127         LDKC2Tuple_usizeTransactionZ* ret = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
1128         ret->a = a;
1129         LDKTransaction b_ref;
1130         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
1131         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
1132         (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data);
1133         b_ref.data_is_owned = false;
1134         ret->b = b_ref;
1135         return (long)ret;
1136 }
1137 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
1138         LDKC2Tuple_usizeTransactionZ *tuple = (LDKC2Tuple_usizeTransactionZ*)ptr;
1139         return tuple->a;
1140 }
1141 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
1142         LDKC2Tuple_usizeTransactionZ *tuple = (LDKC2Tuple_usizeTransactionZ*)ptr;
1143         LDKTransaction b_var = tuple->b;
1144         jbyteArray b_arr = (*_env)->NewByteArray(_env, b_var.datalen);
1145         (*_env)->SetByteArrayRegion(_env, b_arr, 0, b_var.datalen, b_var.data);
1146         return b_arr;
1147 }
1148 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1usizeTransactionZZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1149         LDKCVec_C2Tuple_usizeTransactionZZ *vec = (LDKCVec_C2Tuple_usizeTransactionZZ*)ptr;
1150         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2Tuple_usizeTransactionZ));
1151 }
1152 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1usizeTransactionZZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
1153         LDKCVec_C2Tuple_usizeTransactionZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "LDKCVec_C2Tuple_usizeTransactionZZ");
1154         ret->datalen = (*env)->GetArrayLength(env, elems);
1155         if (ret->datalen == 0) {
1156                 ret->data = NULL;
1157         } else {
1158                 ret->data = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ) * ret->datalen, "LDKCVec_C2Tuple_usizeTransactionZZ Data");
1159                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1160                 for (size_t i = 0; i < ret->datalen; i++) {
1161                         jlong arr_elem = java_elems[i];
1162                         LDKC2Tuple_usizeTransactionZ arr_elem_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_elem;
1163                         FREE((void*)arr_elem);
1164                         ret->data[i] = arr_elem_conv;
1165                 }
1166                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1167         }
1168         return (long)ret;
1169 }
1170 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1171         return ((LDKCResult_NoneChannelMonitorUpdateErrZ*)arg)->result_ok;
1172 }
1173 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1174         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
1175         CHECK(val->result_ok);
1176         return *val->contents.result;
1177 }
1178 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1179         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
1180         CHECK(!val->result_ok);
1181         jclass err_conv = LDKChannelMonitorUpdateErr_to_java(_env, (*val->contents.err));
1182         return err_conv;
1183 }
1184 static inline LDKCResult_NoneChannelMonitorUpdateErrZ CResult_NoneChannelMonitorUpdateErrZ_clone(const LDKCResult_NoneChannelMonitorUpdateErrZ *orig) {
1185         LDKCResult_NoneChannelMonitorUpdateErrZ res = { .result_ok = orig->result_ok };
1186         if (orig->result_ok) {
1187                 res.contents.result = NULL;
1188         } else {
1189                 LDKChannelMonitorUpdateErr* contents = MALLOC(sizeof(LDKChannelMonitorUpdateErr), "LDKChannelMonitorUpdateErr result Err clone");
1190                 *contents = ChannelMonitorUpdateErr_clone(orig->contents.err);
1191                 res.contents.err = contents;
1192         }
1193         return res;
1194 }
1195 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1MonitorEventZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1196         LDKCVec_MonitorEventZ *vec = (LDKCVec_MonitorEventZ*)ptr;
1197         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
1198         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
1199         for (size_t i = 0; i < vec->datalen; i++) {
1200                 CHECK((((long)vec->data[i].inner) & 1) == 0);
1201                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
1202         }
1203         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
1204         return ret;
1205 }
1206 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1MonitorEventZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
1207         LDKCVec_MonitorEventZ *ret = MALLOC(sizeof(LDKCVec_MonitorEventZ), "LDKCVec_MonitorEventZ");
1208         ret->datalen = (*env)->GetArrayLength(env, elems);
1209         if (ret->datalen == 0) {
1210                 ret->data = NULL;
1211         } else {
1212                 ret->data = MALLOC(sizeof(LDKMonitorEvent) * ret->datalen, "LDKCVec_MonitorEventZ Data");
1213                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1214                 for (size_t i = 0; i < ret->datalen; i++) {
1215                         jlong arr_elem = java_elems[i];
1216                         LDKMonitorEvent arr_elem_conv;
1217                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
1218                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
1219                         if (arr_elem_conv.inner != NULL)
1220                                 arr_elem_conv = MonitorEvent_clone(&arr_elem_conv);
1221                         ret->data[i] = arr_elem_conv;
1222                 }
1223                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1224         }
1225         return (long)ret;
1226 }
1227 static inline LDKCVec_MonitorEventZ CVec_MonitorEventZ_clone(const LDKCVec_MonitorEventZ *orig) {
1228         LDKCVec_MonitorEventZ ret = { .data = MALLOC(sizeof(LDKMonitorEvent) * orig->datalen, "LDKCVec_MonitorEventZ clone bytes"), .datalen = orig->datalen };
1229         for (size_t i = 0; i < ret.datalen; i++) {
1230                 ret.data[i] = MonitorEvent_clone(&orig->data[i]);
1231         }
1232         return ret;
1233 }
1234 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelMonitorUpdateDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1235         return ((LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg)->result_ok;
1236 }
1237 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelMonitorUpdateDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1238         LDKCResult_ChannelMonitorUpdateDecodeErrorZ *val = (LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg;
1239         CHECK(val->result_ok);
1240         LDKChannelMonitorUpdate res_var = (*val->contents.result);
1241         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1242         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1243         long res_ref = (long)res_var.inner & ~1;
1244         return res_ref;
1245 }
1246 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelMonitorUpdateDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1247         LDKCResult_ChannelMonitorUpdateDecodeErrorZ *val = (LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)arg;
1248         CHECK(!val->result_ok);
1249         LDKDecodeError err_var = (*val->contents.err);
1250         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1251         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1252         long err_ref = (long)err_var.inner & ~1;
1253         return err_ref;
1254 }
1255 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1256         return ((LDKCResult_NoneMonitorUpdateErrorZ*)arg)->result_ok;
1257 }
1258 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1259         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
1260         CHECK(val->result_ok);
1261         return *val->contents.result;
1262 }
1263 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1264         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
1265         CHECK(!val->result_ok);
1266         LDKMonitorUpdateError err_var = (*val->contents.err);
1267         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1268         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1269         long err_ref = (long)err_var.inner & ~1;
1270         return err_ref;
1271 }
1272 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) {
1273         LDKC2Tuple_OutPointScriptZ* ret = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
1274         LDKOutPoint a_conv;
1275         a_conv.inner = (void*)(a & (~1));
1276         a_conv.is_owned = (a & 1) || (a == 0);
1277         if (a_conv.inner != NULL)
1278                 a_conv = OutPoint_clone(&a_conv);
1279         ret->a = a_conv;
1280         LDKCVec_u8Z b_ref;
1281         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
1282         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
1283         (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data);
1284         ret->b = b_ref;
1285         return (long)ret;
1286 }
1287 static inline LDKC2Tuple_OutPointScriptZ C2Tuple_OutPointScriptZ_clone(const LDKC2Tuple_OutPointScriptZ *orig) {
1288         LDKC2Tuple_OutPointScriptZ ret = {
1289                 .a = OutPoint_clone(&orig->a),
1290                 .b = CVec_u8Z_clone(&orig->b),
1291         };
1292         return ret;
1293 }
1294 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
1295         LDKC2Tuple_OutPointScriptZ *tuple = (LDKC2Tuple_OutPointScriptZ*)ptr;
1296         LDKOutPoint a_var = tuple->a;
1297         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1298         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1299         long a_ref = (long)a_var.inner & ~1;
1300         return a_ref;
1301 }
1302 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
1303         LDKC2Tuple_OutPointScriptZ *tuple = (LDKC2Tuple_OutPointScriptZ*)ptr;
1304         LDKCVec_u8Z b_var = tuple->b;
1305         jbyteArray b_arr = (*_env)->NewByteArray(_env, b_var.datalen);
1306         (*_env)->SetByteArrayRegion(_env, b_arr, 0, b_var.datalen, b_var.data);
1307         return b_arr;
1308 }
1309 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1TransactionZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1310         LDKCVec_TransactionZ *vec = (LDKCVec_TransactionZ*)ptr;
1311         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKTransaction));
1312 }
1313 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u32TxOutZ_1new(JNIEnv *_env, jclass _b, jint a, jlong b) {
1314         LDKC2Tuple_u32TxOutZ* ret = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
1315         ret->a = a;
1316         LDKTxOut b_conv = *(LDKTxOut*)b;
1317         FREE((void*)b);
1318         ret->b = b_conv;
1319         return (long)ret;
1320 }
1321 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u32TxOutZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
1322         LDKC2Tuple_u32TxOutZ *tuple = (LDKC2Tuple_u32TxOutZ*)ptr;
1323         return tuple->a;
1324 }
1325 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1u32TxOutZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
1326         LDKC2Tuple_u32TxOutZ *tuple = (LDKC2Tuple_u32TxOutZ*)ptr;
1327         long b_ref = (long)&tuple->b;
1328         return (long)b_ref;
1329 }
1330 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1u32TxOutZZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1331         LDKCVec_C2Tuple_u32TxOutZZ *vec = (LDKCVec_C2Tuple_u32TxOutZZ*)ptr;
1332         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2Tuple_u32TxOutZ));
1333 }
1334 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1u32TxOutZZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
1335         LDKCVec_C2Tuple_u32TxOutZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_u32TxOutZZ), "LDKCVec_C2Tuple_u32TxOutZZ");
1336         ret->datalen = (*env)->GetArrayLength(env, elems);
1337         if (ret->datalen == 0) {
1338                 ret->data = NULL;
1339         } else {
1340                 ret->data = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ) * ret->datalen, "LDKCVec_C2Tuple_u32TxOutZZ Data");
1341                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1342                 for (size_t i = 0; i < ret->datalen; i++) {
1343                         jlong arr_elem = java_elems[i];
1344                         LDKC2Tuple_u32TxOutZ arr_elem_conv = *(LDKC2Tuple_u32TxOutZ*)arr_elem;
1345                         FREE((void*)arr_elem);
1346                         ret->data[i] = arr_elem_conv;
1347                 }
1348                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1349         }
1350         return (long)ret;
1351 }
1352 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1new(JNIEnv *_env, jclass _b, jbyteArray a, jlongArray b) {
1353         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* ret = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
1354         LDKThirtyTwoBytes a_ref;
1355         CHECK((*_env)->GetArrayLength (_env, a) == 32);
1356         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
1357         ret->a = a_ref;
1358         LDKCVec_C2Tuple_u32TxOutZZ b_constr;
1359         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
1360         if (b_constr.datalen > 0)
1361                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
1362         else
1363                 b_constr.data = NULL;
1364         long* b_vals = (*_env)->GetLongArrayElements (_env, b, NULL);
1365         for (size_t a = 0; a < b_constr.datalen; a++) {
1366                 long arr_conv_26 = b_vals[a];
1367                 LDKC2Tuple_u32TxOutZ arr_conv_26_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_26;
1368                 FREE((void*)arr_conv_26);
1369                 b_constr.data[a] = arr_conv_26_conv;
1370         }
1371         (*_env)->ReleaseLongArrayElements (_env, b, b_vals, 0);
1372         ret->b = b_constr;
1373         return (long)ret;
1374 }
1375 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
1376         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *tuple = (LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)ptr;
1377         jbyteArray a_arr = (*_env)->NewByteArray(_env, 32);
1378         (*_env)->SetByteArrayRegion(_env, a_arr, 0, 32, tuple->a.data);
1379         return a_arr;
1380 }
1381 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
1382         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ *tuple = (LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)ptr;
1383         LDKCVec_C2Tuple_u32TxOutZZ b_var = tuple->b;
1384         jlongArray b_arr = (*_env)->NewLongArray(_env, b_var.datalen);
1385         jlong *b_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, b_arr, NULL);
1386         for (size_t a = 0; a < b_var.datalen; a++) {
1387                 long arr_conv_26_ref = (long)&b_var.data[a];
1388                 b_arr_ptr[a] = arr_conv_26_ref;
1389         }
1390         (*_env)->ReleasePrimitiveArrayCritical(_env, b_arr, b_arr_ptr, 0);
1391         return b_arr;
1392 }
1393 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1394         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ *vec = (LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ*)ptr;
1395         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ));
1396 }
1397 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
1398         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ *ret = MALLOC(sizeof(LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ), "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ");
1399         ret->datalen = (*env)->GetArrayLength(env, elems);
1400         if (ret->datalen == 0) {
1401                 ret->data = NULL;
1402         } else {
1403                 ret->data = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ) * ret->datalen, "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ Data");
1404                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1405                 for (size_t i = 0; i < ret->datalen; i++) {
1406                         jlong arr_elem = java_elems[i];
1407                         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ arr_elem_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)arr_elem;
1408                         FREE((void*)arr_elem);
1409                         ret->data[i] = arr_elem_conv;
1410                 }
1411                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1412         }
1413         return (long)ret;
1414 }
1415 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1SignatureZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1416         LDKCVec_SignatureZ *vec = (LDKCVec_SignatureZ*)ptr;
1417         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKSignature));
1418 }
1419 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1SignatureCVec_1SignatureZZ_1new(JNIEnv *_env, jclass _b, jbyteArray a, jobjectArray b) {
1420         LDKC2Tuple_SignatureCVec_SignatureZZ* ret = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
1421         LDKSignature a_ref;
1422         CHECK((*_env)->GetArrayLength (_env, a) == 64);
1423         (*_env)->GetByteArrayRegion (_env, a, 0, 64, a_ref.compact_form);
1424         ret->a = a_ref;
1425         LDKCVec_SignatureZ b_constr;
1426         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
1427         if (b_constr.datalen > 0)
1428                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
1429         else
1430                 b_constr.data = NULL;
1431         for (size_t i = 0; i < b_constr.datalen; i++) {
1432                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, b, i);
1433                 LDKSignature arr_conv_8_ref;
1434                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
1435                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
1436                 b_constr.data[i] = arr_conv_8_ref;
1437         }
1438         ret->b = b_constr;
1439         return (long)ret;
1440 }
1441 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1SignatureCVec_1SignatureZZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
1442         LDKC2Tuple_SignatureCVec_SignatureZZ *tuple = (LDKC2Tuple_SignatureCVec_SignatureZZ*)ptr;
1443         jbyteArray a_arr = (*_env)->NewByteArray(_env, 64);
1444         (*_env)->SetByteArrayRegion(_env, a_arr, 0, 64, tuple->a.compact_form);
1445         return a_arr;
1446 }
1447 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1SignatureCVec_1SignatureZZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
1448         LDKC2Tuple_SignatureCVec_SignatureZZ *tuple = (LDKC2Tuple_SignatureCVec_SignatureZZ*)ptr;
1449         LDKCVec_SignatureZ b_var = tuple->b;
1450         jobjectArray b_arr = (*_env)->NewObjectArray(_env, b_var.datalen, arr_of_B_clz, NULL);
1451         for (size_t i = 0; i < b_var.datalen; i++) {
1452                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 64);
1453                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 64, b_var.data[i].compact_form);
1454                 (*_env)->SetObjectArrayElement(_env, b_arr, i, arr_conv_8_arr);
1455         }
1456         return b_arr;
1457 }
1458 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1459         return ((LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg)->result_ok;
1460 }
1461 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1462         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
1463         CHECK(val->result_ok);
1464         long res_ref = (long)&(*val->contents.result);
1465         return res_ref;
1466 }
1467 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1468         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
1469         CHECK(!val->result_ok);
1470         return *val->contents.err;
1471 }
1472 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1473         return ((LDKCResult_SignatureNoneZ*)arg)->result_ok;
1474 }
1475 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1476         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
1477         CHECK(val->result_ok);
1478         jbyteArray res_arr = (*_env)->NewByteArray(_env, 64);
1479         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 64, (*val->contents.result).compact_form);
1480         return res_arr;
1481 }
1482 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1483         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
1484         CHECK(!val->result_ok);
1485         return *val->contents.err;
1486 }
1487 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1488         return ((LDKCResult_CVec_SignatureZNoneZ*)arg)->result_ok;
1489 }
1490 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1491         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
1492         CHECK(val->result_ok);
1493         LDKCVec_SignatureZ res_var = (*val->contents.result);
1494         jobjectArray res_arr = (*_env)->NewObjectArray(_env, res_var.datalen, arr_of_B_clz, NULL);
1495         for (size_t i = 0; i < res_var.datalen; i++) {
1496                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 64);
1497                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 64, res_var.data[i].compact_form);
1498                 (*_env)->SetObjectArrayElement(_env, res_arr, i, arr_conv_8_arr);
1499         }
1500         return res_arr;
1501 }
1502 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1503         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
1504         CHECK(!val->result_ok);
1505         return *val->contents.err;
1506 }
1507 typedef struct LDKChannelKeys_JCalls {
1508         atomic_size_t refcnt;
1509         JavaVM *vm;
1510         jweak o;
1511         jmethodID get_per_commitment_point_meth;
1512         jmethodID release_commitment_secret_meth;
1513         jmethodID key_derivation_params_meth;
1514         jmethodID sign_counterparty_commitment_meth;
1515         jmethodID sign_holder_commitment_meth;
1516         jmethodID sign_holder_commitment_htlc_transactions_meth;
1517         jmethodID sign_justice_transaction_meth;
1518         jmethodID sign_counterparty_htlc_transaction_meth;
1519         jmethodID sign_closing_transaction_meth;
1520         jmethodID sign_channel_announcement_meth;
1521         jmethodID ready_channel_meth;
1522         jmethodID write_meth;
1523 } LDKChannelKeys_JCalls;
1524 LDKPublicKey get_per_commitment_point_jcall(const void* this_arg, uint64_t idx) {
1525         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1526         JNIEnv *_env;
1527         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1528         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1529         CHECK(obj != NULL);
1530         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_per_commitment_point_meth, idx);
1531         LDKPublicKey arg_ref;
1532         CHECK((*_env)->GetArrayLength (_env, arg) == 33);
1533         (*_env)->GetByteArrayRegion (_env, arg, 0, 33, arg_ref.compressed_form);
1534         return arg_ref;
1535 }
1536 LDKThirtyTwoBytes release_commitment_secret_jcall(const void* this_arg, uint64_t idx) {
1537         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1538         JNIEnv *_env;
1539         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1540         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1541         CHECK(obj != NULL);
1542         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->release_commitment_secret_meth, idx);
1543         LDKThirtyTwoBytes arg_ref;
1544         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
1545         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.data);
1546         return arg_ref;
1547 }
1548 LDKC2Tuple_u64u64Z key_derivation_params_jcall(const void* this_arg) {
1549         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1550         JNIEnv *_env;
1551         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1552         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1553         CHECK(obj != NULL);
1554         LDKC2Tuple_u64u64Z* ret = (LDKC2Tuple_u64u64Z*)(*_env)->CallLongMethod(_env, obj, j_calls->key_derivation_params_meth);
1555         LDKC2Tuple_u64u64Z ret_conv = *(LDKC2Tuple_u64u64Z*)ret;
1556         FREE((void*)ret);
1557         return ret_conv;
1558 }
1559 LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment_jcall(const void* this_arg, const struct LDKCommitmentTransaction *NONNULL_PTR commitment_tx) {
1560         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1561         JNIEnv *_env;
1562         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1563         LDKCommitmentTransaction commitment_tx_var = *commitment_tx;
1564         if (commitment_tx->inner != NULL)
1565                 commitment_tx_var = CommitmentTransaction_clone(commitment_tx);
1566         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1567         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1568         long commitment_tx_ref = (long)commitment_tx_var.inner;
1569         if (commitment_tx_var.is_owned) {
1570                 commitment_tx_ref |= 1;
1571         }
1572         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1573         CHECK(obj != NULL);
1574         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_counterparty_commitment_meth, commitment_tx_ref);
1575         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)ret;
1576         FREE((void*)ret);
1577         return ret_conv;
1578 }
1579 LDKCResult_SignatureNoneZ sign_holder_commitment_jcall(const void* this_arg, const struct LDKHolderCommitmentTransaction *NONNULL_PTR commitment_tx) {
1580         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1581         JNIEnv *_env;
1582         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1583         LDKHolderCommitmentTransaction commitment_tx_var = *commitment_tx;
1584         if (commitment_tx->inner != NULL)
1585                 commitment_tx_var = HolderCommitmentTransaction_clone(commitment_tx);
1586         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1587         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1588         long commitment_tx_ref = (long)commitment_tx_var.inner;
1589         if (commitment_tx_var.is_owned) {
1590                 commitment_tx_ref |= 1;
1591         }
1592         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1593         CHECK(obj != NULL);
1594         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_holder_commitment_meth, commitment_tx_ref);
1595         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1596         FREE((void*)ret);
1597         return ret_conv;
1598 }
1599 LDKCResult_CVec_SignatureZNoneZ sign_holder_commitment_htlc_transactions_jcall(const void* this_arg, const struct LDKHolderCommitmentTransaction *NONNULL_PTR commitment_tx) {
1600         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1601         JNIEnv *_env;
1602         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1603         LDKHolderCommitmentTransaction commitment_tx_var = *commitment_tx;
1604         if (commitment_tx->inner != NULL)
1605                 commitment_tx_var = HolderCommitmentTransaction_clone(commitment_tx);
1606         CHECK((((long)commitment_tx_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1607         CHECK((((long)&commitment_tx_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1608         long commitment_tx_ref = (long)commitment_tx_var.inner;
1609         if (commitment_tx_var.is_owned) {
1610                 commitment_tx_ref |= 1;
1611         }
1612         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1613         CHECK(obj != NULL);
1614         LDKCResult_CVec_SignatureZNoneZ* ret = (LDKCResult_CVec_SignatureZNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_holder_commitment_htlc_transactions_meth, commitment_tx_ref);
1615         LDKCResult_CVec_SignatureZNoneZ ret_conv = *(LDKCResult_CVec_SignatureZNoneZ*)ret;
1616         FREE((void*)ret);
1617         return ret_conv;
1618 }
1619 LDKCResult_SignatureNoneZ sign_justice_transaction_jcall(const void* this_arg, struct LDKTransaction justice_tx, uintptr_t input, uint64_t amount, const uint8_t (*per_commitment_key)[32], const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc) {
1620         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1621         JNIEnv *_env;
1622         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1623         LDKTransaction justice_tx_var = justice_tx;
1624         jbyteArray justice_tx_arr = (*_env)->NewByteArray(_env, justice_tx_var.datalen);
1625         (*_env)->SetByteArrayRegion(_env, justice_tx_arr, 0, justice_tx_var.datalen, justice_tx_var.data);
1626         Transaction_free(justice_tx_var);
1627         jbyteArray per_commitment_key_arr = (*_env)->NewByteArray(_env, 32);
1628         (*_env)->SetByteArrayRegion(_env, per_commitment_key_arr, 0, 32, *per_commitment_key);
1629         LDKHTLCOutputInCommitment htlc_var = *htlc;
1630         if (htlc->inner != NULL)
1631                 htlc_var = HTLCOutputInCommitment_clone(htlc);
1632         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1633         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1634         long htlc_ref = (long)htlc_var.inner;
1635         if (htlc_var.is_owned) {
1636                 htlc_ref |= 1;
1637         }
1638         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1639         CHECK(obj != NULL);
1640         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_justice_transaction_meth, justice_tx_arr, input, amount, per_commitment_key_arr, htlc_ref);
1641         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1642         FREE((void*)ret);
1643         return ret_conv;
1644 }
1645 LDKCResult_SignatureNoneZ sign_counterparty_htlc_transaction_jcall(const void* this_arg, struct LDKTransaction htlc_tx, uintptr_t input, uint64_t amount, struct LDKPublicKey per_commitment_point, const struct LDKHTLCOutputInCommitment *NONNULL_PTR htlc) {
1646         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1647         JNIEnv *_env;
1648         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1649         LDKTransaction htlc_tx_var = htlc_tx;
1650         jbyteArray htlc_tx_arr = (*_env)->NewByteArray(_env, htlc_tx_var.datalen);
1651         (*_env)->SetByteArrayRegion(_env, htlc_tx_arr, 0, htlc_tx_var.datalen, htlc_tx_var.data);
1652         Transaction_free(htlc_tx_var);
1653         jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33);
1654         (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, per_commitment_point.compressed_form);
1655         LDKHTLCOutputInCommitment htlc_var = *htlc;
1656         if (htlc->inner != NULL)
1657                 htlc_var = HTLCOutputInCommitment_clone(htlc);
1658         CHECK((((long)htlc_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1659         CHECK((((long)&htlc_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1660         long htlc_ref = (long)htlc_var.inner;
1661         if (htlc_var.is_owned) {
1662                 htlc_ref |= 1;
1663         }
1664         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1665         CHECK(obj != NULL);
1666         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);
1667         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1668         FREE((void*)ret);
1669         return ret_conv;
1670 }
1671 LDKCResult_SignatureNoneZ sign_closing_transaction_jcall(const void* this_arg, struct LDKTransaction closing_tx) {
1672         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_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         LDKTransaction closing_tx_var = closing_tx;
1676         jbyteArray closing_tx_arr = (*_env)->NewByteArray(_env, closing_tx_var.datalen);
1677         (*_env)->SetByteArrayRegion(_env, closing_tx_arr, 0, closing_tx_var.datalen, closing_tx_var.data);
1678         Transaction_free(closing_tx_var);
1679         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1680         CHECK(obj != NULL);
1681         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_closing_transaction_meth, closing_tx_arr);
1682         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1683         FREE((void*)ret);
1684         return ret_conv;
1685 }
1686 LDKCResult_SignatureNoneZ sign_channel_announcement_jcall(const void* this_arg, const struct LDKUnsignedChannelAnnouncement *NONNULL_PTR msg) {
1687         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1688         JNIEnv *_env;
1689         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1690         LDKUnsignedChannelAnnouncement msg_var = *msg;
1691         if (msg->inner != NULL)
1692                 msg_var = UnsignedChannelAnnouncement_clone(msg);
1693         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1694         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1695         long msg_ref = (long)msg_var.inner;
1696         if (msg_var.is_owned) {
1697                 msg_ref |= 1;
1698         }
1699         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1700         CHECK(obj != NULL);
1701         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_channel_announcement_meth, msg_ref);
1702         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1703         FREE((void*)ret);
1704         return ret_conv;
1705 }
1706 void ready_channel_jcall(void* this_arg, const struct LDKChannelTransactionParameters *NONNULL_PTR channel_parameters) {
1707         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1708         JNIEnv *_env;
1709         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1710         LDKChannelTransactionParameters channel_parameters_var = *channel_parameters;
1711         if (channel_parameters->inner != NULL)
1712                 channel_parameters_var = ChannelTransactionParameters_clone(channel_parameters);
1713         CHECK((((long)channel_parameters_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1714         CHECK((((long)&channel_parameters_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1715         long channel_parameters_ref = (long)channel_parameters_var.inner;
1716         if (channel_parameters_var.is_owned) {
1717                 channel_parameters_ref |= 1;
1718         }
1719         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1720         CHECK(obj != NULL);
1721         return (*_env)->CallVoidMethod(_env, obj, j_calls->ready_channel_meth, channel_parameters_ref);
1722 }
1723 LDKCVec_u8Z write_jcall(const void* this_arg) {
1724         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1725         JNIEnv *_env;
1726         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1727         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1728         CHECK(obj != NULL);
1729         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->write_meth);
1730         LDKCVec_u8Z arg_ref;
1731         arg_ref.datalen = (*_env)->GetArrayLength (_env, arg);
1732         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
1733         (*_env)->GetByteArrayRegion(_env, arg, 0, arg_ref.datalen, arg_ref.data);
1734         return arg_ref;
1735 }
1736 static void LDKChannelKeys_JCalls_free(void* this_arg) {
1737         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1738         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1739                 JNIEnv *env;
1740                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1741                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1742                 FREE(j_calls);
1743         }
1744 }
1745 static void* LDKChannelKeys_JCalls_clone(const void* this_arg) {
1746         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1747         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1748         return (void*) this_arg;
1749 }
1750 static inline LDKChannelKeys LDKChannelKeys_init (JNIEnv * env, jclass _a, jobject o, jlong pubkeys) {
1751         jclass c = (*env)->GetObjectClass(env, o);
1752         CHECK(c != NULL);
1753         LDKChannelKeys_JCalls *calls = MALLOC(sizeof(LDKChannelKeys_JCalls), "LDKChannelKeys_JCalls");
1754         atomic_init(&calls->refcnt, 1);
1755         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1756         calls->o = (*env)->NewWeakGlobalRef(env, o);
1757         calls->get_per_commitment_point_meth = (*env)->GetMethodID(env, c, "get_per_commitment_point", "(J)[B");
1758         CHECK(calls->get_per_commitment_point_meth != NULL);
1759         calls->release_commitment_secret_meth = (*env)->GetMethodID(env, c, "release_commitment_secret", "(J)[B");
1760         CHECK(calls->release_commitment_secret_meth != NULL);
1761         calls->key_derivation_params_meth = (*env)->GetMethodID(env, c, "key_derivation_params", "()J");
1762         CHECK(calls->key_derivation_params_meth != NULL);
1763         calls->sign_counterparty_commitment_meth = (*env)->GetMethodID(env, c, "sign_counterparty_commitment", "(J)J");
1764         CHECK(calls->sign_counterparty_commitment_meth != NULL);
1765         calls->sign_holder_commitment_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment", "(J)J");
1766         CHECK(calls->sign_holder_commitment_meth != NULL);
1767         calls->sign_holder_commitment_htlc_transactions_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment_htlc_transactions", "(J)J");
1768         CHECK(calls->sign_holder_commitment_htlc_transactions_meth != NULL);
1769         calls->sign_justice_transaction_meth = (*env)->GetMethodID(env, c, "sign_justice_transaction", "([BJJ[BJ)J");
1770         CHECK(calls->sign_justice_transaction_meth != NULL);
1771         calls->sign_counterparty_htlc_transaction_meth = (*env)->GetMethodID(env, c, "sign_counterparty_htlc_transaction", "([BJJ[BJ)J");
1772         CHECK(calls->sign_counterparty_htlc_transaction_meth != NULL);
1773         calls->sign_closing_transaction_meth = (*env)->GetMethodID(env, c, "sign_closing_transaction", "([B)J");
1774         CHECK(calls->sign_closing_transaction_meth != NULL);
1775         calls->sign_channel_announcement_meth = (*env)->GetMethodID(env, c, "sign_channel_announcement", "(J)J");
1776         CHECK(calls->sign_channel_announcement_meth != NULL);
1777         calls->ready_channel_meth = (*env)->GetMethodID(env, c, "ready_channel", "(J)V");
1778         CHECK(calls->ready_channel_meth != NULL);
1779         calls->write_meth = (*env)->GetMethodID(env, c, "write", "()[B");
1780         CHECK(calls->write_meth != NULL);
1781
1782         LDKChannelPublicKeys pubkeys_conv;
1783         pubkeys_conv.inner = (void*)(pubkeys & (~1));
1784         pubkeys_conv.is_owned = (pubkeys & 1) || (pubkeys == 0);
1785         if (pubkeys_conv.inner != NULL)
1786                 pubkeys_conv = ChannelPublicKeys_clone(&pubkeys_conv);
1787
1788         LDKChannelKeys ret = {
1789                 .this_arg = (void*) calls,
1790                 .get_per_commitment_point = get_per_commitment_point_jcall,
1791                 .release_commitment_secret = release_commitment_secret_jcall,
1792                 .key_derivation_params = key_derivation_params_jcall,
1793                 .sign_counterparty_commitment = sign_counterparty_commitment_jcall,
1794                 .sign_holder_commitment = sign_holder_commitment_jcall,
1795                 .sign_holder_commitment_htlc_transactions = sign_holder_commitment_htlc_transactions_jcall,
1796                 .sign_justice_transaction = sign_justice_transaction_jcall,
1797                 .sign_counterparty_htlc_transaction = sign_counterparty_htlc_transaction_jcall,
1798                 .sign_closing_transaction = sign_closing_transaction_jcall,
1799                 .sign_channel_announcement = sign_channel_announcement_jcall,
1800                 .ready_channel = ready_channel_jcall,
1801                 .clone = LDKChannelKeys_JCalls_clone,
1802                 .write = write_jcall,
1803                 .free = LDKChannelKeys_JCalls_free,
1804                 .pubkeys = pubkeys_conv,
1805                 .set_pubkeys = NULL,
1806         };
1807         return ret;
1808 }
1809 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1new (JNIEnv * env, jclass _a, jobject o, jlong pubkeys) {
1810         LDKChannelKeys *res_ptr = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1811         *res_ptr = LDKChannelKeys_init(env, _a, o, pubkeys);
1812         return (long)res_ptr;
1813 }
1814 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1815         jobject ret = (*env)->NewLocalRef(env, ((LDKChannelKeys_JCalls*)val)->o);
1816         CHECK(ret != NULL);
1817         return ret;
1818 }
1819 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_arg, jlong idx) {
1820         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1821         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
1822         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (this_arg_conv->get_per_commitment_point)(this_arg_conv->this_arg, idx).compressed_form);
1823         return arg_arr;
1824 }
1825
1826 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1release_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_arg, jlong idx) {
1827         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1828         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
1829         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->release_commitment_secret)(this_arg_conv->this_arg, idx).data);
1830         return arg_arr;
1831 }
1832
1833 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1key_1derivation_1params(JNIEnv * _env, jclass _b, jlong this_arg) {
1834         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1835         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
1836         *ret_ref = (this_arg_conv->key_derivation_params)(this_arg_conv->this_arg);
1837         return (long)ret_ref;
1838 }
1839
1840 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jlong commitment_tx) {
1841         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1842         LDKCommitmentTransaction commitment_tx_conv;
1843         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1844         commitment_tx_conv.is_owned = false;
1845         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
1846         *ret_conv = (this_arg_conv->sign_counterparty_commitment)(this_arg_conv->this_arg, &commitment_tx_conv);
1847         return (long)ret_conv;
1848 }
1849
1850 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jlong commitment_tx) {
1851         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1852         LDKHolderCommitmentTransaction commitment_tx_conv;
1853         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1854         commitment_tx_conv.is_owned = false;
1855         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1856         *ret_conv = (this_arg_conv->sign_holder_commitment)(this_arg_conv->this_arg, &commitment_tx_conv);
1857         return (long)ret_conv;
1858 }
1859
1860 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1commitment_1htlc_1transactions(JNIEnv * _env, jclass _b, jlong this_arg, jlong commitment_tx) {
1861         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1862         LDKHolderCommitmentTransaction commitment_tx_conv;
1863         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
1864         commitment_tx_conv.is_owned = false;
1865         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
1866         *ret_conv = (this_arg_conv->sign_holder_commitment_htlc_transactions)(this_arg_conv->this_arg, &commitment_tx_conv);
1867         return (long)ret_conv;
1868 }
1869
1870 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) {
1871         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1872         LDKTransaction justice_tx_ref;
1873         justice_tx_ref.datalen = (*_env)->GetArrayLength (_env, justice_tx);
1874         justice_tx_ref.data = MALLOC(justice_tx_ref.datalen, "LDKTransaction Bytes");
1875         (*_env)->GetByteArrayRegion(_env, justice_tx, 0, justice_tx_ref.datalen, justice_tx_ref.data);
1876         justice_tx_ref.data_is_owned = true;
1877         unsigned char per_commitment_key_arr[32];
1878         CHECK((*_env)->GetArrayLength (_env, per_commitment_key) == 32);
1879         (*_env)->GetByteArrayRegion (_env, per_commitment_key, 0, 32, per_commitment_key_arr);
1880         unsigned char (*per_commitment_key_ref)[32] = &per_commitment_key_arr;
1881         LDKHTLCOutputInCommitment htlc_conv;
1882         htlc_conv.inner = (void*)(htlc & (~1));
1883         htlc_conv.is_owned = false;
1884         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1885         *ret_conv = (this_arg_conv->sign_justice_transaction)(this_arg_conv->this_arg, justice_tx_ref, input, amount, per_commitment_key_ref, &htlc_conv);
1886         return (long)ret_conv;
1887 }
1888
1889 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) {
1890         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1891         LDKTransaction htlc_tx_ref;
1892         htlc_tx_ref.datalen = (*_env)->GetArrayLength (_env, htlc_tx);
1893         htlc_tx_ref.data = MALLOC(htlc_tx_ref.datalen, "LDKTransaction Bytes");
1894         (*_env)->GetByteArrayRegion(_env, htlc_tx, 0, htlc_tx_ref.datalen, htlc_tx_ref.data);
1895         htlc_tx_ref.data_is_owned = true;
1896         LDKPublicKey per_commitment_point_ref;
1897         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
1898         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
1899         LDKHTLCOutputInCommitment htlc_conv;
1900         htlc_conv.inner = (void*)(htlc & (~1));
1901         htlc_conv.is_owned = false;
1902         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1903         *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);
1904         return (long)ret_conv;
1905 }
1906
1907 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1closing_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray closing_tx) {
1908         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1909         LDKTransaction closing_tx_ref;
1910         closing_tx_ref.datalen = (*_env)->GetArrayLength (_env, closing_tx);
1911         closing_tx_ref.data = MALLOC(closing_tx_ref.datalen, "LDKTransaction Bytes");
1912         (*_env)->GetByteArrayRegion(_env, closing_tx, 0, closing_tx_ref.datalen, closing_tx_ref.data);
1913         closing_tx_ref.data_is_owned = true;
1914         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1915         *ret_conv = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_ref);
1916         return (long)ret_conv;
1917 }
1918
1919 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1channel_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
1920         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1921         LDKUnsignedChannelAnnouncement msg_conv;
1922         msg_conv.inner = (void*)(msg & (~1));
1923         msg_conv.is_owned = false;
1924         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
1925         *ret_conv = (this_arg_conv->sign_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
1926         return (long)ret_conv;
1927 }
1928
1929 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1ready_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong channel_parameters) {
1930         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1931         LDKChannelTransactionParameters channel_parameters_conv;
1932         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
1933         channel_parameters_conv.is_owned = false;
1934         (this_arg_conv->ready_channel)(this_arg_conv->this_arg, &channel_parameters_conv);
1935 }
1936
1937 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1write(JNIEnv * _env, jclass _b, jlong this_arg) {
1938         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1939         LDKCVec_u8Z arg_var = (this_arg_conv->write)(this_arg_conv->this_arg);
1940         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
1941         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
1942         CVec_u8Z_free(arg_var);
1943         return arg_arr;
1944 }
1945
1946 LDKChannelPublicKeys LDKChannelKeys_set_get_pubkeys(LDKChannelKeys* this_arg) {
1947         if (this_arg->set_pubkeys != NULL)
1948                 this_arg->set_pubkeys(this_arg);
1949         return this_arg->pubkeys;
1950 }
1951 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
1952         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1953         LDKChannelPublicKeys ret_var = LDKChannelKeys_set_get_pubkeys(this_arg_conv);
1954         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1955         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1956         long ret_ref = (long)ret_var.inner;
1957         if (ret_var.is_owned) {
1958                 ret_ref |= 1;
1959         }
1960         return ret_ref;
1961 }
1962
1963 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelMonitorZ_1new(JNIEnv *_env, jclass _b, jbyteArray a, jlong b) {
1964         LDKC2Tuple_BlockHashChannelMonitorZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
1965         LDKThirtyTwoBytes a_ref;
1966         CHECK((*_env)->GetArrayLength (_env, a) == 32);
1967         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
1968         ret->a = a_ref;
1969         LDKChannelMonitor b_conv;
1970         b_conv.inner = (void*)(b & (~1));
1971         b_conv.is_owned = (b & 1) || (b == 0);
1972         // Warning: we may need a move here but can't clone!
1973         ret->b = b_conv;
1974         return (long)ret;
1975 }
1976 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelMonitorZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
1977         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)ptr;
1978         jbyteArray a_arr = (*_env)->NewByteArray(_env, 32);
1979         (*_env)->SetByteArrayRegion(_env, a_arr, 0, 32, tuple->a.data);
1980         return a_arr;
1981 }
1982 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelMonitorZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
1983         LDKC2Tuple_BlockHashChannelMonitorZ *tuple = (LDKC2Tuple_BlockHashChannelMonitorZ*)ptr;
1984         LDKChannelMonitor b_var = tuple->b;
1985         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1986         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1987         long b_ref = (long)b_var.inner & ~1;
1988         return b_ref;
1989 }
1990 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1991         return ((LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg)->result_ok;
1992 }
1993 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1994         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg;
1995         CHECK(val->result_ok);
1996         long res_ref = (long)&(*val->contents.result);
1997         return res_ref;
1998 }
1999 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2000         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)arg;
2001         CHECK(!val->result_ok);
2002         LDKDecodeError err_var = (*val->contents.err);
2003         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2004         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2005         long err_ref = (long)err_var.inner & ~1;
2006         return err_ref;
2007 }
2008 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2009         return ((LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg)->result_ok;
2010 }
2011 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2012         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg;
2013         CHECK(val->result_ok);
2014         long res_ref = (long)&(*val->contents.result);
2015         return res_ref;
2016 }
2017 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SpendableOutputDescriptorDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2018         LDKCResult_SpendableOutputDescriptorDecodeErrorZ *val = (LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)arg;
2019         CHECK(!val->result_ok);
2020         LDKDecodeError err_var = (*val->contents.err);
2021         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2022         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2023         long err_ref = (long)err_var.inner & ~1;
2024         return err_ref;
2025 }
2026 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChanKeySignerDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2027         return ((LDKCResult_ChanKeySignerDecodeErrorZ*)arg)->result_ok;
2028 }
2029 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChanKeySignerDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2030         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)arg;
2031         CHECK(val->result_ok);
2032         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
2033         *ret = (*val->contents.result);
2034         return (long)ret;
2035 }
2036 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChanKeySignerDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2037         LDKCResult_ChanKeySignerDecodeErrorZ *val = (LDKCResult_ChanKeySignerDecodeErrorZ*)arg;
2038         CHECK(!val->result_ok);
2039         LDKDecodeError err_var = (*val->contents.err);
2040         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2041         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2042         long err_ref = (long)err_var.inner & ~1;
2043         return err_ref;
2044 }
2045 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2046         return ((LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg)->result_ok;
2047 }
2048 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2049         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg;
2050         CHECK(val->result_ok);
2051         LDKInMemoryChannelKeys res_var = (*val->contents.result);
2052         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2053         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2054         long res_ref = (long)res_var.inner & ~1;
2055         return res_ref;
2056 }
2057 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InMemoryChannelKeysDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2058         LDKCResult_InMemoryChannelKeysDecodeErrorZ *val = (LDKCResult_InMemoryChannelKeysDecodeErrorZ*)arg;
2059         CHECK(!val->result_ok);
2060         LDKDecodeError err_var = (*val->contents.err);
2061         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2062         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2063         long err_ref = (long)err_var.inner & ~1;
2064         return err_ref;
2065 }
2066 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2067         return ((LDKCResult_TxOutAccessErrorZ*)arg)->result_ok;
2068 }
2069 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2070         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
2071         CHECK(val->result_ok);
2072         long res_ref = (long)&(*val->contents.result);
2073         return (long)res_ref;
2074 }
2075 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2076         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
2077         CHECK(!val->result_ok);
2078         jclass err_conv = LDKAccessError_to_java(_env, (*val->contents.err));
2079         return err_conv;
2080 }
2081 static jclass LDKAPIError_APIMisuseError_class = NULL;
2082 static jmethodID LDKAPIError_APIMisuseError_meth = NULL;
2083 static jclass LDKAPIError_FeeRateTooHigh_class = NULL;
2084 static jmethodID LDKAPIError_FeeRateTooHigh_meth = NULL;
2085 static jclass LDKAPIError_RouteError_class = NULL;
2086 static jmethodID LDKAPIError_RouteError_meth = NULL;
2087 static jclass LDKAPIError_ChannelUnavailable_class = NULL;
2088 static jmethodID LDKAPIError_ChannelUnavailable_meth = NULL;
2089 static jclass LDKAPIError_MonitorUpdateFailed_class = NULL;
2090 static jmethodID LDKAPIError_MonitorUpdateFailed_meth = NULL;
2091 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKAPIError_init (JNIEnv * env, jclass _a) {
2092         LDKAPIError_APIMisuseError_class =
2093                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$APIMisuseError;"));
2094         CHECK(LDKAPIError_APIMisuseError_class != NULL);
2095         LDKAPIError_APIMisuseError_meth = (*env)->GetMethodID(env, LDKAPIError_APIMisuseError_class, "<init>", "([B)V");
2096         CHECK(LDKAPIError_APIMisuseError_meth != NULL);
2097         LDKAPIError_FeeRateTooHigh_class =
2098                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$FeeRateTooHigh;"));
2099         CHECK(LDKAPIError_FeeRateTooHigh_class != NULL);
2100         LDKAPIError_FeeRateTooHigh_meth = (*env)->GetMethodID(env, LDKAPIError_FeeRateTooHigh_class, "<init>", "([BI)V");
2101         CHECK(LDKAPIError_FeeRateTooHigh_meth != NULL);
2102         LDKAPIError_RouteError_class =
2103                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$RouteError;"));
2104         CHECK(LDKAPIError_RouteError_class != NULL);
2105         LDKAPIError_RouteError_meth = (*env)->GetMethodID(env, LDKAPIError_RouteError_class, "<init>", "(Ljava/lang/String;)V");
2106         CHECK(LDKAPIError_RouteError_meth != NULL);
2107         LDKAPIError_ChannelUnavailable_class =
2108                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$ChannelUnavailable;"));
2109         CHECK(LDKAPIError_ChannelUnavailable_class != NULL);
2110         LDKAPIError_ChannelUnavailable_meth = (*env)->GetMethodID(env, LDKAPIError_ChannelUnavailable_class, "<init>", "([B)V");
2111         CHECK(LDKAPIError_ChannelUnavailable_meth != NULL);
2112         LDKAPIError_MonitorUpdateFailed_class =
2113                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$MonitorUpdateFailed;"));
2114         CHECK(LDKAPIError_MonitorUpdateFailed_class != NULL);
2115         LDKAPIError_MonitorUpdateFailed_meth = (*env)->GetMethodID(env, LDKAPIError_MonitorUpdateFailed_class, "<init>", "()V");
2116         CHECK(LDKAPIError_MonitorUpdateFailed_meth != NULL);
2117 }
2118 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAPIError_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
2119         LDKAPIError *obj = (LDKAPIError*)ptr;
2120         switch(obj->tag) {
2121                 case LDKAPIError_APIMisuseError: {
2122                         LDKCVec_u8Z err_var = obj->api_misuse_error.err;
2123                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
2124                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
2125                         return (*_env)->NewObject(_env, LDKAPIError_APIMisuseError_class, LDKAPIError_APIMisuseError_meth, err_arr);
2126                 }
2127                 case LDKAPIError_FeeRateTooHigh: {
2128                         LDKCVec_u8Z err_var = obj->fee_rate_too_high.err;
2129                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
2130                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
2131                         return (*_env)->NewObject(_env, LDKAPIError_FeeRateTooHigh_class, LDKAPIError_FeeRateTooHigh_meth, err_arr, obj->fee_rate_too_high.feerate);
2132                 }
2133                 case LDKAPIError_RouteError: {
2134                         LDKStr err_str = obj->route_error.err;
2135                         char* err_buf = MALLOC(err_str.len + 1, "str conv buf");
2136                         memcpy(err_buf, err_str.chars, err_str.len);
2137                         err_buf[err_str.len] = 0;
2138                         jstring err_conv = (*_env)->NewStringUTF(_env, err_str.chars);
2139                         FREE(err_buf);
2140                         return (*_env)->NewObject(_env, LDKAPIError_RouteError_class, LDKAPIError_RouteError_meth, err_conv);
2141                 }
2142                 case LDKAPIError_ChannelUnavailable: {
2143                         LDKCVec_u8Z err_var = obj->channel_unavailable.err;
2144                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
2145                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
2146                         return (*_env)->NewObject(_env, LDKAPIError_ChannelUnavailable_class, LDKAPIError_ChannelUnavailable_meth, err_arr);
2147                 }
2148                 case LDKAPIError_MonitorUpdateFailed: {
2149                         return (*_env)->NewObject(_env, LDKAPIError_MonitorUpdateFailed_class, LDKAPIError_MonitorUpdateFailed_meth);
2150                 }
2151                 default: abort();
2152         }
2153 }
2154 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2155         return ((LDKCResult_NoneAPIErrorZ*)arg)->result_ok;
2156 }
2157 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2158         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
2159         CHECK(val->result_ok);
2160         return *val->contents.result;
2161 }
2162 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2163         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
2164         CHECK(!val->result_ok);
2165         long err_ref = (long)&(*val->contents.err);
2166         return err_ref;
2167 }
2168 static inline LDKCResult_NoneAPIErrorZ CResult_NoneAPIErrorZ_clone(const LDKCResult_NoneAPIErrorZ *orig) {
2169         LDKCResult_NoneAPIErrorZ res = { .result_ok = orig->result_ok };
2170         if (orig->result_ok) {
2171                 res.contents.result = NULL;
2172         } else {
2173                 LDKAPIError* contents = MALLOC(sizeof(LDKAPIError), "LDKAPIError result Err clone");
2174                 *contents = APIError_clone(orig->contents.err);
2175                 res.contents.err = contents;
2176         }
2177         return res;
2178 }
2179 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1ChannelDetailsZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2180         LDKCVec_ChannelDetailsZ *vec = (LDKCVec_ChannelDetailsZ*)ptr;
2181         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
2182         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
2183         for (size_t i = 0; i < vec->datalen; i++) {
2184                 CHECK((((long)vec->data[i].inner) & 1) == 0);
2185                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
2186         }
2187         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
2188         return ret;
2189 }
2190 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1ChannelDetailsZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
2191         LDKCVec_ChannelDetailsZ *ret = MALLOC(sizeof(LDKCVec_ChannelDetailsZ), "LDKCVec_ChannelDetailsZ");
2192         ret->datalen = (*env)->GetArrayLength(env, elems);
2193         if (ret->datalen == 0) {
2194                 ret->data = NULL;
2195         } else {
2196                 ret->data = MALLOC(sizeof(LDKChannelDetails) * ret->datalen, "LDKCVec_ChannelDetailsZ Data");
2197                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2198                 for (size_t i = 0; i < ret->datalen; i++) {
2199                         jlong arr_elem = java_elems[i];
2200                         LDKChannelDetails arr_elem_conv;
2201                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2202                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2203                         if (arr_elem_conv.inner != NULL)
2204                                 arr_elem_conv = ChannelDetails_clone(&arr_elem_conv);
2205                         ret->data[i] = arr_elem_conv;
2206                 }
2207                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2208         }
2209         return (long)ret;
2210 }
2211 static inline LDKCVec_ChannelDetailsZ CVec_ChannelDetailsZ_clone(const LDKCVec_ChannelDetailsZ *orig) {
2212         LDKCVec_ChannelDetailsZ ret = { .data = MALLOC(sizeof(LDKChannelDetails) * orig->datalen, "LDKCVec_ChannelDetailsZ clone bytes"), .datalen = orig->datalen };
2213         for (size_t i = 0; i < ret.datalen; i++) {
2214                 ret.data[i] = ChannelDetails_clone(&orig->data[i]);
2215         }
2216         return ret;
2217 }
2218 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2219         return ((LDKCResult_NonePaymentSendFailureZ*)arg)->result_ok;
2220 }
2221 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2222         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
2223         CHECK(val->result_ok);
2224         return *val->contents.result;
2225 }
2226 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2227         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
2228         CHECK(!val->result_ok);
2229         LDKPaymentSendFailure err_var = (*val->contents.err);
2230         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2231         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2232         long err_ref = (long)err_var.inner & ~1;
2233         return err_ref;
2234 }
2235 static jclass LDKNetAddress_IPv4_class = NULL;
2236 static jmethodID LDKNetAddress_IPv4_meth = NULL;
2237 static jclass LDKNetAddress_IPv6_class = NULL;
2238 static jmethodID LDKNetAddress_IPv6_meth = NULL;
2239 static jclass LDKNetAddress_OnionV2_class = NULL;
2240 static jmethodID LDKNetAddress_OnionV2_meth = NULL;
2241 static jclass LDKNetAddress_OnionV3_class = NULL;
2242 static jmethodID LDKNetAddress_OnionV3_meth = NULL;
2243 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKNetAddress_init (JNIEnv * env, jclass _a) {
2244         LDKNetAddress_IPv4_class =
2245                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv4;"));
2246         CHECK(LDKNetAddress_IPv4_class != NULL);
2247         LDKNetAddress_IPv4_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv4_class, "<init>", "([BS)V");
2248         CHECK(LDKNetAddress_IPv4_meth != NULL);
2249         LDKNetAddress_IPv6_class =
2250                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv6;"));
2251         CHECK(LDKNetAddress_IPv6_class != NULL);
2252         LDKNetAddress_IPv6_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv6_class, "<init>", "([BS)V");
2253         CHECK(LDKNetAddress_IPv6_meth != NULL);
2254         LDKNetAddress_OnionV2_class =
2255                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV2;"));
2256         CHECK(LDKNetAddress_OnionV2_class != NULL);
2257         LDKNetAddress_OnionV2_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV2_class, "<init>", "([BS)V");
2258         CHECK(LDKNetAddress_OnionV2_meth != NULL);
2259         LDKNetAddress_OnionV3_class =
2260                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV3;"));
2261         CHECK(LDKNetAddress_OnionV3_class != NULL);
2262         LDKNetAddress_OnionV3_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV3_class, "<init>", "([BSBS)V");
2263         CHECK(LDKNetAddress_OnionV3_meth != NULL);
2264 }
2265 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKNetAddress_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
2266         LDKNetAddress *obj = (LDKNetAddress*)ptr;
2267         switch(obj->tag) {
2268                 case LDKNetAddress_IPv4: {
2269                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 4);
2270                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 4, obj->i_pv4.addr.data);
2271                         return (*_env)->NewObject(_env, LDKNetAddress_IPv4_class, LDKNetAddress_IPv4_meth, addr_arr, obj->i_pv4.port);
2272                 }
2273                 case LDKNetAddress_IPv6: {
2274                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 16);
2275                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 16, obj->i_pv6.addr.data);
2276                         return (*_env)->NewObject(_env, LDKNetAddress_IPv6_class, LDKNetAddress_IPv6_meth, addr_arr, obj->i_pv6.port);
2277                 }
2278                 case LDKNetAddress_OnionV2: {
2279                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 10);
2280                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 10, obj->onion_v2.addr.data);
2281                         return (*_env)->NewObject(_env, LDKNetAddress_OnionV2_class, LDKNetAddress_OnionV2_meth, addr_arr, obj->onion_v2.port);
2282                 }
2283                 case LDKNetAddress_OnionV3: {
2284                         jbyteArray ed25519_pubkey_arr = (*_env)->NewByteArray(_env, 32);
2285                         (*_env)->SetByteArrayRegion(_env, ed25519_pubkey_arr, 0, 32, obj->onion_v3.ed25519_pubkey.data);
2286                         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);
2287                 }
2288                 default: abort();
2289         }
2290 }
2291 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1NetAddressZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2292         LDKCVec_NetAddressZ *vec = (LDKCVec_NetAddressZ*)ptr;
2293         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKNetAddress));
2294 }
2295 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1NetAddressZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
2296         LDKCVec_NetAddressZ *ret = MALLOC(sizeof(LDKCVec_NetAddressZ), "LDKCVec_NetAddressZ");
2297         ret->datalen = (*env)->GetArrayLength(env, elems);
2298         if (ret->datalen == 0) {
2299                 ret->data = NULL;
2300         } else {
2301                 ret->data = MALLOC(sizeof(LDKNetAddress) * ret->datalen, "LDKCVec_NetAddressZ Data");
2302                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2303                 for (size_t i = 0; i < ret->datalen; i++) {
2304                         jlong arr_elem = java_elems[i];
2305                         LDKNetAddress arr_elem_conv = *(LDKNetAddress*)arr_elem;
2306                         FREE((void*)arr_elem);
2307                         ret->data[i] = arr_elem_conv;
2308                 }
2309                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2310         }
2311         return (long)ret;
2312 }
2313 static inline LDKCVec_NetAddressZ CVec_NetAddressZ_clone(const LDKCVec_NetAddressZ *orig) {
2314         LDKCVec_NetAddressZ ret = { .data = MALLOC(sizeof(LDKNetAddress) * orig->datalen, "LDKCVec_NetAddressZ clone bytes"), .datalen = orig->datalen };
2315         for (size_t i = 0; i < ret.datalen; i++) {
2316                 ret.data[i] = NetAddress_clone(&orig->data[i]);
2317         }
2318         return ret;
2319 }
2320 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1ChannelMonitorZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2321         LDKCVec_ChannelMonitorZ *vec = (LDKCVec_ChannelMonitorZ*)ptr;
2322         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
2323         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
2324         for (size_t i = 0; i < vec->datalen; i++) {
2325                 CHECK((((long)vec->data[i].inner) & 1) == 0);
2326                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
2327         }
2328         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
2329         return ret;
2330 }
2331 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1ChannelMonitorZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
2332         LDKCVec_ChannelMonitorZ *ret = MALLOC(sizeof(LDKCVec_ChannelMonitorZ), "LDKCVec_ChannelMonitorZ");
2333         ret->datalen = (*env)->GetArrayLength(env, elems);
2334         if (ret->datalen == 0) {
2335                 ret->data = NULL;
2336         } else {
2337                 ret->data = MALLOC(sizeof(LDKChannelMonitor) * ret->datalen, "LDKCVec_ChannelMonitorZ Data");
2338                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2339                 for (size_t i = 0; i < ret->datalen; i++) {
2340                         jlong arr_elem = java_elems[i];
2341                         LDKChannelMonitor arr_elem_conv;
2342                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2343                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2344                         // Warning: we may need a move here but can't clone!
2345                         ret->data[i] = arr_elem_conv;
2346                 }
2347                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2348         }
2349         return (long)ret;
2350 }
2351 typedef struct LDKWatch_JCalls {
2352         atomic_size_t refcnt;
2353         JavaVM *vm;
2354         jweak o;
2355         jmethodID watch_channel_meth;
2356         jmethodID update_channel_meth;
2357         jmethodID release_pending_monitor_events_meth;
2358 } LDKWatch_JCalls;
2359 LDKCResult_NoneChannelMonitorUpdateErrZ watch_channel_jcall(const void* this_arg, struct LDKOutPoint funding_txo, struct LDKChannelMonitor monitor) {
2360         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2361         JNIEnv *_env;
2362         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2363         LDKOutPoint funding_txo_var = funding_txo;
2364         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2365         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2366         long funding_txo_ref = (long)funding_txo_var.inner;
2367         if (funding_txo_var.is_owned) {
2368                 funding_txo_ref |= 1;
2369         }
2370         LDKChannelMonitor monitor_var = monitor;
2371         CHECK((((long)monitor_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2372         CHECK((((long)&monitor_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2373         long monitor_ref = (long)monitor_var.inner;
2374         if (monitor_var.is_owned) {
2375                 monitor_ref |= 1;
2376         }
2377         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2378         CHECK(obj != NULL);
2379         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->watch_channel_meth, funding_txo_ref, monitor_ref);
2380         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2381         FREE((void*)ret);
2382         return ret_conv;
2383 }
2384 LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_jcall(const void* this_arg, struct LDKOutPoint funding_txo, struct LDKChannelMonitorUpdate update) {
2385         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2386         JNIEnv *_env;
2387         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2388         LDKOutPoint funding_txo_var = funding_txo;
2389         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2390         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2391         long funding_txo_ref = (long)funding_txo_var.inner;
2392         if (funding_txo_var.is_owned) {
2393                 funding_txo_ref |= 1;
2394         }
2395         LDKChannelMonitorUpdate update_var = update;
2396         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2397         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2398         long update_ref = (long)update_var.inner;
2399         if (update_var.is_owned) {
2400                 update_ref |= 1;
2401         }
2402         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2403         CHECK(obj != NULL);
2404         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->update_channel_meth, funding_txo_ref, update_ref);
2405         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2406         FREE((void*)ret);
2407         return ret_conv;
2408 }
2409 LDKCVec_MonitorEventZ release_pending_monitor_events_jcall(const void* this_arg) {
2410         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2411         JNIEnv *_env;
2412         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2413         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2414         CHECK(obj != NULL);
2415         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->release_pending_monitor_events_meth);
2416         LDKCVec_MonitorEventZ arg_constr;
2417         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
2418         if (arg_constr.datalen > 0)
2419                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
2420         else
2421                 arg_constr.data = NULL;
2422         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
2423         for (size_t o = 0; o < arg_constr.datalen; o++) {
2424                 long arr_conv_14 = arg_vals[o];
2425                 LDKMonitorEvent arr_conv_14_conv;
2426                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
2427                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
2428                 if (arr_conv_14_conv.inner != NULL)
2429                         arr_conv_14_conv = MonitorEvent_clone(&arr_conv_14_conv);
2430                 arg_constr.data[o] = arr_conv_14_conv;
2431         }
2432         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
2433         return arg_constr;
2434 }
2435 static void LDKWatch_JCalls_free(void* this_arg) {
2436         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2437         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2438                 JNIEnv *env;
2439                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2440                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2441                 FREE(j_calls);
2442         }
2443 }
2444 static void* LDKWatch_JCalls_clone(const void* this_arg) {
2445         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2446         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2447         return (void*) this_arg;
2448 }
2449 static inline LDKWatch LDKWatch_init (JNIEnv * env, jclass _a, jobject o) {
2450         jclass c = (*env)->GetObjectClass(env, o);
2451         CHECK(c != NULL);
2452         LDKWatch_JCalls *calls = MALLOC(sizeof(LDKWatch_JCalls), "LDKWatch_JCalls");
2453         atomic_init(&calls->refcnt, 1);
2454         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2455         calls->o = (*env)->NewWeakGlobalRef(env, o);
2456         calls->watch_channel_meth = (*env)->GetMethodID(env, c, "watch_channel", "(JJ)J");
2457         CHECK(calls->watch_channel_meth != NULL);
2458         calls->update_channel_meth = (*env)->GetMethodID(env, c, "update_channel", "(JJ)J");
2459         CHECK(calls->update_channel_meth != NULL);
2460         calls->release_pending_monitor_events_meth = (*env)->GetMethodID(env, c, "release_pending_monitor_events", "()[J");
2461         CHECK(calls->release_pending_monitor_events_meth != NULL);
2462
2463         LDKWatch ret = {
2464                 .this_arg = (void*) calls,
2465                 .watch_channel = watch_channel_jcall,
2466                 .update_channel = update_channel_jcall,
2467                 .release_pending_monitor_events = release_pending_monitor_events_jcall,
2468                 .free = LDKWatch_JCalls_free,
2469         };
2470         return ret;
2471 }
2472 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKWatch_1new (JNIEnv * env, jclass _a, jobject o) {
2473         LDKWatch *res_ptr = MALLOC(sizeof(LDKWatch), "LDKWatch");
2474         *res_ptr = LDKWatch_init(env, _a, o);
2475         return (long)res_ptr;
2476 }
2477 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKWatch_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2478         jobject ret = (*env)->NewLocalRef(env, ((LDKWatch_JCalls*)val)->o);
2479         CHECK(ret != NULL);
2480         return ret;
2481 }
2482 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Watch_1watch_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong funding_txo, jlong monitor) {
2483         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2484         LDKOutPoint funding_txo_conv;
2485         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2486         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2487         if (funding_txo_conv.inner != NULL)
2488                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2489         LDKChannelMonitor monitor_conv;
2490         monitor_conv.inner = (void*)(monitor & (~1));
2491         monitor_conv.is_owned = (monitor & 1) || (monitor == 0);
2492         // Warning: we may need a move here but can't clone!
2493         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2494         *ret_conv = (this_arg_conv->watch_channel)(this_arg_conv->this_arg, funding_txo_conv, monitor_conv);
2495         return (long)ret_conv;
2496 }
2497
2498 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Watch_1update_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong funding_txo, jlong update) {
2499         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2500         LDKOutPoint funding_txo_conv;
2501         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2502         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2503         if (funding_txo_conv.inner != NULL)
2504                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2505         LDKChannelMonitorUpdate update_conv;
2506         update_conv.inner = (void*)(update & (~1));
2507         update_conv.is_owned = (update & 1) || (update == 0);
2508         if (update_conv.inner != NULL)
2509                 update_conv = ChannelMonitorUpdate_clone(&update_conv);
2510         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2511         *ret_conv = (this_arg_conv->update_channel)(this_arg_conv->this_arg, funding_txo_conv, update_conv);
2512         return (long)ret_conv;
2513 }
2514
2515 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_Watch_1release_1pending_1monitor_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
2516         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2517         LDKCVec_MonitorEventZ ret_var = (this_arg_conv->release_pending_monitor_events)(this_arg_conv->this_arg);
2518         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
2519         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
2520         for (size_t o = 0; o < ret_var.datalen; o++) {
2521                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
2522                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2523                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2524                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
2525                 if (arr_conv_14_var.is_owned) {
2526                         arr_conv_14_ref |= 1;
2527                 }
2528                 ret_arr_ptr[o] = arr_conv_14_ref;
2529         }
2530         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
2531         FREE(ret_var.data);
2532         return ret_arr;
2533 }
2534
2535 typedef struct LDKBroadcasterInterface_JCalls {
2536         atomic_size_t refcnt;
2537         JavaVM *vm;
2538         jweak o;
2539         jmethodID broadcast_transaction_meth;
2540 } LDKBroadcasterInterface_JCalls;
2541 void broadcast_transaction_jcall(const void* this_arg, struct LDKTransaction tx) {
2542         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2543         JNIEnv *_env;
2544         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2545         LDKTransaction tx_var = tx;
2546         jbyteArray tx_arr = (*_env)->NewByteArray(_env, tx_var.datalen);
2547         (*_env)->SetByteArrayRegion(_env, tx_arr, 0, tx_var.datalen, tx_var.data);
2548         Transaction_free(tx_var);
2549         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2550         CHECK(obj != NULL);
2551         return (*_env)->CallVoidMethod(_env, obj, j_calls->broadcast_transaction_meth, tx_arr);
2552 }
2553 static void LDKBroadcasterInterface_JCalls_free(void* this_arg) {
2554         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2555         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2556                 JNIEnv *env;
2557                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2558                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2559                 FREE(j_calls);
2560         }
2561 }
2562 static void* LDKBroadcasterInterface_JCalls_clone(const void* this_arg) {
2563         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2564         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2565         return (void*) this_arg;
2566 }
2567 static inline LDKBroadcasterInterface LDKBroadcasterInterface_init (JNIEnv * env, jclass _a, jobject o) {
2568         jclass c = (*env)->GetObjectClass(env, o);
2569         CHECK(c != NULL);
2570         LDKBroadcasterInterface_JCalls *calls = MALLOC(sizeof(LDKBroadcasterInterface_JCalls), "LDKBroadcasterInterface_JCalls");
2571         atomic_init(&calls->refcnt, 1);
2572         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2573         calls->o = (*env)->NewWeakGlobalRef(env, o);
2574         calls->broadcast_transaction_meth = (*env)->GetMethodID(env, c, "broadcast_transaction", "([B)V");
2575         CHECK(calls->broadcast_transaction_meth != NULL);
2576
2577         LDKBroadcasterInterface ret = {
2578                 .this_arg = (void*) calls,
2579                 .broadcast_transaction = broadcast_transaction_jcall,
2580                 .free = LDKBroadcasterInterface_JCalls_free,
2581         };
2582         return ret;
2583 }
2584 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1new (JNIEnv * env, jclass _a, jobject o) {
2585         LDKBroadcasterInterface *res_ptr = MALLOC(sizeof(LDKBroadcasterInterface), "LDKBroadcasterInterface");
2586         *res_ptr = LDKBroadcasterInterface_init(env, _a, o);
2587         return (long)res_ptr;
2588 }
2589 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2590         jobject ret = (*env)->NewLocalRef(env, ((LDKBroadcasterInterface_JCalls*)val)->o);
2591         CHECK(ret != NULL);
2592         return ret;
2593 }
2594 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1broadcast_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray tx) {
2595         LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg;
2596         LDKTransaction tx_ref;
2597         tx_ref.datalen = (*_env)->GetArrayLength (_env, tx);
2598         tx_ref.data = MALLOC(tx_ref.datalen, "LDKTransaction Bytes");
2599         (*_env)->GetByteArrayRegion(_env, tx, 0, tx_ref.datalen, tx_ref.data);
2600         tx_ref.data_is_owned = true;
2601         (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_ref);
2602 }
2603
2604 typedef struct LDKKeysInterface_JCalls {
2605         atomic_size_t refcnt;
2606         JavaVM *vm;
2607         jweak o;
2608         jmethodID get_node_secret_meth;
2609         jmethodID get_destination_script_meth;
2610         jmethodID get_shutdown_pubkey_meth;
2611         jmethodID get_channel_keys_meth;
2612         jmethodID get_secure_random_bytes_meth;
2613         jmethodID read_chan_signer_meth;
2614 } LDKKeysInterface_JCalls;
2615 LDKSecretKey get_node_secret_jcall(const void* this_arg) {
2616         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2617         JNIEnv *_env;
2618         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2619         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2620         CHECK(obj != NULL);
2621         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_node_secret_meth);
2622         LDKSecretKey arg_ref;
2623         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
2624         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.bytes);
2625         return arg_ref;
2626 }
2627 LDKCVec_u8Z get_destination_script_jcall(const void* this_arg) {
2628         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2629         JNIEnv *_env;
2630         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2631         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2632         CHECK(obj != NULL);
2633         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_destination_script_meth);
2634         LDKCVec_u8Z arg_ref;
2635         arg_ref.datalen = (*_env)->GetArrayLength (_env, arg);
2636         arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes");
2637         (*_env)->GetByteArrayRegion(_env, arg, 0, arg_ref.datalen, arg_ref.data);
2638         return arg_ref;
2639 }
2640 LDKPublicKey get_shutdown_pubkey_jcall(const void* this_arg) {
2641         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2642         JNIEnv *_env;
2643         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2644         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2645         CHECK(obj != NULL);
2646         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_shutdown_pubkey_meth);
2647         LDKPublicKey arg_ref;
2648         CHECK((*_env)->GetArrayLength (_env, arg) == 33);
2649         (*_env)->GetByteArrayRegion (_env, arg, 0, 33, arg_ref.compressed_form);
2650         return arg_ref;
2651 }
2652 LDKChannelKeys get_channel_keys_jcall(const void* this_arg, bool inbound, uint64_t channel_value_satoshis) {
2653         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2654         JNIEnv *_env;
2655         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2656         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2657         CHECK(obj != NULL);
2658         LDKChannelKeys* ret = (LDKChannelKeys*)(*_env)->CallLongMethod(_env, obj, j_calls->get_channel_keys_meth, inbound, channel_value_satoshis);
2659         LDKChannelKeys ret_conv = *(LDKChannelKeys*)ret;
2660         ret_conv = ChannelKeys_clone(ret);
2661         return ret_conv;
2662 }
2663 LDKThirtyTwoBytes get_secure_random_bytes_jcall(const void* this_arg) {
2664         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2665         JNIEnv *_env;
2666         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2667         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2668         CHECK(obj != NULL);
2669         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_secure_random_bytes_meth);
2670         LDKThirtyTwoBytes arg_ref;
2671         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
2672         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.data);
2673         return arg_ref;
2674 }
2675 LDKCResult_ChanKeySignerDecodeErrorZ read_chan_signer_jcall(const void* this_arg, struct LDKu8slice reader) {
2676         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2677         JNIEnv *_env;
2678         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2679         LDKu8slice reader_var = reader;
2680         jbyteArray reader_arr = (*_env)->NewByteArray(_env, reader_var.datalen);
2681         (*_env)->SetByteArrayRegion(_env, reader_arr, 0, reader_var.datalen, reader_var.data);
2682         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2683         CHECK(obj != NULL);
2684         LDKCResult_ChanKeySignerDecodeErrorZ* ret = (LDKCResult_ChanKeySignerDecodeErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->read_chan_signer_meth, reader_arr);
2685         LDKCResult_ChanKeySignerDecodeErrorZ ret_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)ret;
2686         FREE((void*)ret);
2687         return ret_conv;
2688 }
2689 static void LDKKeysInterface_JCalls_free(void* this_arg) {
2690         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2691         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2692                 JNIEnv *env;
2693                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2694                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2695                 FREE(j_calls);
2696         }
2697 }
2698 static void* LDKKeysInterface_JCalls_clone(const void* this_arg) {
2699         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2700         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2701         return (void*) this_arg;
2702 }
2703 static inline LDKKeysInterface LDKKeysInterface_init (JNIEnv * env, jclass _a, jobject o) {
2704         jclass c = (*env)->GetObjectClass(env, o);
2705         CHECK(c != NULL);
2706         LDKKeysInterface_JCalls *calls = MALLOC(sizeof(LDKKeysInterface_JCalls), "LDKKeysInterface_JCalls");
2707         atomic_init(&calls->refcnt, 1);
2708         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2709         calls->o = (*env)->NewWeakGlobalRef(env, o);
2710         calls->get_node_secret_meth = (*env)->GetMethodID(env, c, "get_node_secret", "()[B");
2711         CHECK(calls->get_node_secret_meth != NULL);
2712         calls->get_destination_script_meth = (*env)->GetMethodID(env, c, "get_destination_script", "()[B");
2713         CHECK(calls->get_destination_script_meth != NULL);
2714         calls->get_shutdown_pubkey_meth = (*env)->GetMethodID(env, c, "get_shutdown_pubkey", "()[B");
2715         CHECK(calls->get_shutdown_pubkey_meth != NULL);
2716         calls->get_channel_keys_meth = (*env)->GetMethodID(env, c, "get_channel_keys", "(ZJ)J");
2717         CHECK(calls->get_channel_keys_meth != NULL);
2718         calls->get_secure_random_bytes_meth = (*env)->GetMethodID(env, c, "get_secure_random_bytes", "()[B");
2719         CHECK(calls->get_secure_random_bytes_meth != NULL);
2720         calls->read_chan_signer_meth = (*env)->GetMethodID(env, c, "read_chan_signer", "([B)J");
2721         CHECK(calls->read_chan_signer_meth != NULL);
2722
2723         LDKKeysInterface ret = {
2724                 .this_arg = (void*) calls,
2725                 .get_node_secret = get_node_secret_jcall,
2726                 .get_destination_script = get_destination_script_jcall,
2727                 .get_shutdown_pubkey = get_shutdown_pubkey_jcall,
2728                 .get_channel_keys = get_channel_keys_jcall,
2729                 .get_secure_random_bytes = get_secure_random_bytes_jcall,
2730                 .read_chan_signer = read_chan_signer_jcall,
2731                 .free = LDKKeysInterface_JCalls_free,
2732         };
2733         return ret;
2734 }
2735 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1new (JNIEnv * env, jclass _a, jobject o) {
2736         LDKKeysInterface *res_ptr = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
2737         *res_ptr = LDKKeysInterface_init(env, _a, o);
2738         return (long)res_ptr;
2739 }
2740 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2741         jobject ret = (*env)->NewLocalRef(env, ((LDKKeysInterface_JCalls*)val)->o);
2742         CHECK(ret != NULL);
2743         return ret;
2744 }
2745 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1node_1secret(JNIEnv * _env, jclass _b, jlong this_arg) {
2746         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2747         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
2748         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->get_node_secret)(this_arg_conv->this_arg).bytes);
2749         return arg_arr;
2750 }
2751
2752 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1destination_1script(JNIEnv * _env, jclass _b, jlong this_arg) {
2753         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2754         LDKCVec_u8Z arg_var = (this_arg_conv->get_destination_script)(this_arg_conv->this_arg);
2755         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
2756         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
2757         CVec_u8Z_free(arg_var);
2758         return arg_arr;
2759 }
2760
2761 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_arg) {
2762         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2763         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
2764         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (this_arg_conv->get_shutdown_pubkey)(this_arg_conv->this_arg).compressed_form);
2765         return arg_arr;
2766 }
2767
2768 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) {
2769         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2770         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
2771         *ret = (this_arg_conv->get_channel_keys)(this_arg_conv->this_arg, inbound, channel_value_satoshis);
2772         return (long)ret;
2773 }
2774
2775 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1secure_1random_1bytes(JNIEnv * _env, jclass _b, jlong this_arg) {
2776         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2777         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
2778         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->get_secure_random_bytes)(this_arg_conv->this_arg).data);
2779         return arg_arr;
2780 }
2781
2782 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_KeysInterface_1read_1chan_1signer(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray reader) {
2783         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2784         LDKu8slice reader_ref;
2785         reader_ref.datalen = (*_env)->GetArrayLength (_env, reader);
2786         reader_ref.data = (*_env)->GetByteArrayElements (_env, reader, NULL);
2787         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
2788         *ret_conv = (this_arg_conv->read_chan_signer)(this_arg_conv->this_arg, reader_ref);
2789         (*_env)->ReleaseByteArrayElements(_env, reader, (int8_t*)reader_ref.data, 0);
2790         return (long)ret_conv;
2791 }
2792
2793 typedef struct LDKFeeEstimator_JCalls {
2794         atomic_size_t refcnt;
2795         JavaVM *vm;
2796         jweak o;
2797         jmethodID get_est_sat_per_1000_weight_meth;
2798 } LDKFeeEstimator_JCalls;
2799 uint32_t get_est_sat_per_1000_weight_jcall(const void* this_arg, enum LDKConfirmationTarget confirmation_target) {
2800         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2801         JNIEnv *_env;
2802         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2803         jclass confirmation_target_conv = LDKConfirmationTarget_to_java(_env, confirmation_target);
2804         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2805         CHECK(obj != NULL);
2806         return (*_env)->CallIntMethod(_env, obj, j_calls->get_est_sat_per_1000_weight_meth, confirmation_target_conv);
2807 }
2808 static void LDKFeeEstimator_JCalls_free(void* this_arg) {
2809         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2810         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2811                 JNIEnv *env;
2812                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2813                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2814                 FREE(j_calls);
2815         }
2816 }
2817 static void* LDKFeeEstimator_JCalls_clone(const void* this_arg) {
2818         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2819         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2820         return (void*) this_arg;
2821 }
2822 static inline LDKFeeEstimator LDKFeeEstimator_init (JNIEnv * env, jclass _a, jobject o) {
2823         jclass c = (*env)->GetObjectClass(env, o);
2824         CHECK(c != NULL);
2825         LDKFeeEstimator_JCalls *calls = MALLOC(sizeof(LDKFeeEstimator_JCalls), "LDKFeeEstimator_JCalls");
2826         atomic_init(&calls->refcnt, 1);
2827         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2828         calls->o = (*env)->NewWeakGlobalRef(env, o);
2829         calls->get_est_sat_per_1000_weight_meth = (*env)->GetMethodID(env, c, "get_est_sat_per_1000_weight", "(Lorg/ldk/enums/LDKConfirmationTarget;)I");
2830         CHECK(calls->get_est_sat_per_1000_weight_meth != NULL);
2831
2832         LDKFeeEstimator ret = {
2833                 .this_arg = (void*) calls,
2834                 .get_est_sat_per_1000_weight = get_est_sat_per_1000_weight_jcall,
2835                 .free = LDKFeeEstimator_JCalls_free,
2836         };
2837         return ret;
2838 }
2839 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1new (JNIEnv * env, jclass _a, jobject o) {
2840         LDKFeeEstimator *res_ptr = MALLOC(sizeof(LDKFeeEstimator), "LDKFeeEstimator");
2841         *res_ptr = LDKFeeEstimator_init(env, _a, o);
2842         return (long)res_ptr;
2843 }
2844 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2845         jobject ret = (*env)->NewLocalRef(env, ((LDKFeeEstimator_JCalls*)val)->o);
2846         CHECK(ret != NULL);
2847         return ret;
2848 }
2849 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) {
2850         LDKFeeEstimator* this_arg_conv = (LDKFeeEstimator*)this_arg;
2851         LDKConfirmationTarget confirmation_target_conv = LDKConfirmationTarget_from_java(_env, confirmation_target);
2852         jint ret_val = (this_arg_conv->get_est_sat_per_1000_weight)(this_arg_conv->this_arg, confirmation_target_conv);
2853         return ret_val;
2854 }
2855
2856 typedef struct LDKLogger_JCalls {
2857         atomic_size_t refcnt;
2858         JavaVM *vm;
2859         jweak o;
2860         jmethodID log_meth;
2861 } LDKLogger_JCalls;
2862 void log_jcall(const void* this_arg, const char *record) {
2863         LDKLogger_JCalls *j_calls = (LDKLogger_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         jstring record_conv = (*_env)->NewStringUTF(_env, record);
2867         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2868         CHECK(obj != NULL);
2869         return (*_env)->CallVoidMethod(_env, obj, j_calls->log_meth, record_conv);
2870 }
2871 static void LDKLogger_JCalls_free(void* this_arg) {
2872         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2873         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2874                 JNIEnv *env;
2875                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2876                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2877                 FREE(j_calls);
2878         }
2879 }
2880 static void* LDKLogger_JCalls_clone(const void* this_arg) {
2881         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
2882         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2883         return (void*) this_arg;
2884 }
2885 static inline LDKLogger LDKLogger_init (JNIEnv * env, jclass _a, jobject o) {
2886         jclass c = (*env)->GetObjectClass(env, o);
2887         CHECK(c != NULL);
2888         LDKLogger_JCalls *calls = MALLOC(sizeof(LDKLogger_JCalls), "LDKLogger_JCalls");
2889         atomic_init(&calls->refcnt, 1);
2890         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2891         calls->o = (*env)->NewWeakGlobalRef(env, o);
2892         calls->log_meth = (*env)->GetMethodID(env, c, "log", "(Ljava/lang/String;)V");
2893         CHECK(calls->log_meth != NULL);
2894
2895         LDKLogger ret = {
2896                 .this_arg = (void*) calls,
2897                 .log = log_jcall,
2898                 .free = LDKLogger_JCalls_free,
2899         };
2900         return ret;
2901 }
2902 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKLogger_1new (JNIEnv * env, jclass _a, jobject o) {
2903         LDKLogger *res_ptr = MALLOC(sizeof(LDKLogger), "LDKLogger");
2904         *res_ptr = LDKLogger_init(env, _a, o);
2905         return (long)res_ptr;
2906 }
2907 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKLogger_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2908         jobject ret = (*env)->NewLocalRef(env, ((LDKLogger_JCalls*)val)->o);
2909         CHECK(ret != NULL);
2910         return ret;
2911 }
2912 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelManagerZ_1new(JNIEnv *_env, jclass _b, jbyteArray a, jlong b) {
2913         LDKC2Tuple_BlockHashChannelManagerZ* ret = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
2914         LDKThirtyTwoBytes a_ref;
2915         CHECK((*_env)->GetArrayLength (_env, a) == 32);
2916         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
2917         ret->a = a_ref;
2918         LDKChannelManager b_conv;
2919         b_conv.inner = (void*)(b & (~1));
2920         b_conv.is_owned = (b & 1) || (b == 0);
2921         // Warning: we may need a move here but can't clone!
2922         ret->b = b_conv;
2923         return (long)ret;
2924 }
2925 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelManagerZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
2926         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)ptr;
2927         jbyteArray a_arr = (*_env)->NewByteArray(_env, 32);
2928         (*_env)->SetByteArrayRegion(_env, a_arr, 0, 32, tuple->a.data);
2929         return a_arr;
2930 }
2931 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1BlockHashChannelManagerZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
2932         LDKC2Tuple_BlockHashChannelManagerZ *tuple = (LDKC2Tuple_BlockHashChannelManagerZ*)ptr;
2933         LDKChannelManager b_var = tuple->b;
2934         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2935         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2936         long b_ref = (long)b_var.inner & ~1;
2937         return b_ref;
2938 }
2939 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2940         return ((LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg)->result_ok;
2941 }
2942 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2943         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg;
2944         CHECK(val->result_ok);
2945         long res_ref = (long)&(*val->contents.result);
2946         return res_ref;
2947 }
2948 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2949         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ *val = (LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)arg;
2950         CHECK(!val->result_ok);
2951         LDKDecodeError err_var = (*val->contents.err);
2952         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2953         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2954         long err_ref = (long)err_var.inner & ~1;
2955         return err_ref;
2956 }
2957 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetAddressu8Z_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2958         return ((LDKCResult_NetAddressu8Z*)arg)->result_ok;
2959 }
2960 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetAddressu8Z_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2961         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)arg;
2962         CHECK(val->result_ok);
2963         long res_ref = (long)&(*val->contents.result);
2964         return res_ref;
2965 }
2966 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetAddressu8Z_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2967         LDKCResult_NetAddressu8Z *val = (LDKCResult_NetAddressu8Z*)arg;
2968         CHECK(!val->result_ok);
2969         return *val->contents.err;
2970 }
2971 static inline LDKCResult_NetAddressu8Z CResult_NetAddressu8Z_clone(const LDKCResult_NetAddressu8Z *orig) {
2972         LDKCResult_NetAddressu8Z res = { .result_ok = orig->result_ok };
2973         if (orig->result_ok) {
2974                 LDKNetAddress* contents = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress result OK clone");
2975                 *contents = NetAddress_clone(orig->contents.result);
2976                 res.contents.result = contents;
2977         } else {
2978                 jbyte* contents = MALLOC(sizeof(jbyte), "jbyte result Err clone");
2979                 *contents = *orig->contents.err;
2980                 res.contents.err = contents;
2981         }
2982         return res;
2983 }
2984 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
2985         return ((LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg)->result_ok;
2986 }
2987 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
2988         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg;
2989         CHECK(val->result_ok);
2990         LDKCResult_NetAddressu8Z* res_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
2991         *res_conv = (*val->contents.result);
2992         *res_conv = CResult_NetAddressu8Z_clone(res_conv);
2993         return (long)res_conv;
2994 }
2995 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CResult_1NetAddressu8ZDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
2996         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ *val = (LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)arg;
2997         CHECK(!val->result_ok);
2998         LDKDecodeError err_var = (*val->contents.err);
2999         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3000         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3001         long err_ref = (long)err_var.inner & ~1;
3002         return err_ref;
3003 }
3004 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1u64Z_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3005         LDKCVec_u64Z *vec = (LDKCVec_u64Z*)ptr;
3006         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(uint64_t));
3007 }
3008 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1u64Z_1new(JNIEnv *env, jclass _b, jlongArray elems){
3009         LDKCVec_u64Z *ret = MALLOC(sizeof(LDKCVec_u64Z), "LDKCVec_u64Z");
3010         ret->datalen = (*env)->GetArrayLength(env, elems);
3011         if (ret->datalen == 0) {
3012                 ret->data = NULL;
3013         } else {
3014                 ret->data = MALLOC(sizeof(uint64_t) * ret->datalen, "LDKCVec_u64Z Data");
3015                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3016                 for (size_t i = 0; i < ret->datalen; i++) {
3017                         ret->data[i] = java_elems[i];
3018                 }
3019                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3020         }
3021         return (long)ret;
3022 }
3023 static inline LDKCVec_u64Z CVec_u64Z_clone(const LDKCVec_u64Z *orig) {
3024         LDKCVec_u64Z ret = { .data = MALLOC(sizeof(jlong) * orig->datalen, "LDKCVec_u64Z clone bytes"), .datalen = orig->datalen };
3025         memcpy(ret.data, orig->data, sizeof(jlong) * ret.datalen);
3026         return ret;
3027 }
3028 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateAddHTLCZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3029         LDKCVec_UpdateAddHTLCZ *vec = (LDKCVec_UpdateAddHTLCZ*)ptr;
3030         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3031         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3032         for (size_t i = 0; i < vec->datalen; i++) {
3033                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3034                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3035         }
3036         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3037         return ret;
3038 }
3039 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateAddHTLCZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3040         LDKCVec_UpdateAddHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateAddHTLCZ), "LDKCVec_UpdateAddHTLCZ");
3041         ret->datalen = (*env)->GetArrayLength(env, elems);
3042         if (ret->datalen == 0) {
3043                 ret->data = NULL;
3044         } else {
3045                 ret->data = MALLOC(sizeof(LDKUpdateAddHTLC) * ret->datalen, "LDKCVec_UpdateAddHTLCZ Data");
3046                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3047                 for (size_t i = 0; i < ret->datalen; i++) {
3048                         jlong arr_elem = java_elems[i];
3049                         LDKUpdateAddHTLC arr_elem_conv;
3050                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3051                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3052                         if (arr_elem_conv.inner != NULL)
3053                                 arr_elem_conv = UpdateAddHTLC_clone(&arr_elem_conv);
3054                         ret->data[i] = arr_elem_conv;
3055                 }
3056                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3057         }
3058         return (long)ret;
3059 }
3060 static inline LDKCVec_UpdateAddHTLCZ CVec_UpdateAddHTLCZ_clone(const LDKCVec_UpdateAddHTLCZ *orig) {
3061         LDKCVec_UpdateAddHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateAddHTLC) * orig->datalen, "LDKCVec_UpdateAddHTLCZ clone bytes"), .datalen = orig->datalen };
3062         for (size_t i = 0; i < ret.datalen; i++) {
3063                 ret.data[i] = UpdateAddHTLC_clone(&orig->data[i]);
3064         }
3065         return ret;
3066 }
3067 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFulfillHTLCZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3068         LDKCVec_UpdateFulfillHTLCZ *vec = (LDKCVec_UpdateFulfillHTLCZ*)ptr;
3069         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3070         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3071         for (size_t i = 0; i < vec->datalen; i++) {
3072                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3073                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3074         }
3075         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3076         return ret;
3077 }
3078 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFulfillHTLCZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3079         LDKCVec_UpdateFulfillHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFulfillHTLCZ), "LDKCVec_UpdateFulfillHTLCZ");
3080         ret->datalen = (*env)->GetArrayLength(env, elems);
3081         if (ret->datalen == 0) {
3082                 ret->data = NULL;
3083         } else {
3084                 ret->data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * ret->datalen, "LDKCVec_UpdateFulfillHTLCZ Data");
3085                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3086                 for (size_t i = 0; i < ret->datalen; i++) {
3087                         jlong arr_elem = java_elems[i];
3088                         LDKUpdateFulfillHTLC arr_elem_conv;
3089                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3090                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3091                         if (arr_elem_conv.inner != NULL)
3092                                 arr_elem_conv = UpdateFulfillHTLC_clone(&arr_elem_conv);
3093                         ret->data[i] = arr_elem_conv;
3094                 }
3095                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3096         }
3097         return (long)ret;
3098 }
3099 static inline LDKCVec_UpdateFulfillHTLCZ CVec_UpdateFulfillHTLCZ_clone(const LDKCVec_UpdateFulfillHTLCZ *orig) {
3100         LDKCVec_UpdateFulfillHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * orig->datalen, "LDKCVec_UpdateFulfillHTLCZ clone bytes"), .datalen = orig->datalen };
3101         for (size_t i = 0; i < ret.datalen; i++) {
3102                 ret.data[i] = UpdateFulfillHTLC_clone(&orig->data[i]);
3103         }
3104         return ret;
3105 }
3106 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFailHTLCZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3107         LDKCVec_UpdateFailHTLCZ *vec = (LDKCVec_UpdateFailHTLCZ*)ptr;
3108         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3109         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3110         for (size_t i = 0; i < vec->datalen; i++) {
3111                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3112                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3113         }
3114         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3115         return ret;
3116 }
3117 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFailHTLCZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3118         LDKCVec_UpdateFailHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailHTLCZ), "LDKCVec_UpdateFailHTLCZ");
3119         ret->datalen = (*env)->GetArrayLength(env, elems);
3120         if (ret->datalen == 0) {
3121                 ret->data = NULL;
3122         } else {
3123                 ret->data = MALLOC(sizeof(LDKUpdateFailHTLC) * ret->datalen, "LDKCVec_UpdateFailHTLCZ Data");
3124                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3125                 for (size_t i = 0; i < ret->datalen; i++) {
3126                         jlong arr_elem = java_elems[i];
3127                         LDKUpdateFailHTLC arr_elem_conv;
3128                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3129                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3130                         if (arr_elem_conv.inner != NULL)
3131                                 arr_elem_conv = UpdateFailHTLC_clone(&arr_elem_conv);
3132                         ret->data[i] = arr_elem_conv;
3133                 }
3134                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3135         }
3136         return (long)ret;
3137 }
3138 static inline LDKCVec_UpdateFailHTLCZ CVec_UpdateFailHTLCZ_clone(const LDKCVec_UpdateFailHTLCZ *orig) {
3139         LDKCVec_UpdateFailHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailHTLC) * orig->datalen, "LDKCVec_UpdateFailHTLCZ clone bytes"), .datalen = orig->datalen };
3140         for (size_t i = 0; i < ret.datalen; i++) {
3141                 ret.data[i] = UpdateFailHTLC_clone(&orig->data[i]);
3142         }
3143         return ret;
3144 }
3145 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFailMalformedHTLCZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3146         LDKCVec_UpdateFailMalformedHTLCZ *vec = (LDKCVec_UpdateFailMalformedHTLCZ*)ptr;
3147         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3148         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3149         for (size_t i = 0; i < vec->datalen; i++) {
3150                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3151                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3152         }
3153         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3154         return ret;
3155 }
3156 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1UpdateFailMalformedHTLCZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3157         LDKCVec_UpdateFailMalformedHTLCZ *ret = MALLOC(sizeof(LDKCVec_UpdateFailMalformedHTLCZ), "LDKCVec_UpdateFailMalformedHTLCZ");
3158         ret->datalen = (*env)->GetArrayLength(env, elems);
3159         if (ret->datalen == 0) {
3160                 ret->data = NULL;
3161         } else {
3162                 ret->data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * ret->datalen, "LDKCVec_UpdateFailMalformedHTLCZ Data");
3163                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3164                 for (size_t i = 0; i < ret->datalen; i++) {
3165                         jlong arr_elem = java_elems[i];
3166                         LDKUpdateFailMalformedHTLC arr_elem_conv;
3167                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3168                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3169                         if (arr_elem_conv.inner != NULL)
3170                                 arr_elem_conv = UpdateFailMalformedHTLC_clone(&arr_elem_conv);
3171                         ret->data[i] = arr_elem_conv;
3172                 }
3173                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3174         }
3175         return (long)ret;
3176 }
3177 static inline LDKCVec_UpdateFailMalformedHTLCZ CVec_UpdateFailMalformedHTLCZ_clone(const LDKCVec_UpdateFailMalformedHTLCZ *orig) {
3178         LDKCVec_UpdateFailMalformedHTLCZ ret = { .data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * orig->datalen, "LDKCVec_UpdateFailMalformedHTLCZ clone bytes"), .datalen = orig->datalen };
3179         for (size_t i = 0; i < ret.datalen; i++) {
3180                 ret.data[i] = UpdateFailMalformedHTLC_clone(&orig->data[i]);
3181         }
3182         return ret;
3183 }
3184 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3185         return ((LDKCResult_boolLightningErrorZ*)arg)->result_ok;
3186 }
3187 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3188         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3189         CHECK(val->result_ok);
3190         return *val->contents.result;
3191 }
3192 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3193         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3194         CHECK(!val->result_ok);
3195         LDKLightningError err_var = (*val->contents.err);
3196         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3197         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3198         long err_ref = (long)err_var.inner & ~1;
3199         return err_ref;
3200 }
3201 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1new(JNIEnv *_env, jclass _b, jlong a, jlong b, jlong c) {
3202         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
3203         LDKChannelAnnouncement a_conv;
3204         a_conv.inner = (void*)(a & (~1));
3205         a_conv.is_owned = (a & 1) || (a == 0);
3206         if (a_conv.inner != NULL)
3207                 a_conv = ChannelAnnouncement_clone(&a_conv);
3208         ret->a = a_conv;
3209         LDKChannelUpdate b_conv;
3210         b_conv.inner = (void*)(b & (~1));
3211         b_conv.is_owned = (b & 1) || (b == 0);
3212         if (b_conv.inner != NULL)
3213                 b_conv = ChannelUpdate_clone(&b_conv);
3214         ret->b = b_conv;
3215         LDKChannelUpdate c_conv;
3216         c_conv.inner = (void*)(c & (~1));
3217         c_conv.is_owned = (c & 1) || (c == 0);
3218         if (c_conv.inner != NULL)
3219                 c_conv = ChannelUpdate_clone(&c_conv);
3220         ret->c = c_conv;
3221         return (long)ret;
3222 }
3223 static inline LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(const LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *orig) {
3224         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ ret = {
3225                 .a = ChannelAnnouncement_clone(&orig->a),
3226                 .b = ChannelUpdate_clone(&orig->b),
3227                 .c = ChannelUpdate_clone(&orig->c),
3228         };
3229         return ret;
3230 }
3231 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) {
3232         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
3233         LDKChannelAnnouncement a_var = tuple->a;
3234         CHECK((((long)a_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3235         CHECK((((long)&a_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3236         long a_ref = (long)a_var.inner & ~1;
3237         return a_ref;
3238 }
3239 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) {
3240         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
3241         LDKChannelUpdate b_var = tuple->b;
3242         CHECK((((long)b_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3243         CHECK((((long)&b_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3244         long b_ref = (long)b_var.inner & ~1;
3245         return b_ref;
3246 }
3247 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1get_1c(JNIEnv *_env, jclass _b, jlong ptr) {
3248         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ *tuple = (LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)ptr;
3249         LDKChannelUpdate c_var = tuple->c;
3250         CHECK((((long)c_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3251         CHECK((((long)&c_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3252         long c_ref = (long)c_var.inner & ~1;
3253         return c_ref;
3254 }
3255 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3256         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *vec = (LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ*)ptr;
3257         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ));
3258 }
3259 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3260         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *ret = MALLOC(sizeof(LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ");
3261         ret->datalen = (*env)->GetArrayLength(env, elems);
3262         if (ret->datalen == 0) {
3263                 ret->data = NULL;
3264         } else {
3265                 ret->data = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) * ret->datalen, "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Data");
3266                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3267                 for (size_t i = 0; i < ret->datalen; i++) {
3268                         jlong arr_elem = java_elems[i];
3269                         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_elem_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_elem;
3270                         FREE((void*)arr_elem);
3271                         ret->data[i] = arr_elem_conv;
3272                 }
3273                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3274         }
3275         return (long)ret;
3276 }
3277 static inline LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_clone(const LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ *orig) {
3278         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret = { .data = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ) * orig->datalen, "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ clone bytes"), .datalen = orig->datalen };
3279         for (size_t i = 0; i < ret.datalen; i++) {
3280                 ret.data[i] = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_clone(&orig->data[i]);
3281         }
3282         return ret;
3283 }
3284 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1NodeAnnouncementZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3285         LDKCVec_NodeAnnouncementZ *vec = (LDKCVec_NodeAnnouncementZ*)ptr;
3286         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3287         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3288         for (size_t i = 0; i < vec->datalen; i++) {
3289                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3290                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3291         }
3292         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3293         return ret;
3294 }
3295 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1NodeAnnouncementZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3296         LDKCVec_NodeAnnouncementZ *ret = MALLOC(sizeof(LDKCVec_NodeAnnouncementZ), "LDKCVec_NodeAnnouncementZ");
3297         ret->datalen = (*env)->GetArrayLength(env, elems);
3298         if (ret->datalen == 0) {
3299                 ret->data = NULL;
3300         } else {
3301                 ret->data = MALLOC(sizeof(LDKNodeAnnouncement) * ret->datalen, "LDKCVec_NodeAnnouncementZ Data");
3302                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3303                 for (size_t i = 0; i < ret->datalen; i++) {
3304                         jlong arr_elem = java_elems[i];
3305                         LDKNodeAnnouncement arr_elem_conv;
3306                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3307                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3308                         if (arr_elem_conv.inner != NULL)
3309                                 arr_elem_conv = NodeAnnouncement_clone(&arr_elem_conv);
3310                         ret->data[i] = arr_elem_conv;
3311                 }
3312                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3313         }
3314         return (long)ret;
3315 }
3316 static inline LDKCVec_NodeAnnouncementZ CVec_NodeAnnouncementZ_clone(const LDKCVec_NodeAnnouncementZ *orig) {
3317         LDKCVec_NodeAnnouncementZ ret = { .data = MALLOC(sizeof(LDKNodeAnnouncement) * orig->datalen, "LDKCVec_NodeAnnouncementZ clone bytes"), .datalen = orig->datalen };
3318         for (size_t i = 0; i < ret.datalen; i++) {
3319                 ret.data[i] = NodeAnnouncement_clone(&orig->data[i]);
3320         }
3321         return ret;
3322 }
3323 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneLightningErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3324         return ((LDKCResult_NoneLightningErrorZ*)arg)->result_ok;
3325 }
3326 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneLightningErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3327         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)arg;
3328         CHECK(val->result_ok);
3329         return *val->contents.result;
3330 }
3331 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneLightningErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3332         LDKCResult_NoneLightningErrorZ *val = (LDKCResult_NoneLightningErrorZ*)arg;
3333         CHECK(!val->result_ok);
3334         LDKLightningError err_var = (*val->contents.err);
3335         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3336         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3337         long err_ref = (long)err_var.inner & ~1;
3338         return err_ref;
3339 }
3340 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelReestablishDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3341         return ((LDKCResult_ChannelReestablishDecodeErrorZ*)arg)->result_ok;
3342 }
3343 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelReestablishDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3344         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)arg;
3345         CHECK(val->result_ok);
3346         LDKChannelReestablish res_var = (*val->contents.result);
3347         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3348         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3349         long res_ref = (long)res_var.inner & ~1;
3350         return res_ref;
3351 }
3352 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ChannelReestablishDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3353         LDKCResult_ChannelReestablishDecodeErrorZ *val = (LDKCResult_ChannelReestablishDecodeErrorZ*)arg;
3354         CHECK(!val->result_ok);
3355         LDKDecodeError err_var = (*val->contents.err);
3356         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3357         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3358         long err_ref = (long)err_var.inner & ~1;
3359         return err_ref;
3360 }
3361 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InitDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3362         return ((LDKCResult_InitDecodeErrorZ*)arg)->result_ok;
3363 }
3364 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InitDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3365         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)arg;
3366         CHECK(val->result_ok);
3367         LDKInit res_var = (*val->contents.result);
3368         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3369         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3370         long res_ref = (long)res_var.inner & ~1;
3371         return res_ref;
3372 }
3373 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1InitDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3374         LDKCResult_InitDecodeErrorZ *val = (LDKCResult_InitDecodeErrorZ*)arg;
3375         CHECK(!val->result_ok);
3376         LDKDecodeError err_var = (*val->contents.err);
3377         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3378         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3379         long err_ref = (long)err_var.inner & ~1;
3380         return err_ref;
3381 }
3382 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PingDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3383         return ((LDKCResult_PingDecodeErrorZ*)arg)->result_ok;
3384 }
3385 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PingDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3386         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)arg;
3387         CHECK(val->result_ok);
3388         LDKPing res_var = (*val->contents.result);
3389         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3390         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3391         long res_ref = (long)res_var.inner & ~1;
3392         return res_ref;
3393 }
3394 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PingDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3395         LDKCResult_PingDecodeErrorZ *val = (LDKCResult_PingDecodeErrorZ*)arg;
3396         CHECK(!val->result_ok);
3397         LDKDecodeError err_var = (*val->contents.err);
3398         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3399         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3400         long err_ref = (long)err_var.inner & ~1;
3401         return err_ref;
3402 }
3403 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PongDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3404         return ((LDKCResult_PongDecodeErrorZ*)arg)->result_ok;
3405 }
3406 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PongDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3407         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)arg;
3408         CHECK(val->result_ok);
3409         LDKPong res_var = (*val->contents.result);
3410         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3411         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3412         long res_ref = (long)res_var.inner & ~1;
3413         return res_ref;
3414 }
3415 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PongDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3416         LDKCResult_PongDecodeErrorZ *val = (LDKCResult_PongDecodeErrorZ*)arg;
3417         CHECK(!val->result_ok);
3418         LDKDecodeError err_var = (*val->contents.err);
3419         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3420         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3421         long err_ref = (long)err_var.inner & ~1;
3422         return err_ref;
3423 }
3424 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3425         return ((LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg)->result_ok;
3426 }
3427 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3428         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg;
3429         CHECK(val->result_ok);
3430         LDKUnsignedChannelAnnouncement res_var = (*val->contents.result);
3431         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3432         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3433         long res_ref = (long)res_var.inner & ~1;
3434         return res_ref;
3435 }
3436 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelAnnouncementDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3437         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)arg;
3438         CHECK(!val->result_ok);
3439         LDKDecodeError err_var = (*val->contents.err);
3440         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3441         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3442         long err_ref = (long)err_var.inner & ~1;
3443         return err_ref;
3444 }
3445 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3446         return ((LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg)->result_ok;
3447 }
3448 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3449         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg;
3450         CHECK(val->result_ok);
3451         LDKUnsignedChannelUpdate res_var = (*val->contents.result);
3452         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3453         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3454         long res_ref = (long)res_var.inner & ~1;
3455         return res_ref;
3456 }
3457 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedChannelUpdateDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3458         LDKCResult_UnsignedChannelUpdateDecodeErrorZ *val = (LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)arg;
3459         CHECK(!val->result_ok);
3460         LDKDecodeError err_var = (*val->contents.err);
3461         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3462         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3463         long err_ref = (long)err_var.inner & ~1;
3464         return err_ref;
3465 }
3466 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ErrorMessageDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3467         return ((LDKCResult_ErrorMessageDecodeErrorZ*)arg)->result_ok;
3468 }
3469 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ErrorMessageDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3470         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)arg;
3471         CHECK(val->result_ok);
3472         LDKErrorMessage res_var = (*val->contents.result);
3473         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3474         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3475         long res_ref = (long)res_var.inner & ~1;
3476         return res_ref;
3477 }
3478 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ErrorMessageDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3479         LDKCResult_ErrorMessageDecodeErrorZ *val = (LDKCResult_ErrorMessageDecodeErrorZ*)arg;
3480         CHECK(!val->result_ok);
3481         LDKDecodeError err_var = (*val->contents.err);
3482         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3483         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3484         long err_ref = (long)err_var.inner & ~1;
3485         return err_ref;
3486 }
3487 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3488         return ((LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg)->result_ok;
3489 }
3490 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3491         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg;
3492         CHECK(val->result_ok);
3493         LDKUnsignedNodeAnnouncement res_var = (*val->contents.result);
3494         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3495         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3496         long res_ref = (long)res_var.inner & ~1;
3497         return res_ref;
3498 }
3499 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1UnsignedNodeAnnouncementDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3500         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ *val = (LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)arg;
3501         CHECK(!val->result_ok);
3502         LDKDecodeError err_var = (*val->contents.err);
3503         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3504         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3505         long err_ref = (long)err_var.inner & ~1;
3506         return err_ref;
3507 }
3508 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3509         return ((LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg)->result_ok;
3510 }
3511 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3512         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg;
3513         CHECK(val->result_ok);
3514         LDKQueryShortChannelIds res_var = (*val->contents.result);
3515         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3516         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3517         long res_ref = (long)res_var.inner & ~1;
3518         return res_ref;
3519 }
3520 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryShortChannelIdsDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3521         LDKCResult_QueryShortChannelIdsDecodeErrorZ *val = (LDKCResult_QueryShortChannelIdsDecodeErrorZ*)arg;
3522         CHECK(!val->result_ok);
3523         LDKDecodeError err_var = (*val->contents.err);
3524         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3525         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3526         long err_ref = (long)err_var.inner & ~1;
3527         return err_ref;
3528 }
3529 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3530         return ((LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg)->result_ok;
3531 }
3532 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3533         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg;
3534         CHECK(val->result_ok);
3535         LDKReplyShortChannelIdsEnd res_var = (*val->contents.result);
3536         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3537         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3538         long res_ref = (long)res_var.inner & ~1;
3539         return res_ref;
3540 }
3541 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyShortChannelIdsEndDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3542         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ *val = (LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)arg;
3543         CHECK(!val->result_ok);
3544         LDKDecodeError err_var = (*val->contents.err);
3545         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3546         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3547         long err_ref = (long)err_var.inner & ~1;
3548         return err_ref;
3549 }
3550 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryChannelRangeDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3551         return ((LDKCResult_QueryChannelRangeDecodeErrorZ*)arg)->result_ok;
3552 }
3553 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryChannelRangeDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3554         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)arg;
3555         CHECK(val->result_ok);
3556         LDKQueryChannelRange res_var = (*val->contents.result);
3557         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3558         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3559         long res_ref = (long)res_var.inner & ~1;
3560         return res_ref;
3561 }
3562 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1QueryChannelRangeDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3563         LDKCResult_QueryChannelRangeDecodeErrorZ *val = (LDKCResult_QueryChannelRangeDecodeErrorZ*)arg;
3564         CHECK(!val->result_ok);
3565         LDKDecodeError err_var = (*val->contents.err);
3566         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3567         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3568         long err_ref = (long)err_var.inner & ~1;
3569         return err_ref;
3570 }
3571 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyChannelRangeDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3572         return ((LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg)->result_ok;
3573 }
3574 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyChannelRangeDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3575         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg;
3576         CHECK(val->result_ok);
3577         LDKReplyChannelRange res_var = (*val->contents.result);
3578         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3579         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3580         long res_ref = (long)res_var.inner & ~1;
3581         return res_ref;
3582 }
3583 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1ReplyChannelRangeDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3584         LDKCResult_ReplyChannelRangeDecodeErrorZ *val = (LDKCResult_ReplyChannelRangeDecodeErrorZ*)arg;
3585         CHECK(!val->result_ok);
3586         LDKDecodeError err_var = (*val->contents.err);
3587         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3588         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3589         long err_ref = (long)err_var.inner & ~1;
3590         return err_ref;
3591 }
3592 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1GossipTimestampFilterDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3593         return ((LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg)->result_ok;
3594 }
3595 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1GossipTimestampFilterDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3596         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg;
3597         CHECK(val->result_ok);
3598         LDKGossipTimestampFilter res_var = (*val->contents.result);
3599         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3600         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3601         long res_ref = (long)res_var.inner & ~1;
3602         return res_ref;
3603 }
3604 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1GossipTimestampFilterDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3605         LDKCResult_GossipTimestampFilterDecodeErrorZ *val = (LDKCResult_GossipTimestampFilterDecodeErrorZ*)arg;
3606         CHECK(!val->result_ok);
3607         LDKDecodeError err_var = (*val->contents.err);
3608         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3609         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3610         long err_ref = (long)err_var.inner & ~1;
3611         return err_ref;
3612 }
3613 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1PublicKeyZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3614         LDKCVec_PublicKeyZ *vec = (LDKCVec_PublicKeyZ*)ptr;
3615         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKPublicKey));
3616 }
3617 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3618         return ((LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg)->result_ok;
3619 }
3620 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3621         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
3622         CHECK(val->result_ok);
3623         LDKCVec_u8Z res_var = (*val->contents.result);
3624         jbyteArray res_arr = (*_env)->NewByteArray(_env, res_var.datalen);
3625         (*_env)->SetByteArrayRegion(_env, res_arr, 0, res_var.datalen, res_var.data);
3626         return res_arr;
3627 }
3628 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3629         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
3630         CHECK(!val->result_ok);
3631         LDKPeerHandleError err_var = (*val->contents.err);
3632         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3633         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3634         long err_ref = (long)err_var.inner & ~1;
3635         return err_ref;
3636 }
3637 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3638         return ((LDKCResult_NonePeerHandleErrorZ*)arg)->result_ok;
3639 }
3640 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3641         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
3642         CHECK(val->result_ok);
3643         return *val->contents.result;
3644 }
3645 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3646         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
3647         CHECK(!val->result_ok);
3648         LDKPeerHandleError err_var = (*val->contents.err);
3649         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3650         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3651         long err_ref = (long)err_var.inner & ~1;
3652         return err_ref;
3653 }
3654 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3655         return ((LDKCResult_boolPeerHandleErrorZ*)arg)->result_ok;
3656 }
3657 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3658         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
3659         CHECK(val->result_ok);
3660         return *val->contents.result;
3661 }
3662 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3663         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
3664         CHECK(!val->result_ok);
3665         LDKPeerHandleError err_var = (*val->contents.err);
3666         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3667         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3668         long err_ref = (long)err_var.inner & ~1;
3669         return err_ref;
3670 }
3671 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3672         return ((LDKCResult_SecretKeySecpErrorZ*)arg)->result_ok;
3673 }
3674 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3675         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
3676         CHECK(val->result_ok);
3677         jbyteArray res_arr = (*_env)->NewByteArray(_env, 32);
3678         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 32, (*val->contents.result).bytes);
3679         return res_arr;
3680 }
3681 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3682         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
3683         CHECK(!val->result_ok);
3684         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
3685         return err_conv;
3686 }
3687 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3688         return ((LDKCResult_PublicKeySecpErrorZ*)arg)->result_ok;
3689 }
3690 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3691         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
3692         CHECK(val->result_ok);
3693         jbyteArray res_arr = (*_env)->NewByteArray(_env, 33);
3694         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 33, (*val->contents.result).compressed_form);
3695         return res_arr;
3696 }
3697 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3698         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
3699         CHECK(!val->result_ok);
3700         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
3701         return err_conv;
3702 }
3703 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3704         return ((LDKCResult_TxCreationKeysSecpErrorZ*)arg)->result_ok;
3705 }
3706 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3707         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
3708         CHECK(val->result_ok);
3709         LDKTxCreationKeys res_var = (*val->contents.result);
3710         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3711         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3712         long res_ref = (long)res_var.inner & ~1;
3713         return res_ref;
3714 }
3715 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3716         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
3717         CHECK(!val->result_ok);
3718         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
3719         return err_conv;
3720 }
3721 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TrustedCommitmentTransactionNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3722         return ((LDKCResult_TrustedCommitmentTransactionNoneZ*)arg)->result_ok;
3723 }
3724 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TrustedCommitmentTransactionNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3725         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)arg;
3726         CHECK(val->result_ok);
3727         LDKTrustedCommitmentTransaction res_var = (*val->contents.result);
3728         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3729         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3730         long res_ref = (long)res_var.inner & ~1;
3731         return res_ref;
3732 }
3733 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TrustedCommitmentTransactionNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3734         LDKCResult_TrustedCommitmentTransactionNoneZ *val = (LDKCResult_TrustedCommitmentTransactionNoneZ*)arg;
3735         CHECK(!val->result_ok);
3736         return *val->contents.err;
3737 }
3738 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1RouteHopZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3739         LDKCVec_RouteHopZ *vec = (LDKCVec_RouteHopZ*)ptr;
3740         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3741         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3742         for (size_t i = 0; i < vec->datalen; i++) {
3743                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3744                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3745         }
3746         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3747         return ret;
3748 }
3749 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1RouteHopZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3750         LDKCVec_RouteHopZ *ret = MALLOC(sizeof(LDKCVec_RouteHopZ), "LDKCVec_RouteHopZ");
3751         ret->datalen = (*env)->GetArrayLength(env, elems);
3752         if (ret->datalen == 0) {
3753                 ret->data = NULL;
3754         } else {
3755                 ret->data = MALLOC(sizeof(LDKRouteHop) * ret->datalen, "LDKCVec_RouteHopZ Data");
3756                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3757                 for (size_t i = 0; i < ret->datalen; i++) {
3758                         jlong arr_elem = java_elems[i];
3759                         LDKRouteHop arr_elem_conv;
3760                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3761                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3762                         if (arr_elem_conv.inner != NULL)
3763                                 arr_elem_conv = RouteHop_clone(&arr_elem_conv);
3764                         ret->data[i] = arr_elem_conv;
3765                 }
3766                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3767         }
3768         return (long)ret;
3769 }
3770 static inline LDKCVec_RouteHopZ CVec_RouteHopZ_clone(const LDKCVec_RouteHopZ *orig) {
3771         LDKCVec_RouteHopZ ret = { .data = MALLOC(sizeof(LDKRouteHop) * orig->datalen, "LDKCVec_RouteHopZ clone bytes"), .datalen = orig->datalen };
3772         for (size_t i = 0; i < ret.datalen; i++) {
3773                 ret.data[i] = RouteHop_clone(&orig->data[i]);
3774         }
3775         return ret;
3776 }
3777 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVec_1CVec_1RouteHopZZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3778         LDKCVec_CVec_RouteHopZZ *vec = (LDKCVec_CVec_RouteHopZZ*)ptr;
3779         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKCVec_RouteHopZ));
3780 }
3781 static inline LDKCVec_CVec_RouteHopZZ CVec_CVec_RouteHopZZ_clone(const LDKCVec_CVec_RouteHopZZ *orig) {
3782         LDKCVec_CVec_RouteHopZZ ret = { .data = MALLOC(sizeof(LDKCVec_RouteHopZ) * orig->datalen, "LDKCVec_CVec_RouteHopZZ clone bytes"), .datalen = orig->datalen };
3783         for (size_t i = 0; i < ret.datalen; i++) {
3784                 ret.data[i] = CVec_RouteHopZ_clone(&orig->data[i]);
3785         }
3786         return ret;
3787 }
3788 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3789         return ((LDKCResult_RouteDecodeErrorZ*)arg)->result_ok;
3790 }
3791 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3792         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)arg;
3793         CHECK(val->result_ok);
3794         LDKRoute res_var = (*val->contents.result);
3795         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3796         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3797         long res_ref = (long)res_var.inner & ~1;
3798         return res_ref;
3799 }
3800 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3801         LDKCResult_RouteDecodeErrorZ *val = (LDKCResult_RouteDecodeErrorZ*)arg;
3802         CHECK(!val->result_ok);
3803         LDKDecodeError err_var = (*val->contents.err);
3804         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3805         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3806         long err_ref = (long)err_var.inner & ~1;
3807         return err_ref;
3808 }
3809 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVec_1RouteHintZ_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3810         LDKCVec_RouteHintZ *vec = (LDKCVec_RouteHintZ*)ptr;
3811         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3812         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3813         for (size_t i = 0; i < vec->datalen; i++) {
3814                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3815                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3816         }
3817         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3818         return ret;
3819 }
3820 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVec_1RouteHintZ_1new(JNIEnv *env, jclass _b, jlongArray elems){
3821         LDKCVec_RouteHintZ *ret = MALLOC(sizeof(LDKCVec_RouteHintZ), "LDKCVec_RouteHintZ");
3822         ret->datalen = (*env)->GetArrayLength(env, elems);
3823         if (ret->datalen == 0) {
3824                 ret->data = NULL;
3825         } else {
3826                 ret->data = MALLOC(sizeof(LDKRouteHint) * ret->datalen, "LDKCVec_RouteHintZ Data");
3827                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3828                 for (size_t i = 0; i < ret->datalen; i++) {
3829                         jlong arr_elem = java_elems[i];
3830                         LDKRouteHint arr_elem_conv;
3831                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3832                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3833                         if (arr_elem_conv.inner != NULL)
3834                                 arr_elem_conv = RouteHint_clone(&arr_elem_conv);
3835                         ret->data[i] = arr_elem_conv;
3836                 }
3837                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3838         }
3839         return (long)ret;
3840 }
3841 static inline LDKCVec_RouteHintZ CVec_RouteHintZ_clone(const LDKCVec_RouteHintZ *orig) {
3842         LDKCVec_RouteHintZ ret = { .data = MALLOC(sizeof(LDKRouteHint) * orig->datalen, "LDKCVec_RouteHintZ clone bytes"), .datalen = orig->datalen };
3843         for (size_t i = 0; i < ret.datalen; i++) {
3844                 ret.data[i] = RouteHint_clone(&orig->data[i]);
3845         }
3846         return ret;
3847 }
3848 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3849         return ((LDKCResult_RouteLightningErrorZ*)arg)->result_ok;
3850 }
3851 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3852         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
3853         CHECK(val->result_ok);
3854         LDKRoute res_var = (*val->contents.result);
3855         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3856         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3857         long res_ref = (long)res_var.inner & ~1;
3858         return res_ref;
3859 }
3860 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3861         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
3862         CHECK(!val->result_ok);
3863         LDKLightningError err_var = (*val->contents.err);
3864         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3865         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3866         long err_ref = (long)err_var.inner & ~1;
3867         return err_ref;
3868 }
3869 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RoutingFeesDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3870         return ((LDKCResult_RoutingFeesDecodeErrorZ*)arg)->result_ok;
3871 }
3872 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RoutingFeesDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3873         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)arg;
3874         CHECK(val->result_ok);
3875         LDKRoutingFees res_var = (*val->contents.result);
3876         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3877         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3878         long res_ref = (long)res_var.inner & ~1;
3879         return res_ref;
3880 }
3881 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RoutingFeesDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3882         LDKCResult_RoutingFeesDecodeErrorZ *val = (LDKCResult_RoutingFeesDecodeErrorZ*)arg;
3883         CHECK(!val->result_ok);
3884         LDKDecodeError err_var = (*val->contents.err);
3885         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3886         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3887         long err_ref = (long)err_var.inner & ~1;
3888         return err_ref;
3889 }
3890 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3891         return ((LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg)->result_ok;
3892 }
3893 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3894         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg;
3895         CHECK(val->result_ok);
3896         LDKNodeAnnouncementInfo res_var = (*val->contents.result);
3897         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3898         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3899         long res_ref = (long)res_var.inner & ~1;
3900         return res_ref;
3901 }
3902 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeAnnouncementInfoDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3903         LDKCResult_NodeAnnouncementInfoDecodeErrorZ *val = (LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)arg;
3904         CHECK(!val->result_ok);
3905         LDKDecodeError err_var = (*val->contents.err);
3906         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3907         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3908         long err_ref = (long)err_var.inner & ~1;
3909         return err_ref;
3910 }
3911 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeInfoDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3912         return ((LDKCResult_NodeInfoDecodeErrorZ*)arg)->result_ok;
3913 }
3914 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeInfoDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3915         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)arg;
3916         CHECK(val->result_ok);
3917         LDKNodeInfo res_var = (*val->contents.result);
3918         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3919         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3920         long res_ref = (long)res_var.inner & ~1;
3921         return res_ref;
3922 }
3923 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NodeInfoDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3924         LDKCResult_NodeInfoDecodeErrorZ *val = (LDKCResult_NodeInfoDecodeErrorZ*)arg;
3925         CHECK(!val->result_ok);
3926         LDKDecodeError err_var = (*val->contents.err);
3927         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3928         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3929         long err_ref = (long)err_var.inner & ~1;
3930         return err_ref;
3931 }
3932 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetworkGraphDecodeErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3933         return ((LDKCResult_NetworkGraphDecodeErrorZ*)arg)->result_ok;
3934 }
3935 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetworkGraphDecodeErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3936         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)arg;
3937         CHECK(val->result_ok);
3938         LDKNetworkGraph res_var = (*val->contents.result);
3939         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3940         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3941         long res_ref = (long)res_var.inner & ~1;
3942         return res_ref;
3943 }
3944 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NetworkGraphDecodeErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3945         LDKCResult_NetworkGraphDecodeErrorZ *val = (LDKCResult_NetworkGraphDecodeErrorZ*)arg;
3946         CHECK(!val->result_ok);
3947         LDKDecodeError err_var = (*val->contents.err);
3948         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3949         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3950         long err_ref = (long)err_var.inner & ~1;
3951         return err_ref;
3952 }
3953 typedef struct LDKMessageSendEventsProvider_JCalls {
3954         atomic_size_t refcnt;
3955         JavaVM *vm;
3956         jweak o;
3957         jmethodID get_and_clear_pending_msg_events_meth;
3958 } LDKMessageSendEventsProvider_JCalls;
3959 LDKCVec_MessageSendEventZ get_and_clear_pending_msg_events_jcall(const void* this_arg) {
3960         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
3961         JNIEnv *_env;
3962         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3963         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3964         CHECK(obj != NULL);
3965         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_and_clear_pending_msg_events_meth);
3966         LDKCVec_MessageSendEventZ arg_constr;
3967         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
3968         if (arg_constr.datalen > 0)
3969                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
3970         else
3971                 arg_constr.data = NULL;
3972         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
3973         for (size_t s = 0; s < arg_constr.datalen; s++) {
3974                 long arr_conv_18 = arg_vals[s];
3975                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
3976                 FREE((void*)arr_conv_18);
3977                 arg_constr.data[s] = arr_conv_18_conv;
3978         }
3979         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
3980         return arg_constr;
3981 }
3982 static void LDKMessageSendEventsProvider_JCalls_free(void* this_arg) {
3983         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
3984         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3985                 JNIEnv *env;
3986                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3987                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
3988                 FREE(j_calls);
3989         }
3990 }
3991 static void* LDKMessageSendEventsProvider_JCalls_clone(const void* this_arg) {
3992         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
3993         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3994         return (void*) this_arg;
3995 }
3996 static inline LDKMessageSendEventsProvider LDKMessageSendEventsProvider_init (JNIEnv * env, jclass _a, jobject o) {
3997         jclass c = (*env)->GetObjectClass(env, o);
3998         CHECK(c != NULL);
3999         LDKMessageSendEventsProvider_JCalls *calls = MALLOC(sizeof(LDKMessageSendEventsProvider_JCalls), "LDKMessageSendEventsProvider_JCalls");
4000         atomic_init(&calls->refcnt, 1);
4001         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4002         calls->o = (*env)->NewWeakGlobalRef(env, o);
4003         calls->get_and_clear_pending_msg_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_msg_events", "()[J");
4004         CHECK(calls->get_and_clear_pending_msg_events_meth != NULL);
4005
4006         LDKMessageSendEventsProvider ret = {
4007                 .this_arg = (void*) calls,
4008                 .get_and_clear_pending_msg_events = get_and_clear_pending_msg_events_jcall,
4009                 .free = LDKMessageSendEventsProvider_JCalls_free,
4010         };
4011         return ret;
4012 }
4013 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1new (JNIEnv * env, jclass _a, jobject o) {
4014         LDKMessageSendEventsProvider *res_ptr = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
4015         *res_ptr = LDKMessageSendEventsProvider_init(env, _a, o);
4016         return (long)res_ptr;
4017 }
4018 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4019         jobject ret = (*env)->NewLocalRef(env, ((LDKMessageSendEventsProvider_JCalls*)val)->o);
4020         CHECK(ret != NULL);
4021         return ret;
4022 }
4023 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1get_1and_1clear_1pending_1msg_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
4024         LDKMessageSendEventsProvider* this_arg_conv = (LDKMessageSendEventsProvider*)this_arg;
4025         LDKCVec_MessageSendEventZ ret_var = (this_arg_conv->get_and_clear_pending_msg_events)(this_arg_conv->this_arg);
4026         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
4027         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
4028         for (size_t s = 0; s < ret_var.datalen; s++) {
4029                 LDKMessageSendEvent *arr_conv_18_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
4030                 *arr_conv_18_copy = MessageSendEvent_clone(&ret_var.data[s]);
4031                 long arr_conv_18_ref = (long)arr_conv_18_copy;
4032                 ret_arr_ptr[s] = arr_conv_18_ref;
4033         }
4034         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
4035         FREE(ret_var.data);
4036         return ret_arr;
4037 }
4038
4039 typedef struct LDKEventsProvider_JCalls {
4040         atomic_size_t refcnt;
4041         JavaVM *vm;
4042         jweak o;
4043         jmethodID get_and_clear_pending_events_meth;
4044 } LDKEventsProvider_JCalls;
4045 LDKCVec_EventZ get_and_clear_pending_events_jcall(const void* this_arg) {
4046         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
4047         JNIEnv *_env;
4048         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4049         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4050         CHECK(obj != NULL);
4051         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_and_clear_pending_events_meth);
4052         LDKCVec_EventZ arg_constr;
4053         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4054         if (arg_constr.datalen > 0)
4055                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
4056         else
4057                 arg_constr.data = NULL;
4058         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4059         for (size_t h = 0; h < arg_constr.datalen; h++) {
4060                 long arr_conv_7 = arg_vals[h];
4061                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
4062                 FREE((void*)arr_conv_7);
4063                 arg_constr.data[h] = arr_conv_7_conv;
4064         }
4065         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4066         return arg_constr;
4067 }
4068 static void LDKEventsProvider_JCalls_free(void* this_arg) {
4069         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
4070         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4071                 JNIEnv *env;
4072                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4073                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4074                 FREE(j_calls);
4075         }
4076 }
4077 static void* LDKEventsProvider_JCalls_clone(const void* this_arg) {
4078         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
4079         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4080         return (void*) this_arg;
4081 }
4082 static inline LDKEventsProvider LDKEventsProvider_init (JNIEnv * env, jclass _a, jobject o) {
4083         jclass c = (*env)->GetObjectClass(env, o);
4084         CHECK(c != NULL);
4085         LDKEventsProvider_JCalls *calls = MALLOC(sizeof(LDKEventsProvider_JCalls), "LDKEventsProvider_JCalls");
4086         atomic_init(&calls->refcnt, 1);
4087         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4088         calls->o = (*env)->NewWeakGlobalRef(env, o);
4089         calls->get_and_clear_pending_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_events", "()[J");
4090         CHECK(calls->get_and_clear_pending_events_meth != NULL);
4091
4092         LDKEventsProvider ret = {
4093                 .this_arg = (void*) calls,
4094                 .get_and_clear_pending_events = get_and_clear_pending_events_jcall,
4095                 .free = LDKEventsProvider_JCalls_free,
4096         };
4097         return ret;
4098 }
4099 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1new (JNIEnv * env, jclass _a, jobject o) {
4100         LDKEventsProvider *res_ptr = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
4101         *res_ptr = LDKEventsProvider_init(env, _a, o);
4102         return (long)res_ptr;
4103 }
4104 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4105         jobject ret = (*env)->NewLocalRef(env, ((LDKEventsProvider_JCalls*)val)->o);
4106         CHECK(ret != NULL);
4107         return ret;
4108 }
4109 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_EventsProvider_1get_1and_1clear_1pending_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
4110         LDKEventsProvider* this_arg_conv = (LDKEventsProvider*)this_arg;
4111         LDKCVec_EventZ ret_var = (this_arg_conv->get_and_clear_pending_events)(this_arg_conv->this_arg);
4112         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
4113         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
4114         for (size_t h = 0; h < ret_var.datalen; h++) {
4115                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
4116                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
4117                 long arr_conv_7_ref = (long)arr_conv_7_copy;
4118                 ret_arr_ptr[h] = arr_conv_7_ref;
4119         }
4120         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
4121         FREE(ret_var.data);
4122         return ret_arr;
4123 }
4124
4125 typedef struct LDKAccess_JCalls {
4126         atomic_size_t refcnt;
4127         JavaVM *vm;
4128         jweak o;
4129         jmethodID get_utxo_meth;
4130 } LDKAccess_JCalls;
4131 LDKCResult_TxOutAccessErrorZ get_utxo_jcall(const void* this_arg, const uint8_t (*genesis_hash)[32], uint64_t short_channel_id) {
4132         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
4133         JNIEnv *_env;
4134         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4135         jbyteArray genesis_hash_arr = (*_env)->NewByteArray(_env, 32);
4136         (*_env)->SetByteArrayRegion(_env, genesis_hash_arr, 0, 32, *genesis_hash);
4137         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4138         CHECK(obj != NULL);
4139         LDKCResult_TxOutAccessErrorZ* ret = (LDKCResult_TxOutAccessErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->get_utxo_meth, genesis_hash_arr, short_channel_id);
4140         LDKCResult_TxOutAccessErrorZ ret_conv = *(LDKCResult_TxOutAccessErrorZ*)ret;
4141         FREE((void*)ret);
4142         return ret_conv;
4143 }
4144 static void LDKAccess_JCalls_free(void* this_arg) {
4145         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
4146         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4147                 JNIEnv *env;
4148                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4149                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4150                 FREE(j_calls);
4151         }
4152 }
4153 static void* LDKAccess_JCalls_clone(const void* this_arg) {
4154         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
4155         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4156         return (void*) this_arg;
4157 }
4158 static inline LDKAccess LDKAccess_init (JNIEnv * env, jclass _a, jobject o) {
4159         jclass c = (*env)->GetObjectClass(env, o);
4160         CHECK(c != NULL);
4161         LDKAccess_JCalls *calls = MALLOC(sizeof(LDKAccess_JCalls), "LDKAccess_JCalls");
4162         atomic_init(&calls->refcnt, 1);
4163         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4164         calls->o = (*env)->NewWeakGlobalRef(env, o);
4165         calls->get_utxo_meth = (*env)->GetMethodID(env, c, "get_utxo", "([BJ)J");
4166         CHECK(calls->get_utxo_meth != NULL);
4167
4168         LDKAccess ret = {
4169                 .this_arg = (void*) calls,
4170                 .get_utxo = get_utxo_jcall,
4171                 .free = LDKAccess_JCalls_free,
4172         };
4173         return ret;
4174 }
4175 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKAccess_1new (JNIEnv * env, jclass _a, jobject o) {
4176         LDKAccess *res_ptr = MALLOC(sizeof(LDKAccess), "LDKAccess");
4177         *res_ptr = LDKAccess_init(env, _a, o);
4178         return (long)res_ptr;
4179 }
4180 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAccess_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4181         jobject ret = (*env)->NewLocalRef(env, ((LDKAccess_JCalls*)val)->o);
4182         CHECK(ret != NULL);
4183         return ret;
4184 }
4185 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) {
4186         LDKAccess* this_arg_conv = (LDKAccess*)this_arg;
4187         unsigned char genesis_hash_arr[32];
4188         CHECK((*_env)->GetArrayLength (_env, genesis_hash) == 32);
4189         (*_env)->GetByteArrayRegion (_env, genesis_hash, 0, 32, genesis_hash_arr);
4190         unsigned char (*genesis_hash_ref)[32] = &genesis_hash_arr;
4191         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
4192         *ret_conv = (this_arg_conv->get_utxo)(this_arg_conv->this_arg, genesis_hash_ref, short_channel_id);
4193         return (long)ret_conv;
4194 }
4195
4196 typedef struct LDKFilter_JCalls {
4197         atomic_size_t refcnt;
4198         JavaVM *vm;
4199         jweak o;
4200         jmethodID register_tx_meth;
4201         jmethodID register_output_meth;
4202 } LDKFilter_JCalls;
4203 void register_tx_jcall(const void* this_arg, const uint8_t (*txid)[32], struct LDKu8slice script_pubkey) {
4204         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4205         JNIEnv *_env;
4206         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4207         jbyteArray txid_arr = (*_env)->NewByteArray(_env, 32);
4208         (*_env)->SetByteArrayRegion(_env, txid_arr, 0, 32, *txid);
4209         LDKu8slice script_pubkey_var = script_pubkey;
4210         jbyteArray script_pubkey_arr = (*_env)->NewByteArray(_env, script_pubkey_var.datalen);
4211         (*_env)->SetByteArrayRegion(_env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
4212         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4213         CHECK(obj != NULL);
4214         return (*_env)->CallVoidMethod(_env, obj, j_calls->register_tx_meth, txid_arr, script_pubkey_arr);
4215 }
4216 void register_output_jcall(const void* this_arg, const struct LDKOutPoint *NONNULL_PTR outpoint, struct LDKu8slice script_pubkey) {
4217         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4218         JNIEnv *_env;
4219         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4220         LDKOutPoint outpoint_var = *outpoint;
4221         if (outpoint->inner != NULL)
4222                 outpoint_var = OutPoint_clone(outpoint);
4223         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4224         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4225         long outpoint_ref = (long)outpoint_var.inner;
4226         if (outpoint_var.is_owned) {
4227                 outpoint_ref |= 1;
4228         }
4229         LDKu8slice script_pubkey_var = script_pubkey;
4230         jbyteArray script_pubkey_arr = (*_env)->NewByteArray(_env, script_pubkey_var.datalen);
4231         (*_env)->SetByteArrayRegion(_env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
4232         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4233         CHECK(obj != NULL);
4234         return (*_env)->CallVoidMethod(_env, obj, j_calls->register_output_meth, outpoint_ref, script_pubkey_arr);
4235 }
4236 static void LDKFilter_JCalls_free(void* this_arg) {
4237         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4238         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4239                 JNIEnv *env;
4240                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4241                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4242                 FREE(j_calls);
4243         }
4244 }
4245 static void* LDKFilter_JCalls_clone(const void* this_arg) {
4246         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
4247         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4248         return (void*) this_arg;
4249 }
4250 static inline LDKFilter LDKFilter_init (JNIEnv * env, jclass _a, jobject o) {
4251         jclass c = (*env)->GetObjectClass(env, o);
4252         CHECK(c != NULL);
4253         LDKFilter_JCalls *calls = MALLOC(sizeof(LDKFilter_JCalls), "LDKFilter_JCalls");
4254         atomic_init(&calls->refcnt, 1);
4255         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4256         calls->o = (*env)->NewWeakGlobalRef(env, o);
4257         calls->register_tx_meth = (*env)->GetMethodID(env, c, "register_tx", "([B[B)V");
4258         CHECK(calls->register_tx_meth != NULL);
4259         calls->register_output_meth = (*env)->GetMethodID(env, c, "register_output", "(J[B)V");
4260         CHECK(calls->register_output_meth != NULL);
4261
4262         LDKFilter ret = {
4263                 .this_arg = (void*) calls,
4264                 .register_tx = register_tx_jcall,
4265                 .register_output = register_output_jcall,
4266                 .free = LDKFilter_JCalls_free,
4267         };
4268         return ret;
4269 }
4270 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFilter_1new (JNIEnv * env, jclass _a, jobject o) {
4271         LDKFilter *res_ptr = MALLOC(sizeof(LDKFilter), "LDKFilter");
4272         *res_ptr = LDKFilter_init(env, _a, o);
4273         return (long)res_ptr;
4274 }
4275 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFilter_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4276         jobject ret = (*env)->NewLocalRef(env, ((LDKFilter_JCalls*)val)->o);
4277         CHECK(ret != NULL);
4278         return ret;
4279 }
4280 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1tx(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray txid, jbyteArray script_pubkey) {
4281         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
4282         unsigned char txid_arr[32];
4283         CHECK((*_env)->GetArrayLength (_env, txid) == 32);
4284         (*_env)->GetByteArrayRegion (_env, txid, 0, 32, txid_arr);
4285         unsigned char (*txid_ref)[32] = &txid_arr;
4286         LDKu8slice script_pubkey_ref;
4287         script_pubkey_ref.datalen = (*_env)->GetArrayLength (_env, script_pubkey);
4288         script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL);
4289         (this_arg_conv->register_tx)(this_arg_conv->this_arg, txid_ref, script_pubkey_ref);
4290         (*_env)->ReleaseByteArrayElements(_env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
4291 }
4292
4293 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1output(JNIEnv * _env, jclass _b, jlong this_arg, jlong outpoint, jbyteArray script_pubkey) {
4294         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
4295         LDKOutPoint outpoint_conv;
4296         outpoint_conv.inner = (void*)(outpoint & (~1));
4297         outpoint_conv.is_owned = false;
4298         LDKu8slice script_pubkey_ref;
4299         script_pubkey_ref.datalen = (*_env)->GetArrayLength (_env, script_pubkey);
4300         script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL);
4301         (this_arg_conv->register_output)(this_arg_conv->this_arg, &outpoint_conv, script_pubkey_ref);
4302         (*_env)->ReleaseByteArrayElements(_env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
4303 }
4304
4305 typedef struct LDKPersist_JCalls {
4306         atomic_size_t refcnt;
4307         JavaVM *vm;
4308         jweak o;
4309         jmethodID persist_new_channel_meth;
4310         jmethodID update_persisted_channel_meth;
4311 } LDKPersist_JCalls;
4312 LDKCResult_NoneChannelMonitorUpdateErrZ persist_new_channel_jcall(const void* this_arg, struct LDKOutPoint id, const struct LDKChannelMonitor *NONNULL_PTR data) {
4313         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4314         JNIEnv *_env;
4315         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4316         LDKOutPoint id_var = id;
4317         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4318         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4319         long id_ref = (long)id_var.inner;
4320         if (id_var.is_owned) {
4321                 id_ref |= 1;
4322         }
4323         LDKChannelMonitor data_var = *data;
4324         // Warning: we may need a move here but can't clone!
4325         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4326         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4327         long data_ref = (long)data_var.inner;
4328         if (data_var.is_owned) {
4329                 data_ref |= 1;
4330         }
4331         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4332         CHECK(obj != NULL);
4333         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->persist_new_channel_meth, id_ref, data_ref);
4334         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
4335         FREE((void*)ret);
4336         return ret_conv;
4337 }
4338 LDKCResult_NoneChannelMonitorUpdateErrZ update_persisted_channel_jcall(const void* this_arg, struct LDKOutPoint id, const struct LDKChannelMonitorUpdate *NONNULL_PTR update, const struct LDKChannelMonitor *NONNULL_PTR data) {
4339         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4340         JNIEnv *_env;
4341         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4342         LDKOutPoint id_var = id;
4343         CHECK((((long)id_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4344         CHECK((((long)&id_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4345         long id_ref = (long)id_var.inner;
4346         if (id_var.is_owned) {
4347                 id_ref |= 1;
4348         }
4349         LDKChannelMonitorUpdate update_var = *update;
4350         if (update->inner != NULL)
4351                 update_var = ChannelMonitorUpdate_clone(update);
4352         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4353         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4354         long update_ref = (long)update_var.inner;
4355         if (update_var.is_owned) {
4356                 update_ref |= 1;
4357         }
4358         LDKChannelMonitor data_var = *data;
4359         // Warning: we may need a move here but can't clone!
4360         CHECK((((long)data_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4361         CHECK((((long)&data_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4362         long data_ref = (long)data_var.inner;
4363         if (data_var.is_owned) {
4364                 data_ref |= 1;
4365         }
4366         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4367         CHECK(obj != NULL);
4368         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->update_persisted_channel_meth, id_ref, update_ref, data_ref);
4369         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
4370         FREE((void*)ret);
4371         return ret_conv;
4372 }
4373 static void LDKPersist_JCalls_free(void* this_arg) {
4374         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4375         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4376                 JNIEnv *env;
4377                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4378                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4379                 FREE(j_calls);
4380         }
4381 }
4382 static void* LDKPersist_JCalls_clone(const void* this_arg) {
4383         LDKPersist_JCalls *j_calls = (LDKPersist_JCalls*) this_arg;
4384         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4385         return (void*) this_arg;
4386 }
4387 static inline LDKPersist LDKPersist_init (JNIEnv * env, jclass _a, jobject o) {
4388         jclass c = (*env)->GetObjectClass(env, o);
4389         CHECK(c != NULL);
4390         LDKPersist_JCalls *calls = MALLOC(sizeof(LDKPersist_JCalls), "LDKPersist_JCalls");
4391         atomic_init(&calls->refcnt, 1);
4392         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4393         calls->o = (*env)->NewWeakGlobalRef(env, o);
4394         calls->persist_new_channel_meth = (*env)->GetMethodID(env, c, "persist_new_channel", "(JJ)J");
4395         CHECK(calls->persist_new_channel_meth != NULL);
4396         calls->update_persisted_channel_meth = (*env)->GetMethodID(env, c, "update_persisted_channel", "(JJJ)J");
4397         CHECK(calls->update_persisted_channel_meth != NULL);
4398
4399         LDKPersist ret = {
4400                 .this_arg = (void*) calls,
4401                 .persist_new_channel = persist_new_channel_jcall,
4402                 .update_persisted_channel = update_persisted_channel_jcall,
4403                 .free = LDKPersist_JCalls_free,
4404         };
4405         return ret;
4406 }
4407 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKPersist_1new (JNIEnv * env, jclass _a, jobject o) {
4408         LDKPersist *res_ptr = MALLOC(sizeof(LDKPersist), "LDKPersist");
4409         *res_ptr = LDKPersist_init(env, _a, o);
4410         return (long)res_ptr;
4411 }
4412 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKPersist_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4413         jobject ret = (*env)->NewLocalRef(env, ((LDKPersist_JCalls*)val)->o);
4414         CHECK(ret != NULL);
4415         return ret;
4416 }
4417 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Persist_1persist_1new_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong id, jlong data) {
4418         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
4419         LDKOutPoint id_conv;
4420         id_conv.inner = (void*)(id & (~1));
4421         id_conv.is_owned = (id & 1) || (id == 0);
4422         if (id_conv.inner != NULL)
4423                 id_conv = OutPoint_clone(&id_conv);
4424         LDKChannelMonitor data_conv;
4425         data_conv.inner = (void*)(data & (~1));
4426         data_conv.is_owned = false;
4427         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4428         *ret_conv = (this_arg_conv->persist_new_channel)(this_arg_conv->this_arg, id_conv, &data_conv);
4429         return (long)ret_conv;
4430 }
4431
4432 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Persist_1update_1persisted_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong id, jlong update, jlong data) {
4433         LDKPersist* this_arg_conv = (LDKPersist*)this_arg;
4434         LDKOutPoint id_conv;
4435         id_conv.inner = (void*)(id & (~1));
4436         id_conv.is_owned = (id & 1) || (id == 0);
4437         if (id_conv.inner != NULL)
4438                 id_conv = OutPoint_clone(&id_conv);
4439         LDKChannelMonitorUpdate update_conv;
4440         update_conv.inner = (void*)(update & (~1));
4441         update_conv.is_owned = false;
4442         LDKChannelMonitor data_conv;
4443         data_conv.inner = (void*)(data & (~1));
4444         data_conv.is_owned = false;
4445         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4446         *ret_conv = (this_arg_conv->update_persisted_channel)(this_arg_conv->this_arg, id_conv, &update_conv, &data_conv);
4447         return (long)ret_conv;
4448 }
4449
4450 typedef struct LDKChannelMessageHandler_JCalls {
4451         atomic_size_t refcnt;
4452         JavaVM *vm;
4453         jweak o;
4454         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
4455         jmethodID handle_open_channel_meth;
4456         jmethodID handle_accept_channel_meth;
4457         jmethodID handle_funding_created_meth;
4458         jmethodID handle_funding_signed_meth;
4459         jmethodID handle_funding_locked_meth;
4460         jmethodID handle_shutdown_meth;
4461         jmethodID handle_closing_signed_meth;
4462         jmethodID handle_update_add_htlc_meth;
4463         jmethodID handle_update_fulfill_htlc_meth;
4464         jmethodID handle_update_fail_htlc_meth;
4465         jmethodID handle_update_fail_malformed_htlc_meth;
4466         jmethodID handle_commitment_signed_meth;
4467         jmethodID handle_revoke_and_ack_meth;
4468         jmethodID handle_update_fee_meth;
4469         jmethodID handle_announcement_signatures_meth;
4470         jmethodID peer_disconnected_meth;
4471         jmethodID peer_connected_meth;
4472         jmethodID handle_channel_reestablish_meth;
4473         jmethodID handle_error_meth;
4474 } LDKChannelMessageHandler_JCalls;
4475 void handle_open_channel_jcall(const void* this_arg, struct LDKPublicKey their_node_id, struct LDKInitFeatures their_features, const struct LDKOpenChannel *NONNULL_PTR msg) {
4476         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4477         JNIEnv *_env;
4478         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4479         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4480         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4481         LDKInitFeatures their_features_var = their_features;
4482         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4483         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4484         long their_features_ref = (long)their_features_var.inner;
4485         if (their_features_var.is_owned) {
4486                 their_features_ref |= 1;
4487         }
4488         LDKOpenChannel msg_var = *msg;
4489         if (msg->inner != NULL)
4490                 msg_var = OpenChannel_clone(msg);
4491         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4492         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4493         long msg_ref = (long)msg_var.inner;
4494         if (msg_var.is_owned) {
4495                 msg_ref |= 1;
4496         }
4497         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4498         CHECK(obj != NULL);
4499         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_open_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
4500 }
4501 void handle_accept_channel_jcall(const void* this_arg, struct LDKPublicKey their_node_id, struct LDKInitFeatures their_features, const struct LDKAcceptChannel *NONNULL_PTR msg) {
4502         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4503         JNIEnv *_env;
4504         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4505         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4506         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4507         LDKInitFeatures their_features_var = their_features;
4508         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4509         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4510         long their_features_ref = (long)their_features_var.inner;
4511         if (their_features_var.is_owned) {
4512                 their_features_ref |= 1;
4513         }
4514         LDKAcceptChannel msg_var = *msg;
4515         if (msg->inner != NULL)
4516                 msg_var = AcceptChannel_clone(msg);
4517         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4518         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4519         long msg_ref = (long)msg_var.inner;
4520         if (msg_var.is_owned) {
4521                 msg_ref |= 1;
4522         }
4523         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4524         CHECK(obj != NULL);
4525         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_accept_channel_meth, their_node_id_arr, their_features_ref, msg_ref);
4526 }
4527 void handle_funding_created_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKFundingCreated *NONNULL_PTR msg) {
4528         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4529         JNIEnv *_env;
4530         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4531         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4532         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4533         LDKFundingCreated msg_var = *msg;
4534         if (msg->inner != NULL)
4535                 msg_var = FundingCreated_clone(msg);
4536         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4537         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4538         long msg_ref = (long)msg_var.inner;
4539         if (msg_var.is_owned) {
4540                 msg_ref |= 1;
4541         }
4542         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4543         CHECK(obj != NULL);
4544         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_created_meth, their_node_id_arr, msg_ref);
4545 }
4546 void handle_funding_signed_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKFundingSigned *NONNULL_PTR msg) {
4547         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4548         JNIEnv *_env;
4549         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4550         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4551         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4552         LDKFundingSigned msg_var = *msg;
4553         if (msg->inner != NULL)
4554                 msg_var = FundingSigned_clone(msg);
4555         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4556         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4557         long msg_ref = (long)msg_var.inner;
4558         if (msg_var.is_owned) {
4559                 msg_ref |= 1;
4560         }
4561         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4562         CHECK(obj != NULL);
4563         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_signed_meth, their_node_id_arr, msg_ref);
4564 }
4565 void handle_funding_locked_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKFundingLocked *NONNULL_PTR msg) {
4566         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4567         JNIEnv *_env;
4568         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4569         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4570         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4571         LDKFundingLocked msg_var = *msg;
4572         if (msg->inner != NULL)
4573                 msg_var = FundingLocked_clone(msg);
4574         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4575         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4576         long msg_ref = (long)msg_var.inner;
4577         if (msg_var.is_owned) {
4578                 msg_ref |= 1;
4579         }
4580         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4581         CHECK(obj != NULL);
4582         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_locked_meth, their_node_id_arr, msg_ref);
4583 }
4584 void handle_shutdown_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKShutdown *NONNULL_PTR msg) {
4585         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4586         JNIEnv *_env;
4587         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4588         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4589         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4590         LDKShutdown msg_var = *msg;
4591         if (msg->inner != NULL)
4592                 msg_var = Shutdown_clone(msg);
4593         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4594         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4595         long msg_ref = (long)msg_var.inner;
4596         if (msg_var.is_owned) {
4597                 msg_ref |= 1;
4598         }
4599         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4600         CHECK(obj != NULL);
4601         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_shutdown_meth, their_node_id_arr, msg_ref);
4602 }
4603 void handle_closing_signed_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKClosingSigned *NONNULL_PTR msg) {
4604         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4605         JNIEnv *_env;
4606         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4607         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4608         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4609         LDKClosingSigned msg_var = *msg;
4610         if (msg->inner != NULL)
4611                 msg_var = ClosingSigned_clone(msg);
4612         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4613         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4614         long msg_ref = (long)msg_var.inner;
4615         if (msg_var.is_owned) {
4616                 msg_ref |= 1;
4617         }
4618         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4619         CHECK(obj != NULL);
4620         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_closing_signed_meth, their_node_id_arr, msg_ref);
4621 }
4622 void handle_update_add_htlc_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateAddHTLC *NONNULL_PTR msg) {
4623         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4624         JNIEnv *_env;
4625         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4626         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4627         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4628         LDKUpdateAddHTLC msg_var = *msg;
4629         if (msg->inner != NULL)
4630                 msg_var = UpdateAddHTLC_clone(msg);
4631         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4632         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4633         long msg_ref = (long)msg_var.inner;
4634         if (msg_var.is_owned) {
4635                 msg_ref |= 1;
4636         }
4637         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4638         CHECK(obj != NULL);
4639         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_add_htlc_meth, their_node_id_arr, msg_ref);
4640 }
4641 void handle_update_fulfill_htlc_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateFulfillHTLC *NONNULL_PTR msg) {
4642         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4643         JNIEnv *_env;
4644         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4645         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4646         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4647         LDKUpdateFulfillHTLC msg_var = *msg;
4648         if (msg->inner != NULL)
4649                 msg_var = UpdateFulfillHTLC_clone(msg);
4650         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4651         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4652         long msg_ref = (long)msg_var.inner;
4653         if (msg_var.is_owned) {
4654                 msg_ref |= 1;
4655         }
4656         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4657         CHECK(obj != NULL);
4658         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fulfill_htlc_meth, their_node_id_arr, msg_ref);
4659 }
4660 void handle_update_fail_htlc_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateFailHTLC *NONNULL_PTR msg) {
4661         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4662         JNIEnv *_env;
4663         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4664         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4665         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4666         LDKUpdateFailHTLC msg_var = *msg;
4667         if (msg->inner != NULL)
4668                 msg_var = UpdateFailHTLC_clone(msg);
4669         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4670         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4671         long msg_ref = (long)msg_var.inner;
4672         if (msg_var.is_owned) {
4673                 msg_ref |= 1;
4674         }
4675         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4676         CHECK(obj != NULL);
4677         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fail_htlc_meth, their_node_id_arr, msg_ref);
4678 }
4679 void handle_update_fail_malformed_htlc_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateFailMalformedHTLC *NONNULL_PTR msg) {
4680         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4681         JNIEnv *_env;
4682         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4683         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4684         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4685         LDKUpdateFailMalformedHTLC msg_var = *msg;
4686         if (msg->inner != NULL)
4687                 msg_var = UpdateFailMalformedHTLC_clone(msg);
4688         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4689         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4690         long msg_ref = (long)msg_var.inner;
4691         if (msg_var.is_owned) {
4692                 msg_ref |= 1;
4693         }
4694         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4695         CHECK(obj != NULL);
4696         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fail_malformed_htlc_meth, their_node_id_arr, msg_ref);
4697 }
4698 void handle_commitment_signed_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKCommitmentSigned *NONNULL_PTR msg) {
4699         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4700         JNIEnv *_env;
4701         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4702         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4703         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4704         LDKCommitmentSigned msg_var = *msg;
4705         if (msg->inner != NULL)
4706                 msg_var = CommitmentSigned_clone(msg);
4707         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4708         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4709         long msg_ref = (long)msg_var.inner;
4710         if (msg_var.is_owned) {
4711                 msg_ref |= 1;
4712         }
4713         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4714         CHECK(obj != NULL);
4715         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_commitment_signed_meth, their_node_id_arr, msg_ref);
4716 }
4717 void handle_revoke_and_ack_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKRevokeAndACK *NONNULL_PTR msg) {
4718         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4719         JNIEnv *_env;
4720         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4721         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4722         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4723         LDKRevokeAndACK msg_var = *msg;
4724         if (msg->inner != NULL)
4725                 msg_var = RevokeAndACK_clone(msg);
4726         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4727         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4728         long msg_ref = (long)msg_var.inner;
4729         if (msg_var.is_owned) {
4730                 msg_ref |= 1;
4731         }
4732         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4733         CHECK(obj != NULL);
4734         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_revoke_and_ack_meth, their_node_id_arr, msg_ref);
4735 }
4736 void handle_update_fee_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKUpdateFee *NONNULL_PTR msg) {
4737         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4738         JNIEnv *_env;
4739         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4740         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4741         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4742         LDKUpdateFee msg_var = *msg;
4743         if (msg->inner != NULL)
4744                 msg_var = UpdateFee_clone(msg);
4745         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4746         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4747         long msg_ref = (long)msg_var.inner;
4748         if (msg_var.is_owned) {
4749                 msg_ref |= 1;
4750         }
4751         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4752         CHECK(obj != NULL);
4753         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fee_meth, their_node_id_arr, msg_ref);
4754 }
4755 void handle_announcement_signatures_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKAnnouncementSignatures *NONNULL_PTR msg) {
4756         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4757         JNIEnv *_env;
4758         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4759         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4760         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4761         LDKAnnouncementSignatures msg_var = *msg;
4762         if (msg->inner != NULL)
4763                 msg_var = AnnouncementSignatures_clone(msg);
4764         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4765         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4766         long msg_ref = (long)msg_var.inner;
4767         if (msg_var.is_owned) {
4768                 msg_ref |= 1;
4769         }
4770         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4771         CHECK(obj != NULL);
4772         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_announcement_signatures_meth, their_node_id_arr, msg_ref);
4773 }
4774 void peer_disconnected_jcall(const void* this_arg, struct LDKPublicKey their_node_id, bool no_connection_possible) {
4775         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4776         JNIEnv *_env;
4777         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4778         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4779         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4780         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4781         CHECK(obj != NULL);
4782         return (*_env)->CallVoidMethod(_env, obj, j_calls->peer_disconnected_meth, their_node_id_arr, no_connection_possible);
4783 }
4784 void peer_connected_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKInit *NONNULL_PTR msg) {
4785         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4786         JNIEnv *_env;
4787         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4788         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4789         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4790         LDKInit msg_var = *msg;
4791         if (msg->inner != NULL)
4792                 msg_var = Init_clone(msg);
4793         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4794         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4795         long msg_ref = (long)msg_var.inner;
4796         if (msg_var.is_owned) {
4797                 msg_ref |= 1;
4798         }
4799         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4800         CHECK(obj != NULL);
4801         return (*_env)->CallVoidMethod(_env, obj, j_calls->peer_connected_meth, their_node_id_arr, msg_ref);
4802 }
4803 void handle_channel_reestablish_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKChannelReestablish *NONNULL_PTR msg) {
4804         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4805         JNIEnv *_env;
4806         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4807         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4808         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4809         LDKChannelReestablish msg_var = *msg;
4810         if (msg->inner != NULL)
4811                 msg_var = ChannelReestablish_clone(msg);
4812         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4813         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4814         long msg_ref = (long)msg_var.inner;
4815         if (msg_var.is_owned) {
4816                 msg_ref |= 1;
4817         }
4818         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4819         CHECK(obj != NULL);
4820         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_channel_reestablish_meth, their_node_id_arr, msg_ref);
4821 }
4822 void handle_error_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKErrorMessage *NONNULL_PTR msg) {
4823         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4824         JNIEnv *_env;
4825         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
4826         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
4827         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
4828         LDKErrorMessage msg_var = *msg;
4829         if (msg->inner != NULL)
4830                 msg_var = ErrorMessage_clone(msg);
4831         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4832         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4833         long msg_ref = (long)msg_var.inner;
4834         if (msg_var.is_owned) {
4835                 msg_ref |= 1;
4836         }
4837         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
4838         CHECK(obj != NULL);
4839         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_error_meth, their_node_id_arr, msg_ref);
4840 }
4841 static void LDKChannelMessageHandler_JCalls_free(void* this_arg) {
4842         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4843         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4844                 JNIEnv *env;
4845                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4846                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4847                 FREE(j_calls);
4848         }
4849 }
4850 static void* LDKChannelMessageHandler_JCalls_clone(const void* this_arg) {
4851         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
4852         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4853         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
4854         return (void*) this_arg;
4855 }
4856 static inline LDKChannelMessageHandler LDKChannelMessageHandler_init (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
4857         jclass c = (*env)->GetObjectClass(env, o);
4858         CHECK(c != NULL);
4859         LDKChannelMessageHandler_JCalls *calls = MALLOC(sizeof(LDKChannelMessageHandler_JCalls), "LDKChannelMessageHandler_JCalls");
4860         atomic_init(&calls->refcnt, 1);
4861         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4862         calls->o = (*env)->NewWeakGlobalRef(env, o);
4863         calls->handle_open_channel_meth = (*env)->GetMethodID(env, c, "handle_open_channel", "([BJJ)V");
4864         CHECK(calls->handle_open_channel_meth != NULL);
4865         calls->handle_accept_channel_meth = (*env)->GetMethodID(env, c, "handle_accept_channel", "([BJJ)V");
4866         CHECK(calls->handle_accept_channel_meth != NULL);
4867         calls->handle_funding_created_meth = (*env)->GetMethodID(env, c, "handle_funding_created", "([BJ)V");
4868         CHECK(calls->handle_funding_created_meth != NULL);
4869         calls->handle_funding_signed_meth = (*env)->GetMethodID(env, c, "handle_funding_signed", "([BJ)V");
4870         CHECK(calls->handle_funding_signed_meth != NULL);
4871         calls->handle_funding_locked_meth = (*env)->GetMethodID(env, c, "handle_funding_locked", "([BJ)V");
4872         CHECK(calls->handle_funding_locked_meth != NULL);
4873         calls->handle_shutdown_meth = (*env)->GetMethodID(env, c, "handle_shutdown", "([BJ)V");
4874         CHECK(calls->handle_shutdown_meth != NULL);
4875         calls->handle_closing_signed_meth = (*env)->GetMethodID(env, c, "handle_closing_signed", "([BJ)V");
4876         CHECK(calls->handle_closing_signed_meth != NULL);
4877         calls->handle_update_add_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_add_htlc", "([BJ)V");
4878         CHECK(calls->handle_update_add_htlc_meth != NULL);
4879         calls->handle_update_fulfill_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fulfill_htlc", "([BJ)V");
4880         CHECK(calls->handle_update_fulfill_htlc_meth != NULL);
4881         calls->handle_update_fail_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_htlc", "([BJ)V");
4882         CHECK(calls->handle_update_fail_htlc_meth != NULL);
4883         calls->handle_update_fail_malformed_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_malformed_htlc", "([BJ)V");
4884         CHECK(calls->handle_update_fail_malformed_htlc_meth != NULL);
4885         calls->handle_commitment_signed_meth = (*env)->GetMethodID(env, c, "handle_commitment_signed", "([BJ)V");
4886         CHECK(calls->handle_commitment_signed_meth != NULL);
4887         calls->handle_revoke_and_ack_meth = (*env)->GetMethodID(env, c, "handle_revoke_and_ack", "([BJ)V");
4888         CHECK(calls->handle_revoke_and_ack_meth != NULL);
4889         calls->handle_update_fee_meth = (*env)->GetMethodID(env, c, "handle_update_fee", "([BJ)V");
4890         CHECK(calls->handle_update_fee_meth != NULL);
4891         calls->handle_announcement_signatures_meth = (*env)->GetMethodID(env, c, "handle_announcement_signatures", "([BJ)V");
4892         CHECK(calls->handle_announcement_signatures_meth != NULL);
4893         calls->peer_disconnected_meth = (*env)->GetMethodID(env, c, "peer_disconnected", "([BZ)V");
4894         CHECK(calls->peer_disconnected_meth != NULL);
4895         calls->peer_connected_meth = (*env)->GetMethodID(env, c, "peer_connected", "([BJ)V");
4896         CHECK(calls->peer_connected_meth != NULL);
4897         calls->handle_channel_reestablish_meth = (*env)->GetMethodID(env, c, "handle_channel_reestablish", "([BJ)V");
4898         CHECK(calls->handle_channel_reestablish_meth != NULL);
4899         calls->handle_error_meth = (*env)->GetMethodID(env, c, "handle_error", "([BJ)V");
4900         CHECK(calls->handle_error_meth != NULL);
4901
4902         LDKChannelMessageHandler ret = {
4903                 .this_arg = (void*) calls,
4904                 .handle_open_channel = handle_open_channel_jcall,
4905                 .handle_accept_channel = handle_accept_channel_jcall,
4906                 .handle_funding_created = handle_funding_created_jcall,
4907                 .handle_funding_signed = handle_funding_signed_jcall,
4908                 .handle_funding_locked = handle_funding_locked_jcall,
4909                 .handle_shutdown = handle_shutdown_jcall,
4910                 .handle_closing_signed = handle_closing_signed_jcall,
4911                 .handle_update_add_htlc = handle_update_add_htlc_jcall,
4912                 .handle_update_fulfill_htlc = handle_update_fulfill_htlc_jcall,
4913                 .handle_update_fail_htlc = handle_update_fail_htlc_jcall,
4914                 .handle_update_fail_malformed_htlc = handle_update_fail_malformed_htlc_jcall,
4915                 .handle_commitment_signed = handle_commitment_signed_jcall,
4916                 .handle_revoke_and_ack = handle_revoke_and_ack_jcall,
4917                 .handle_update_fee = handle_update_fee_jcall,
4918                 .handle_announcement_signatures = handle_announcement_signatures_jcall,
4919                 .peer_disconnected = peer_disconnected_jcall,
4920                 .peer_connected = peer_connected_jcall,
4921                 .handle_channel_reestablish = handle_channel_reestablish_jcall,
4922                 .handle_error = handle_error_jcall,
4923                 .free = LDKChannelMessageHandler_JCalls_free,
4924                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(env, _a, MessageSendEventsProvider),
4925         };
4926         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
4927         return ret;
4928 }
4929 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1new (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
4930         LDKChannelMessageHandler *res_ptr = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
4931         *res_ptr = LDKChannelMessageHandler_init(env, _a, o, MessageSendEventsProvider);
4932         return (long)res_ptr;
4933 }
4934 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4935         jobject ret = (*env)->NewLocalRef(env, ((LDKChannelMessageHandler_JCalls*)val)->o);
4936         CHECK(ret != NULL);
4937         return ret;
4938 }
4939 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) {
4940         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4941         LDKPublicKey their_node_id_ref;
4942         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
4943         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4944         LDKInitFeatures their_features_conv;
4945         their_features_conv.inner = (void*)(their_features & (~1));
4946         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
4947         // Warning: we may need a move here but can't clone!
4948         LDKOpenChannel msg_conv;
4949         msg_conv.inner = (void*)(msg & (~1));
4950         msg_conv.is_owned = false;
4951         (this_arg_conv->handle_open_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
4952 }
4953
4954 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) {
4955         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4956         LDKPublicKey their_node_id_ref;
4957         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
4958         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4959         LDKInitFeatures their_features_conv;
4960         their_features_conv.inner = (void*)(their_features & (~1));
4961         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
4962         // Warning: we may need a move here but can't clone!
4963         LDKAcceptChannel msg_conv;
4964         msg_conv.inner = (void*)(msg & (~1));
4965         msg_conv.is_owned = false;
4966         (this_arg_conv->handle_accept_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
4967 }
4968
4969 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) {
4970         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4971         LDKPublicKey their_node_id_ref;
4972         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
4973         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4974         LDKFundingCreated msg_conv;
4975         msg_conv.inner = (void*)(msg & (~1));
4976         msg_conv.is_owned = false;
4977         (this_arg_conv->handle_funding_created)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4978 }
4979
4980 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) {
4981         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4982         LDKPublicKey their_node_id_ref;
4983         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
4984         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4985         LDKFundingSigned msg_conv;
4986         msg_conv.inner = (void*)(msg & (~1));
4987         msg_conv.is_owned = false;
4988         (this_arg_conv->handle_funding_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
4989 }
4990
4991 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) {
4992         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
4993         LDKPublicKey their_node_id_ref;
4994         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
4995         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
4996         LDKFundingLocked msg_conv;
4997         msg_conv.inner = (void*)(msg & (~1));
4998         msg_conv.is_owned = false;
4999         (this_arg_conv->handle_funding_locked)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5000 }
5001
5002 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1shutdown(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5003         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5004         LDKPublicKey their_node_id_ref;
5005         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5006         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5007         LDKShutdown msg_conv;
5008         msg_conv.inner = (void*)(msg & (~1));
5009         msg_conv.is_owned = false;
5010         (this_arg_conv->handle_shutdown)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5011 }
5012
5013 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) {
5014         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5015         LDKPublicKey their_node_id_ref;
5016         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5017         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5018         LDKClosingSigned msg_conv;
5019         msg_conv.inner = (void*)(msg & (~1));
5020         msg_conv.is_owned = false;
5021         (this_arg_conv->handle_closing_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5022 }
5023
5024 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) {
5025         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5026         LDKPublicKey their_node_id_ref;
5027         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5028         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5029         LDKUpdateAddHTLC msg_conv;
5030         msg_conv.inner = (void*)(msg & (~1));
5031         msg_conv.is_owned = false;
5032         (this_arg_conv->handle_update_add_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5033 }
5034
5035 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) {
5036         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5037         LDKPublicKey their_node_id_ref;
5038         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5039         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5040         LDKUpdateFulfillHTLC msg_conv;
5041         msg_conv.inner = (void*)(msg & (~1));
5042         msg_conv.is_owned = false;
5043         (this_arg_conv->handle_update_fulfill_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5044 }
5045
5046 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) {
5047         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5048         LDKPublicKey their_node_id_ref;
5049         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5050         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5051         LDKUpdateFailHTLC msg_conv;
5052         msg_conv.inner = (void*)(msg & (~1));
5053         msg_conv.is_owned = false;
5054         (this_arg_conv->handle_update_fail_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5055 }
5056
5057 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) {
5058         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5059         LDKPublicKey their_node_id_ref;
5060         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5061         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5062         LDKUpdateFailMalformedHTLC msg_conv;
5063         msg_conv.inner = (void*)(msg & (~1));
5064         msg_conv.is_owned = false;
5065         (this_arg_conv->handle_update_fail_malformed_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5066 }
5067
5068 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) {
5069         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5070         LDKPublicKey their_node_id_ref;
5071         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5072         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5073         LDKCommitmentSigned msg_conv;
5074         msg_conv.inner = (void*)(msg & (~1));
5075         msg_conv.is_owned = false;
5076         (this_arg_conv->handle_commitment_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5077 }
5078
5079 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) {
5080         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5081         LDKPublicKey their_node_id_ref;
5082         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5083         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5084         LDKRevokeAndACK msg_conv;
5085         msg_conv.inner = (void*)(msg & (~1));
5086         msg_conv.is_owned = false;
5087         (this_arg_conv->handle_revoke_and_ack)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5088 }
5089
5090 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) {
5091         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5092         LDKPublicKey their_node_id_ref;
5093         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5094         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5095         LDKUpdateFee msg_conv;
5096         msg_conv.inner = (void*)(msg & (~1));
5097         msg_conv.is_owned = false;
5098         (this_arg_conv->handle_update_fee)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5099 }
5100
5101 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) {
5102         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5103         LDKPublicKey their_node_id_ref;
5104         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5105         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5106         LDKAnnouncementSignatures msg_conv;
5107         msg_conv.inner = (void*)(msg & (~1));
5108         msg_conv.is_owned = false;
5109         (this_arg_conv->handle_announcement_signatures)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5110 }
5111
5112 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) {
5113         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5114         LDKPublicKey their_node_id_ref;
5115         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5116         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5117         (this_arg_conv->peer_disconnected)(this_arg_conv->this_arg, their_node_id_ref, no_connection_possible);
5118 }
5119
5120 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1peer_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5121         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5122         LDKPublicKey their_node_id_ref;
5123         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5124         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5125         LDKInit msg_conv;
5126         msg_conv.inner = (void*)(msg & (~1));
5127         msg_conv.is_owned = false;
5128         (this_arg_conv->peer_connected)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5129 }
5130
5131 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) {
5132         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5133         LDKPublicKey their_node_id_ref;
5134         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5135         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5136         LDKChannelReestablish msg_conv;
5137         msg_conv.inner = (void*)(msg & (~1));
5138         msg_conv.is_owned = false;
5139         (this_arg_conv->handle_channel_reestablish)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5140 }
5141
5142 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1error(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5143         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
5144         LDKPublicKey their_node_id_ref;
5145         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5146         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5147         LDKErrorMessage msg_conv;
5148         msg_conv.inner = (void*)(msg & (~1));
5149         msg_conv.is_owned = false;
5150         (this_arg_conv->handle_error)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
5151 }
5152
5153 typedef struct LDKRoutingMessageHandler_JCalls {
5154         atomic_size_t refcnt;
5155         JavaVM *vm;
5156         jweak o;
5157         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
5158         jmethodID handle_node_announcement_meth;
5159         jmethodID handle_channel_announcement_meth;
5160         jmethodID handle_channel_update_meth;
5161         jmethodID handle_htlc_fail_channel_update_meth;
5162         jmethodID get_next_channel_announcements_meth;
5163         jmethodID get_next_node_announcements_meth;
5164         jmethodID sync_routing_table_meth;
5165         jmethodID handle_reply_channel_range_meth;
5166         jmethodID handle_reply_short_channel_ids_end_meth;
5167         jmethodID handle_query_channel_range_meth;
5168         jmethodID handle_query_short_channel_ids_meth;
5169 } LDKRoutingMessageHandler_JCalls;
5170 LDKCResult_boolLightningErrorZ handle_node_announcement_jcall(const void* this_arg, const struct LDKNodeAnnouncement *NONNULL_PTR msg) {
5171         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5172         JNIEnv *_env;
5173         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5174         LDKNodeAnnouncement msg_var = *msg;
5175         if (msg->inner != NULL)
5176                 msg_var = NodeAnnouncement_clone(msg);
5177         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5178         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5179         long msg_ref = (long)msg_var.inner;
5180         if (msg_var.is_owned) {
5181                 msg_ref |= 1;
5182         }
5183         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5184         CHECK(obj != NULL);
5185         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_node_announcement_meth, msg_ref);
5186         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
5187         FREE((void*)ret);
5188         return ret_conv;
5189 }
5190 LDKCResult_boolLightningErrorZ handle_channel_announcement_jcall(const void* this_arg, const struct LDKChannelAnnouncement *NONNULL_PTR msg) {
5191         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5192         JNIEnv *_env;
5193         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5194         LDKChannelAnnouncement msg_var = *msg;
5195         if (msg->inner != NULL)
5196                 msg_var = ChannelAnnouncement_clone(msg);
5197         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5198         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5199         long msg_ref = (long)msg_var.inner;
5200         if (msg_var.is_owned) {
5201                 msg_ref |= 1;
5202         }
5203         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5204         CHECK(obj != NULL);
5205         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_channel_announcement_meth, msg_ref);
5206         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
5207         FREE((void*)ret);
5208         return ret_conv;
5209 }
5210 LDKCResult_boolLightningErrorZ handle_channel_update_jcall(const void* this_arg, const struct LDKChannelUpdate *NONNULL_PTR msg) {
5211         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5212         JNIEnv *_env;
5213         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5214         LDKChannelUpdate msg_var = *msg;
5215         if (msg->inner != NULL)
5216                 msg_var = ChannelUpdate_clone(msg);
5217         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5218         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5219         long msg_ref = (long)msg_var.inner;
5220         if (msg_var.is_owned) {
5221                 msg_ref |= 1;
5222         }
5223         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5224         CHECK(obj != NULL);
5225         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_channel_update_meth, msg_ref);
5226         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
5227         FREE((void*)ret);
5228         return ret_conv;
5229 }
5230 void handle_htlc_fail_channel_update_jcall(const void* this_arg, const struct LDKHTLCFailChannelUpdate *NONNULL_PTR update) {
5231         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5232         JNIEnv *_env;
5233         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5234         long ret_update = (long)update;
5235         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5236         CHECK(obj != NULL);
5237         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_htlc_fail_channel_update_meth, ret_update);
5238 }
5239 LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcements_jcall(const void* this_arg, uint64_t starting_point, uint8_t batch_amount) {
5240         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5241         JNIEnv *_env;
5242         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5243         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5244         CHECK(obj != NULL);
5245         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_next_channel_announcements_meth, starting_point, batch_amount);
5246         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ arg_constr;
5247         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5248         if (arg_constr.datalen > 0)
5249                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
5250         else
5251                 arg_constr.data = NULL;
5252         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5253         for (size_t l = 0; l < arg_constr.datalen; l++) {
5254                 long arr_conv_63 = arg_vals[l];
5255                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
5256                 FREE((void*)arr_conv_63);
5257                 arg_constr.data[l] = arr_conv_63_conv;
5258         }
5259         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5260         return arg_constr;
5261 }
5262 LDKCVec_NodeAnnouncementZ get_next_node_announcements_jcall(const void* this_arg, struct LDKPublicKey starting_point, uint8_t batch_amount) {
5263         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5264         JNIEnv *_env;
5265         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5266         jbyteArray starting_point_arr = (*_env)->NewByteArray(_env, 33);
5267         (*_env)->SetByteArrayRegion(_env, starting_point_arr, 0, 33, starting_point.compressed_form);
5268         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5269         CHECK(obj != NULL);
5270         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_next_node_announcements_meth, starting_point_arr, batch_amount);
5271         LDKCVec_NodeAnnouncementZ 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(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
5275         else
5276                 arg_constr.data = NULL;
5277         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5278         for (size_t s = 0; s < arg_constr.datalen; s++) {
5279                 long arr_conv_18 = arg_vals[s];
5280                 LDKNodeAnnouncement arr_conv_18_conv;
5281                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
5282                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
5283                 if (arr_conv_18_conv.inner != NULL)
5284                         arr_conv_18_conv = NodeAnnouncement_clone(&arr_conv_18_conv);
5285                 arg_constr.data[s] = arr_conv_18_conv;
5286         }
5287         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5288         return arg_constr;
5289 }
5290 void sync_routing_table_jcall(const void* this_arg, struct LDKPublicKey their_node_id, const struct LDKInit *NONNULL_PTR init) {
5291         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5292         JNIEnv *_env;
5293         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5294         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
5295         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5296         LDKInit init_var = *init;
5297         if (init->inner != NULL)
5298                 init_var = Init_clone(init);
5299         CHECK((((long)init_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5300         CHECK((((long)&init_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5301         long init_ref = (long)init_var.inner;
5302         if (init_var.is_owned) {
5303                 init_ref |= 1;
5304         }
5305         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5306         CHECK(obj != NULL);
5307         return (*_env)->CallVoidMethod(_env, obj, j_calls->sync_routing_table_meth, their_node_id_arr, init_ref);
5308 }
5309 LDKCResult_NoneLightningErrorZ handle_reply_channel_range_jcall(const void* this_arg, struct LDKPublicKey their_node_id, struct LDKReplyChannelRange msg) {
5310         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5311         JNIEnv *_env;
5312         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5313         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
5314         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5315         LDKReplyChannelRange msg_var = msg;
5316         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5317         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5318         long msg_ref = (long)msg_var.inner;
5319         if (msg_var.is_owned) {
5320                 msg_ref |= 1;
5321         }
5322         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5323         CHECK(obj != NULL);
5324         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_reply_channel_range_meth, their_node_id_arr, msg_ref);
5325         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5326         FREE((void*)ret);
5327         return ret_conv;
5328 }
5329 LDKCResult_NoneLightningErrorZ handle_reply_short_channel_ids_end_jcall(const void* this_arg, struct LDKPublicKey their_node_id, struct LDKReplyShortChannelIdsEnd msg) {
5330         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5331         JNIEnv *_env;
5332         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5333         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
5334         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5335         LDKReplyShortChannelIdsEnd msg_var = msg;
5336         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5337         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5338         long msg_ref = (long)msg_var.inner;
5339         if (msg_var.is_owned) {
5340                 msg_ref |= 1;
5341         }
5342         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5343         CHECK(obj != NULL);
5344         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_reply_short_channel_ids_end_meth, their_node_id_arr, msg_ref);
5345         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5346         FREE((void*)ret);
5347         return ret_conv;
5348 }
5349 LDKCResult_NoneLightningErrorZ handle_query_channel_range_jcall(const void* this_arg, struct LDKPublicKey their_node_id, struct LDKQueryChannelRange msg) {
5350         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5351         JNIEnv *_env;
5352         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5353         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
5354         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5355         LDKQueryChannelRange msg_var = msg;
5356         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5357         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5358         long msg_ref = (long)msg_var.inner;
5359         if (msg_var.is_owned) {
5360                 msg_ref |= 1;
5361         }
5362         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5363         CHECK(obj != NULL);
5364         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_query_channel_range_meth, their_node_id_arr, msg_ref);
5365         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5366         FREE((void*)ret);
5367         return ret_conv;
5368 }
5369 LDKCResult_NoneLightningErrorZ handle_query_short_channel_ids_jcall(const void* this_arg, struct LDKPublicKey their_node_id, struct LDKQueryShortChannelIds msg) {
5370         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5371         JNIEnv *_env;
5372         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5373         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
5374         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
5375         LDKQueryShortChannelIds msg_var = msg;
5376         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5377         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5378         long msg_ref = (long)msg_var.inner;
5379         if (msg_var.is_owned) {
5380                 msg_ref |= 1;
5381         }
5382         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5383         CHECK(obj != NULL);
5384         LDKCResult_NoneLightningErrorZ* ret = (LDKCResult_NoneLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_query_short_channel_ids_meth, their_node_id_arr, msg_ref);
5385         LDKCResult_NoneLightningErrorZ ret_conv = *(LDKCResult_NoneLightningErrorZ*)ret;
5386         FREE((void*)ret);
5387         return ret_conv;
5388 }
5389 static void LDKRoutingMessageHandler_JCalls_free(void* this_arg) {
5390         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5391         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
5392                 JNIEnv *env;
5393                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5394                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
5395                 FREE(j_calls);
5396         }
5397 }
5398 static void* LDKRoutingMessageHandler_JCalls_clone(const void* this_arg) {
5399         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
5400         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
5401         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
5402         return (void*) this_arg;
5403 }
5404 static inline LDKRoutingMessageHandler LDKRoutingMessageHandler_init (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
5405         jclass c = (*env)->GetObjectClass(env, o);
5406         CHECK(c != NULL);
5407         LDKRoutingMessageHandler_JCalls *calls = MALLOC(sizeof(LDKRoutingMessageHandler_JCalls), "LDKRoutingMessageHandler_JCalls");
5408         atomic_init(&calls->refcnt, 1);
5409         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
5410         calls->o = (*env)->NewWeakGlobalRef(env, o);
5411         calls->handle_node_announcement_meth = (*env)->GetMethodID(env, c, "handle_node_announcement", "(J)J");
5412         CHECK(calls->handle_node_announcement_meth != NULL);
5413         calls->handle_channel_announcement_meth = (*env)->GetMethodID(env, c, "handle_channel_announcement", "(J)J");
5414         CHECK(calls->handle_channel_announcement_meth != NULL);
5415         calls->handle_channel_update_meth = (*env)->GetMethodID(env, c, "handle_channel_update", "(J)J");
5416         CHECK(calls->handle_channel_update_meth != NULL);
5417         calls->handle_htlc_fail_channel_update_meth = (*env)->GetMethodID(env, c, "handle_htlc_fail_channel_update", "(J)V");
5418         CHECK(calls->handle_htlc_fail_channel_update_meth != NULL);
5419         calls->get_next_channel_announcements_meth = (*env)->GetMethodID(env, c, "get_next_channel_announcements", "(JB)[J");
5420         CHECK(calls->get_next_channel_announcements_meth != NULL);
5421         calls->get_next_node_announcements_meth = (*env)->GetMethodID(env, c, "get_next_node_announcements", "([BB)[J");
5422         CHECK(calls->get_next_node_announcements_meth != NULL);
5423         calls->sync_routing_table_meth = (*env)->GetMethodID(env, c, "sync_routing_table", "([BJ)V");
5424         CHECK(calls->sync_routing_table_meth != NULL);
5425         calls->handle_reply_channel_range_meth = (*env)->GetMethodID(env, c, "handle_reply_channel_range", "([BJ)J");
5426         CHECK(calls->handle_reply_channel_range_meth != NULL);
5427         calls->handle_reply_short_channel_ids_end_meth = (*env)->GetMethodID(env, c, "handle_reply_short_channel_ids_end", "([BJ)J");
5428         CHECK(calls->handle_reply_short_channel_ids_end_meth != NULL);
5429         calls->handle_query_channel_range_meth = (*env)->GetMethodID(env, c, "handle_query_channel_range", "([BJ)J");
5430         CHECK(calls->handle_query_channel_range_meth != NULL);
5431         calls->handle_query_short_channel_ids_meth = (*env)->GetMethodID(env, c, "handle_query_short_channel_ids", "([BJ)J");
5432         CHECK(calls->handle_query_short_channel_ids_meth != NULL);
5433
5434         LDKRoutingMessageHandler ret = {
5435                 .this_arg = (void*) calls,
5436                 .handle_node_announcement = handle_node_announcement_jcall,
5437                 .handle_channel_announcement = handle_channel_announcement_jcall,
5438                 .handle_channel_update = handle_channel_update_jcall,
5439                 .handle_htlc_fail_channel_update = handle_htlc_fail_channel_update_jcall,
5440                 .get_next_channel_announcements = get_next_channel_announcements_jcall,
5441                 .get_next_node_announcements = get_next_node_announcements_jcall,
5442                 .sync_routing_table = sync_routing_table_jcall,
5443                 .handle_reply_channel_range = handle_reply_channel_range_jcall,
5444                 .handle_reply_short_channel_ids_end = handle_reply_short_channel_ids_end_jcall,
5445                 .handle_query_channel_range = handle_query_channel_range_jcall,
5446                 .handle_query_short_channel_ids = handle_query_short_channel_ids_jcall,
5447                 .free = LDKRoutingMessageHandler_JCalls_free,
5448                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(env, _a, MessageSendEventsProvider),
5449         };
5450         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
5451         return ret;
5452 }
5453 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1new (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
5454         LDKRoutingMessageHandler *res_ptr = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
5455         *res_ptr = LDKRoutingMessageHandler_init(env, _a, o, MessageSendEventsProvider);
5456         return (long)res_ptr;
5457 }
5458 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
5459         jobject ret = (*env)->NewLocalRef(env, ((LDKRoutingMessageHandler_JCalls*)val)->o);
5460         CHECK(ret != NULL);
5461         return ret;
5462 }
5463 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1node_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
5464         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5465         LDKNodeAnnouncement msg_conv;
5466         msg_conv.inner = (void*)(msg & (~1));
5467         msg_conv.is_owned = false;
5468         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5469         *ret_conv = (this_arg_conv->handle_node_announcement)(this_arg_conv->this_arg, &msg_conv);
5470         return (long)ret_conv;
5471 }
5472
5473 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
5474         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5475         LDKChannelAnnouncement msg_conv;
5476         msg_conv.inner = (void*)(msg & (~1));
5477         msg_conv.is_owned = false;
5478         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5479         *ret_conv = (this_arg_conv->handle_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
5480         return (long)ret_conv;
5481 }
5482
5483 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1update(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
5484         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5485         LDKChannelUpdate msg_conv;
5486         msg_conv.inner = (void*)(msg & (~1));
5487         msg_conv.is_owned = false;
5488         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
5489         *ret_conv = (this_arg_conv->handle_channel_update)(this_arg_conv->this_arg, &msg_conv);
5490         return (long)ret_conv;
5491 }
5492
5493 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1htlc_1fail_1channel_1update(JNIEnv * _env, jclass _b, jlong this_arg, jlong update) {
5494         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5495         LDKHTLCFailChannelUpdate* update_conv = (LDKHTLCFailChannelUpdate*)update;
5496         (this_arg_conv->handle_htlc_fail_channel_update)(this_arg_conv->this_arg, update_conv);
5497 }
5498
5499 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) {
5500         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5501         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret_var = (this_arg_conv->get_next_channel_announcements)(this_arg_conv->this_arg, starting_point, batch_amount);
5502         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
5503         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
5504         for (size_t l = 0; l < ret_var.datalen; l++) {
5505                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* arr_conv_63_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
5506                 *arr_conv_63_ref = ret_var.data[l];
5507                 arr_conv_63_ref->a = ChannelAnnouncement_clone(&arr_conv_63_ref->a);
5508                 arr_conv_63_ref->b = ChannelUpdate_clone(&arr_conv_63_ref->b);
5509                 arr_conv_63_ref->c = ChannelUpdate_clone(&arr_conv_63_ref->c);
5510                 ret_arr_ptr[l] = (long)arr_conv_63_ref;
5511         }
5512         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
5513         FREE(ret_var.data);
5514         return ret_arr;
5515 }
5516
5517 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) {
5518         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5519         LDKPublicKey starting_point_ref;
5520         CHECK((*_env)->GetArrayLength (_env, starting_point) == 33);
5521         (*_env)->GetByteArrayRegion (_env, starting_point, 0, 33, starting_point_ref.compressed_form);
5522         LDKCVec_NodeAnnouncementZ ret_var = (this_arg_conv->get_next_node_announcements)(this_arg_conv->this_arg, starting_point_ref, batch_amount);
5523         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
5524         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
5525         for (size_t s = 0; s < ret_var.datalen; s++) {
5526                 LDKNodeAnnouncement arr_conv_18_var = ret_var.data[s];
5527                 CHECK((((long)arr_conv_18_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5528                 CHECK((((long)&arr_conv_18_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5529                 long arr_conv_18_ref = (long)arr_conv_18_var.inner;
5530                 if (arr_conv_18_var.is_owned) {
5531                         arr_conv_18_ref |= 1;
5532                 }
5533                 ret_arr_ptr[s] = arr_conv_18_ref;
5534         }
5535         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
5536         FREE(ret_var.data);
5537         return ret_arr;
5538 }
5539
5540 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1sync_1routing_1table(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong init) {
5541         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5542         LDKPublicKey their_node_id_ref;
5543         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5544         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5545         LDKInit init_conv;
5546         init_conv.inner = (void*)(init & (~1));
5547         init_conv.is_owned = false;
5548         (this_arg_conv->sync_routing_table)(this_arg_conv->this_arg, their_node_id_ref, &init_conv);
5549 }
5550
5551 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1reply_1channel_1range(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5552         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5553         LDKPublicKey their_node_id_ref;
5554         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5555         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5556         LDKReplyChannelRange msg_conv;
5557         msg_conv.inner = (void*)(msg & (~1));
5558         msg_conv.is_owned = (msg & 1) || (msg == 0);
5559         if (msg_conv.inner != NULL)
5560                 msg_conv = ReplyChannelRange_clone(&msg_conv);
5561         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5562         *ret_conv = (this_arg_conv->handle_reply_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5563         return (long)ret_conv;
5564 }
5565
5566 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1reply_1short_1channel_1ids_1end(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5567         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5568         LDKPublicKey their_node_id_ref;
5569         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5570         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5571         LDKReplyShortChannelIdsEnd msg_conv;
5572         msg_conv.inner = (void*)(msg & (~1));
5573         msg_conv.is_owned = (msg & 1) || (msg == 0);
5574         if (msg_conv.inner != NULL)
5575                 msg_conv = ReplyShortChannelIdsEnd_clone(&msg_conv);
5576         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5577         *ret_conv = (this_arg_conv->handle_reply_short_channel_ids_end)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5578         return (long)ret_conv;
5579 }
5580
5581 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1query_1channel_1range(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5582         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5583         LDKPublicKey their_node_id_ref;
5584         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5585         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5586         LDKQueryChannelRange msg_conv;
5587         msg_conv.inner = (void*)(msg & (~1));
5588         msg_conv.is_owned = (msg & 1) || (msg == 0);
5589         if (msg_conv.inner != NULL)
5590                 msg_conv = QueryChannelRange_clone(&msg_conv);
5591         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5592         *ret_conv = (this_arg_conv->handle_query_channel_range)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5593         return (long)ret_conv;
5594 }
5595
5596 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1query_1short_1channel_1ids(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
5597         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
5598         LDKPublicKey their_node_id_ref;
5599         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
5600         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
5601         LDKQueryShortChannelIds msg_conv;
5602         msg_conv.inner = (void*)(msg & (~1));
5603         msg_conv.is_owned = (msg & 1) || (msg == 0);
5604         if (msg_conv.inner != NULL)
5605                 msg_conv = QueryShortChannelIds_clone(&msg_conv);
5606         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
5607         *ret_conv = (this_arg_conv->handle_query_short_channel_ids)(this_arg_conv->this_arg, their_node_id_ref, msg_conv);
5608         return (long)ret_conv;
5609 }
5610
5611 typedef struct LDKSocketDescriptor_JCalls {
5612         atomic_size_t refcnt;
5613         JavaVM *vm;
5614         jweak o;
5615         jmethodID send_data_meth;
5616         jmethodID disconnect_socket_meth;
5617         jmethodID eq_meth;
5618         jmethodID hash_meth;
5619 } LDKSocketDescriptor_JCalls;
5620 uintptr_t send_data_jcall(void* this_arg, struct LDKu8slice data, bool resume_read) {
5621         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5622         JNIEnv *_env;
5623         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5624         LDKu8slice data_var = data;
5625         jbyteArray data_arr = (*_env)->NewByteArray(_env, data_var.datalen);
5626         (*_env)->SetByteArrayRegion(_env, data_arr, 0, data_var.datalen, data_var.data);
5627         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5628         CHECK(obj != NULL);
5629         return (*_env)->CallLongMethod(_env, obj, j_calls->send_data_meth, data_arr, resume_read);
5630 }
5631 void disconnect_socket_jcall(void* this_arg) {
5632         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5633         JNIEnv *_env;
5634         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5635         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5636         CHECK(obj != NULL);
5637         return (*_env)->CallVoidMethod(_env, obj, j_calls->disconnect_socket_meth);
5638 }
5639 bool eq_jcall(const void* this_arg, const struct LDKSocketDescriptor *NONNULL_PTR other_arg) {
5640         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5641         JNIEnv *_env;
5642         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5643         LDKSocketDescriptor *other_arg_clone = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
5644         *other_arg_clone = SocketDescriptor_clone(other_arg);
5645         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5646         CHECK(obj != NULL);
5647         return (*_env)->CallBooleanMethod(_env, obj, j_calls->eq_meth, (long)other_arg_clone);
5648 }
5649 uint64_t hash_jcall(const void* this_arg) {
5650         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5651         JNIEnv *_env;
5652         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
5653         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
5654         CHECK(obj != NULL);
5655         return (*_env)->CallLongMethod(_env, obj, j_calls->hash_meth);
5656 }
5657 static void LDKSocketDescriptor_JCalls_free(void* this_arg) {
5658         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5659         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
5660                 JNIEnv *env;
5661                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
5662                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
5663                 FREE(j_calls);
5664         }
5665 }
5666 static void* LDKSocketDescriptor_JCalls_clone(const void* this_arg) {
5667         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
5668         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
5669         return (void*) this_arg;
5670 }
5671 static inline LDKSocketDescriptor LDKSocketDescriptor_init (JNIEnv * env, jclass _a, jobject o) {
5672         jclass c = (*env)->GetObjectClass(env, o);
5673         CHECK(c != NULL);
5674         LDKSocketDescriptor_JCalls *calls = MALLOC(sizeof(LDKSocketDescriptor_JCalls), "LDKSocketDescriptor_JCalls");
5675         atomic_init(&calls->refcnt, 1);
5676         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
5677         calls->o = (*env)->NewWeakGlobalRef(env, o);
5678         calls->send_data_meth = (*env)->GetMethodID(env, c, "send_data", "([BZ)J");
5679         CHECK(calls->send_data_meth != NULL);
5680         calls->disconnect_socket_meth = (*env)->GetMethodID(env, c, "disconnect_socket", "()V");
5681         CHECK(calls->disconnect_socket_meth != NULL);
5682         calls->eq_meth = (*env)->GetMethodID(env, c, "eq", "(J)Z");
5683         CHECK(calls->eq_meth != NULL);
5684         calls->hash_meth = (*env)->GetMethodID(env, c, "hash", "()J");
5685         CHECK(calls->hash_meth != NULL);
5686
5687         LDKSocketDescriptor ret = {
5688                 .this_arg = (void*) calls,
5689                 .send_data = send_data_jcall,
5690                 .disconnect_socket = disconnect_socket_jcall,
5691                 .eq = eq_jcall,
5692                 .hash = hash_jcall,
5693                 .clone = LDKSocketDescriptor_JCalls_clone,
5694                 .free = LDKSocketDescriptor_JCalls_free,
5695         };
5696         return ret;
5697 }
5698 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1new (JNIEnv * env, jclass _a, jobject o) {
5699         LDKSocketDescriptor *res_ptr = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
5700         *res_ptr = LDKSocketDescriptor_init(env, _a, o);
5701         return (long)res_ptr;
5702 }
5703 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
5704         jobject ret = (*env)->NewLocalRef(env, ((LDKSocketDescriptor_JCalls*)val)->o);
5705         CHECK(ret != NULL);
5706         return ret;
5707 }
5708 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1send_1data(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray data, jboolean resume_read) {
5709         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
5710         LDKu8slice data_ref;
5711         data_ref.datalen = (*_env)->GetArrayLength (_env, data);
5712         data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL);
5713         jlong ret_val = (this_arg_conv->send_data)(this_arg_conv->this_arg, data_ref, resume_read);
5714         (*_env)->ReleaseByteArrayElements(_env, data, (int8_t*)data_ref.data, 0);
5715         return ret_val;
5716 }
5717
5718 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1disconnect_1socket(JNIEnv * _env, jclass _b, jlong this_arg) {
5719         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
5720         (this_arg_conv->disconnect_socket)(this_arg_conv->this_arg);
5721 }
5722
5723 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1hash(JNIEnv * _env, jclass _b, jlong this_arg) {
5724         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
5725         jlong ret_val = (this_arg_conv->hash)(this_arg_conv->this_arg);
5726         return ret_val;
5727 }
5728
5729 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Transaction_1free(JNIEnv * _env, jclass _b, jbyteArray _res) {
5730         LDKTransaction _res_ref;
5731         _res_ref.datalen = (*_env)->GetArrayLength (_env, _res);
5732         _res_ref.data = MALLOC(_res_ref.datalen, "LDKTransaction Bytes");
5733         (*_env)->GetByteArrayRegion(_env, _res, 0, _res_ref.datalen, _res_ref.data);
5734         _res_ref.data_is_owned = true;
5735         Transaction_free(_res_ref);
5736 }
5737
5738 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxOut_1free(JNIEnv * _env, jclass _b, jlong _res) {
5739         LDKTxOut _res_conv = *(LDKTxOut*)_res;
5740         FREE((void*)_res);
5741         TxOut_free(_res_conv);
5742 }
5743
5744 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SpendableOutputDescriptorZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
5745         LDKCVec_SpendableOutputDescriptorZ _res_constr;
5746         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
5747         if (_res_constr.datalen > 0)
5748                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSpendableOutputDescriptor), "LDKCVec_SpendableOutputDescriptorZ Elements");
5749         else
5750                 _res_constr.data = NULL;
5751         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
5752         for (size_t b = 0; b < _res_constr.datalen; b++) {
5753                 long arr_conv_27 = _res_vals[b];
5754                 LDKSpendableOutputDescriptor arr_conv_27_conv = *(LDKSpendableOutputDescriptor*)arr_conv_27;
5755                 FREE((void*)arr_conv_27);
5756                 _res_constr.data[b] = arr_conv_27_conv;
5757         }
5758         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
5759         CVec_SpendableOutputDescriptorZ_free(_res_constr);
5760 }
5761
5762 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MessageSendEventZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
5763         LDKCVec_MessageSendEventZ _res_constr;
5764         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
5765         if (_res_constr.datalen > 0)
5766                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
5767         else
5768                 _res_constr.data = NULL;
5769         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
5770         for (size_t s = 0; s < _res_constr.datalen; s++) {
5771                 long arr_conv_18 = _res_vals[s];
5772                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
5773                 FREE((void*)arr_conv_18);
5774                 _res_constr.data[s] = arr_conv_18_conv;
5775         }
5776         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
5777         CVec_MessageSendEventZ_free(_res_constr);
5778 }
5779
5780 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1EventZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
5781         LDKCVec_EventZ _res_constr;
5782         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
5783         if (_res_constr.datalen > 0)
5784                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
5785         else
5786                 _res_constr.data = NULL;
5787         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
5788         for (size_t h = 0; h < _res_constr.datalen; h++) {
5789                 long arr_conv_7 = _res_vals[h];
5790                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
5791                 FREE((void*)arr_conv_7);
5792                 _res_constr.data[h] = arr_conv_7_conv;
5793         }
5794         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
5795         CVec_EventZ_free(_res_constr);
5796 }
5797
5798 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
5799         LDKC2Tuple_usizeTransactionZ _res_conv = *(LDKC2Tuple_usizeTransactionZ*)_res;
5800         FREE((void*)_res);
5801         C2Tuple_usizeTransactionZ_free(_res_conv);
5802 }
5803
5804 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1new(JNIEnv * _env, jclass _b, jlong a, jbyteArray b) {
5805         LDKTransaction b_ref;
5806         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
5807         b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes");
5808         (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data);
5809         b_ref.data_is_owned = true;
5810         LDKC2Tuple_usizeTransactionZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
5811         *ret_ref = C2Tuple_usizeTransactionZ_new(a, b_ref);
5812         // XXX: We likely need to clone here, but no _clone fn is available for byte[]
5813         return (long)ret_ref;
5814 }
5815
5816 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1usizeTransactionZZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
5817         LDKCVec_C2Tuple_usizeTransactionZZ _res_constr;
5818         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
5819         if (_res_constr.datalen > 0)
5820                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
5821         else
5822                 _res_constr.data = NULL;
5823         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
5824         for (size_t y = 0; y < _res_constr.datalen; y++) {
5825                 long arr_conv_24 = _res_vals[y];
5826                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
5827                 FREE((void*)arr_conv_24);
5828                 _res_constr.data[y] = arr_conv_24_conv;
5829         }
5830         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
5831         CVec_C2Tuple_usizeTransactionZZ_free(_res_constr);
5832 }
5833
5834 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1ok(JNIEnv * _env, jclass _b) {
5835         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
5836         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_ok();
5837         return (long)ret_conv;
5838 }
5839
5840 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1err(JNIEnv * _env, jclass _b, jclass e) {
5841         LDKChannelMonitorUpdateErr e_conv = LDKChannelMonitorUpdateErr_from_java(_env, e);
5842         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
5843         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_err(e_conv);
5844         return (long)ret_conv;
5845 }
5846
5847 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
5848         LDKCResult_NoneChannelMonitorUpdateErrZ _res_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)_res;
5849         FREE((void*)_res);
5850         CResult_NoneChannelMonitorUpdateErrZ_free(_res_conv);
5851 }
5852
5853 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MonitorEventZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
5854         LDKCVec_MonitorEventZ _res_constr;
5855         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
5856         if (_res_constr.datalen > 0)
5857                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
5858         else
5859                 _res_constr.data = NULL;
5860         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
5861         for (size_t o = 0; o < _res_constr.datalen; o++) {
5862                 long arr_conv_14 = _res_vals[o];
5863                 LDKMonitorEvent arr_conv_14_conv;
5864                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
5865                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
5866                 _res_constr.data[o] = arr_conv_14_conv;
5867         }
5868         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
5869         CVec_MonitorEventZ_free(_res_constr);
5870 }
5871
5872 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelMonitorUpdateDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
5873         LDKChannelMonitorUpdate o_conv;
5874         o_conv.inner = (void*)(o & (~1));
5875         o_conv.is_owned = (o & 1) || (o == 0);
5876         if (o_conv.inner != NULL)
5877                 o_conv = ChannelMonitorUpdate_clone(&o_conv);
5878         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
5879         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_ok(o_conv);
5880         return (long)ret_conv;
5881 }
5882
5883 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelMonitorUpdateDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
5884         LDKDecodeError e_conv;
5885         e_conv.inner = (void*)(e & (~1));
5886         e_conv.is_owned = (e & 1) || (e == 0);
5887         // Warning: we may need a move here but can't clone!
5888         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
5889         *ret_conv = CResult_ChannelMonitorUpdateDecodeErrorZ_err(e_conv);
5890         return (long)ret_conv;
5891 }
5892
5893 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelMonitorUpdateDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
5894         LDKCResult_ChannelMonitorUpdateDecodeErrorZ _res_conv = *(LDKCResult_ChannelMonitorUpdateDecodeErrorZ*)_res;
5895         FREE((void*)_res);
5896         CResult_ChannelMonitorUpdateDecodeErrorZ_free(_res_conv);
5897 }
5898
5899 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1ok(JNIEnv * _env, jclass _b) {
5900         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
5901         *ret_conv = CResult_NoneMonitorUpdateErrorZ_ok();
5902         return (long)ret_conv;
5903 }
5904
5905 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
5906         LDKMonitorUpdateError e_conv;
5907         e_conv.inner = (void*)(e & (~1));
5908         e_conv.is_owned = (e & 1) || (e == 0);
5909         // Warning: we may need a move here but can't clone!
5910         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
5911         *ret_conv = CResult_NoneMonitorUpdateErrorZ_err(e_conv);
5912         return (long)ret_conv;
5913 }
5914
5915 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
5916         LDKCResult_NoneMonitorUpdateErrorZ _res_conv = *(LDKCResult_NoneMonitorUpdateErrorZ*)_res;
5917         FREE((void*)_res);
5918         CResult_NoneMonitorUpdateErrorZ_free(_res_conv);
5919 }
5920
5921 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
5922         LDKC2Tuple_OutPointScriptZ _res_conv = *(LDKC2Tuple_OutPointScriptZ*)_res;
5923         FREE((void*)_res);
5924         C2Tuple_OutPointScriptZ_free(_res_conv);
5925 }
5926
5927 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1new(JNIEnv * _env, jclass _b, jlong a, jbyteArray b) {
5928         LDKOutPoint a_conv;
5929         a_conv.inner = (void*)(a & (~1));
5930         a_conv.is_owned = (a & 1) || (a == 0);
5931         if (a_conv.inner != NULL)
5932                 a_conv = OutPoint_clone(&a_conv);
5933         LDKCVec_u8Z b_ref;
5934         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
5935         b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes");
5936         (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data);
5937         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
5938         *ret_ref = C2Tuple_OutPointScriptZ_new(a_conv, b_ref);
5939         ret_ref->a = OutPoint_clone(&ret_ref->a);
5940         ret_ref->b = CVec_u8Z_clone(&ret_ref->b);
5941         return (long)ret_ref;
5942 }
5943
5944 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TransactionZ_1free(JNIEnv * _env, jclass _b, jobjectArray _res) {
5945         LDKCVec_TransactionZ _res_constr;
5946         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
5947         if (_res_constr.datalen > 0)
5948                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKTransaction), "LDKCVec_TransactionZ Elements");
5949         else
5950                 _res_constr.data = NULL;
5951         for (size_t i = 0; i < _res_constr.datalen; i++) {
5952                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, _res, i);
5953                 LDKTransaction arr_conv_8_ref;
5954                 arr_conv_8_ref.datalen = (*_env)->GetArrayLength (_env, arr_conv_8);
5955                 arr_conv_8_ref.data = MALLOC(arr_conv_8_ref.datalen, "LDKTransaction Bytes");
5956                 (*_env)->GetByteArrayRegion(_env, arr_conv_8, 0, arr_conv_8_ref.datalen, arr_conv_8_ref.data);
5957                 arr_conv_8_ref.data_is_owned = true;
5958                 _res_constr.data[i] = arr_conv_8_ref;
5959         }
5960         CVec_TransactionZ_free(_res_constr);
5961 }
5962
5963 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u32TxOutZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
5964         LDKC2Tuple_u32TxOutZ _res_conv = *(LDKC2Tuple_u32TxOutZ*)_res;
5965         FREE((void*)_res);
5966         C2Tuple_u32TxOutZ_free(_res_conv);
5967 }
5968
5969 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u32TxOutZ_1new(JNIEnv * _env, jclass _b, jint a, jlong b) {
5970         LDKTxOut b_conv = *(LDKTxOut*)b;
5971         FREE((void*)b);
5972         LDKC2Tuple_u32TxOutZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_u32TxOutZ), "LDKC2Tuple_u32TxOutZ");
5973         *ret_ref = C2Tuple_u32TxOutZ_new(a, b_conv);
5974         // XXX: We likely need to clone here, but no _clone fn is available for TxOut
5975         return (long)ret_ref;
5976 }
5977
5978 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1u32TxOutZZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
5979         LDKCVec_C2Tuple_u32TxOutZZ _res_constr;
5980         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
5981         if (_res_constr.datalen > 0)
5982                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
5983         else
5984                 _res_constr.data = NULL;
5985         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
5986         for (size_t a = 0; a < _res_constr.datalen; a++) {
5987                 long arr_conv_26 = _res_vals[a];
5988                 LDKC2Tuple_u32TxOutZ arr_conv_26_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_26;
5989                 FREE((void*)arr_conv_26);
5990                 _res_constr.data[a] = arr_conv_26_conv;
5991         }
5992         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
5993         CVec_C2Tuple_u32TxOutZZ_free(_res_constr);
5994 }
5995
5996 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
5997         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ _res_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)_res;
5998         FREE((void*)_res);
5999         C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_free(_res_conv);
6000 }
6001
6002 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jlongArray b) {
6003         LDKThirtyTwoBytes a_ref;
6004         CHECK((*_env)->GetArrayLength (_env, a) == 32);
6005         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
6006         LDKCVec_C2Tuple_u32TxOutZZ b_constr;
6007         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
6008         if (b_constr.datalen > 0)
6009                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKC2Tuple_u32TxOutZ), "LDKCVec_C2Tuple_u32TxOutZZ Elements");
6010         else
6011                 b_constr.data = NULL;
6012         long* b_vals = (*_env)->GetLongArrayElements (_env, b, NULL);
6013         for (size_t a = 0; a < b_constr.datalen; a++) {
6014                 long arr_conv_26 = b_vals[a];
6015                 LDKC2Tuple_u32TxOutZ arr_conv_26_conv = *(LDKC2Tuple_u32TxOutZ*)arr_conv_26;
6016                 FREE((void*)arr_conv_26);
6017                 b_constr.data[a] = arr_conv_26_conv;
6018         }
6019         (*_env)->ReleaseLongArrayElements (_env, b, b_vals, 0);
6020         LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
6021         *ret_ref = C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ_new(a_ref, b_constr);
6022         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
6023         // XXX: We likely need to clone here, but no _clone fn is available for TwoTuple<Integer, TxOut>[]
6024         return (long)ret_ref;
6025 }
6026
6027 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1TxidCVec_1C2Tuple_1u32TxOutZZZZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6028         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ _res_constr;
6029         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6030         if (_res_constr.datalen > 0)
6031                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ Elements");
6032         else
6033                 _res_constr.data = NULL;
6034         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6035         for (size_t u = 0; u < _res_constr.datalen; u++) {
6036                 long arr_conv_46 = _res_vals[u];
6037                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ arr_conv_46_conv = *(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ*)arr_conv_46;
6038                 FREE((void*)arr_conv_46);
6039                 _res_constr.data[u] = arr_conv_46_conv;
6040         }
6041         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6042         CVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ_free(_res_constr);
6043 }
6044
6045 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelMonitorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6046         LDKC2Tuple_BlockHashChannelMonitorZ _res_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)_res;
6047         FREE((void*)_res);
6048         C2Tuple_BlockHashChannelMonitorZ_free(_res_conv);
6049 }
6050
6051 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelMonitorZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jlong b) {
6052         LDKThirtyTwoBytes a_ref;
6053         CHECK((*_env)->GetArrayLength (_env, a) == 32);
6054         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
6055         LDKChannelMonitor b_conv;
6056         b_conv.inner = (void*)(b & (~1));
6057         b_conv.is_owned = (b & 1) || (b == 0);
6058         // Warning: we may need a move here but can't clone!
6059         LDKC2Tuple_BlockHashChannelMonitorZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelMonitorZ), "LDKC2Tuple_BlockHashChannelMonitorZ");
6060         *ret_ref = C2Tuple_BlockHashChannelMonitorZ_new(a_ref, b_conv);
6061         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
6062         // XXX: We likely need to clone here, but no _clone fn is available for ChannelMonitor
6063         return (long)ret_ref;
6064 }
6065
6066 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6067         LDKC2Tuple_BlockHashChannelMonitorZ o_conv = *(LDKC2Tuple_BlockHashChannelMonitorZ*)o;
6068         FREE((void*)o);
6069         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
6070         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_ok(o_conv);
6071         return (long)ret_conv;
6072 }
6073
6074 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6075         LDKDecodeError e_conv;
6076         e_conv.inner = (void*)(e & (~1));
6077         e_conv.is_owned = (e & 1) || (e == 0);
6078         // Warning: we may need a move here but can't clone!
6079         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
6080         *ret_conv = CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_err(e_conv);
6081         return (long)ret_conv;
6082 }
6083
6084 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelMonitorZDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6085         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ*)_res;
6086         FREE((void*)_res);
6087         CResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_free(_res_conv);
6088 }
6089
6090 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1free(JNIEnv * _env, jclass _b, jlong _res) {
6091         LDKC2Tuple_u64u64Z _res_conv = *(LDKC2Tuple_u64u64Z*)_res;
6092         FREE((void*)_res);
6093         C2Tuple_u64u64Z_free(_res_conv);
6094 }
6095
6096 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1new(JNIEnv * _env, jclass _b, jlong a, jlong b) {
6097         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
6098         *ret_ref = C2Tuple_u64u64Z_new(a, b);
6099         return (long)ret_ref;
6100 }
6101
6102 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SpendableOutputDescriptorDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6103         LDKSpendableOutputDescriptor o_conv = *(LDKSpendableOutputDescriptor*)o;
6104         FREE((void*)o);
6105         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
6106         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_ok(o_conv);
6107         return (long)ret_conv;
6108 }
6109
6110 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SpendableOutputDescriptorDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6111         LDKDecodeError e_conv;
6112         e_conv.inner = (void*)(e & (~1));
6113         e_conv.is_owned = (e & 1) || (e == 0);
6114         // Warning: we may need a move here but can't clone!
6115         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
6116         *ret_conv = CResult_SpendableOutputDescriptorDecodeErrorZ_err(e_conv);
6117         return (long)ret_conv;
6118 }
6119
6120 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SpendableOutputDescriptorDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6121         LDKCResult_SpendableOutputDescriptorDecodeErrorZ _res_conv = *(LDKCResult_SpendableOutputDescriptorDecodeErrorZ*)_res;
6122         FREE((void*)_res);
6123         CResult_SpendableOutputDescriptorDecodeErrorZ_free(_res_conv);
6124 }
6125
6126 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SignatureZ_1free(JNIEnv * _env, jclass _b, jobjectArray _res) {
6127         LDKCVec_SignatureZ _res_constr;
6128         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6129         if (_res_constr.datalen > 0)
6130                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
6131         else
6132                 _res_constr.data = NULL;
6133         for (size_t i = 0; i < _res_constr.datalen; i++) {
6134                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, _res, i);
6135                 LDKSignature arr_conv_8_ref;
6136                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
6137                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
6138                 _res_constr.data[i] = arr_conv_8_ref;
6139         }
6140         CVec_SignatureZ_free(_res_constr);
6141 }
6142
6143 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6144         LDKC2Tuple_SignatureCVec_SignatureZZ _res_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)_res;
6145         FREE((void*)_res);
6146         C2Tuple_SignatureCVec_SignatureZZ_free(_res_conv);
6147 }
6148
6149 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jobjectArray b) {
6150         LDKSignature a_ref;
6151         CHECK((*_env)->GetArrayLength (_env, a) == 64);
6152         (*_env)->GetByteArrayRegion (_env, a, 0, 64, a_ref.compact_form);
6153         LDKCVec_SignatureZ b_constr;
6154         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
6155         if (b_constr.datalen > 0)
6156                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
6157         else
6158                 b_constr.data = NULL;
6159         for (size_t i = 0; i < b_constr.datalen; i++) {
6160                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, b, i);
6161                 LDKSignature arr_conv_8_ref;
6162                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
6163                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
6164                 b_constr.data[i] = arr_conv_8_ref;
6165         }
6166         LDKC2Tuple_SignatureCVec_SignatureZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
6167         *ret_ref = C2Tuple_SignatureCVec_SignatureZZ_new(a_ref, b_constr);
6168         // XXX: We likely need to clone here, but no _clone fn is available for byte[]
6169         // XXX: We likely need to clone here, but no _clone fn is available for byte[][]
6170         return (long)ret_ref;
6171 }
6172
6173 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6174         LDKC2Tuple_SignatureCVec_SignatureZZ o_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)o;
6175         FREE((void*)o);
6176         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
6177         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(o_conv);
6178         return (long)ret_conv;
6179 }
6180
6181 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1err(JNIEnv * _env, jclass _b) {
6182         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
6183         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err();
6184         return (long)ret_conv;
6185 }
6186
6187 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6188         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ _res_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)_res;
6189         FREE((void*)_res);
6190         CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(_res_conv);
6191 }
6192
6193 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1ok(JNIEnv * _env, jclass _b, jbyteArray o) {
6194         LDKSignature o_ref;
6195         CHECK((*_env)->GetArrayLength (_env, o) == 64);
6196         (*_env)->GetByteArrayRegion (_env, o, 0, 64, o_ref.compact_form);
6197         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
6198         *ret_conv = CResult_SignatureNoneZ_ok(o_ref);
6199         return (long)ret_conv;
6200 }
6201
6202 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1err(JNIEnv * _env, jclass _b) {
6203         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
6204         *ret_conv = CResult_SignatureNoneZ_err();
6205         return (long)ret_conv;
6206 }
6207
6208 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6209         LDKCResult_SignatureNoneZ _res_conv = *(LDKCResult_SignatureNoneZ*)_res;
6210         FREE((void*)_res);
6211         CResult_SignatureNoneZ_free(_res_conv);
6212 }
6213
6214 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1ok(JNIEnv * _env, jclass _b, jobjectArray o) {
6215         LDKCVec_SignatureZ o_constr;
6216         o_constr.datalen = (*_env)->GetArrayLength (_env, o);
6217         if (o_constr.datalen > 0)
6218                 o_constr.data = MALLOC(o_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
6219         else
6220                 o_constr.data = NULL;
6221         for (size_t i = 0; i < o_constr.datalen; i++) {
6222                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, o, i);
6223                 LDKSignature arr_conv_8_ref;
6224                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
6225                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
6226                 o_constr.data[i] = arr_conv_8_ref;
6227         }
6228         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
6229         *ret_conv = CResult_CVec_SignatureZNoneZ_ok(o_constr);
6230         return (long)ret_conv;
6231 }
6232
6233 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1err(JNIEnv * _env, jclass _b) {
6234         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
6235         *ret_conv = CResult_CVec_SignatureZNoneZ_err();
6236         return (long)ret_conv;
6237 }
6238
6239 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6240         LDKCResult_CVec_SignatureZNoneZ _res_conv = *(LDKCResult_CVec_SignatureZNoneZ*)_res;
6241         FREE((void*)_res);
6242         CResult_CVec_SignatureZNoneZ_free(_res_conv);
6243 }
6244
6245 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ChanKeySignerDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6246         LDKChannelKeys o_conv = *(LDKChannelKeys*)o;
6247         if (o_conv.free == LDKChannelKeys_JCalls_free) {
6248                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6249                 LDKChannelKeys_JCalls_clone(o_conv.this_arg);
6250         }
6251         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
6252         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_ok(o_conv);
6253         return (long)ret_conv;
6254 }
6255
6256 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ChanKeySignerDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6257         LDKDecodeError e_conv;
6258         e_conv.inner = (void*)(e & (~1));
6259         e_conv.is_owned = (e & 1) || (e == 0);
6260         // Warning: we may need a move here but can't clone!
6261         LDKCResult_ChanKeySignerDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChanKeySignerDecodeErrorZ), "LDKCResult_ChanKeySignerDecodeErrorZ");
6262         *ret_conv = CResult_ChanKeySignerDecodeErrorZ_err(e_conv);
6263         return (long)ret_conv;
6264 }
6265
6266 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ChanKeySignerDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6267         LDKCResult_ChanKeySignerDecodeErrorZ _res_conv = *(LDKCResult_ChanKeySignerDecodeErrorZ*)_res;
6268         FREE((void*)_res);
6269         CResult_ChanKeySignerDecodeErrorZ_free(_res_conv);
6270 }
6271
6272 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1InMemoryChannelKeysDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6273         LDKInMemoryChannelKeys o_conv;
6274         o_conv.inner = (void*)(o & (~1));
6275         o_conv.is_owned = (o & 1) || (o == 0);
6276         if (o_conv.inner != NULL)
6277                 o_conv = InMemoryChannelKeys_clone(&o_conv);
6278         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
6279         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_ok(o_conv);
6280         return (long)ret_conv;
6281 }
6282
6283 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1InMemoryChannelKeysDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6284         LDKDecodeError e_conv;
6285         e_conv.inner = (void*)(e & (~1));
6286         e_conv.is_owned = (e & 1) || (e == 0);
6287         // Warning: we may need a move here but can't clone!
6288         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
6289         *ret_conv = CResult_InMemoryChannelKeysDecodeErrorZ_err(e_conv);
6290         return (long)ret_conv;
6291 }
6292
6293 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1InMemoryChannelKeysDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6294         LDKCResult_InMemoryChannelKeysDecodeErrorZ _res_conv = *(LDKCResult_InMemoryChannelKeysDecodeErrorZ*)_res;
6295         FREE((void*)_res);
6296         CResult_InMemoryChannelKeysDecodeErrorZ_free(_res_conv);
6297 }
6298
6299 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6300         LDKTxOut o_conv = *(LDKTxOut*)o;
6301         FREE((void*)o);
6302         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
6303         *ret_conv = CResult_TxOutAccessErrorZ_ok(o_conv);
6304         return (long)ret_conv;
6305 }
6306
6307 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1err(JNIEnv * _env, jclass _b, jclass e) {
6308         LDKAccessError e_conv = LDKAccessError_from_java(_env, e);
6309         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
6310         *ret_conv = CResult_TxOutAccessErrorZ_err(e_conv);
6311         return (long)ret_conv;
6312 }
6313
6314 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6315         LDKCResult_TxOutAccessErrorZ _res_conv = *(LDKCResult_TxOutAccessErrorZ*)_res;
6316         FREE((void*)_res);
6317         CResult_TxOutAccessErrorZ_free(_res_conv);
6318 }
6319
6320 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1ok(JNIEnv * _env, jclass _b) {
6321         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
6322         *ret_conv = CResult_NoneAPIErrorZ_ok();
6323         return (long)ret_conv;
6324 }
6325
6326 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6327         LDKAPIError e_conv = *(LDKAPIError*)e;
6328         FREE((void*)e);
6329         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
6330         *ret_conv = CResult_NoneAPIErrorZ_err(e_conv);
6331         return (long)ret_conv;
6332 }
6333
6334 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6335         LDKCResult_NoneAPIErrorZ _res_conv = *(LDKCResult_NoneAPIErrorZ*)_res;
6336         FREE((void*)_res);
6337         CResult_NoneAPIErrorZ_free(_res_conv);
6338 }
6339
6340 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelDetailsZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6341         LDKCVec_ChannelDetailsZ _res_constr;
6342         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6343         if (_res_constr.datalen > 0)
6344                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
6345         else
6346                 _res_constr.data = NULL;
6347         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6348         for (size_t q = 0; q < _res_constr.datalen; q++) {
6349                 long arr_conv_16 = _res_vals[q];
6350                 LDKChannelDetails arr_conv_16_conv;
6351                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
6352                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
6353                 _res_constr.data[q] = arr_conv_16_conv;
6354         }
6355         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6356         CVec_ChannelDetailsZ_free(_res_constr);
6357 }
6358
6359 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1ok(JNIEnv * _env, jclass _b) {
6360         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
6361         *ret_conv = CResult_NonePaymentSendFailureZ_ok();
6362         return (long)ret_conv;
6363 }
6364
6365 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6366         LDKPaymentSendFailure e_conv;
6367         e_conv.inner = (void*)(e & (~1));
6368         e_conv.is_owned = (e & 1) || (e == 0);
6369         // Warning: we may need a move here but can't clone!
6370         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
6371         *ret_conv = CResult_NonePaymentSendFailureZ_err(e_conv);
6372         return (long)ret_conv;
6373 }
6374
6375 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6376         LDKCResult_NonePaymentSendFailureZ _res_conv = *(LDKCResult_NonePaymentSendFailureZ*)_res;
6377         FREE((void*)_res);
6378         CResult_NonePaymentSendFailureZ_free(_res_conv);
6379 }
6380
6381 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NetAddressZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6382         LDKCVec_NetAddressZ _res_constr;
6383         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6384         if (_res_constr.datalen > 0)
6385                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
6386         else
6387                 _res_constr.data = NULL;
6388         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6389         for (size_t m = 0; m < _res_constr.datalen; m++) {
6390                 long arr_conv_12 = _res_vals[m];
6391                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
6392                 FREE((void*)arr_conv_12);
6393                 _res_constr.data[m] = arr_conv_12_conv;
6394         }
6395         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6396         CVec_NetAddressZ_free(_res_constr);
6397 }
6398
6399 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelMonitorZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6400         LDKCVec_ChannelMonitorZ _res_constr;
6401         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6402         if (_res_constr.datalen > 0)
6403                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
6404         else
6405                 _res_constr.data = NULL;
6406         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6407         for (size_t q = 0; q < _res_constr.datalen; q++) {
6408                 long arr_conv_16 = _res_vals[q];
6409                 LDKChannelMonitor arr_conv_16_conv;
6410                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
6411                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
6412                 _res_constr.data[q] = arr_conv_16_conv;
6413         }
6414         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6415         CVec_ChannelMonitorZ_free(_res_constr);
6416 }
6417
6418 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelManagerZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6419         LDKC2Tuple_BlockHashChannelManagerZ _res_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)_res;
6420         FREE((void*)_res);
6421         C2Tuple_BlockHashChannelManagerZ_free(_res_conv);
6422 }
6423
6424 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelManagerZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jlong b) {
6425         LDKThirtyTwoBytes a_ref;
6426         CHECK((*_env)->GetArrayLength (_env, a) == 32);
6427         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
6428         LDKChannelManager b_conv;
6429         b_conv.inner = (void*)(b & (~1));
6430         b_conv.is_owned = (b & 1) || (b == 0);
6431         // Warning: we may need a move here but can't clone!
6432         LDKC2Tuple_BlockHashChannelManagerZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_BlockHashChannelManagerZ), "LDKC2Tuple_BlockHashChannelManagerZ");
6433         *ret_ref = C2Tuple_BlockHashChannelManagerZ_new(a_ref, b_conv);
6434         ret_ref->a = ThirtyTwoBytes_clone(&ret_ref->a);
6435         // XXX: We likely need to clone here, but no _clone fn is available for ChannelManager
6436         return (long)ret_ref;
6437 }
6438
6439 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6440         LDKC2Tuple_BlockHashChannelManagerZ o_conv = *(LDKC2Tuple_BlockHashChannelManagerZ*)o;
6441         FREE((void*)o);
6442         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
6443         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_ok(o_conv);
6444         return (long)ret_conv;
6445 }
6446
6447 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6448         LDKDecodeError e_conv;
6449         e_conv.inner = (void*)(e & (~1));
6450         e_conv.is_owned = (e & 1) || (e == 0);
6451         // Warning: we may need a move here but can't clone!
6452         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
6453         *ret_conv = CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_err(e_conv);
6454         return (long)ret_conv;
6455 }
6456
6457 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1BlockHashChannelManagerZDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6458         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ _res_conv = *(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ*)_res;
6459         FREE((void*)_res);
6460         CResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_free(_res_conv);
6461 }
6462
6463 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NetAddressu8Z_1ok(JNIEnv * _env, jclass _b, jlong o) {
6464         LDKNetAddress o_conv = *(LDKNetAddress*)o;
6465         FREE((void*)o);
6466         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
6467         *ret_conv = CResult_NetAddressu8Z_ok(o_conv);
6468         return (long)ret_conv;
6469 }
6470
6471 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NetAddressu8Z_1err(JNIEnv * _env, jclass _b, jbyte e) {
6472         LDKCResult_NetAddressu8Z* ret_conv = MALLOC(sizeof(LDKCResult_NetAddressu8Z), "LDKCResult_NetAddressu8Z");
6473         *ret_conv = CResult_NetAddressu8Z_err(e);
6474         return (long)ret_conv;
6475 }
6476
6477 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NetAddressu8Z_1free(JNIEnv * _env, jclass _b, jlong _res) {
6478         LDKCResult_NetAddressu8Z _res_conv = *(LDKCResult_NetAddressu8Z*)_res;
6479         FREE((void*)_res);
6480         CResult_NetAddressu8Z_free(_res_conv);
6481 }
6482
6483 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6484         LDKCResult_NetAddressu8Z o_conv = *(LDKCResult_NetAddressu8Z*)o;
6485         FREE((void*)o);
6486         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
6487         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_ok(o_conv);
6488         return (long)ret_conv;
6489 }
6490
6491 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6492         LDKDecodeError e_conv;
6493         e_conv.inner = (void*)(e & (~1));
6494         e_conv.is_owned = (e & 1) || (e == 0);
6495         // Warning: we may need a move here but can't clone!
6496         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
6497         *ret_conv = CResult_CResult_NetAddressu8ZDecodeErrorZ_err(e_conv);
6498         return (long)ret_conv;
6499 }
6500
6501 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CResult_1NetAddressu8ZDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6502         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ _res_conv = *(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ*)_res;
6503         FREE((void*)_res);
6504         CResult_CResult_NetAddressu8ZDecodeErrorZ_free(_res_conv);
6505 }
6506
6507 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u64Z_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6508         LDKCVec_u64Z _res_constr;
6509         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6510         if (_res_constr.datalen > 0)
6511                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
6512         else
6513                 _res_constr.data = NULL;
6514         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6515         for (size_t g = 0; g < _res_constr.datalen; g++) {
6516                 long arr_conv_6 = _res_vals[g];
6517                 _res_constr.data[g] = arr_conv_6;
6518         }
6519         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6520         CVec_u64Z_free(_res_constr);
6521 }
6522
6523 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateAddHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6524         LDKCVec_UpdateAddHTLCZ _res_constr;
6525         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6526         if (_res_constr.datalen > 0)
6527                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
6528         else
6529                 _res_constr.data = NULL;
6530         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6531         for (size_t p = 0; p < _res_constr.datalen; p++) {
6532                 long arr_conv_15 = _res_vals[p];
6533                 LDKUpdateAddHTLC arr_conv_15_conv;
6534                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
6535                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
6536                 _res_constr.data[p] = arr_conv_15_conv;
6537         }
6538         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6539         CVec_UpdateAddHTLCZ_free(_res_constr);
6540 }
6541
6542 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFulfillHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6543         LDKCVec_UpdateFulfillHTLCZ _res_constr;
6544         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6545         if (_res_constr.datalen > 0)
6546                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
6547         else
6548                 _res_constr.data = NULL;
6549         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6550         for (size_t t = 0; t < _res_constr.datalen; t++) {
6551                 long arr_conv_19 = _res_vals[t];
6552                 LDKUpdateFulfillHTLC arr_conv_19_conv;
6553                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
6554                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
6555                 _res_constr.data[t] = arr_conv_19_conv;
6556         }
6557         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6558         CVec_UpdateFulfillHTLCZ_free(_res_constr);
6559 }
6560
6561 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6562         LDKCVec_UpdateFailHTLCZ _res_constr;
6563         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6564         if (_res_constr.datalen > 0)
6565                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
6566         else
6567                 _res_constr.data = NULL;
6568         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6569         for (size_t q = 0; q < _res_constr.datalen; q++) {
6570                 long arr_conv_16 = _res_vals[q];
6571                 LDKUpdateFailHTLC arr_conv_16_conv;
6572                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
6573                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
6574                 _res_constr.data[q] = arr_conv_16_conv;
6575         }
6576         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6577         CVec_UpdateFailHTLCZ_free(_res_constr);
6578 }
6579
6580 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailMalformedHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6581         LDKCVec_UpdateFailMalformedHTLCZ _res_constr;
6582         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6583         if (_res_constr.datalen > 0)
6584                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
6585         else
6586                 _res_constr.data = NULL;
6587         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6588         for (size_t z = 0; z < _res_constr.datalen; z++) {
6589                 long arr_conv_25 = _res_vals[z];
6590                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
6591                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
6592                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
6593                 _res_constr.data[z] = arr_conv_25_conv;
6594         }
6595         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6596         CVec_UpdateFailMalformedHTLCZ_free(_res_constr);
6597 }
6598
6599 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1ok(JNIEnv * _env, jclass _b, jboolean o) {
6600         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
6601         *ret_conv = CResult_boolLightningErrorZ_ok(o);
6602         return (long)ret_conv;
6603 }
6604
6605 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6606         LDKLightningError e_conv;
6607         e_conv.inner = (void*)(e & (~1));
6608         e_conv.is_owned = (e & 1) || (e == 0);
6609         // Warning: we may need a move here but can't clone!
6610         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
6611         *ret_conv = CResult_boolLightningErrorZ_err(e_conv);
6612         return (long)ret_conv;
6613 }
6614
6615 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6616         LDKCResult_boolLightningErrorZ _res_conv = *(LDKCResult_boolLightningErrorZ*)_res;
6617         FREE((void*)_res);
6618         CResult_boolLightningErrorZ_free(_res_conv);
6619 }
6620
6621 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6622         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ _res_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)_res;
6623         FREE((void*)_res);
6624         C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(_res_conv);
6625 }
6626
6627 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1new(JNIEnv * _env, jclass _b, jlong a, jlong b, jlong c) {
6628         LDKChannelAnnouncement a_conv;
6629         a_conv.inner = (void*)(a & (~1));
6630         a_conv.is_owned = (a & 1) || (a == 0);
6631         if (a_conv.inner != NULL)
6632                 a_conv = ChannelAnnouncement_clone(&a_conv);
6633         LDKChannelUpdate b_conv;
6634         b_conv.inner = (void*)(b & (~1));
6635         b_conv.is_owned = (b & 1) || (b == 0);
6636         if (b_conv.inner != NULL)
6637                 b_conv = ChannelUpdate_clone(&b_conv);
6638         LDKChannelUpdate c_conv;
6639         c_conv.inner = (void*)(c & (~1));
6640         c_conv.is_owned = (c & 1) || (c == 0);
6641         if (c_conv.inner != NULL)
6642                 c_conv = ChannelUpdate_clone(&c_conv);
6643         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
6644         *ret_ref = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(a_conv, b_conv, c_conv);
6645         ret_ref->a = ChannelAnnouncement_clone(&ret_ref->a);
6646         ret_ref->b = ChannelUpdate_clone(&ret_ref->b);
6647         ret_ref->c = ChannelUpdate_clone(&ret_ref->c);
6648         return (long)ret_ref;
6649 }
6650
6651 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6652         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ _res_constr;
6653         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6654         if (_res_constr.datalen > 0)
6655                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
6656         else
6657                 _res_constr.data = NULL;
6658         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6659         for (size_t l = 0; l < _res_constr.datalen; l++) {
6660                 long arr_conv_63 = _res_vals[l];
6661                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
6662                 FREE((void*)arr_conv_63);
6663                 _res_constr.data[l] = arr_conv_63_conv;
6664         }
6665         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6666         CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(_res_constr);
6667 }
6668
6669 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NodeAnnouncementZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
6670         LDKCVec_NodeAnnouncementZ _res_constr;
6671         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
6672         if (_res_constr.datalen > 0)
6673                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
6674         else
6675                 _res_constr.data = NULL;
6676         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
6677         for (size_t s = 0; s < _res_constr.datalen; s++) {
6678                 long arr_conv_18 = _res_vals[s];
6679                 LDKNodeAnnouncement arr_conv_18_conv;
6680                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
6681                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
6682                 _res_constr.data[s] = arr_conv_18_conv;
6683         }
6684         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
6685         CVec_NodeAnnouncementZ_free(_res_constr);
6686 }
6687
6688 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneLightningErrorZ_1ok(JNIEnv * _env, jclass _b) {
6689         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
6690         *ret_conv = CResult_NoneLightningErrorZ_ok();
6691         return (long)ret_conv;
6692 }
6693
6694 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneLightningErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6695         LDKLightningError e_conv;
6696         e_conv.inner = (void*)(e & (~1));
6697         e_conv.is_owned = (e & 1) || (e == 0);
6698         // Warning: we may need a move here but can't clone!
6699         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
6700         *ret_conv = CResult_NoneLightningErrorZ_err(e_conv);
6701         return (long)ret_conv;
6702 }
6703
6704 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneLightningErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6705         LDKCResult_NoneLightningErrorZ _res_conv = *(LDKCResult_NoneLightningErrorZ*)_res;
6706         FREE((void*)_res);
6707         CResult_NoneLightningErrorZ_free(_res_conv);
6708 }
6709
6710 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelReestablishDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6711         LDKChannelReestablish o_conv;
6712         o_conv.inner = (void*)(o & (~1));
6713         o_conv.is_owned = (o & 1) || (o == 0);
6714         if (o_conv.inner != NULL)
6715                 o_conv = ChannelReestablish_clone(&o_conv);
6716         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
6717         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_ok(o_conv);
6718         return (long)ret_conv;
6719 }
6720
6721 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelReestablishDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6722         LDKDecodeError e_conv;
6723         e_conv.inner = (void*)(e & (~1));
6724         e_conv.is_owned = (e & 1) || (e == 0);
6725         // Warning: we may need a move here but can't clone!
6726         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
6727         *ret_conv = CResult_ChannelReestablishDecodeErrorZ_err(e_conv);
6728         return (long)ret_conv;
6729 }
6730
6731 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ChannelReestablishDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6732         LDKCResult_ChannelReestablishDecodeErrorZ _res_conv = *(LDKCResult_ChannelReestablishDecodeErrorZ*)_res;
6733         FREE((void*)_res);
6734         CResult_ChannelReestablishDecodeErrorZ_free(_res_conv);
6735 }
6736
6737 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1InitDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6738         LDKInit o_conv;
6739         o_conv.inner = (void*)(o & (~1));
6740         o_conv.is_owned = (o & 1) || (o == 0);
6741         if (o_conv.inner != NULL)
6742                 o_conv = Init_clone(&o_conv);
6743         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
6744         *ret_conv = CResult_InitDecodeErrorZ_ok(o_conv);
6745         return (long)ret_conv;
6746 }
6747
6748 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1InitDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6749         LDKDecodeError e_conv;
6750         e_conv.inner = (void*)(e & (~1));
6751         e_conv.is_owned = (e & 1) || (e == 0);
6752         // Warning: we may need a move here but can't clone!
6753         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
6754         *ret_conv = CResult_InitDecodeErrorZ_err(e_conv);
6755         return (long)ret_conv;
6756 }
6757
6758 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1InitDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6759         LDKCResult_InitDecodeErrorZ _res_conv = *(LDKCResult_InitDecodeErrorZ*)_res;
6760         FREE((void*)_res);
6761         CResult_InitDecodeErrorZ_free(_res_conv);
6762 }
6763
6764 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PingDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6765         LDKPing o_conv;
6766         o_conv.inner = (void*)(o & (~1));
6767         o_conv.is_owned = (o & 1) || (o == 0);
6768         if (o_conv.inner != NULL)
6769                 o_conv = Ping_clone(&o_conv);
6770         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
6771         *ret_conv = CResult_PingDecodeErrorZ_ok(o_conv);
6772         return (long)ret_conv;
6773 }
6774
6775 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PingDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6776         LDKDecodeError e_conv;
6777         e_conv.inner = (void*)(e & (~1));
6778         e_conv.is_owned = (e & 1) || (e == 0);
6779         // Warning: we may need a move here but can't clone!
6780         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
6781         *ret_conv = CResult_PingDecodeErrorZ_err(e_conv);
6782         return (long)ret_conv;
6783 }
6784
6785 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PingDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6786         LDKCResult_PingDecodeErrorZ _res_conv = *(LDKCResult_PingDecodeErrorZ*)_res;
6787         FREE((void*)_res);
6788         CResult_PingDecodeErrorZ_free(_res_conv);
6789 }
6790
6791 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PongDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6792         LDKPong o_conv;
6793         o_conv.inner = (void*)(o & (~1));
6794         o_conv.is_owned = (o & 1) || (o == 0);
6795         if (o_conv.inner != NULL)
6796                 o_conv = Pong_clone(&o_conv);
6797         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
6798         *ret_conv = CResult_PongDecodeErrorZ_ok(o_conv);
6799         return (long)ret_conv;
6800 }
6801
6802 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PongDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6803         LDKDecodeError e_conv;
6804         e_conv.inner = (void*)(e & (~1));
6805         e_conv.is_owned = (e & 1) || (e == 0);
6806         // Warning: we may need a move here but can't clone!
6807         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
6808         *ret_conv = CResult_PongDecodeErrorZ_err(e_conv);
6809         return (long)ret_conv;
6810 }
6811
6812 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PongDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6813         LDKCResult_PongDecodeErrorZ _res_conv = *(LDKCResult_PongDecodeErrorZ*)_res;
6814         FREE((void*)_res);
6815         CResult_PongDecodeErrorZ_free(_res_conv);
6816 }
6817
6818 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6819         LDKUnsignedChannelAnnouncement o_conv;
6820         o_conv.inner = (void*)(o & (~1));
6821         o_conv.is_owned = (o & 1) || (o == 0);
6822         if (o_conv.inner != NULL)
6823                 o_conv = UnsignedChannelAnnouncement_clone(&o_conv);
6824         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
6825         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_ok(o_conv);
6826         return (long)ret_conv;
6827 }
6828
6829 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6830         LDKDecodeError e_conv;
6831         e_conv.inner = (void*)(e & (~1));
6832         e_conv.is_owned = (e & 1) || (e == 0);
6833         // Warning: we may need a move here but can't clone!
6834         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
6835         *ret_conv = CResult_UnsignedChannelAnnouncementDecodeErrorZ_err(e_conv);
6836         return (long)ret_conv;
6837 }
6838
6839 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelAnnouncementDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6840         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ*)_res;
6841         FREE((void*)_res);
6842         CResult_UnsignedChannelAnnouncementDecodeErrorZ_free(_res_conv);
6843 }
6844
6845 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelUpdateDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6846         LDKUnsignedChannelUpdate o_conv;
6847         o_conv.inner = (void*)(o & (~1));
6848         o_conv.is_owned = (o & 1) || (o == 0);
6849         if (o_conv.inner != NULL)
6850                 o_conv = UnsignedChannelUpdate_clone(&o_conv);
6851         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
6852         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_ok(o_conv);
6853         return (long)ret_conv;
6854 }
6855
6856 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelUpdateDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6857         LDKDecodeError e_conv;
6858         e_conv.inner = (void*)(e & (~1));
6859         e_conv.is_owned = (e & 1) || (e == 0);
6860         // Warning: we may need a move here but can't clone!
6861         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
6862         *ret_conv = CResult_UnsignedChannelUpdateDecodeErrorZ_err(e_conv);
6863         return (long)ret_conv;
6864 }
6865
6866 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedChannelUpdateDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6867         LDKCResult_UnsignedChannelUpdateDecodeErrorZ _res_conv = *(LDKCResult_UnsignedChannelUpdateDecodeErrorZ*)_res;
6868         FREE((void*)_res);
6869         CResult_UnsignedChannelUpdateDecodeErrorZ_free(_res_conv);
6870 }
6871
6872 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ErrorMessageDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6873         LDKErrorMessage o_conv;
6874         o_conv.inner = (void*)(o & (~1));
6875         o_conv.is_owned = (o & 1) || (o == 0);
6876         if (o_conv.inner != NULL)
6877                 o_conv = ErrorMessage_clone(&o_conv);
6878         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
6879         *ret_conv = CResult_ErrorMessageDecodeErrorZ_ok(o_conv);
6880         return (long)ret_conv;
6881 }
6882
6883 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ErrorMessageDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6884         LDKDecodeError e_conv;
6885         e_conv.inner = (void*)(e & (~1));
6886         e_conv.is_owned = (e & 1) || (e == 0);
6887         // Warning: we may need a move here but can't clone!
6888         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
6889         *ret_conv = CResult_ErrorMessageDecodeErrorZ_err(e_conv);
6890         return (long)ret_conv;
6891 }
6892
6893 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ErrorMessageDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6894         LDKCResult_ErrorMessageDecodeErrorZ _res_conv = *(LDKCResult_ErrorMessageDecodeErrorZ*)_res;
6895         FREE((void*)_res);
6896         CResult_ErrorMessageDecodeErrorZ_free(_res_conv);
6897 }
6898
6899 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6900         LDKUnsignedNodeAnnouncement o_conv;
6901         o_conv.inner = (void*)(o & (~1));
6902         o_conv.is_owned = (o & 1) || (o == 0);
6903         if (o_conv.inner != NULL)
6904                 o_conv = UnsignedNodeAnnouncement_clone(&o_conv);
6905         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
6906         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_ok(o_conv);
6907         return (long)ret_conv;
6908 }
6909
6910 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6911         LDKDecodeError e_conv;
6912         e_conv.inner = (void*)(e & (~1));
6913         e_conv.is_owned = (e & 1) || (e == 0);
6914         // Warning: we may need a move here but can't clone!
6915         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
6916         *ret_conv = CResult_UnsignedNodeAnnouncementDecodeErrorZ_err(e_conv);
6917         return (long)ret_conv;
6918 }
6919
6920 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1UnsignedNodeAnnouncementDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6921         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ _res_conv = *(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ*)_res;
6922         FREE((void*)_res);
6923         CResult_UnsignedNodeAnnouncementDecodeErrorZ_free(_res_conv);
6924 }
6925
6926 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1QueryShortChannelIdsDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6927         LDKQueryShortChannelIds o_conv;
6928         o_conv.inner = (void*)(o & (~1));
6929         o_conv.is_owned = (o & 1) || (o == 0);
6930         if (o_conv.inner != NULL)
6931                 o_conv = QueryShortChannelIds_clone(&o_conv);
6932         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
6933         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_ok(o_conv);
6934         return (long)ret_conv;
6935 }
6936
6937 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1QueryShortChannelIdsDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6938         LDKDecodeError e_conv;
6939         e_conv.inner = (void*)(e & (~1));
6940         e_conv.is_owned = (e & 1) || (e == 0);
6941         // Warning: we may need a move here but can't clone!
6942         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
6943         *ret_conv = CResult_QueryShortChannelIdsDecodeErrorZ_err(e_conv);
6944         return (long)ret_conv;
6945 }
6946
6947 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1QueryShortChannelIdsDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6948         LDKCResult_QueryShortChannelIdsDecodeErrorZ _res_conv = *(LDKCResult_QueryShortChannelIdsDecodeErrorZ*)_res;
6949         FREE((void*)_res);
6950         CResult_QueryShortChannelIdsDecodeErrorZ_free(_res_conv);
6951 }
6952
6953 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6954         LDKReplyShortChannelIdsEnd o_conv;
6955         o_conv.inner = (void*)(o & (~1));
6956         o_conv.is_owned = (o & 1) || (o == 0);
6957         if (o_conv.inner != NULL)
6958                 o_conv = ReplyShortChannelIdsEnd_clone(&o_conv);
6959         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
6960         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_ok(o_conv);
6961         return (long)ret_conv;
6962 }
6963
6964 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6965         LDKDecodeError e_conv;
6966         e_conv.inner = (void*)(e & (~1));
6967         e_conv.is_owned = (e & 1) || (e == 0);
6968         // Warning: we may need a move here but can't clone!
6969         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
6970         *ret_conv = CResult_ReplyShortChannelIdsEndDecodeErrorZ_err(e_conv);
6971         return (long)ret_conv;
6972 }
6973
6974 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyShortChannelIdsEndDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
6975         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ _res_conv = *(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ*)_res;
6976         FREE((void*)_res);
6977         CResult_ReplyShortChannelIdsEndDecodeErrorZ_free(_res_conv);
6978 }
6979
6980 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1QueryChannelRangeDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
6981         LDKQueryChannelRange o_conv;
6982         o_conv.inner = (void*)(o & (~1));
6983         o_conv.is_owned = (o & 1) || (o == 0);
6984         if (o_conv.inner != NULL)
6985                 o_conv = QueryChannelRange_clone(&o_conv);
6986         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
6987         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_ok(o_conv);
6988         return (long)ret_conv;
6989 }
6990
6991 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1QueryChannelRangeDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
6992         LDKDecodeError e_conv;
6993         e_conv.inner = (void*)(e & (~1));
6994         e_conv.is_owned = (e & 1) || (e == 0);
6995         // Warning: we may need a move here but can't clone!
6996         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
6997         *ret_conv = CResult_QueryChannelRangeDecodeErrorZ_err(e_conv);
6998         return (long)ret_conv;
6999 }
7000
7001 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1QueryChannelRangeDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7002         LDKCResult_QueryChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_QueryChannelRangeDecodeErrorZ*)_res;
7003         FREE((void*)_res);
7004         CResult_QueryChannelRangeDecodeErrorZ_free(_res_conv);
7005 }
7006
7007 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyChannelRangeDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7008         LDKReplyChannelRange o_conv;
7009         o_conv.inner = (void*)(o & (~1));
7010         o_conv.is_owned = (o & 1) || (o == 0);
7011         if (o_conv.inner != NULL)
7012                 o_conv = ReplyChannelRange_clone(&o_conv);
7013         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
7014         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_ok(o_conv);
7015         return (long)ret_conv;
7016 }
7017
7018 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyChannelRangeDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7019         LDKDecodeError e_conv;
7020         e_conv.inner = (void*)(e & (~1));
7021         e_conv.is_owned = (e & 1) || (e == 0);
7022         // Warning: we may need a move here but can't clone!
7023         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
7024         *ret_conv = CResult_ReplyChannelRangeDecodeErrorZ_err(e_conv);
7025         return (long)ret_conv;
7026 }
7027
7028 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1ReplyChannelRangeDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7029         LDKCResult_ReplyChannelRangeDecodeErrorZ _res_conv = *(LDKCResult_ReplyChannelRangeDecodeErrorZ*)_res;
7030         FREE((void*)_res);
7031         CResult_ReplyChannelRangeDecodeErrorZ_free(_res_conv);
7032 }
7033
7034 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1GossipTimestampFilterDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7035         LDKGossipTimestampFilter o_conv;
7036         o_conv.inner = (void*)(o & (~1));
7037         o_conv.is_owned = (o & 1) || (o == 0);
7038         if (o_conv.inner != NULL)
7039                 o_conv = GossipTimestampFilter_clone(&o_conv);
7040         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
7041         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_ok(o_conv);
7042         return (long)ret_conv;
7043 }
7044
7045 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1GossipTimestampFilterDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7046         LDKDecodeError e_conv;
7047         e_conv.inner = (void*)(e & (~1));
7048         e_conv.is_owned = (e & 1) || (e == 0);
7049         // Warning: we may need a move here but can't clone!
7050         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
7051         *ret_conv = CResult_GossipTimestampFilterDecodeErrorZ_err(e_conv);
7052         return (long)ret_conv;
7053 }
7054
7055 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1GossipTimestampFilterDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7056         LDKCResult_GossipTimestampFilterDecodeErrorZ _res_conv = *(LDKCResult_GossipTimestampFilterDecodeErrorZ*)_res;
7057         FREE((void*)_res);
7058         CResult_GossipTimestampFilterDecodeErrorZ_free(_res_conv);
7059 }
7060
7061 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1PublicKeyZ_1free(JNIEnv * _env, jclass _b, jobjectArray _res) {
7062         LDKCVec_PublicKeyZ _res_constr;
7063         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
7064         if (_res_constr.datalen > 0)
7065                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKPublicKey), "LDKCVec_PublicKeyZ Elements");
7066         else
7067                 _res_constr.data = NULL;
7068         for (size_t i = 0; i < _res_constr.datalen; i++) {
7069                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, _res, i);
7070                 LDKPublicKey arr_conv_8_ref;
7071                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 33);
7072                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 33, arr_conv_8_ref.compressed_form);
7073                 _res_constr.data[i] = arr_conv_8_ref;
7074         }
7075         CVec_PublicKeyZ_free(_res_constr);
7076 }
7077
7078 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u8Z_1free(JNIEnv * _env, jclass _b, jbyteArray _res) {
7079         LDKCVec_u8Z _res_ref;
7080         _res_ref.datalen = (*_env)->GetArrayLength (_env, _res);
7081         _res_ref.data = MALLOC(_res_ref.datalen, "LDKCVec_u8Z Bytes");
7082         (*_env)->GetByteArrayRegion(_env, _res, 0, _res_ref.datalen, _res_ref.data);
7083         CVec_u8Z_free(_res_ref);
7084 }
7085
7086 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray o) {
7087         LDKCVec_u8Z o_ref;
7088         o_ref.datalen = (*_env)->GetArrayLength (_env, o);
7089         o_ref.data = MALLOC(o_ref.datalen, "LDKCVec_u8Z Bytes");
7090         (*_env)->GetByteArrayRegion(_env, o, 0, o_ref.datalen, o_ref.data);
7091         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
7092         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_ok(o_ref);
7093         return (long)ret_conv;
7094 }
7095
7096 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7097         LDKPeerHandleError e_conv;
7098         e_conv.inner = (void*)(e & (~1));
7099         e_conv.is_owned = (e & 1) || (e == 0);
7100         // Warning: we may need a move here but can't clone!
7101         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
7102         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_err(e_conv);
7103         return (long)ret_conv;
7104 }
7105
7106 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7107         LDKCResult_CVec_u8ZPeerHandleErrorZ _res_conv = *(LDKCResult_CVec_u8ZPeerHandleErrorZ*)_res;
7108         FREE((void*)_res);
7109         CResult_CVec_u8ZPeerHandleErrorZ_free(_res_conv);
7110 }
7111
7112 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b) {
7113         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
7114         *ret_conv = CResult_NonePeerHandleErrorZ_ok();
7115         return (long)ret_conv;
7116 }
7117
7118 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7119         LDKPeerHandleError e_conv;
7120         e_conv.inner = (void*)(e & (~1));
7121         e_conv.is_owned = (e & 1) || (e == 0);
7122         // Warning: we may need a move here but can't clone!
7123         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
7124         *ret_conv = CResult_NonePeerHandleErrorZ_err(e_conv);
7125         return (long)ret_conv;
7126 }
7127
7128 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7129         LDKCResult_NonePeerHandleErrorZ _res_conv = *(LDKCResult_NonePeerHandleErrorZ*)_res;
7130         FREE((void*)_res);
7131         CResult_NonePeerHandleErrorZ_free(_res_conv);
7132 }
7133
7134 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b, jboolean o) {
7135         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
7136         *ret_conv = CResult_boolPeerHandleErrorZ_ok(o);
7137         return (long)ret_conv;
7138 }
7139
7140 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7141         LDKPeerHandleError e_conv;
7142         e_conv.inner = (void*)(e & (~1));
7143         e_conv.is_owned = (e & 1) || (e == 0);
7144         // Warning: we may need a move here but can't clone!
7145         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
7146         *ret_conv = CResult_boolPeerHandleErrorZ_err(e_conv);
7147         return (long)ret_conv;
7148 }
7149
7150 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7151         LDKCResult_boolPeerHandleErrorZ _res_conv = *(LDKCResult_boolPeerHandleErrorZ*)_res;
7152         FREE((void*)_res);
7153         CResult_boolPeerHandleErrorZ_free(_res_conv);
7154 }
7155
7156 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray o) {
7157         LDKSecretKey o_ref;
7158         CHECK((*_env)->GetArrayLength (_env, o) == 32);
7159         (*_env)->GetByteArrayRegion (_env, o, 0, 32, o_ref.bytes);
7160         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
7161         *ret_conv = CResult_SecretKeySecpErrorZ_ok(o_ref);
7162         return (long)ret_conv;
7163 }
7164
7165 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass e) {
7166         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_java(_env, e);
7167         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
7168         *ret_conv = CResult_SecretKeySecpErrorZ_err(e_conv);
7169         return (long)ret_conv;
7170 }
7171
7172 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7173         LDKCResult_SecretKeySecpErrorZ _res_conv = *(LDKCResult_SecretKeySecpErrorZ*)_res;
7174         FREE((void*)_res);
7175         CResult_SecretKeySecpErrorZ_free(_res_conv);
7176 }
7177
7178 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray o) {
7179         LDKPublicKey o_ref;
7180         CHECK((*_env)->GetArrayLength (_env, o) == 33);
7181         (*_env)->GetByteArrayRegion (_env, o, 0, 33, o_ref.compressed_form);
7182         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
7183         *ret_conv = CResult_PublicKeySecpErrorZ_ok(o_ref);
7184         return (long)ret_conv;
7185 }
7186
7187 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass e) {
7188         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_java(_env, e);
7189         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
7190         *ret_conv = CResult_PublicKeySecpErrorZ_err(e_conv);
7191         return (long)ret_conv;
7192 }
7193
7194 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7195         LDKCResult_PublicKeySecpErrorZ _res_conv = *(LDKCResult_PublicKeySecpErrorZ*)_res;
7196         FREE((void*)_res);
7197         CResult_PublicKeySecpErrorZ_free(_res_conv);
7198 }
7199
7200 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7201         LDKTxCreationKeys o_conv;
7202         o_conv.inner = (void*)(o & (~1));
7203         o_conv.is_owned = (o & 1) || (o == 0);
7204         if (o_conv.inner != NULL)
7205                 o_conv = TxCreationKeys_clone(&o_conv);
7206         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
7207         *ret_conv = CResult_TxCreationKeysSecpErrorZ_ok(o_conv);
7208         return (long)ret_conv;
7209 }
7210
7211 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass e) {
7212         LDKSecp256k1Error e_conv = LDKSecp256k1Error_from_java(_env, e);
7213         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
7214         *ret_conv = CResult_TxCreationKeysSecpErrorZ_err(e_conv);
7215         return (long)ret_conv;
7216 }
7217
7218 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7219         LDKCResult_TxCreationKeysSecpErrorZ _res_conv = *(LDKCResult_TxCreationKeysSecpErrorZ*)_res;
7220         FREE((void*)_res);
7221         CResult_TxCreationKeysSecpErrorZ_free(_res_conv);
7222 }
7223
7224 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TrustedCommitmentTransactionNoneZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7225         LDKTrustedCommitmentTransaction o_conv;
7226         o_conv.inner = (void*)(o & (~1));
7227         o_conv.is_owned = (o & 1) || (o == 0);
7228         // Warning: we may need a move here but can't clone!
7229         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
7230         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_ok(o_conv);
7231         return (long)ret_conv;
7232 }
7233
7234 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TrustedCommitmentTransactionNoneZ_1err(JNIEnv * _env, jclass _b) {
7235         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
7236         *ret_conv = CResult_TrustedCommitmentTransactionNoneZ_err();
7237         return (long)ret_conv;
7238 }
7239
7240 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TrustedCommitmentTransactionNoneZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7241         LDKCResult_TrustedCommitmentTransactionNoneZ _res_conv = *(LDKCResult_TrustedCommitmentTransactionNoneZ*)_res;
7242         FREE((void*)_res);
7243         CResult_TrustedCommitmentTransactionNoneZ_free(_res_conv);
7244 }
7245
7246 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHopZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
7247         LDKCVec_RouteHopZ _res_constr;
7248         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
7249         if (_res_constr.datalen > 0)
7250                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
7251         else
7252                 _res_constr.data = NULL;
7253         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
7254         for (size_t k = 0; k < _res_constr.datalen; k++) {
7255                 long arr_conv_10 = _res_vals[k];
7256                 LDKRouteHop arr_conv_10_conv;
7257                 arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
7258                 arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
7259                 _res_constr.data[k] = arr_conv_10_conv;
7260         }
7261         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
7262         CVec_RouteHopZ_free(_res_constr);
7263 }
7264
7265 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1CVec_1RouteHopZZ_1free(JNIEnv * _env, jclass _b, jobjectArray _res) {
7266         LDKCVec_CVec_RouteHopZZ _res_constr;
7267         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
7268         if (_res_constr.datalen > 0)
7269                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
7270         else
7271                 _res_constr.data = NULL;
7272         for (size_t m = 0; m < _res_constr.datalen; m++) {
7273                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, _res, m);
7274                 LDKCVec_RouteHopZ arr_conv_12_constr;
7275                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
7276                 if (arr_conv_12_constr.datalen > 0)
7277                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
7278                 else
7279                         arr_conv_12_constr.data = NULL;
7280                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
7281                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
7282                         long arr_conv_10 = arr_conv_12_vals[k];
7283                         LDKRouteHop arr_conv_10_conv;
7284                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
7285                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
7286                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
7287                 }
7288                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
7289                 _res_constr.data[m] = arr_conv_12_constr;
7290         }
7291         CVec_CVec_RouteHopZZ_free(_res_constr);
7292 }
7293
7294 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7295         LDKRoute o_conv;
7296         o_conv.inner = (void*)(o & (~1));
7297         o_conv.is_owned = (o & 1) || (o == 0);
7298         if (o_conv.inner != NULL)
7299                 o_conv = Route_clone(&o_conv);
7300         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
7301         *ret_conv = CResult_RouteDecodeErrorZ_ok(o_conv);
7302         return (long)ret_conv;
7303 }
7304
7305 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7306         LDKDecodeError e_conv;
7307         e_conv.inner = (void*)(e & (~1));
7308         e_conv.is_owned = (e & 1) || (e == 0);
7309         // Warning: we may need a move here but can't clone!
7310         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
7311         *ret_conv = CResult_RouteDecodeErrorZ_err(e_conv);
7312         return (long)ret_conv;
7313 }
7314
7315 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RouteDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7316         LDKCResult_RouteDecodeErrorZ _res_conv = *(LDKCResult_RouteDecodeErrorZ*)_res;
7317         FREE((void*)_res);
7318         CResult_RouteDecodeErrorZ_free(_res_conv);
7319 }
7320
7321 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHintZ_1free(JNIEnv * _env, jclass _b, jlongArray _res) {
7322         LDKCVec_RouteHintZ _res_constr;
7323         _res_constr.datalen = (*_env)->GetArrayLength (_env, _res);
7324         if (_res_constr.datalen > 0)
7325                 _res_constr.data = MALLOC(_res_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
7326         else
7327                 _res_constr.data = NULL;
7328         long* _res_vals = (*_env)->GetLongArrayElements (_env, _res, NULL);
7329         for (size_t l = 0; l < _res_constr.datalen; l++) {
7330                 long arr_conv_11 = _res_vals[l];
7331                 LDKRouteHint arr_conv_11_conv;
7332                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
7333                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
7334                 _res_constr.data[l] = arr_conv_11_conv;
7335         }
7336         (*_env)->ReleaseLongArrayElements (_env, _res, _res_vals, 0);
7337         CVec_RouteHintZ_free(_res_constr);
7338 }
7339
7340 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7341         LDKRoute o_conv;
7342         o_conv.inner = (void*)(o & (~1));
7343         o_conv.is_owned = (o & 1) || (o == 0);
7344         if (o_conv.inner != NULL)
7345                 o_conv = Route_clone(&o_conv);
7346         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
7347         *ret_conv = CResult_RouteLightningErrorZ_ok(o_conv);
7348         return (long)ret_conv;
7349 }
7350
7351 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7352         LDKLightningError e_conv;
7353         e_conv.inner = (void*)(e & (~1));
7354         e_conv.is_owned = (e & 1) || (e == 0);
7355         // Warning: we may need a move here but can't clone!
7356         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
7357         *ret_conv = CResult_RouteLightningErrorZ_err(e_conv);
7358         return (long)ret_conv;
7359 }
7360
7361 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7362         LDKCResult_RouteLightningErrorZ _res_conv = *(LDKCResult_RouteLightningErrorZ*)_res;
7363         FREE((void*)_res);
7364         CResult_RouteLightningErrorZ_free(_res_conv);
7365 }
7366
7367 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RoutingFeesDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7368         LDKRoutingFees o_conv;
7369         o_conv.inner = (void*)(o & (~1));
7370         o_conv.is_owned = (o & 1) || (o == 0);
7371         if (o_conv.inner != NULL)
7372                 o_conv = RoutingFees_clone(&o_conv);
7373         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
7374         *ret_conv = CResult_RoutingFeesDecodeErrorZ_ok(o_conv);
7375         return (long)ret_conv;
7376 }
7377
7378 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RoutingFeesDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7379         LDKDecodeError e_conv;
7380         e_conv.inner = (void*)(e & (~1));
7381         e_conv.is_owned = (e & 1) || (e == 0);
7382         // Warning: we may need a move here but can't clone!
7383         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
7384         *ret_conv = CResult_RoutingFeesDecodeErrorZ_err(e_conv);
7385         return (long)ret_conv;
7386 }
7387
7388 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RoutingFeesDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7389         LDKCResult_RoutingFeesDecodeErrorZ _res_conv = *(LDKCResult_RoutingFeesDecodeErrorZ*)_res;
7390         FREE((void*)_res);
7391         CResult_RoutingFeesDecodeErrorZ_free(_res_conv);
7392 }
7393
7394 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NodeAnnouncementInfoDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7395         LDKNodeAnnouncementInfo o_conv;
7396         o_conv.inner = (void*)(o & (~1));
7397         o_conv.is_owned = (o & 1) || (o == 0);
7398         // Warning: we may need a move here but can't clone!
7399         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
7400         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_ok(o_conv);
7401         return (long)ret_conv;
7402 }
7403
7404 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NodeAnnouncementInfoDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7405         LDKDecodeError e_conv;
7406         e_conv.inner = (void*)(e & (~1));
7407         e_conv.is_owned = (e & 1) || (e == 0);
7408         // Warning: we may need a move here but can't clone!
7409         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
7410         *ret_conv = CResult_NodeAnnouncementInfoDecodeErrorZ_err(e_conv);
7411         return (long)ret_conv;
7412 }
7413
7414 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NodeAnnouncementInfoDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7415         LDKCResult_NodeAnnouncementInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeAnnouncementInfoDecodeErrorZ*)_res;
7416         FREE((void*)_res);
7417         CResult_NodeAnnouncementInfoDecodeErrorZ_free(_res_conv);
7418 }
7419
7420 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NodeInfoDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7421         LDKNodeInfo o_conv;
7422         o_conv.inner = (void*)(o & (~1));
7423         o_conv.is_owned = (o & 1) || (o == 0);
7424         // Warning: we may need a move here but can't clone!
7425         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
7426         *ret_conv = CResult_NodeInfoDecodeErrorZ_ok(o_conv);
7427         return (long)ret_conv;
7428 }
7429
7430 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NodeInfoDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7431         LDKDecodeError e_conv;
7432         e_conv.inner = (void*)(e & (~1));
7433         e_conv.is_owned = (e & 1) || (e == 0);
7434         // Warning: we may need a move here but can't clone!
7435         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
7436         *ret_conv = CResult_NodeInfoDecodeErrorZ_err(e_conv);
7437         return (long)ret_conv;
7438 }
7439
7440 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NodeInfoDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7441         LDKCResult_NodeInfoDecodeErrorZ _res_conv = *(LDKCResult_NodeInfoDecodeErrorZ*)_res;
7442         FREE((void*)_res);
7443         CResult_NodeInfoDecodeErrorZ_free(_res_conv);
7444 }
7445
7446 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NetworkGraphDecodeErrorZ_1ok(JNIEnv * _env, jclass _b, jlong o) {
7447         LDKNetworkGraph o_conv;
7448         o_conv.inner = (void*)(o & (~1));
7449         o_conv.is_owned = (o & 1) || (o == 0);
7450         // Warning: we may need a move here but can't clone!
7451         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
7452         *ret_conv = CResult_NetworkGraphDecodeErrorZ_ok(o_conv);
7453         return (long)ret_conv;
7454 }
7455
7456 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NetworkGraphDecodeErrorZ_1err(JNIEnv * _env, jclass _b, jlong e) {
7457         LDKDecodeError e_conv;
7458         e_conv.inner = (void*)(e & (~1));
7459         e_conv.is_owned = (e & 1) || (e == 0);
7460         // Warning: we may need a move here but can't clone!
7461         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
7462         *ret_conv = CResult_NetworkGraphDecodeErrorZ_err(e_conv);
7463         return (long)ret_conv;
7464 }
7465
7466 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NetworkGraphDecodeErrorZ_1free(JNIEnv * _env, jclass _b, jlong _res) {
7467         LDKCResult_NetworkGraphDecodeErrorZ _res_conv = *(LDKCResult_NetworkGraphDecodeErrorZ*)_res;
7468         FREE((void*)_res);
7469         CResult_NetworkGraphDecodeErrorZ_free(_res_conv);
7470 }
7471
7472 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Event_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7473         LDKEvent this_ptr_conv = *(LDKEvent*)this_ptr;
7474         FREE((void*)this_ptr);
7475         Event_free(this_ptr_conv);
7476 }
7477
7478 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Event_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7479         LDKEvent* orig_conv = (LDKEvent*)orig;
7480         LDKEvent *ret_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
7481         *ret_copy = Event_clone(orig_conv);
7482         long ret_ref = (long)ret_copy;
7483         return ret_ref;
7484 }
7485
7486 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Event_1write(JNIEnv * _env, jclass _b, jlong obj) {
7487         LDKEvent* obj_conv = (LDKEvent*)obj;
7488         LDKCVec_u8Z arg_var = Event_write(obj_conv);
7489         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
7490         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
7491         CVec_u8Z_free(arg_var);
7492         return arg_arr;
7493 }
7494
7495 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7496         LDKMessageSendEvent this_ptr_conv = *(LDKMessageSendEvent*)this_ptr;
7497         FREE((void*)this_ptr);
7498         MessageSendEvent_free(this_ptr_conv);
7499 }
7500
7501 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7502         LDKMessageSendEvent* orig_conv = (LDKMessageSendEvent*)orig;
7503         LDKMessageSendEvent *ret_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
7504         *ret_copy = MessageSendEvent_clone(orig_conv);
7505         long ret_ref = (long)ret_copy;
7506         return ret_ref;
7507 }
7508
7509 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7510         LDKMessageSendEventsProvider this_ptr_conv = *(LDKMessageSendEventsProvider*)this_ptr;
7511         FREE((void*)this_ptr);
7512         MessageSendEventsProvider_free(this_ptr_conv);
7513 }
7514
7515 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_EventsProvider_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7516         LDKEventsProvider this_ptr_conv = *(LDKEventsProvider*)this_ptr;
7517         FREE((void*)this_ptr);
7518         EventsProvider_free(this_ptr_conv);
7519 }
7520
7521 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_APIError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7522         LDKAPIError this_ptr_conv = *(LDKAPIError*)this_ptr;
7523         FREE((void*)this_ptr);
7524         APIError_free(this_ptr_conv);
7525 }
7526
7527 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_APIError_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7528         LDKAPIError* orig_conv = (LDKAPIError*)orig;
7529         LDKAPIError *ret_copy = MALLOC(sizeof(LDKAPIError), "LDKAPIError");
7530         *ret_copy = APIError_clone(orig_conv);
7531         long ret_ref = (long)ret_copy;
7532         return ret_ref;
7533 }
7534
7535 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7536         LDKLevel* orig_conv = (LDKLevel*)orig;
7537         jclass ret_conv = LDKLevel_to_java(_env, Level_clone(orig_conv));
7538         return ret_conv;
7539 }
7540
7541 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1max(JNIEnv * _env, jclass _b) {
7542         jclass ret_conv = LDKLevel_to_java(_env, Level_max());
7543         return ret_conv;
7544 }
7545
7546 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Logger_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7547         LDKLogger this_ptr_conv = *(LDKLogger*)this_ptr;
7548         FREE((void*)this_ptr);
7549         Logger_free(this_ptr_conv);
7550 }
7551
7552 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7553         LDKChannelHandshakeConfig this_ptr_conv;
7554         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7555         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7556         ChannelHandshakeConfig_free(this_ptr_conv);
7557 }
7558
7559 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7560         LDKChannelHandshakeConfig orig_conv;
7561         orig_conv.inner = (void*)(orig & (~1));
7562         orig_conv.is_owned = false;
7563         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_clone(&orig_conv);
7564         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7565         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7566         long ret_ref = (long)ret_var.inner;
7567         if (ret_var.is_owned) {
7568                 ret_ref |= 1;
7569         }
7570         return ret_ref;
7571 }
7572
7573 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
7574         LDKChannelHandshakeConfig this_ptr_conv;
7575         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7576         this_ptr_conv.is_owned = false;
7577         jint ret_val = ChannelHandshakeConfig_get_minimum_depth(&this_ptr_conv);
7578         return ret_val;
7579 }
7580
7581 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
7582         LDKChannelHandshakeConfig this_ptr_conv;
7583         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7584         this_ptr_conv.is_owned = false;
7585         ChannelHandshakeConfig_set_minimum_depth(&this_ptr_conv, val);
7586 }
7587
7588 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
7589         LDKChannelHandshakeConfig this_ptr_conv;
7590         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7591         this_ptr_conv.is_owned = false;
7592         jshort ret_val = ChannelHandshakeConfig_get_our_to_self_delay(&this_ptr_conv);
7593         return ret_val;
7594 }
7595
7596 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1our_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7597         LDKChannelHandshakeConfig this_ptr_conv;
7598         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7599         this_ptr_conv.is_owned = false;
7600         ChannelHandshakeConfig_set_our_to_self_delay(&this_ptr_conv, val);
7601 }
7602
7603 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7604         LDKChannelHandshakeConfig this_ptr_conv;
7605         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7606         this_ptr_conv.is_owned = false;
7607         jlong ret_val = ChannelHandshakeConfig_get_our_htlc_minimum_msat(&this_ptr_conv);
7608         return ret_val;
7609 }
7610
7611 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1our_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7612         LDKChannelHandshakeConfig this_ptr_conv;
7613         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7614         this_ptr_conv.is_owned = false;
7615         ChannelHandshakeConfig_set_our_htlc_minimum_msat(&this_ptr_conv, val);
7616 }
7617
7618 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) {
7619         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_new(minimum_depth_arg, our_to_self_delay_arg, our_htlc_minimum_msat_arg);
7620         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7621         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7622         long ret_ref = (long)ret_var.inner;
7623         if (ret_var.is_owned) {
7624                 ret_ref |= 1;
7625         }
7626         return ret_ref;
7627 }
7628
7629 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1default(JNIEnv * _env, jclass _b) {
7630         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_default();
7631         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7632         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7633         long ret_ref = (long)ret_var.inner;
7634         if (ret_var.is_owned) {
7635                 ret_ref |= 1;
7636         }
7637         return ret_ref;
7638 }
7639
7640 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7641         LDKChannelHandshakeLimits this_ptr_conv;
7642         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7643         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7644         ChannelHandshakeLimits_free(this_ptr_conv);
7645 }
7646
7647 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7648         LDKChannelHandshakeLimits orig_conv;
7649         orig_conv.inner = (void*)(orig & (~1));
7650         orig_conv.is_owned = false;
7651         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_clone(&orig_conv);
7652         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7653         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7654         long ret_ref = (long)ret_var.inner;
7655         if (ret_var.is_owned) {
7656                 ret_ref |= 1;
7657         }
7658         return ret_ref;
7659 }
7660
7661 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7662         LDKChannelHandshakeLimits this_ptr_conv;
7663         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7664         this_ptr_conv.is_owned = false;
7665         jlong ret_val = ChannelHandshakeLimits_get_min_funding_satoshis(&this_ptr_conv);
7666         return ret_val;
7667 }
7668
7669 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7670         LDKChannelHandshakeLimits this_ptr_conv;
7671         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7672         this_ptr_conv.is_owned = false;
7673         ChannelHandshakeLimits_set_min_funding_satoshis(&this_ptr_conv, val);
7674 }
7675
7676 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7677         LDKChannelHandshakeLimits this_ptr_conv;
7678         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7679         this_ptr_conv.is_owned = false;
7680         jlong ret_val = ChannelHandshakeLimits_get_max_htlc_minimum_msat(&this_ptr_conv);
7681         return ret_val;
7682 }
7683
7684 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7685         LDKChannelHandshakeLimits this_ptr_conv;
7686         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7687         this_ptr_conv.is_owned = false;
7688         ChannelHandshakeLimits_set_max_htlc_minimum_msat(&this_ptr_conv, val);
7689 }
7690
7691 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7692         LDKChannelHandshakeLimits this_ptr_conv;
7693         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7694         this_ptr_conv.is_owned = false;
7695         jlong ret_val = ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(&this_ptr_conv);
7696         return ret_val;
7697 }
7698
7699 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) {
7700         LDKChannelHandshakeLimits this_ptr_conv;
7701         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7702         this_ptr_conv.is_owned = false;
7703         ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
7704 }
7705
7706 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7707         LDKChannelHandshakeLimits this_ptr_conv;
7708         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7709         this_ptr_conv.is_owned = false;
7710         jlong ret_val = ChannelHandshakeLimits_get_max_channel_reserve_satoshis(&this_ptr_conv);
7711         return ret_val;
7712 }
7713
7714 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7715         LDKChannelHandshakeLimits this_ptr_conv;
7716         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7717         this_ptr_conv.is_owned = false;
7718         ChannelHandshakeLimits_set_max_channel_reserve_satoshis(&this_ptr_conv, val);
7719 }
7720
7721 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
7722         LDKChannelHandshakeLimits this_ptr_conv;
7723         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7724         this_ptr_conv.is_owned = false;
7725         jshort ret_val = ChannelHandshakeLimits_get_min_max_accepted_htlcs(&this_ptr_conv);
7726         return ret_val;
7727 }
7728
7729 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7730         LDKChannelHandshakeLimits this_ptr_conv;
7731         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7732         this_ptr_conv.is_owned = false;
7733         ChannelHandshakeLimits_set_min_max_accepted_htlcs(&this_ptr_conv, val);
7734 }
7735
7736 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7737         LDKChannelHandshakeLimits this_ptr_conv;
7738         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7739         this_ptr_conv.is_owned = false;
7740         jlong ret_val = ChannelHandshakeLimits_get_min_dust_limit_satoshis(&this_ptr_conv);
7741         return ret_val;
7742 }
7743
7744 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7745         LDKChannelHandshakeLimits this_ptr_conv;
7746         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7747         this_ptr_conv.is_owned = false;
7748         ChannelHandshakeLimits_set_min_dust_limit_satoshis(&this_ptr_conv, val);
7749 }
7750
7751 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7752         LDKChannelHandshakeLimits this_ptr_conv;
7753         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7754         this_ptr_conv.is_owned = false;
7755         jlong ret_val = ChannelHandshakeLimits_get_max_dust_limit_satoshis(&this_ptr_conv);
7756         return ret_val;
7757 }
7758
7759 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7760         LDKChannelHandshakeLimits this_ptr_conv;
7761         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7762         this_ptr_conv.is_owned = false;
7763         ChannelHandshakeLimits_set_max_dust_limit_satoshis(&this_ptr_conv, val);
7764 }
7765
7766 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
7767         LDKChannelHandshakeLimits this_ptr_conv;
7768         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7769         this_ptr_conv.is_owned = false;
7770         jint ret_val = ChannelHandshakeLimits_get_max_minimum_depth(&this_ptr_conv);
7771         return ret_val;
7772 }
7773
7774 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
7775         LDKChannelHandshakeLimits this_ptr_conv;
7776         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7777         this_ptr_conv.is_owned = false;
7778         ChannelHandshakeLimits_set_max_minimum_depth(&this_ptr_conv, val);
7779 }
7780
7781 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1force_1announced_1channel_1preference(JNIEnv * _env, jclass _b, jlong this_ptr) {
7782         LDKChannelHandshakeLimits this_ptr_conv;
7783         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7784         this_ptr_conv.is_owned = false;
7785         jboolean ret_val = ChannelHandshakeLimits_get_force_announced_channel_preference(&this_ptr_conv);
7786         return ret_val;
7787 }
7788
7789 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1force_1announced_1channel_1preference(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
7790         LDKChannelHandshakeLimits this_ptr_conv;
7791         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7792         this_ptr_conv.is_owned = false;
7793         ChannelHandshakeLimits_set_force_announced_channel_preference(&this_ptr_conv, val);
7794 }
7795
7796 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1their_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
7797         LDKChannelHandshakeLimits this_ptr_conv;
7798         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7799         this_ptr_conv.is_owned = false;
7800         jshort ret_val = ChannelHandshakeLimits_get_their_to_self_delay(&this_ptr_conv);
7801         return ret_val;
7802 }
7803
7804 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1their_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7805         LDKChannelHandshakeLimits this_ptr_conv;
7806         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7807         this_ptr_conv.is_owned = false;
7808         ChannelHandshakeLimits_set_their_to_self_delay(&this_ptr_conv, val);
7809 }
7810
7811 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) {
7812         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);
7813         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7814         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7815         long ret_ref = (long)ret_var.inner;
7816         if (ret_var.is_owned) {
7817                 ret_ref |= 1;
7818         }
7819         return ret_ref;
7820 }
7821
7822 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1default(JNIEnv * _env, jclass _b) {
7823         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_default();
7824         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7825         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7826         long ret_ref = (long)ret_var.inner;
7827         if (ret_var.is_owned) {
7828                 ret_ref |= 1;
7829         }
7830         return ret_ref;
7831 }
7832
7833 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7834         LDKChannelConfig this_ptr_conv;
7835         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7836         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7837         ChannelConfig_free(this_ptr_conv);
7838 }
7839
7840 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7841         LDKChannelConfig orig_conv;
7842         orig_conv.inner = (void*)(orig & (~1));
7843         orig_conv.is_owned = false;
7844         LDKChannelConfig ret_var = ChannelConfig_clone(&orig_conv);
7845         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7846         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7847         long ret_ref = (long)ret_var.inner;
7848         if (ret_var.is_owned) {
7849                 ret_ref |= 1;
7850         }
7851         return ret_ref;
7852 }
7853
7854 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
7855         LDKChannelConfig this_ptr_conv;
7856         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7857         this_ptr_conv.is_owned = false;
7858         jint ret_val = ChannelConfig_get_fee_proportional_millionths(&this_ptr_conv);
7859         return ret_val;
7860 }
7861
7862 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
7863         LDKChannelConfig this_ptr_conv;
7864         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7865         this_ptr_conv.is_owned = false;
7866         ChannelConfig_set_fee_proportional_millionths(&this_ptr_conv, val);
7867 }
7868
7869 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1announced_1channel(JNIEnv * _env, jclass _b, jlong this_ptr) {
7870         LDKChannelConfig this_ptr_conv;
7871         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7872         this_ptr_conv.is_owned = false;
7873         jboolean ret_val = ChannelConfig_get_announced_channel(&this_ptr_conv);
7874         return ret_val;
7875 }
7876
7877 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1announced_1channel(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
7878         LDKChannelConfig this_ptr_conv;
7879         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7880         this_ptr_conv.is_owned = false;
7881         ChannelConfig_set_announced_channel(&this_ptr_conv, val);
7882 }
7883
7884 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1commit_1upfront_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
7885         LDKChannelConfig this_ptr_conv;
7886         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7887         this_ptr_conv.is_owned = false;
7888         jboolean ret_val = ChannelConfig_get_commit_upfront_shutdown_pubkey(&this_ptr_conv);
7889         return ret_val;
7890 }
7891
7892 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1commit_1upfront_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
7893         LDKChannelConfig this_ptr_conv;
7894         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7895         this_ptr_conv.is_owned = false;
7896         ChannelConfig_set_commit_upfront_shutdown_pubkey(&this_ptr_conv, val);
7897 }
7898
7899 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) {
7900         LDKChannelConfig ret_var = ChannelConfig_new(fee_proportional_millionths_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
7901         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7902         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7903         long ret_ref = (long)ret_var.inner;
7904         if (ret_var.is_owned) {
7905                 ret_ref |= 1;
7906         }
7907         return ret_ref;
7908 }
7909
7910 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1default(JNIEnv * _env, jclass _b) {
7911         LDKChannelConfig ret_var = ChannelConfig_default();
7912         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7913         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7914         long ret_ref = (long)ret_var.inner;
7915         if (ret_var.is_owned) {
7916                 ret_ref |= 1;
7917         }
7918         return ret_ref;
7919 }
7920
7921 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1write(JNIEnv * _env, jclass _b, jlong obj) {
7922         LDKChannelConfig obj_conv;
7923         obj_conv.inner = (void*)(obj & (~1));
7924         obj_conv.is_owned = false;
7925         LDKCVec_u8Z arg_var = ChannelConfig_write(&obj_conv);
7926         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
7927         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
7928         CVec_u8Z_free(arg_var);
7929         return arg_arr;
7930 }
7931
7932 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
7933         LDKu8slice ser_ref;
7934         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
7935         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
7936         LDKChannelConfig ret_var = ChannelConfig_read(ser_ref);
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         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
7944         return ret_ref;
7945 }
7946
7947 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7948         LDKUserConfig this_ptr_conv;
7949         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7950         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7951         UserConfig_free(this_ptr_conv);
7952 }
7953
7954 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7955         LDKUserConfig orig_conv;
7956         orig_conv.inner = (void*)(orig & (~1));
7957         orig_conv.is_owned = false;
7958         LDKUserConfig ret_var = UserConfig_clone(&orig_conv);
7959         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7960         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7961         long ret_ref = (long)ret_var.inner;
7962         if (ret_var.is_owned) {
7963                 ret_ref |= 1;
7964         }
7965         return ret_ref;
7966 }
7967
7968 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1own_1channel_1config(JNIEnv * _env, jclass _b, jlong this_ptr) {
7969         LDKUserConfig this_ptr_conv;
7970         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7971         this_ptr_conv.is_owned = false;
7972         LDKChannelHandshakeConfig ret_var = UserConfig_get_own_channel_config(&this_ptr_conv);
7973         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7974         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7975         long ret_ref = (long)ret_var.inner;
7976         if (ret_var.is_owned) {
7977                 ret_ref |= 1;
7978         }
7979         return ret_ref;
7980 }
7981
7982 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1own_1channel_1config(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7983         LDKUserConfig this_ptr_conv;
7984         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7985         this_ptr_conv.is_owned = false;
7986         LDKChannelHandshakeConfig val_conv;
7987         val_conv.inner = (void*)(val & (~1));
7988         val_conv.is_owned = (val & 1) || (val == 0);
7989         if (val_conv.inner != NULL)
7990                 val_conv = ChannelHandshakeConfig_clone(&val_conv);
7991         UserConfig_set_own_channel_config(&this_ptr_conv, val_conv);
7992 }
7993
7994 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1peer_1channel_1config_1limits(JNIEnv * _env, jclass _b, jlong this_ptr) {
7995         LDKUserConfig this_ptr_conv;
7996         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7997         this_ptr_conv.is_owned = false;
7998         LDKChannelHandshakeLimits ret_var = UserConfig_get_peer_channel_config_limits(&this_ptr_conv);
7999         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8000         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8001         long ret_ref = (long)ret_var.inner;
8002         if (ret_var.is_owned) {
8003                 ret_ref |= 1;
8004         }
8005         return ret_ref;
8006 }
8007
8008 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1peer_1channel_1config_1limits(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8009         LDKUserConfig this_ptr_conv;
8010         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8011         this_ptr_conv.is_owned = false;
8012         LDKChannelHandshakeLimits val_conv;
8013         val_conv.inner = (void*)(val & (~1));
8014         val_conv.is_owned = (val & 1) || (val == 0);
8015         if (val_conv.inner != NULL)
8016                 val_conv = ChannelHandshakeLimits_clone(&val_conv);
8017         UserConfig_set_peer_channel_config_limits(&this_ptr_conv, val_conv);
8018 }
8019
8020 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1channel_1options(JNIEnv * _env, jclass _b, jlong this_ptr) {
8021         LDKUserConfig this_ptr_conv;
8022         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8023         this_ptr_conv.is_owned = false;
8024         LDKChannelConfig ret_var = UserConfig_get_channel_options(&this_ptr_conv);
8025         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8026         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8027         long ret_ref = (long)ret_var.inner;
8028         if (ret_var.is_owned) {
8029                 ret_ref |= 1;
8030         }
8031         return ret_ref;
8032 }
8033
8034 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1channel_1options(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8035         LDKUserConfig this_ptr_conv;
8036         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8037         this_ptr_conv.is_owned = false;
8038         LDKChannelConfig val_conv;
8039         val_conv.inner = (void*)(val & (~1));
8040         val_conv.is_owned = (val & 1) || (val == 0);
8041         if (val_conv.inner != NULL)
8042                 val_conv = ChannelConfig_clone(&val_conv);
8043         UserConfig_set_channel_options(&this_ptr_conv, val_conv);
8044 }
8045
8046 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) {
8047         LDKChannelHandshakeConfig own_channel_config_arg_conv;
8048         own_channel_config_arg_conv.inner = (void*)(own_channel_config_arg & (~1));
8049         own_channel_config_arg_conv.is_owned = (own_channel_config_arg & 1) || (own_channel_config_arg == 0);
8050         if (own_channel_config_arg_conv.inner != NULL)
8051                 own_channel_config_arg_conv = ChannelHandshakeConfig_clone(&own_channel_config_arg_conv);
8052         LDKChannelHandshakeLimits peer_channel_config_limits_arg_conv;
8053         peer_channel_config_limits_arg_conv.inner = (void*)(peer_channel_config_limits_arg & (~1));
8054         peer_channel_config_limits_arg_conv.is_owned = (peer_channel_config_limits_arg & 1) || (peer_channel_config_limits_arg == 0);
8055         if (peer_channel_config_limits_arg_conv.inner != NULL)
8056                 peer_channel_config_limits_arg_conv = ChannelHandshakeLimits_clone(&peer_channel_config_limits_arg_conv);
8057         LDKChannelConfig channel_options_arg_conv;
8058         channel_options_arg_conv.inner = (void*)(channel_options_arg & (~1));
8059         channel_options_arg_conv.is_owned = (channel_options_arg & 1) || (channel_options_arg == 0);
8060         if (channel_options_arg_conv.inner != NULL)
8061                 channel_options_arg_conv = ChannelConfig_clone(&channel_options_arg_conv);
8062         LDKUserConfig ret_var = UserConfig_new(own_channel_config_arg_conv, peer_channel_config_limits_arg_conv, channel_options_arg_conv);
8063         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8064         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8065         long ret_ref = (long)ret_var.inner;
8066         if (ret_var.is_owned) {
8067                 ret_ref |= 1;
8068         }
8069         return ret_ref;
8070 }
8071
8072 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1default(JNIEnv * _env, jclass _b) {
8073         LDKUserConfig ret_var = UserConfig_default();
8074         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8075         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8076         long ret_ref = (long)ret_var.inner;
8077         if (ret_var.is_owned) {
8078                 ret_ref |= 1;
8079         }
8080         return ret_ref;
8081 }
8082
8083 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_AccessError_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8084         LDKAccessError* orig_conv = (LDKAccessError*)orig;
8085         jclass ret_conv = LDKAccessError_to_java(_env, AccessError_clone(orig_conv));
8086         return ret_conv;
8087 }
8088
8089 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Access_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8090         LDKAccess this_ptr_conv = *(LDKAccess*)this_ptr;
8091         FREE((void*)this_ptr);
8092         Access_free(this_ptr_conv);
8093 }
8094
8095 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Watch_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8096         LDKWatch this_ptr_conv = *(LDKWatch*)this_ptr;
8097         FREE((void*)this_ptr);
8098         Watch_free(this_ptr_conv);
8099 }
8100
8101 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8102         LDKFilter this_ptr_conv = *(LDKFilter*)this_ptr;
8103         FREE((void*)this_ptr);
8104         Filter_free(this_ptr_conv);
8105 }
8106
8107 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8108         LDKBroadcasterInterface this_ptr_conv = *(LDKBroadcasterInterface*)this_ptr;
8109         FREE((void*)this_ptr);
8110         BroadcasterInterface_free(this_ptr_conv);
8111 }
8112
8113 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ConfirmationTarget_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8114         LDKConfirmationTarget* orig_conv = (LDKConfirmationTarget*)orig;
8115         jclass ret_conv = LDKConfirmationTarget_to_java(_env, ConfirmationTarget_clone(orig_conv));
8116         return ret_conv;
8117 }
8118
8119 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FeeEstimator_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8120         LDKFeeEstimator this_ptr_conv = *(LDKFeeEstimator*)this_ptr;
8121         FREE((void*)this_ptr);
8122         FeeEstimator_free(this_ptr_conv);
8123 }
8124
8125 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8126         LDKChainMonitor this_ptr_conv;
8127         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8128         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8129         ChainMonitor_free(this_ptr_conv);
8130 }
8131
8132 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1block_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jlongArray txdata, jint height) {
8133         LDKChainMonitor this_arg_conv;
8134         this_arg_conv.inner = (void*)(this_arg & (~1));
8135         this_arg_conv.is_owned = false;
8136         unsigned char header_arr[80];
8137         CHECK((*_env)->GetArrayLength (_env, header) == 80);
8138         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
8139         unsigned char (*header_ref)[80] = &header_arr;
8140         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
8141         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
8142         if (txdata_constr.datalen > 0)
8143                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
8144         else
8145                 txdata_constr.data = NULL;
8146         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
8147         for (size_t y = 0; y < txdata_constr.datalen; y++) {
8148                 long arr_conv_24 = txdata_vals[y];
8149                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
8150                 FREE((void*)arr_conv_24);
8151                 txdata_constr.data[y] = arr_conv_24_conv;
8152         }
8153         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
8154         ChainMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
8155 }
8156
8157 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1block_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jint disconnected_height) {
8158         LDKChainMonitor this_arg_conv;
8159         this_arg_conv.inner = (void*)(this_arg & (~1));
8160         this_arg_conv.is_owned = false;
8161         unsigned char header_arr[80];
8162         CHECK((*_env)->GetArrayLength (_env, header) == 80);
8163         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
8164         unsigned char (*header_ref)[80] = &header_arr;
8165         ChainMonitor_block_disconnected(&this_arg_conv, header_ref, disconnected_height);
8166 }
8167
8168 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1new(JNIEnv * _env, jclass _b, jlong chain_source, jlong broadcaster, jlong logger, jlong feeest, jlong persister) {
8169         LDKFilter* chain_source_conv = (LDKFilter*)chain_source;
8170         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
8171         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
8172                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8173                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
8174         }
8175         LDKLogger logger_conv = *(LDKLogger*)logger;
8176         if (logger_conv.free == LDKLogger_JCalls_free) {
8177                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8178                 LDKLogger_JCalls_clone(logger_conv.this_arg);
8179         }
8180         LDKFeeEstimator feeest_conv = *(LDKFeeEstimator*)feeest;
8181         if (feeest_conv.free == LDKFeeEstimator_JCalls_free) {
8182                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8183                 LDKFeeEstimator_JCalls_clone(feeest_conv.this_arg);
8184         }
8185         LDKPersist persister_conv = *(LDKPersist*)persister;
8186         if (persister_conv.free == LDKPersist_JCalls_free) {
8187                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8188                 LDKPersist_JCalls_clone(persister_conv.this_arg);
8189         }
8190         LDKChainMonitor ret_var = ChainMonitor_new(chain_source_conv, broadcaster_conv, logger_conv, feeest_conv, persister_conv);
8191         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8192         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8193         long ret_ref = (long)ret_var.inner;
8194         if (ret_var.is_owned) {
8195                 ret_ref |= 1;
8196         }
8197         return ret_ref;
8198 }
8199
8200 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1Watch(JNIEnv * _env, jclass _b, jlong this_arg) {
8201         LDKChainMonitor this_arg_conv;
8202         this_arg_conv.inner = (void*)(this_arg & (~1));
8203         this_arg_conv.is_owned = false;
8204         LDKWatch* ret = MALLOC(sizeof(LDKWatch), "LDKWatch");
8205         *ret = ChainMonitor_as_Watch(&this_arg_conv);
8206         return (long)ret;
8207 }
8208
8209 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1EventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
8210         LDKChainMonitor this_arg_conv;
8211         this_arg_conv.inner = (void*)(this_arg & (~1));
8212         this_arg_conv.is_owned = false;
8213         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
8214         *ret = ChainMonitor_as_EventsProvider(&this_arg_conv);
8215         return (long)ret;
8216 }
8217
8218 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8219         LDKChannelMonitorUpdate this_ptr_conv;
8220         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8221         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8222         ChannelMonitorUpdate_free(this_ptr_conv);
8223 }
8224
8225 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8226         LDKChannelMonitorUpdate orig_conv;
8227         orig_conv.inner = (void*)(orig & (~1));
8228         orig_conv.is_owned = false;
8229         LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_clone(&orig_conv);
8230         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8231         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8232         long ret_ref = (long)ret_var.inner;
8233         if (ret_var.is_owned) {
8234                 ret_ref |= 1;
8235         }
8236         return ret_ref;
8237 }
8238
8239 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1get_1update_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8240         LDKChannelMonitorUpdate this_ptr_conv;
8241         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8242         this_ptr_conv.is_owned = false;
8243         jlong ret_val = ChannelMonitorUpdate_get_update_id(&this_ptr_conv);
8244         return ret_val;
8245 }
8246
8247 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1set_1update_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8248         LDKChannelMonitorUpdate this_ptr_conv;
8249         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8250         this_ptr_conv.is_owned = false;
8251         ChannelMonitorUpdate_set_update_id(&this_ptr_conv, val);
8252 }
8253
8254 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
8255         LDKChannelMonitorUpdate obj_conv;
8256         obj_conv.inner = (void*)(obj & (~1));
8257         obj_conv.is_owned = false;
8258         LDKCVec_u8Z arg_var = ChannelMonitorUpdate_write(&obj_conv);
8259         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8260         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8261         CVec_u8Z_free(arg_var);
8262         return arg_arr;
8263 }
8264
8265 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
8266         LDKu8slice ser_ref;
8267         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
8268         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
8269         LDKCResult_ChannelMonitorUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelMonitorUpdateDecodeErrorZ), "LDKCResult_ChannelMonitorUpdateDecodeErrorZ");
8270         *ret_conv = ChannelMonitorUpdate_read(ser_ref);
8271         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
8272         return (long)ret_conv;
8273 }
8274
8275 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdateErr_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8276         LDKChannelMonitorUpdateErr* orig_conv = (LDKChannelMonitorUpdateErr*)orig;
8277         jclass ret_conv = LDKChannelMonitorUpdateErr_to_java(_env, ChannelMonitorUpdateErr_clone(orig_conv));
8278         return ret_conv;
8279 }
8280
8281 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorUpdateError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8282         LDKMonitorUpdateError this_ptr_conv;
8283         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8284         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8285         MonitorUpdateError_free(this_ptr_conv);
8286 }
8287
8288 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8289         LDKMonitorEvent this_ptr_conv;
8290         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8291         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8292         MonitorEvent_free(this_ptr_conv);
8293 }
8294
8295 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8296         LDKMonitorEvent orig_conv;
8297         orig_conv.inner = (void*)(orig & (~1));
8298         orig_conv.is_owned = false;
8299         LDKMonitorEvent ret_var = MonitorEvent_clone(&orig_conv);
8300         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8301         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8302         long ret_ref = (long)ret_var.inner;
8303         if (ret_var.is_owned) {
8304                 ret_ref |= 1;
8305         }
8306         return ret_ref;
8307 }
8308
8309 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8310         LDKHTLCUpdate this_ptr_conv;
8311         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8312         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8313         HTLCUpdate_free(this_ptr_conv);
8314 }
8315
8316 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8317         LDKHTLCUpdate orig_conv;
8318         orig_conv.inner = (void*)(orig & (~1));
8319         orig_conv.is_owned = false;
8320         LDKHTLCUpdate ret_var = HTLCUpdate_clone(&orig_conv);
8321         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8322         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8323         long ret_ref = (long)ret_var.inner;
8324         if (ret_var.is_owned) {
8325                 ret_ref |= 1;
8326         }
8327         return ret_ref;
8328 }
8329
8330 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
8331         LDKHTLCUpdate obj_conv;
8332         obj_conv.inner = (void*)(obj & (~1));
8333         obj_conv.is_owned = false;
8334         LDKCVec_u8Z arg_var = HTLCUpdate_write(&obj_conv);
8335         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8336         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8337         CVec_u8Z_free(arg_var);
8338         return arg_arr;
8339 }
8340
8341 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
8342         LDKu8slice ser_ref;
8343         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
8344         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
8345         LDKHTLCUpdate ret_var = HTLCUpdate_read(ser_ref);
8346         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8347         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8348         long ret_ref = (long)ret_var.inner;
8349         if (ret_var.is_owned) {
8350                 ret_ref |= 1;
8351         }
8352         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
8353         return ret_ref;
8354 }
8355
8356 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8357         LDKChannelMonitor this_ptr_conv;
8358         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8359         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8360         ChannelMonitor_free(this_ptr_conv);
8361 }
8362
8363 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1write(JNIEnv * _env, jclass _b, jlong obj) {
8364         LDKChannelMonitor obj_conv;
8365         obj_conv.inner = (void*)(obj & (~1));
8366         obj_conv.is_owned = false;
8367         LDKCVec_u8Z arg_var = ChannelMonitor_write(&obj_conv);
8368         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8369         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8370         CVec_u8Z_free(arg_var);
8371         return arg_arr;
8372 }
8373
8374 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1update_1monitor(JNIEnv * _env, jclass _b, jlong this_arg, jlong updates, jlong broadcaster, jlong fee_estimator, jlong logger) {
8375         LDKChannelMonitor this_arg_conv;
8376         this_arg_conv.inner = (void*)(this_arg & (~1));
8377         this_arg_conv.is_owned = false;
8378         LDKChannelMonitorUpdate updates_conv;
8379         updates_conv.inner = (void*)(updates & (~1));
8380         updates_conv.is_owned = false;
8381         LDKBroadcasterInterface* broadcaster_conv = (LDKBroadcasterInterface*)broadcaster;
8382         LDKFeeEstimator* fee_estimator_conv = (LDKFeeEstimator*)fee_estimator;
8383         LDKLogger* logger_conv = (LDKLogger*)logger;
8384         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
8385         *ret_conv = ChannelMonitor_update_monitor(&this_arg_conv, &updates_conv, broadcaster_conv, fee_estimator_conv, logger_conv);
8386         return (long)ret_conv;
8387 }
8388
8389 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1update_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
8390         LDKChannelMonitor this_arg_conv;
8391         this_arg_conv.inner = (void*)(this_arg & (~1));
8392         this_arg_conv.is_owned = false;
8393         jlong ret_val = ChannelMonitor_get_latest_update_id(&this_arg_conv);
8394         return ret_val;
8395 }
8396
8397 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1funding_1txo(JNIEnv * _env, jclass _b, jlong this_arg) {
8398         LDKChannelMonitor this_arg_conv;
8399         this_arg_conv.inner = (void*)(this_arg & (~1));
8400         this_arg_conv.is_owned = false;
8401         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
8402         *ret_ref = ChannelMonitor_get_funding_txo(&this_arg_conv);
8403         ret_ref->a = OutPoint_clone(&ret_ref->a);
8404         ret_ref->b = CVec_u8Z_clone(&ret_ref->b);
8405         return (long)ret_ref;
8406 }
8407
8408 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1monitor_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
8409         LDKChannelMonitor this_arg_conv;
8410         this_arg_conv.inner = (void*)(this_arg & (~1));
8411         this_arg_conv.is_owned = false;
8412         LDKCVec_MonitorEventZ ret_var = ChannelMonitor_get_and_clear_pending_monitor_events(&this_arg_conv);
8413         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
8414         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
8415         for (size_t o = 0; o < ret_var.datalen; o++) {
8416                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
8417                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8418                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8419                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
8420                 if (arr_conv_14_var.is_owned) {
8421                         arr_conv_14_ref |= 1;
8422                 }
8423                 ret_arr_ptr[o] = arr_conv_14_ref;
8424         }
8425         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
8426         FREE(ret_var.data);
8427         return ret_arr;
8428 }
8429
8430 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
8431         LDKChannelMonitor this_arg_conv;
8432         this_arg_conv.inner = (void*)(this_arg & (~1));
8433         this_arg_conv.is_owned = false;
8434         LDKCVec_EventZ ret_var = ChannelMonitor_get_and_clear_pending_events(&this_arg_conv);
8435         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
8436         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
8437         for (size_t h = 0; h < ret_var.datalen; h++) {
8438                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
8439                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
8440                 long arr_conv_7_ref = (long)arr_conv_7_copy;
8441                 ret_arr_ptr[h] = arr_conv_7_ref;
8442         }
8443         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
8444         FREE(ret_var.data);
8445         return ret_arr;
8446 }
8447
8448 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1holder_1commitment_1txn(JNIEnv * _env, jclass _b, jlong this_arg, jlong logger) {
8449         LDKChannelMonitor this_arg_conv;
8450         this_arg_conv.inner = (void*)(this_arg & (~1));
8451         this_arg_conv.is_owned = false;
8452         LDKLogger* logger_conv = (LDKLogger*)logger;
8453         LDKCVec_TransactionZ ret_var = ChannelMonitor_get_latest_holder_commitment_txn(&this_arg_conv, logger_conv);
8454         jobjectArray ret_arr = (*_env)->NewObjectArray(_env, ret_var.datalen, arr_of_B_clz, NULL);
8455         for (size_t i = 0; i < ret_var.datalen; i++) {
8456                 LDKTransaction arr_conv_8_var = ret_var.data[i];
8457                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, arr_conv_8_var.datalen);
8458                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, arr_conv_8_var.datalen, arr_conv_8_var.data);
8459                 Transaction_free(arr_conv_8_var);
8460                 (*_env)->SetObjectArrayElement(_env, ret_arr, i, arr_conv_8_arr);
8461         }
8462         FREE(ret_var.data);
8463         return ret_arr;
8464 }
8465
8466 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) {
8467         LDKChannelMonitor this_arg_conv;
8468         this_arg_conv.inner = (void*)(this_arg & (~1));
8469         this_arg_conv.is_owned = false;
8470         unsigned char header_arr[80];
8471         CHECK((*_env)->GetArrayLength (_env, header) == 80);
8472         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
8473         unsigned char (*header_ref)[80] = &header_arr;
8474         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
8475         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
8476         if (txdata_constr.datalen > 0)
8477                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
8478         else
8479                 txdata_constr.data = NULL;
8480         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
8481         for (size_t y = 0; y < txdata_constr.datalen; y++) {
8482                 long arr_conv_24 = txdata_vals[y];
8483                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
8484                 FREE((void*)arr_conv_24);
8485                 txdata_constr.data[y] = arr_conv_24_conv;
8486         }
8487         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
8488         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
8489         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
8490                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8491                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
8492         }
8493         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
8494         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
8495                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8496                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
8497         }
8498         LDKLogger logger_conv = *(LDKLogger*)logger;
8499         if (logger_conv.free == LDKLogger_JCalls_free) {
8500                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8501                 LDKLogger_JCalls_clone(logger_conv.this_arg);
8502         }
8503         LDKCVec_C2Tuple_TxidCVec_C2Tuple_u32TxOutZZZZ ret_var = ChannelMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height, broadcaster_conv, fee_estimator_conv, logger_conv);
8504         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
8505         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
8506         for (size_t u = 0; u < ret_var.datalen; u++) {
8507                 LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ* arr_conv_46_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ), "LDKC2Tuple_TxidCVec_C2Tuple_u32TxOutZZZ");
8508                 *arr_conv_46_ref = ret_var.data[u];
8509                 arr_conv_46_ref->a = ThirtyTwoBytes_clone(&arr_conv_46_ref->a);
8510                 // XXX: We likely need to clone here, but no _clone fn is available for TwoTuple<Integer, TxOut>[]
8511                 ret_arr_ptr[u] = (long)arr_conv_46_ref;
8512         }
8513         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
8514         FREE(ret_var.data);
8515         return ret_arr;
8516 }
8517
8518 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) {
8519         LDKChannelMonitor this_arg_conv;
8520         this_arg_conv.inner = (void*)(this_arg & (~1));
8521         this_arg_conv.is_owned = false;
8522         unsigned char header_arr[80];
8523         CHECK((*_env)->GetArrayLength (_env, header) == 80);
8524         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
8525         unsigned char (*header_ref)[80] = &header_arr;
8526         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
8527         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
8528                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8529                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
8530         }
8531         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
8532         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
8533                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8534                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
8535         }
8536         LDKLogger logger_conv = *(LDKLogger*)logger;
8537         if (logger_conv.free == LDKLogger_JCalls_free) {
8538                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
8539                 LDKLogger_JCalls_clone(logger_conv.this_arg);
8540         }
8541         ChannelMonitor_block_disconnected(&this_arg_conv, header_ref, height, broadcaster_conv, fee_estimator_conv, logger_conv);
8542 }
8543
8544 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Persist_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8545         LDKPersist this_ptr_conv = *(LDKPersist*)this_ptr;
8546         FREE((void*)this_ptr);
8547         Persist_free(this_ptr_conv);
8548 }
8549
8550 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelMonitorZ_1read(JNIEnv * _env, jclass _b, jbyteArray ser, jlong arg) {
8551         LDKu8slice ser_ref;
8552         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
8553         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
8554         LDKKeysInterface* arg_conv = (LDKKeysInterface*)arg;
8555         LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ");
8556         *ret_conv = C2Tuple_BlockHashChannelMonitorZ_read(ser_ref, arg_conv);
8557         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
8558         return (long)ret_conv;
8559 }
8560
8561 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8562         LDKOutPoint this_ptr_conv;
8563         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8564         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8565         OutPoint_free(this_ptr_conv);
8566 }
8567
8568 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8569         LDKOutPoint orig_conv;
8570         orig_conv.inner = (void*)(orig & (~1));
8571         orig_conv.is_owned = false;
8572         LDKOutPoint ret_var = OutPoint_clone(&orig_conv);
8573         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8574         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8575         long ret_ref = (long)ret_var.inner;
8576         if (ret_var.is_owned) {
8577                 ret_ref |= 1;
8578         }
8579         return ret_ref;
8580 }
8581
8582 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1txid(JNIEnv * _env, jclass _b, jlong this_ptr) {
8583         LDKOutPoint this_ptr_conv;
8584         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8585         this_ptr_conv.is_owned = false;
8586         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8587         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OutPoint_get_txid(&this_ptr_conv));
8588         return ret_arr;
8589 }
8590
8591 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1txid(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8592         LDKOutPoint this_ptr_conv;
8593         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8594         this_ptr_conv.is_owned = false;
8595         LDKThirtyTwoBytes val_ref;
8596         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8597         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8598         OutPoint_set_txid(&this_ptr_conv, val_ref);
8599 }
8600
8601 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1index(JNIEnv * _env, jclass _b, jlong this_ptr) {
8602         LDKOutPoint this_ptr_conv;
8603         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8604         this_ptr_conv.is_owned = false;
8605         jshort ret_val = OutPoint_get_index(&this_ptr_conv);
8606         return ret_val;
8607 }
8608
8609 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1index(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8610         LDKOutPoint this_ptr_conv;
8611         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8612         this_ptr_conv.is_owned = false;
8613         OutPoint_set_index(&this_ptr_conv, val);
8614 }
8615
8616 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1new(JNIEnv * _env, jclass _b, jbyteArray txid_arg, jshort index_arg) {
8617         LDKThirtyTwoBytes txid_arg_ref;
8618         CHECK((*_env)->GetArrayLength (_env, txid_arg) == 32);
8619         (*_env)->GetByteArrayRegion (_env, txid_arg, 0, 32, txid_arg_ref.data);
8620         LDKOutPoint ret_var = OutPoint_new(txid_arg_ref, index_arg);
8621         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8622         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8623         long ret_ref = (long)ret_var.inner;
8624         if (ret_var.is_owned) {
8625                 ret_ref |= 1;
8626         }
8627         return ret_ref;
8628 }
8629
8630 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1to_1channel_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
8631         LDKOutPoint this_arg_conv;
8632         this_arg_conv.inner = (void*)(this_arg & (~1));
8633         this_arg_conv.is_owned = false;
8634         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
8635         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, OutPoint_to_channel_id(&this_arg_conv).data);
8636         return arg_arr;
8637 }
8638
8639 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1write(JNIEnv * _env, jclass _b, jlong obj) {
8640         LDKOutPoint obj_conv;
8641         obj_conv.inner = (void*)(obj & (~1));
8642         obj_conv.is_owned = false;
8643         LDKCVec_u8Z arg_var = OutPoint_write(&obj_conv);
8644         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8645         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8646         CVec_u8Z_free(arg_var);
8647         return arg_arr;
8648 }
8649
8650 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
8651         LDKu8slice ser_ref;
8652         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
8653         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
8654         LDKOutPoint ret_var = OutPoint_read(ser_ref);
8655         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8656         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8657         long ret_ref = (long)ret_var.inner;
8658         if (ret_var.is_owned) {
8659                 ret_ref |= 1;
8660         }
8661         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
8662         return ret_ref;
8663 }
8664
8665 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8666         LDKSpendableOutputDescriptor this_ptr_conv = *(LDKSpendableOutputDescriptor*)this_ptr;
8667         FREE((void*)this_ptr);
8668         SpendableOutputDescriptor_free(this_ptr_conv);
8669 }
8670
8671 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8672         LDKSpendableOutputDescriptor* orig_conv = (LDKSpendableOutputDescriptor*)orig;
8673         LDKSpendableOutputDescriptor *ret_copy = MALLOC(sizeof(LDKSpendableOutputDescriptor), "LDKSpendableOutputDescriptor");
8674         *ret_copy = SpendableOutputDescriptor_clone(orig_conv);
8675         long ret_ref = (long)ret_copy;
8676         return ret_ref;
8677 }
8678
8679 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1write(JNIEnv * _env, jclass _b, jlong obj) {
8680         LDKSpendableOutputDescriptor* obj_conv = (LDKSpendableOutputDescriptor*)obj;
8681         LDKCVec_u8Z arg_var = SpendableOutputDescriptor_write(obj_conv);
8682         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8683         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8684         CVec_u8Z_free(arg_var);
8685         return arg_arr;
8686 }
8687
8688 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
8689         LDKu8slice ser_ref;
8690         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
8691         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
8692         LDKCResult_SpendableOutputDescriptorDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SpendableOutputDescriptorDecodeErrorZ), "LDKCResult_SpendableOutputDescriptorDecodeErrorZ");
8693         *ret_conv = SpendableOutputDescriptor_read(ser_ref);
8694         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
8695         return (long)ret_conv;
8696 }
8697
8698 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8699         LDKChannelKeys* orig_conv = (LDKChannelKeys*)orig;
8700         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
8701         *ret = ChannelKeys_clone(orig_conv);
8702         return (long)ret;
8703 }
8704
8705 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8706         LDKChannelKeys this_ptr_conv = *(LDKChannelKeys*)this_ptr;
8707         FREE((void*)this_ptr);
8708         ChannelKeys_free(this_ptr_conv);
8709 }
8710
8711 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysInterface_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8712         LDKKeysInterface this_ptr_conv = *(LDKKeysInterface*)this_ptr;
8713         FREE((void*)this_ptr);
8714         KeysInterface_free(this_ptr_conv);
8715 }
8716
8717 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8718         LDKInMemoryChannelKeys this_ptr_conv;
8719         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8720         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8721         InMemoryChannelKeys_free(this_ptr_conv);
8722 }
8723
8724 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8725         LDKInMemoryChannelKeys orig_conv;
8726         orig_conv.inner = (void*)(orig & (~1));
8727         orig_conv.is_owned = false;
8728         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_clone(&orig_conv);
8729         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8730         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8731         long ret_ref = (long)ret_var.inner;
8732         if (ret_var.is_owned) {
8733                 ret_ref |= 1;
8734         }
8735         return ret_ref;
8736 }
8737
8738 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1funding_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
8739         LDKInMemoryChannelKeys this_ptr_conv;
8740         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8741         this_ptr_conv.is_owned = false;
8742         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8743         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_funding_key(&this_ptr_conv));
8744         return ret_arr;
8745 }
8746
8747 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1funding_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8748         LDKInMemoryChannelKeys this_ptr_conv;
8749         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8750         this_ptr_conv.is_owned = false;
8751         LDKSecretKey val_ref;
8752         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8753         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
8754         InMemoryChannelKeys_set_funding_key(&this_ptr_conv, val_ref);
8755 }
8756
8757 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1revocation_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
8758         LDKInMemoryChannelKeys this_ptr_conv;
8759         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8760         this_ptr_conv.is_owned = false;
8761         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8762         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_revocation_base_key(&this_ptr_conv));
8763         return ret_arr;
8764 }
8765
8766 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1revocation_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8767         LDKInMemoryChannelKeys this_ptr_conv;
8768         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8769         this_ptr_conv.is_owned = false;
8770         LDKSecretKey val_ref;
8771         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8772         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
8773         InMemoryChannelKeys_set_revocation_base_key(&this_ptr_conv, val_ref);
8774 }
8775
8776 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
8777         LDKInMemoryChannelKeys this_ptr_conv;
8778         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8779         this_ptr_conv.is_owned = false;
8780         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8781         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_payment_key(&this_ptr_conv));
8782         return ret_arr;
8783 }
8784
8785 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8786         LDKInMemoryChannelKeys this_ptr_conv;
8787         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8788         this_ptr_conv.is_owned = false;
8789         LDKSecretKey val_ref;
8790         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8791         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
8792         InMemoryChannelKeys_set_payment_key(&this_ptr_conv, val_ref);
8793 }
8794
8795 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1delayed_1payment_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
8796         LDKInMemoryChannelKeys this_ptr_conv;
8797         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8798         this_ptr_conv.is_owned = false;
8799         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8800         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_delayed_payment_base_key(&this_ptr_conv));
8801         return ret_arr;
8802 }
8803
8804 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1delayed_1payment_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8805         LDKInMemoryChannelKeys this_ptr_conv;
8806         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8807         this_ptr_conv.is_owned = false;
8808         LDKSecretKey val_ref;
8809         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8810         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
8811         InMemoryChannelKeys_set_delayed_payment_base_key(&this_ptr_conv, val_ref);
8812 }
8813
8814 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1htlc_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
8815         LDKInMemoryChannelKeys this_ptr_conv;
8816         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8817         this_ptr_conv.is_owned = false;
8818         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8819         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_htlc_base_key(&this_ptr_conv));
8820         return ret_arr;
8821 }
8822
8823 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1htlc_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8824         LDKInMemoryChannelKeys this_ptr_conv;
8825         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8826         this_ptr_conv.is_owned = false;
8827         LDKSecretKey val_ref;
8828         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8829         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
8830         InMemoryChannelKeys_set_htlc_base_key(&this_ptr_conv, val_ref);
8831 }
8832
8833 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1commitment_1seed(JNIEnv * _env, jclass _b, jlong this_ptr) {
8834         LDKInMemoryChannelKeys this_ptr_conv;
8835         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8836         this_ptr_conv.is_owned = false;
8837         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8838         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_commitment_seed(&this_ptr_conv));
8839         return ret_arr;
8840 }
8841
8842 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1commitment_1seed(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8843         LDKInMemoryChannelKeys this_ptr_conv;
8844         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8845         this_ptr_conv.is_owned = false;
8846         LDKThirtyTwoBytes val_ref;
8847         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8848         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8849         InMemoryChannelKeys_set_commitment_seed(&this_ptr_conv, val_ref);
8850 }
8851
8852 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) {
8853         LDKSecretKey funding_key_ref;
8854         CHECK((*_env)->GetArrayLength (_env, funding_key) == 32);
8855         (*_env)->GetByteArrayRegion (_env, funding_key, 0, 32, funding_key_ref.bytes);
8856         LDKSecretKey revocation_base_key_ref;
8857         CHECK((*_env)->GetArrayLength (_env, revocation_base_key) == 32);
8858         (*_env)->GetByteArrayRegion (_env, revocation_base_key, 0, 32, revocation_base_key_ref.bytes);
8859         LDKSecretKey payment_key_ref;
8860         CHECK((*_env)->GetArrayLength (_env, payment_key) == 32);
8861         (*_env)->GetByteArrayRegion (_env, payment_key, 0, 32, payment_key_ref.bytes);
8862         LDKSecretKey delayed_payment_base_key_ref;
8863         CHECK((*_env)->GetArrayLength (_env, delayed_payment_base_key) == 32);
8864         (*_env)->GetByteArrayRegion (_env, delayed_payment_base_key, 0, 32, delayed_payment_base_key_ref.bytes);
8865         LDKSecretKey htlc_base_key_ref;
8866         CHECK((*_env)->GetArrayLength (_env, htlc_base_key) == 32);
8867         (*_env)->GetByteArrayRegion (_env, htlc_base_key, 0, 32, htlc_base_key_ref.bytes);
8868         LDKThirtyTwoBytes commitment_seed_ref;
8869         CHECK((*_env)->GetArrayLength (_env, commitment_seed) == 32);
8870         (*_env)->GetByteArrayRegion (_env, commitment_seed, 0, 32, commitment_seed_ref.data);
8871         LDKC2Tuple_u64u64Z key_derivation_params_conv = *(LDKC2Tuple_u64u64Z*)key_derivation_params;
8872         FREE((void*)key_derivation_params);
8873         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);
8874         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8875         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8876         long ret_ref = (long)ret_var.inner;
8877         if (ret_var.is_owned) {
8878                 ret_ref |= 1;
8879         }
8880         return ret_ref;
8881 }
8882
8883 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
8884         LDKInMemoryChannelKeys this_arg_conv;
8885         this_arg_conv.inner = (void*)(this_arg & (~1));
8886         this_arg_conv.is_owned = false;
8887         LDKChannelPublicKeys ret_var = InMemoryChannelKeys_counterparty_pubkeys(&this_arg_conv);
8888         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8889         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8890         long ret_ref = (long)ret_var.inner;
8891         if (ret_var.is_owned) {
8892                 ret_ref |= 1;
8893         }
8894         return ret_ref;
8895 }
8896
8897 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_arg) {
8898         LDKInMemoryChannelKeys this_arg_conv;
8899         this_arg_conv.inner = (void*)(this_arg & (~1));
8900         this_arg_conv.is_owned = false;
8901         jshort ret_val = InMemoryChannelKeys_counterparty_selected_contest_delay(&this_arg_conv);
8902         return ret_val;
8903 }
8904
8905 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1holder_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_arg) {
8906         LDKInMemoryChannelKeys this_arg_conv;
8907         this_arg_conv.inner = (void*)(this_arg & (~1));
8908         this_arg_conv.is_owned = false;
8909         jshort ret_val = InMemoryChannelKeys_holder_selected_contest_delay(&this_arg_conv);
8910         return ret_val;
8911 }
8912
8913 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1is_1outbound(JNIEnv * _env, jclass _b, jlong this_arg) {
8914         LDKInMemoryChannelKeys this_arg_conv;
8915         this_arg_conv.inner = (void*)(this_arg & (~1));
8916         this_arg_conv.is_owned = false;
8917         jboolean ret_val = InMemoryChannelKeys_is_outbound(&this_arg_conv);
8918         return ret_val;
8919 }
8920
8921 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1funding_1outpoint(JNIEnv * _env, jclass _b, jlong this_arg) {
8922         LDKInMemoryChannelKeys this_arg_conv;
8923         this_arg_conv.inner = (void*)(this_arg & (~1));
8924         this_arg_conv.is_owned = false;
8925         LDKOutPoint ret_var = InMemoryChannelKeys_funding_outpoint(&this_arg_conv);
8926         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8927         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8928         long ret_ref = (long)ret_var.inner;
8929         if (ret_var.is_owned) {
8930                 ret_ref |= 1;
8931         }
8932         return ret_ref;
8933 }
8934
8935 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1channel_1parameters(JNIEnv * _env, jclass _b, jlong this_arg) {
8936         LDKInMemoryChannelKeys this_arg_conv;
8937         this_arg_conv.inner = (void*)(this_arg & (~1));
8938         this_arg_conv.is_owned = false;
8939         LDKChannelTransactionParameters ret_var = InMemoryChannelKeys_get_channel_parameters(&this_arg_conv);
8940         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8941         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8942         long ret_ref = (long)ret_var.inner;
8943         if (ret_var.is_owned) {
8944                 ret_ref |= 1;
8945         }
8946         return ret_ref;
8947 }
8948
8949 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1as_1ChannelKeys(JNIEnv * _env, jclass _b, jlong this_arg) {
8950         LDKInMemoryChannelKeys this_arg_conv;
8951         this_arg_conv.inner = (void*)(this_arg & (~1));
8952         this_arg_conv.is_owned = false;
8953         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
8954         *ret = InMemoryChannelKeys_as_ChannelKeys(&this_arg_conv);
8955         return (long)ret;
8956 }
8957
8958 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
8959         LDKInMemoryChannelKeys obj_conv;
8960         obj_conv.inner = (void*)(obj & (~1));
8961         obj_conv.is_owned = false;
8962         LDKCVec_u8Z arg_var = InMemoryChannelKeys_write(&obj_conv);
8963         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8964         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8965         CVec_u8Z_free(arg_var);
8966         return arg_arr;
8967 }
8968
8969 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
8970         LDKu8slice ser_ref;
8971         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
8972         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
8973         LDKCResult_InMemoryChannelKeysDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InMemoryChannelKeysDecodeErrorZ), "LDKCResult_InMemoryChannelKeysDecodeErrorZ");
8974         *ret_conv = InMemoryChannelKeys_read(ser_ref);
8975         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
8976         return (long)ret_conv;
8977 }
8978
8979 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8980         LDKKeysManager this_ptr_conv;
8981         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8982         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8983         KeysManager_free(this_ptr_conv);
8984 }
8985
8986 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) {
8987         unsigned char seed_arr[32];
8988         CHECK((*_env)->GetArrayLength (_env, seed) == 32);
8989         (*_env)->GetByteArrayRegion (_env, seed, 0, 32, seed_arr);
8990         unsigned char (*seed_ref)[32] = &seed_arr;
8991         LDKNetwork network_conv = LDKNetwork_from_java(_env, network);
8992         LDKKeysManager ret_var = KeysManager_new(seed_ref, network_conv, starting_time_secs, starting_time_nanos);
8993         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8994         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8995         long ret_ref = (long)ret_var.inner;
8996         if (ret_var.is_owned) {
8997                 ret_ref |= 1;
8998         }
8999         return ret_ref;
9000 }
9001
9002 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) {
9003         LDKKeysManager this_arg_conv;
9004         this_arg_conv.inner = (void*)(this_arg & (~1));
9005         this_arg_conv.is_owned = false;
9006         LDKInMemoryChannelKeys ret_var = KeysManager_derive_channel_keys(&this_arg_conv, channel_value_satoshis, params_1, params_2);
9007         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9008         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9009         long ret_ref = (long)ret_var.inner;
9010         if (ret_var.is_owned) {
9011                 ret_ref |= 1;
9012         }
9013         return ret_ref;
9014 }
9015
9016 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_KeysManager_1as_1KeysInterface(JNIEnv * _env, jclass _b, jlong this_arg) {
9017         LDKKeysManager this_arg_conv;
9018         this_arg_conv.inner = (void*)(this_arg & (~1));
9019         this_arg_conv.is_owned = false;
9020         LDKKeysInterface* ret = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
9021         *ret = KeysManager_as_KeysInterface(&this_arg_conv);
9022         return (long)ret;
9023 }
9024
9025 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9026         LDKChannelManager this_ptr_conv;
9027         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9028         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9029         ChannelManager_free(this_ptr_conv);
9030 }
9031
9032 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9033         LDKChannelDetails this_ptr_conv;
9034         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9035         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9036         ChannelDetails_free(this_ptr_conv);
9037 }
9038
9039 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9040         LDKChannelDetails orig_conv;
9041         orig_conv.inner = (void*)(orig & (~1));
9042         orig_conv.is_owned = false;
9043         LDKChannelDetails ret_var = ChannelDetails_clone(&orig_conv);
9044         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9045         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9046         long ret_ref = (long)ret_var.inner;
9047         if (ret_var.is_owned) {
9048                 ret_ref |= 1;
9049         }
9050         return ret_ref;
9051 }
9052
9053 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9054         LDKChannelDetails this_ptr_conv;
9055         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9056         this_ptr_conv.is_owned = false;
9057         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9058         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ChannelDetails_get_channel_id(&this_ptr_conv));
9059         return ret_arr;
9060 }
9061
9062 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9063         LDKChannelDetails this_ptr_conv;
9064         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9065         this_ptr_conv.is_owned = false;
9066         LDKThirtyTwoBytes val_ref;
9067         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9068         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9069         ChannelDetails_set_channel_id(&this_ptr_conv, val_ref);
9070 }
9071
9072 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1remote_1network_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9073         LDKChannelDetails this_ptr_conv;
9074         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9075         this_ptr_conv.is_owned = false;
9076         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9077         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelDetails_get_remote_network_id(&this_ptr_conv).compressed_form);
9078         return arg_arr;
9079 }
9080
9081 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1remote_1network_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9082         LDKChannelDetails this_ptr_conv;
9083         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9084         this_ptr_conv.is_owned = false;
9085         LDKPublicKey val_ref;
9086         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9087         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9088         ChannelDetails_set_remote_network_id(&this_ptr_conv, val_ref);
9089 }
9090
9091 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1counterparty_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
9092         LDKChannelDetails this_ptr_conv;
9093         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9094         this_ptr_conv.is_owned = false;
9095         LDKInitFeatures ret_var = ChannelDetails_get_counterparty_features(&this_ptr_conv);
9096         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9097         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9098         long ret_ref = (long)ret_var.inner;
9099         if (ret_var.is_owned) {
9100                 ret_ref |= 1;
9101         }
9102         return ret_ref;
9103 }
9104
9105 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1counterparty_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9106         LDKChannelDetails this_ptr_conv;
9107         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9108         this_ptr_conv.is_owned = false;
9109         LDKInitFeatures val_conv;
9110         val_conv.inner = (void*)(val & (~1));
9111         val_conv.is_owned = (val & 1) || (val == 0);
9112         // Warning: we may need a move here but can't clone!
9113         ChannelDetails_set_counterparty_features(&this_ptr_conv, val_conv);
9114 }
9115
9116 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1value_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
9117         LDKChannelDetails this_ptr_conv;
9118         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9119         this_ptr_conv.is_owned = false;
9120         jlong ret_val = ChannelDetails_get_channel_value_satoshis(&this_ptr_conv);
9121         return ret_val;
9122 }
9123
9124 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1value_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9125         LDKChannelDetails this_ptr_conv;
9126         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9127         this_ptr_conv.is_owned = false;
9128         ChannelDetails_set_channel_value_satoshis(&this_ptr_conv, val);
9129 }
9130
9131 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1user_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9132         LDKChannelDetails this_ptr_conv;
9133         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9134         this_ptr_conv.is_owned = false;
9135         jlong ret_val = ChannelDetails_get_user_id(&this_ptr_conv);
9136         return ret_val;
9137 }
9138
9139 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1user_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9140         LDKChannelDetails this_ptr_conv;
9141         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9142         this_ptr_conv.is_owned = false;
9143         ChannelDetails_set_user_id(&this_ptr_conv, val);
9144 }
9145
9146 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1outbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
9147         LDKChannelDetails this_ptr_conv;
9148         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9149         this_ptr_conv.is_owned = false;
9150         jlong ret_val = ChannelDetails_get_outbound_capacity_msat(&this_ptr_conv);
9151         return ret_val;
9152 }
9153
9154 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1outbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9155         LDKChannelDetails this_ptr_conv;
9156         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9157         this_ptr_conv.is_owned = false;
9158         ChannelDetails_set_outbound_capacity_msat(&this_ptr_conv, val);
9159 }
9160
9161 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1inbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
9162         LDKChannelDetails this_ptr_conv;
9163         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9164         this_ptr_conv.is_owned = false;
9165         jlong ret_val = ChannelDetails_get_inbound_capacity_msat(&this_ptr_conv);
9166         return ret_val;
9167 }
9168
9169 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1inbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9170         LDKChannelDetails this_ptr_conv;
9171         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9172         this_ptr_conv.is_owned = false;
9173         ChannelDetails_set_inbound_capacity_msat(&this_ptr_conv, val);
9174 }
9175
9176 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1is_1live(JNIEnv * _env, jclass _b, jlong this_ptr) {
9177         LDKChannelDetails this_ptr_conv;
9178         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9179         this_ptr_conv.is_owned = false;
9180         jboolean ret_val = ChannelDetails_get_is_live(&this_ptr_conv);
9181         return ret_val;
9182 }
9183
9184 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1is_1live(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
9185         LDKChannelDetails this_ptr_conv;
9186         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9187         this_ptr_conv.is_owned = false;
9188         ChannelDetails_set_is_live(&this_ptr_conv, val);
9189 }
9190
9191 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PaymentSendFailure_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9192         LDKPaymentSendFailure this_ptr_conv;
9193         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9194         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9195         PaymentSendFailure_free(this_ptr_conv);
9196 }
9197
9198 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) {
9199         LDKNetwork network_conv = LDKNetwork_from_java(_env, network);
9200         LDKFeeEstimator fee_est_conv = *(LDKFeeEstimator*)fee_est;
9201         if (fee_est_conv.free == LDKFeeEstimator_JCalls_free) {
9202                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9203                 LDKFeeEstimator_JCalls_clone(fee_est_conv.this_arg);
9204         }
9205         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
9206         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
9207                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9208                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
9209         }
9210         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
9211         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
9212                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9213                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
9214         }
9215         LDKLogger logger_conv = *(LDKLogger*)logger;
9216         if (logger_conv.free == LDKLogger_JCalls_free) {
9217                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9218                 LDKLogger_JCalls_clone(logger_conv.this_arg);
9219         }
9220         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
9221         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
9222                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9223                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
9224         }
9225         LDKUserConfig config_conv;
9226         config_conv.inner = (void*)(config & (~1));
9227         config_conv.is_owned = (config & 1) || (config == 0);
9228         if (config_conv.inner != NULL)
9229                 config_conv = UserConfig_clone(&config_conv);
9230         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);
9231         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9232         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9233         long ret_ref = (long)ret_var.inner;
9234         if (ret_var.is_owned) {
9235                 ret_ref |= 1;
9236         }
9237         return ret_ref;
9238 }
9239
9240 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) {
9241         LDKChannelManager this_arg_conv;
9242         this_arg_conv.inner = (void*)(this_arg & (~1));
9243         this_arg_conv.is_owned = false;
9244         LDKPublicKey their_network_key_ref;
9245         CHECK((*_env)->GetArrayLength (_env, their_network_key) == 33);
9246         (*_env)->GetByteArrayRegion (_env, their_network_key, 0, 33, their_network_key_ref.compressed_form);
9247         LDKUserConfig override_config_conv;
9248         override_config_conv.inner = (void*)(override_config & (~1));
9249         override_config_conv.is_owned = (override_config & 1) || (override_config == 0);
9250         if (override_config_conv.inner != NULL)
9251                 override_config_conv = UserConfig_clone(&override_config_conv);
9252         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
9253         *ret_conv = ChannelManager_create_channel(&this_arg_conv, their_network_key_ref, channel_value_satoshis, push_msat, user_id, override_config_conv);
9254         return (long)ret_conv;
9255 }
9256
9257 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
9258         LDKChannelManager this_arg_conv;
9259         this_arg_conv.inner = (void*)(this_arg & (~1));
9260         this_arg_conv.is_owned = false;
9261         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_channels(&this_arg_conv);
9262         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
9263         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
9264         for (size_t q = 0; q < ret_var.datalen; q++) {
9265                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
9266                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9267                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9268                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
9269                 if (arr_conv_16_var.is_owned) {
9270                         arr_conv_16_ref |= 1;
9271                 }
9272                 ret_arr_ptr[q] = arr_conv_16_ref;
9273         }
9274         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
9275         FREE(ret_var.data);
9276         return ret_arr;
9277 }
9278
9279 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1usable_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
9280         LDKChannelManager this_arg_conv;
9281         this_arg_conv.inner = (void*)(this_arg & (~1));
9282         this_arg_conv.is_owned = false;
9283         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_usable_channels(&this_arg_conv);
9284         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
9285         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
9286         for (size_t q = 0; q < ret_var.datalen; q++) {
9287                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
9288                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9289                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9290                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
9291                 if (arr_conv_16_var.is_owned) {
9292                         arr_conv_16_ref |= 1;
9293                 }
9294                 ret_arr_ptr[q] = arr_conv_16_ref;
9295         }
9296         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
9297         FREE(ret_var.data);
9298         return ret_arr;
9299 }
9300
9301 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1close_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray channel_id) {
9302         LDKChannelManager this_arg_conv;
9303         this_arg_conv.inner = (void*)(this_arg & (~1));
9304         this_arg_conv.is_owned = false;
9305         unsigned char channel_id_arr[32];
9306         CHECK((*_env)->GetArrayLength (_env, channel_id) == 32);
9307         (*_env)->GetByteArrayRegion (_env, channel_id, 0, 32, channel_id_arr);
9308         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
9309         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
9310         *ret_conv = ChannelManager_close_channel(&this_arg_conv, channel_id_ref);
9311         return (long)ret_conv;
9312 }
9313
9314 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray channel_id) {
9315         LDKChannelManager this_arg_conv;
9316         this_arg_conv.inner = (void*)(this_arg & (~1));
9317         this_arg_conv.is_owned = false;
9318         unsigned char channel_id_arr[32];
9319         CHECK((*_env)->GetArrayLength (_env, channel_id) == 32);
9320         (*_env)->GetByteArrayRegion (_env, channel_id, 0, 32, channel_id_arr);
9321         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
9322         ChannelManager_force_close_channel(&this_arg_conv, channel_id_ref);
9323 }
9324
9325 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1all_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
9326         LDKChannelManager this_arg_conv;
9327         this_arg_conv.inner = (void*)(this_arg & (~1));
9328         this_arg_conv.is_owned = false;
9329         ChannelManager_force_close_all_channels(&this_arg_conv);
9330 }
9331
9332 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) {
9333         LDKChannelManager this_arg_conv;
9334         this_arg_conv.inner = (void*)(this_arg & (~1));
9335         this_arg_conv.is_owned = false;
9336         LDKRoute route_conv;
9337         route_conv.inner = (void*)(route & (~1));
9338         route_conv.is_owned = false;
9339         LDKThirtyTwoBytes payment_hash_ref;
9340         CHECK((*_env)->GetArrayLength (_env, payment_hash) == 32);
9341         (*_env)->GetByteArrayRegion (_env, payment_hash, 0, 32, payment_hash_ref.data);
9342         LDKThirtyTwoBytes payment_secret_ref;
9343         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
9344         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
9345         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
9346         *ret_conv = ChannelManager_send_payment(&this_arg_conv, &route_conv, payment_hash_ref, payment_secret_ref);
9347         return (long)ret_conv;
9348 }
9349
9350 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) {
9351         LDKChannelManager this_arg_conv;
9352         this_arg_conv.inner = (void*)(this_arg & (~1));
9353         this_arg_conv.is_owned = false;
9354         unsigned char temporary_channel_id_arr[32];
9355         CHECK((*_env)->GetArrayLength (_env, temporary_channel_id) == 32);
9356         (*_env)->GetByteArrayRegion (_env, temporary_channel_id, 0, 32, temporary_channel_id_arr);
9357         unsigned char (*temporary_channel_id_ref)[32] = &temporary_channel_id_arr;
9358         LDKOutPoint funding_txo_conv;
9359         funding_txo_conv.inner = (void*)(funding_txo & (~1));
9360         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
9361         if (funding_txo_conv.inner != NULL)
9362                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
9363         ChannelManager_funding_transaction_generated(&this_arg_conv, temporary_channel_id_ref, funding_txo_conv);
9364 }
9365
9366 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) {
9367         LDKChannelManager this_arg_conv;
9368         this_arg_conv.inner = (void*)(this_arg & (~1));
9369         this_arg_conv.is_owned = false;
9370         LDKThreeBytes rgb_ref;
9371         CHECK((*_env)->GetArrayLength (_env, rgb) == 3);
9372         (*_env)->GetByteArrayRegion (_env, rgb, 0, 3, rgb_ref.data);
9373         LDKThirtyTwoBytes alias_ref;
9374         CHECK((*_env)->GetArrayLength (_env, alias) == 32);
9375         (*_env)->GetByteArrayRegion (_env, alias, 0, 32, alias_ref.data);
9376         LDKCVec_NetAddressZ addresses_constr;
9377         addresses_constr.datalen = (*_env)->GetArrayLength (_env, addresses);
9378         if (addresses_constr.datalen > 0)
9379                 addresses_constr.data = MALLOC(addresses_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
9380         else
9381                 addresses_constr.data = NULL;
9382         long* addresses_vals = (*_env)->GetLongArrayElements (_env, addresses, NULL);
9383         for (size_t m = 0; m < addresses_constr.datalen; m++) {
9384                 long arr_conv_12 = addresses_vals[m];
9385                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
9386                 FREE((void*)arr_conv_12);
9387                 addresses_constr.data[m] = arr_conv_12_conv;
9388         }
9389         (*_env)->ReleaseLongArrayElements (_env, addresses, addresses_vals, 0);
9390         ChannelManager_broadcast_node_announcement(&this_arg_conv, rgb_ref, alias_ref, addresses_constr);
9391 }
9392
9393 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1process_1pending_1htlc_1forwards(JNIEnv * _env, jclass _b, jlong this_arg) {
9394         LDKChannelManager this_arg_conv;
9395         this_arg_conv.inner = (void*)(this_arg & (~1));
9396         this_arg_conv.is_owned = false;
9397         ChannelManager_process_pending_htlc_forwards(&this_arg_conv);
9398 }
9399
9400 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1timer_1chan_1freshness_1every_1min(JNIEnv * _env, jclass _b, jlong this_arg) {
9401         LDKChannelManager this_arg_conv;
9402         this_arg_conv.inner = (void*)(this_arg & (~1));
9403         this_arg_conv.is_owned = false;
9404         ChannelManager_timer_chan_freshness_every_min(&this_arg_conv);
9405 }
9406
9407 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) {
9408         LDKChannelManager this_arg_conv;
9409         this_arg_conv.inner = (void*)(this_arg & (~1));
9410         this_arg_conv.is_owned = false;
9411         unsigned char payment_hash_arr[32];
9412         CHECK((*_env)->GetArrayLength (_env, payment_hash) == 32);
9413         (*_env)->GetByteArrayRegion (_env, payment_hash, 0, 32, payment_hash_arr);
9414         unsigned char (*payment_hash_ref)[32] = &payment_hash_arr;
9415         LDKThirtyTwoBytes payment_secret_ref;
9416         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
9417         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
9418         jboolean ret_val = ChannelManager_fail_htlc_backwards(&this_arg_conv, payment_hash_ref, payment_secret_ref);
9419         return ret_val;
9420 }
9421
9422 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) {
9423         LDKChannelManager this_arg_conv;
9424         this_arg_conv.inner = (void*)(this_arg & (~1));
9425         this_arg_conv.is_owned = false;
9426         LDKThirtyTwoBytes payment_preimage_ref;
9427         CHECK((*_env)->GetArrayLength (_env, payment_preimage) == 32);
9428         (*_env)->GetByteArrayRegion (_env, payment_preimage, 0, 32, payment_preimage_ref.data);
9429         LDKThirtyTwoBytes payment_secret_ref;
9430         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
9431         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
9432         jboolean ret_val = ChannelManager_claim_funds(&this_arg_conv, payment_preimage_ref, payment_secret_ref, expected_amount);
9433         return ret_val;
9434 }
9435
9436 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1get_1our_1node_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
9437         LDKChannelManager this_arg_conv;
9438         this_arg_conv.inner = (void*)(this_arg & (~1));
9439         this_arg_conv.is_owned = false;
9440         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9441         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelManager_get_our_node_id(&this_arg_conv).compressed_form);
9442         return arg_arr;
9443 }
9444
9445 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) {
9446         LDKChannelManager this_arg_conv;
9447         this_arg_conv.inner = (void*)(this_arg & (~1));
9448         this_arg_conv.is_owned = false;
9449         LDKOutPoint funding_txo_conv;
9450         funding_txo_conv.inner = (void*)(funding_txo & (~1));
9451         funding_txo_conv.is_owned = false;
9452         ChannelManager_channel_monitor_updated(&this_arg_conv, &funding_txo_conv, highest_applied_update_id);
9453 }
9454
9455 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1MessageSendEventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
9456         LDKChannelManager this_arg_conv;
9457         this_arg_conv.inner = (void*)(this_arg & (~1));
9458         this_arg_conv.is_owned = false;
9459         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
9460         *ret = ChannelManager_as_MessageSendEventsProvider(&this_arg_conv);
9461         return (long)ret;
9462 }
9463
9464 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1EventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
9465         LDKChannelManager this_arg_conv;
9466         this_arg_conv.inner = (void*)(this_arg & (~1));
9467         this_arg_conv.is_owned = false;
9468         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
9469         *ret = ChannelManager_as_EventsProvider(&this_arg_conv);
9470         return (long)ret;
9471 }
9472
9473 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jlongArray txdata, jint height) {
9474         LDKChannelManager this_arg_conv;
9475         this_arg_conv.inner = (void*)(this_arg & (~1));
9476         this_arg_conv.is_owned = false;
9477         unsigned char header_arr[80];
9478         CHECK((*_env)->GetArrayLength (_env, header) == 80);
9479         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
9480         unsigned char (*header_ref)[80] = &header_arr;
9481         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
9482         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
9483         if (txdata_constr.datalen > 0)
9484                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
9485         else
9486                 txdata_constr.data = NULL;
9487         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
9488         for (size_t y = 0; y < txdata_constr.datalen; y++) {
9489                 long arr_conv_24 = txdata_vals[y];
9490                 LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24;
9491                 FREE((void*)arr_conv_24);
9492                 txdata_constr.data[y] = arr_conv_24_conv;
9493         }
9494         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
9495         ChannelManager_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
9496 }
9497
9498 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header) {
9499         LDKChannelManager this_arg_conv;
9500         this_arg_conv.inner = (void*)(this_arg & (~1));
9501         this_arg_conv.is_owned = false;
9502         unsigned char header_arr[80];
9503         CHECK((*_env)->GetArrayLength (_env, header) == 80);
9504         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
9505         unsigned char (*header_ref)[80] = &header_arr;
9506         ChannelManager_block_disconnected(&this_arg_conv, header_ref);
9507 }
9508
9509 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1ChannelMessageHandler(JNIEnv * _env, jclass _b, jlong this_arg) {
9510         LDKChannelManager this_arg_conv;
9511         this_arg_conv.inner = (void*)(this_arg & (~1));
9512         this_arg_conv.is_owned = false;
9513         LDKChannelMessageHandler* ret = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
9514         *ret = ChannelManager_as_ChannelMessageHandler(&this_arg_conv);
9515         return (long)ret;
9516 }
9517
9518 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1write(JNIEnv * _env, jclass _b, jlong obj) {
9519         LDKChannelManager obj_conv;
9520         obj_conv.inner = (void*)(obj & (~1));
9521         obj_conv.is_owned = false;
9522         LDKCVec_u8Z arg_var = ChannelManager_write(&obj_conv);
9523         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
9524         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
9525         CVec_u8Z_free(arg_var);
9526         return arg_arr;
9527 }
9528
9529 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9530         LDKChannelManagerReadArgs this_ptr_conv;
9531         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9532         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9533         ChannelManagerReadArgs_free(this_ptr_conv);
9534 }
9535
9536 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1keys_1manager(JNIEnv * _env, jclass _b, jlong this_ptr) {
9537         LDKChannelManagerReadArgs this_ptr_conv;
9538         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9539         this_ptr_conv.is_owned = false;
9540         long ret_ret = (long)ChannelManagerReadArgs_get_keys_manager(&this_ptr_conv);
9541         return ret_ret;
9542 }
9543
9544 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1keys_1manager(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9545         LDKChannelManagerReadArgs this_ptr_conv;
9546         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9547         this_ptr_conv.is_owned = false;
9548         LDKKeysInterface val_conv = *(LDKKeysInterface*)val;
9549         if (val_conv.free == LDKKeysInterface_JCalls_free) {
9550                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9551                 LDKKeysInterface_JCalls_clone(val_conv.this_arg);
9552         }
9553         ChannelManagerReadArgs_set_keys_manager(&this_ptr_conv, val_conv);
9554 }
9555
9556 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1fee_1estimator(JNIEnv * _env, jclass _b, jlong this_ptr) {
9557         LDKChannelManagerReadArgs this_ptr_conv;
9558         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9559         this_ptr_conv.is_owned = false;
9560         long ret_ret = (long)ChannelManagerReadArgs_get_fee_estimator(&this_ptr_conv);
9561         return ret_ret;
9562 }
9563
9564 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1fee_1estimator(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9565         LDKChannelManagerReadArgs this_ptr_conv;
9566         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9567         this_ptr_conv.is_owned = false;
9568         LDKFeeEstimator val_conv = *(LDKFeeEstimator*)val;
9569         if (val_conv.free == LDKFeeEstimator_JCalls_free) {
9570                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9571                 LDKFeeEstimator_JCalls_clone(val_conv.this_arg);
9572         }
9573         ChannelManagerReadArgs_set_fee_estimator(&this_ptr_conv, val_conv);
9574 }
9575
9576 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1chain_1monitor(JNIEnv * _env, jclass _b, jlong this_ptr) {
9577         LDKChannelManagerReadArgs this_ptr_conv;
9578         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9579         this_ptr_conv.is_owned = false;
9580         long ret_ret = (long)ChannelManagerReadArgs_get_chain_monitor(&this_ptr_conv);
9581         return ret_ret;
9582 }
9583
9584 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1chain_1monitor(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9585         LDKChannelManagerReadArgs this_ptr_conv;
9586         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9587         this_ptr_conv.is_owned = false;
9588         LDKWatch val_conv = *(LDKWatch*)val;
9589         if (val_conv.free == LDKWatch_JCalls_free) {
9590                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9591                 LDKWatch_JCalls_clone(val_conv.this_arg);
9592         }
9593         ChannelManagerReadArgs_set_chain_monitor(&this_ptr_conv, val_conv);
9594 }
9595
9596 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1tx_1broadcaster(JNIEnv * _env, jclass _b, jlong this_ptr) {
9597         LDKChannelManagerReadArgs this_ptr_conv;
9598         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9599         this_ptr_conv.is_owned = false;
9600         long ret_ret = (long)ChannelManagerReadArgs_get_tx_broadcaster(&this_ptr_conv);
9601         return ret_ret;
9602 }
9603
9604 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1tx_1broadcaster(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9605         LDKChannelManagerReadArgs this_ptr_conv;
9606         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9607         this_ptr_conv.is_owned = false;
9608         LDKBroadcasterInterface val_conv = *(LDKBroadcasterInterface*)val;
9609         if (val_conv.free == LDKBroadcasterInterface_JCalls_free) {
9610                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9611                 LDKBroadcasterInterface_JCalls_clone(val_conv.this_arg);
9612         }
9613         ChannelManagerReadArgs_set_tx_broadcaster(&this_ptr_conv, val_conv);
9614 }
9615
9616 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1logger(JNIEnv * _env, jclass _b, jlong this_ptr) {
9617         LDKChannelManagerReadArgs this_ptr_conv;
9618         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9619         this_ptr_conv.is_owned = false;
9620         long ret_ret = (long)ChannelManagerReadArgs_get_logger(&this_ptr_conv);
9621         return ret_ret;
9622 }
9623
9624 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1logger(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9625         LDKChannelManagerReadArgs this_ptr_conv;
9626         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9627         this_ptr_conv.is_owned = false;
9628         LDKLogger val_conv = *(LDKLogger*)val;
9629         if (val_conv.free == LDKLogger_JCalls_free) {
9630                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9631                 LDKLogger_JCalls_clone(val_conv.this_arg);
9632         }
9633         ChannelManagerReadArgs_set_logger(&this_ptr_conv, val_conv);
9634 }
9635
9636 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1default_1config(JNIEnv * _env, jclass _b, jlong this_ptr) {
9637         LDKChannelManagerReadArgs this_ptr_conv;
9638         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9639         this_ptr_conv.is_owned = false;
9640         LDKUserConfig ret_var = ChannelManagerReadArgs_get_default_config(&this_ptr_conv);
9641         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9642         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9643         long ret_ref = (long)ret_var.inner;
9644         if (ret_var.is_owned) {
9645                 ret_ref |= 1;
9646         }
9647         return ret_ref;
9648 }
9649
9650 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1default_1config(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9651         LDKChannelManagerReadArgs this_ptr_conv;
9652         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9653         this_ptr_conv.is_owned = false;
9654         LDKUserConfig val_conv;
9655         val_conv.inner = (void*)(val & (~1));
9656         val_conv.is_owned = (val & 1) || (val == 0);
9657         if (val_conv.inner != NULL)
9658                 val_conv = UserConfig_clone(&val_conv);
9659         ChannelManagerReadArgs_set_default_config(&this_ptr_conv, val_conv);
9660 }
9661
9662 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) {
9663         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
9664         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
9665                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9666                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
9667         }
9668         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
9669         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
9670                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9671                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
9672         }
9673         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
9674         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
9675                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9676                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
9677         }
9678         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
9679         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
9680                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9681                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
9682         }
9683         LDKLogger logger_conv = *(LDKLogger*)logger;
9684         if (logger_conv.free == LDKLogger_JCalls_free) {
9685                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
9686                 LDKLogger_JCalls_clone(logger_conv.this_arg);
9687         }
9688         LDKUserConfig default_config_conv;
9689         default_config_conv.inner = (void*)(default_config & (~1));
9690         default_config_conv.is_owned = (default_config & 1) || (default_config == 0);
9691         if (default_config_conv.inner != NULL)
9692                 default_config_conv = UserConfig_clone(&default_config_conv);
9693         LDKCVec_ChannelMonitorZ channel_monitors_constr;
9694         channel_monitors_constr.datalen = (*_env)->GetArrayLength (_env, channel_monitors);
9695         if (channel_monitors_constr.datalen > 0)
9696                 channel_monitors_constr.data = MALLOC(channel_monitors_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
9697         else
9698                 channel_monitors_constr.data = NULL;
9699         long* channel_monitors_vals = (*_env)->GetLongArrayElements (_env, channel_monitors, NULL);
9700         for (size_t q = 0; q < channel_monitors_constr.datalen; q++) {
9701                 long arr_conv_16 = channel_monitors_vals[q];
9702                 LDKChannelMonitor arr_conv_16_conv;
9703                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
9704                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
9705                 // Warning: we may need a move here but can't clone!
9706                 channel_monitors_constr.data[q] = arr_conv_16_conv;
9707         }
9708         (*_env)->ReleaseLongArrayElements (_env, channel_monitors, channel_monitors_vals, 0);
9709         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);
9710         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9711         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9712         long ret_ref = (long)ret_var.inner;
9713         if (ret_var.is_owned) {
9714                 ret_ref |= 1;
9715         }
9716         return ret_ref;
9717 }
9718
9719 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1BlockHashChannelManagerZ_1read(JNIEnv * _env, jclass _b, jbyteArray ser, jlong arg) {
9720         LDKu8slice ser_ref;
9721         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
9722         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
9723         LDKChannelManagerReadArgs arg_conv;
9724         arg_conv.inner = (void*)(arg & (~1));
9725         arg_conv.is_owned = (arg & 1) || (arg == 0);
9726         // Warning: we may need a move here but can't clone!
9727         LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ), "LDKCResult_C2Tuple_BlockHashChannelManagerZDecodeErrorZ");
9728         *ret_conv = C2Tuple_BlockHashChannelManagerZ_read(ser_ref, arg_conv);
9729         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
9730         return (long)ret_conv;
9731 }
9732
9733 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DecodeError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9734         LDKDecodeError this_ptr_conv;
9735         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9736         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9737         DecodeError_free(this_ptr_conv);
9738 }
9739
9740 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Init_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9741         LDKInit this_ptr_conv;
9742         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9743         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9744         Init_free(this_ptr_conv);
9745 }
9746
9747 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Init_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9748         LDKInit orig_conv;
9749         orig_conv.inner = (void*)(orig & (~1));
9750         orig_conv.is_owned = false;
9751         LDKInit ret_var = Init_clone(&orig_conv);
9752         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9753         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9754         long ret_ref = (long)ret_var.inner;
9755         if (ret_var.is_owned) {
9756                 ret_ref |= 1;
9757         }
9758         return ret_ref;
9759 }
9760
9761 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9762         LDKErrorMessage this_ptr_conv;
9763         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9764         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9765         ErrorMessage_free(this_ptr_conv);
9766 }
9767
9768 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9769         LDKErrorMessage orig_conv;
9770         orig_conv.inner = (void*)(orig & (~1));
9771         orig_conv.is_owned = false;
9772         LDKErrorMessage ret_var = ErrorMessage_clone(&orig_conv);
9773         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9774         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9775         long ret_ref = (long)ret_var.inner;
9776         if (ret_var.is_owned) {
9777                 ret_ref |= 1;
9778         }
9779         return ret_ref;
9780 }
9781
9782 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9783         LDKErrorMessage this_ptr_conv;
9784         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9785         this_ptr_conv.is_owned = false;
9786         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9787         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ErrorMessage_get_channel_id(&this_ptr_conv));
9788         return ret_arr;
9789 }
9790
9791 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9792         LDKErrorMessage this_ptr_conv;
9793         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9794         this_ptr_conv.is_owned = false;
9795         LDKThirtyTwoBytes val_ref;
9796         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9797         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9798         ErrorMessage_set_channel_id(&this_ptr_conv, val_ref);
9799 }
9800
9801 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1data(JNIEnv * _env, jclass _b, jlong this_ptr) {
9802         LDKErrorMessage this_ptr_conv;
9803         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9804         this_ptr_conv.is_owned = false;
9805         LDKStr _str = ErrorMessage_get_data(&this_ptr_conv);
9806         char* _buf = MALLOC(_str.len + 1, "str conv buf");
9807         memcpy(_buf, _str.chars, _str.len);
9808         _buf[_str.len] = 0;
9809         jstring _conv = (*_env)->NewStringUTF(_env, _str.chars);
9810         FREE(_buf);
9811         return _conv;
9812 }
9813
9814 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1data(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9815         LDKErrorMessage this_ptr_conv;
9816         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9817         this_ptr_conv.is_owned = false;
9818         LDKCVec_u8Z val_ref;
9819         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
9820         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
9821         (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data);
9822         ErrorMessage_set_data(&this_ptr_conv, val_ref);
9823 }
9824
9825 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray data_arg) {
9826         LDKThirtyTwoBytes channel_id_arg_ref;
9827         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9828         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9829         LDKCVec_u8Z data_arg_ref;
9830         data_arg_ref.datalen = (*_env)->GetArrayLength (_env, data_arg);
9831         data_arg_ref.data = MALLOC(data_arg_ref.datalen, "LDKCVec_u8Z Bytes");
9832         (*_env)->GetByteArrayRegion(_env, data_arg, 0, data_arg_ref.datalen, data_arg_ref.data);
9833         LDKErrorMessage ret_var = ErrorMessage_new(channel_id_arg_ref, data_arg_ref);
9834         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9835         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9836         long ret_ref = (long)ret_var.inner;
9837         if (ret_var.is_owned) {
9838                 ret_ref |= 1;
9839         }
9840         return ret_ref;
9841 }
9842
9843 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9844         LDKPing this_ptr_conv;
9845         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9846         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9847         Ping_free(this_ptr_conv);
9848 }
9849
9850 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9851         LDKPing orig_conv;
9852         orig_conv.inner = (void*)(orig & (~1));
9853         orig_conv.is_owned = false;
9854         LDKPing ret_var = Ping_clone(&orig_conv);
9855         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9856         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9857         long ret_ref = (long)ret_var.inner;
9858         if (ret_var.is_owned) {
9859                 ret_ref |= 1;
9860         }
9861         return ret_ref;
9862 }
9863
9864 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Ping_1get_1ponglen(JNIEnv * _env, jclass _b, jlong this_ptr) {
9865         LDKPing this_ptr_conv;
9866         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9867         this_ptr_conv.is_owned = false;
9868         jshort ret_val = Ping_get_ponglen(&this_ptr_conv);
9869         return ret_val;
9870 }
9871
9872 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1ponglen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
9873         LDKPing this_ptr_conv;
9874         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9875         this_ptr_conv.is_owned = false;
9876         Ping_set_ponglen(&this_ptr_conv, val);
9877 }
9878
9879 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Ping_1get_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr) {
9880         LDKPing this_ptr_conv;
9881         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9882         this_ptr_conv.is_owned = false;
9883         jshort ret_val = Ping_get_byteslen(&this_ptr_conv);
9884         return ret_val;
9885 }
9886
9887 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
9888         LDKPing this_ptr_conv;
9889         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9890         this_ptr_conv.is_owned = false;
9891         Ping_set_byteslen(&this_ptr_conv, val);
9892 }
9893
9894 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1new(JNIEnv * _env, jclass _b, jshort ponglen_arg, jshort byteslen_arg) {
9895         LDKPing ret_var = Ping_new(ponglen_arg, byteslen_arg);
9896         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9897         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9898         long ret_ref = (long)ret_var.inner;
9899         if (ret_var.is_owned) {
9900                 ret_ref |= 1;
9901         }
9902         return ret_ref;
9903 }
9904
9905 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9906         LDKPong this_ptr_conv;
9907         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9908         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9909         Pong_free(this_ptr_conv);
9910 }
9911
9912 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9913         LDKPong orig_conv;
9914         orig_conv.inner = (void*)(orig & (~1));
9915         orig_conv.is_owned = false;
9916         LDKPong ret_var = Pong_clone(&orig_conv);
9917         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9918         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9919         long ret_ref = (long)ret_var.inner;
9920         if (ret_var.is_owned) {
9921                 ret_ref |= 1;
9922         }
9923         return ret_ref;
9924 }
9925
9926 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Pong_1get_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr) {
9927         LDKPong this_ptr_conv;
9928         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9929         this_ptr_conv.is_owned = false;
9930         jshort ret_val = Pong_get_byteslen(&this_ptr_conv);
9931         return ret_val;
9932 }
9933
9934 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1set_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
9935         LDKPong this_ptr_conv;
9936         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9937         this_ptr_conv.is_owned = false;
9938         Pong_set_byteslen(&this_ptr_conv, val);
9939 }
9940
9941 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1new(JNIEnv * _env, jclass _b, jshort byteslen_arg) {
9942         LDKPong ret_var = Pong_new(byteslen_arg);
9943         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9944         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9945         long ret_ref = (long)ret_var.inner;
9946         if (ret_var.is_owned) {
9947                 ret_ref |= 1;
9948         }
9949         return ret_ref;
9950 }
9951
9952 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9953         LDKOpenChannel this_ptr_conv;
9954         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9955         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9956         OpenChannel_free(this_ptr_conv);
9957 }
9958
9959 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9960         LDKOpenChannel orig_conv;
9961         orig_conv.inner = (void*)(orig & (~1));
9962         orig_conv.is_owned = false;
9963         LDKOpenChannel ret_var = OpenChannel_clone(&orig_conv);
9964         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9965         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9966         long ret_ref = (long)ret_var.inner;
9967         if (ret_var.is_owned) {
9968                 ret_ref |= 1;
9969         }
9970         return ret_ref;
9971 }
9972
9973 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
9974         LDKOpenChannel this_ptr_conv;
9975         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9976         this_ptr_conv.is_owned = false;
9977         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9978         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OpenChannel_get_chain_hash(&this_ptr_conv));
9979         return ret_arr;
9980 }
9981
9982 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9983         LDKOpenChannel this_ptr_conv;
9984         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9985         this_ptr_conv.is_owned = false;
9986         LDKThirtyTwoBytes val_ref;
9987         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9988         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9989         OpenChannel_set_chain_hash(&this_ptr_conv, val_ref);
9990 }
9991
9992 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9993         LDKOpenChannel this_ptr_conv;
9994         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9995         this_ptr_conv.is_owned = false;
9996         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9997         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OpenChannel_get_temporary_channel_id(&this_ptr_conv));
9998         return ret_arr;
9999 }
10000
10001 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10002         LDKOpenChannel this_ptr_conv;
10003         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10004         this_ptr_conv.is_owned = false;
10005         LDKThirtyTwoBytes val_ref;
10006         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10007         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10008         OpenChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
10009 }
10010
10011 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
10012         LDKOpenChannel this_ptr_conv;
10013         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10014         this_ptr_conv.is_owned = false;
10015         jlong ret_val = OpenChannel_get_funding_satoshis(&this_ptr_conv);
10016         return ret_val;
10017 }
10018
10019 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10020         LDKOpenChannel this_ptr_conv;
10021         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10022         this_ptr_conv.is_owned = false;
10023         OpenChannel_set_funding_satoshis(&this_ptr_conv, val);
10024 }
10025
10026 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1push_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10027         LDKOpenChannel this_ptr_conv;
10028         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10029         this_ptr_conv.is_owned = false;
10030         jlong ret_val = OpenChannel_get_push_msat(&this_ptr_conv);
10031         return ret_val;
10032 }
10033
10034 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1push_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10035         LDKOpenChannel this_ptr_conv;
10036         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10037         this_ptr_conv.is_owned = false;
10038         OpenChannel_set_push_msat(&this_ptr_conv, val);
10039 }
10040
10041 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
10042         LDKOpenChannel this_ptr_conv;
10043         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10044         this_ptr_conv.is_owned = false;
10045         jlong ret_val = OpenChannel_get_dust_limit_satoshis(&this_ptr_conv);
10046         return ret_val;
10047 }
10048
10049 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10050         LDKOpenChannel this_ptr_conv;
10051         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10052         this_ptr_conv.is_owned = false;
10053         OpenChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
10054 }
10055
10056 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10057         LDKOpenChannel this_ptr_conv;
10058         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10059         this_ptr_conv.is_owned = false;
10060         jlong ret_val = OpenChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
10061         return ret_val;
10062 }
10063
10064 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) {
10065         LDKOpenChannel this_ptr_conv;
10066         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10067         this_ptr_conv.is_owned = false;
10068         OpenChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
10069 }
10070
10071 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
10072         LDKOpenChannel this_ptr_conv;
10073         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10074         this_ptr_conv.is_owned = false;
10075         jlong ret_val = OpenChannel_get_channel_reserve_satoshis(&this_ptr_conv);
10076         return ret_val;
10077 }
10078
10079 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10080         LDKOpenChannel this_ptr_conv;
10081         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10082         this_ptr_conv.is_owned = false;
10083         OpenChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
10084 }
10085
10086 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10087         LDKOpenChannel this_ptr_conv;
10088         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10089         this_ptr_conv.is_owned = false;
10090         jlong ret_val = OpenChannel_get_htlc_minimum_msat(&this_ptr_conv);
10091         return ret_val;
10092 }
10093
10094 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10095         LDKOpenChannel this_ptr_conv;
10096         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10097         this_ptr_conv.is_owned = false;
10098         OpenChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
10099 }
10100
10101 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr) {
10102         LDKOpenChannel this_ptr_conv;
10103         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10104         this_ptr_conv.is_owned = false;
10105         jint ret_val = OpenChannel_get_feerate_per_kw(&this_ptr_conv);
10106         return ret_val;
10107 }
10108
10109 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10110         LDKOpenChannel this_ptr_conv;
10111         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10112         this_ptr_conv.is_owned = false;
10113         OpenChannel_set_feerate_per_kw(&this_ptr_conv, val);
10114 }
10115
10116 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
10117         LDKOpenChannel this_ptr_conv;
10118         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10119         this_ptr_conv.is_owned = false;
10120         jshort ret_val = OpenChannel_get_to_self_delay(&this_ptr_conv);
10121         return ret_val;
10122 }
10123
10124 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
10125         LDKOpenChannel this_ptr_conv;
10126         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10127         this_ptr_conv.is_owned = false;
10128         OpenChannel_set_to_self_delay(&this_ptr_conv, val);
10129 }
10130
10131 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
10132         LDKOpenChannel this_ptr_conv;
10133         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10134         this_ptr_conv.is_owned = false;
10135         jshort ret_val = OpenChannel_get_max_accepted_htlcs(&this_ptr_conv);
10136         return ret_val;
10137 }
10138
10139 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
10140         LDKOpenChannel this_ptr_conv;
10141         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10142         this_ptr_conv.is_owned = false;
10143         OpenChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
10144 }
10145
10146 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
10147         LDKOpenChannel this_ptr_conv;
10148         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10149         this_ptr_conv.is_owned = false;
10150         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10151         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
10152         return arg_arr;
10153 }
10154
10155 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10156         LDKOpenChannel this_ptr_conv;
10157         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10158         this_ptr_conv.is_owned = false;
10159         LDKPublicKey val_ref;
10160         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10161         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10162         OpenChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
10163 }
10164
10165 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
10166         LDKOpenChannel this_ptr_conv;
10167         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10168         this_ptr_conv.is_owned = false;
10169         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10170         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
10171         return arg_arr;
10172 }
10173
10174 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10175         LDKOpenChannel this_ptr_conv;
10176         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10177         this_ptr_conv.is_owned = false;
10178         LDKPublicKey val_ref;
10179         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10180         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10181         OpenChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
10182 }
10183
10184 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
10185         LDKOpenChannel this_ptr_conv;
10186         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10187         this_ptr_conv.is_owned = false;
10188         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10189         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_payment_point(&this_ptr_conv).compressed_form);
10190         return arg_arr;
10191 }
10192
10193 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10194         LDKOpenChannel this_ptr_conv;
10195         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10196         this_ptr_conv.is_owned = false;
10197         LDKPublicKey val_ref;
10198         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10199         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10200         OpenChannel_set_payment_point(&this_ptr_conv, val_ref);
10201 }
10202
10203 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
10204         LDKOpenChannel this_ptr_conv;
10205         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10206         this_ptr_conv.is_owned = false;
10207         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10208         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
10209         return arg_arr;
10210 }
10211
10212 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10213         LDKOpenChannel this_ptr_conv;
10214         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10215         this_ptr_conv.is_owned = false;
10216         LDKPublicKey val_ref;
10217         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10218         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10219         OpenChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
10220 }
10221
10222 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
10223         LDKOpenChannel this_ptr_conv;
10224         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10225         this_ptr_conv.is_owned = false;
10226         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10227         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
10228         return arg_arr;
10229 }
10230
10231 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10232         LDKOpenChannel this_ptr_conv;
10233         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10234         this_ptr_conv.is_owned = false;
10235         LDKPublicKey val_ref;
10236         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10237         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10238         OpenChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
10239 }
10240
10241 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
10242         LDKOpenChannel this_ptr_conv;
10243         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10244         this_ptr_conv.is_owned = false;
10245         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10246         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
10247         return arg_arr;
10248 }
10249
10250 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10251         LDKOpenChannel this_ptr_conv;
10252         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10253         this_ptr_conv.is_owned = false;
10254         LDKPublicKey val_ref;
10255         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10256         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10257         OpenChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
10258 }
10259
10260 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1flags(JNIEnv * _env, jclass _b, jlong this_ptr) {
10261         LDKOpenChannel this_ptr_conv;
10262         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10263         this_ptr_conv.is_owned = false;
10264         jbyte ret_val = OpenChannel_get_channel_flags(&this_ptr_conv);
10265         return ret_val;
10266 }
10267
10268 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1flags(JNIEnv * _env, jclass _b, jlong this_ptr, jbyte val) {
10269         LDKOpenChannel this_ptr_conv;
10270         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10271         this_ptr_conv.is_owned = false;
10272         OpenChannel_set_channel_flags(&this_ptr_conv, val);
10273 }
10274
10275 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10276         LDKAcceptChannel this_ptr_conv;
10277         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10278         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10279         AcceptChannel_free(this_ptr_conv);
10280 }
10281
10282 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10283         LDKAcceptChannel orig_conv;
10284         orig_conv.inner = (void*)(orig & (~1));
10285         orig_conv.is_owned = false;
10286         LDKAcceptChannel ret_var = AcceptChannel_clone(&orig_conv);
10287         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10288         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10289         long ret_ref = (long)ret_var.inner;
10290         if (ret_var.is_owned) {
10291                 ret_ref |= 1;
10292         }
10293         return ret_ref;
10294 }
10295
10296 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10297         LDKAcceptChannel this_ptr_conv;
10298         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10299         this_ptr_conv.is_owned = false;
10300         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10301         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *AcceptChannel_get_temporary_channel_id(&this_ptr_conv));
10302         return ret_arr;
10303 }
10304
10305 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10306         LDKAcceptChannel this_ptr_conv;
10307         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10308         this_ptr_conv.is_owned = false;
10309         LDKThirtyTwoBytes val_ref;
10310         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10311         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10312         AcceptChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
10313 }
10314
10315 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
10316         LDKAcceptChannel this_ptr_conv;
10317         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10318         this_ptr_conv.is_owned = false;
10319         jlong ret_val = AcceptChannel_get_dust_limit_satoshis(&this_ptr_conv);
10320         return ret_val;
10321 }
10322
10323 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10324         LDKAcceptChannel this_ptr_conv;
10325         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10326         this_ptr_conv.is_owned = false;
10327         AcceptChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
10328 }
10329
10330 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10331         LDKAcceptChannel this_ptr_conv;
10332         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10333         this_ptr_conv.is_owned = false;
10334         jlong ret_val = AcceptChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
10335         return ret_val;
10336 }
10337
10338 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) {
10339         LDKAcceptChannel this_ptr_conv;
10340         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10341         this_ptr_conv.is_owned = false;
10342         AcceptChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
10343 }
10344
10345 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
10346         LDKAcceptChannel this_ptr_conv;
10347         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10348         this_ptr_conv.is_owned = false;
10349         jlong ret_val = AcceptChannel_get_channel_reserve_satoshis(&this_ptr_conv);
10350         return ret_val;
10351 }
10352
10353 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10354         LDKAcceptChannel this_ptr_conv;
10355         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10356         this_ptr_conv.is_owned = false;
10357         AcceptChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
10358 }
10359
10360 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10361         LDKAcceptChannel this_ptr_conv;
10362         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10363         this_ptr_conv.is_owned = false;
10364         jlong ret_val = AcceptChannel_get_htlc_minimum_msat(&this_ptr_conv);
10365         return ret_val;
10366 }
10367
10368 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10369         LDKAcceptChannel this_ptr_conv;
10370         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10371         this_ptr_conv.is_owned = false;
10372         AcceptChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
10373 }
10374
10375 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
10376         LDKAcceptChannel this_ptr_conv;
10377         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10378         this_ptr_conv.is_owned = false;
10379         jint ret_val = AcceptChannel_get_minimum_depth(&this_ptr_conv);
10380         return ret_val;
10381 }
10382
10383 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10384         LDKAcceptChannel this_ptr_conv;
10385         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10386         this_ptr_conv.is_owned = false;
10387         AcceptChannel_set_minimum_depth(&this_ptr_conv, val);
10388 }
10389
10390 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
10391         LDKAcceptChannel this_ptr_conv;
10392         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10393         this_ptr_conv.is_owned = false;
10394         jshort ret_val = AcceptChannel_get_to_self_delay(&this_ptr_conv);
10395         return ret_val;
10396 }
10397
10398 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
10399         LDKAcceptChannel this_ptr_conv;
10400         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10401         this_ptr_conv.is_owned = false;
10402         AcceptChannel_set_to_self_delay(&this_ptr_conv, val);
10403 }
10404
10405 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
10406         LDKAcceptChannel this_ptr_conv;
10407         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10408         this_ptr_conv.is_owned = false;
10409         jshort ret_val = AcceptChannel_get_max_accepted_htlcs(&this_ptr_conv);
10410         return ret_val;
10411 }
10412
10413 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
10414         LDKAcceptChannel this_ptr_conv;
10415         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10416         this_ptr_conv.is_owned = false;
10417         AcceptChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
10418 }
10419
10420 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
10421         LDKAcceptChannel this_ptr_conv;
10422         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10423         this_ptr_conv.is_owned = false;
10424         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10425         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
10426         return arg_arr;
10427 }
10428
10429 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10430         LDKAcceptChannel this_ptr_conv;
10431         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10432         this_ptr_conv.is_owned = false;
10433         LDKPublicKey val_ref;
10434         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10435         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10436         AcceptChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
10437 }
10438
10439 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
10440         LDKAcceptChannel this_ptr_conv;
10441         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10442         this_ptr_conv.is_owned = false;
10443         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10444         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
10445         return arg_arr;
10446 }
10447
10448 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10449         LDKAcceptChannel this_ptr_conv;
10450         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10451         this_ptr_conv.is_owned = false;
10452         LDKPublicKey val_ref;
10453         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10454         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10455         AcceptChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
10456 }
10457
10458 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
10459         LDKAcceptChannel this_ptr_conv;
10460         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10461         this_ptr_conv.is_owned = false;
10462         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10463         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_payment_point(&this_ptr_conv).compressed_form);
10464         return arg_arr;
10465 }
10466
10467 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10468         LDKAcceptChannel this_ptr_conv;
10469         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10470         this_ptr_conv.is_owned = false;
10471         LDKPublicKey val_ref;
10472         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10473         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10474         AcceptChannel_set_payment_point(&this_ptr_conv, val_ref);
10475 }
10476
10477 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
10478         LDKAcceptChannel this_ptr_conv;
10479         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10480         this_ptr_conv.is_owned = false;
10481         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10482         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
10483         return arg_arr;
10484 }
10485
10486 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10487         LDKAcceptChannel this_ptr_conv;
10488         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10489         this_ptr_conv.is_owned = false;
10490         LDKPublicKey val_ref;
10491         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10492         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10493         AcceptChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
10494 }
10495
10496 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
10497         LDKAcceptChannel this_ptr_conv;
10498         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10499         this_ptr_conv.is_owned = false;
10500         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10501         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
10502         return arg_arr;
10503 }
10504
10505 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10506         LDKAcceptChannel this_ptr_conv;
10507         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10508         this_ptr_conv.is_owned = false;
10509         LDKPublicKey val_ref;
10510         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10511         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10512         AcceptChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
10513 }
10514
10515 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
10516         LDKAcceptChannel this_ptr_conv;
10517         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10518         this_ptr_conv.is_owned = false;
10519         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10520         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
10521         return arg_arr;
10522 }
10523
10524 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10525         LDKAcceptChannel this_ptr_conv;
10526         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10527         this_ptr_conv.is_owned = false;
10528         LDKPublicKey val_ref;
10529         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10530         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10531         AcceptChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
10532 }
10533
10534 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10535         LDKFundingCreated this_ptr_conv;
10536         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10537         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10538         FundingCreated_free(this_ptr_conv);
10539 }
10540
10541 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingCreated_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10542         LDKFundingCreated orig_conv;
10543         orig_conv.inner = (void*)(orig & (~1));
10544         orig_conv.is_owned = false;
10545         LDKFundingCreated ret_var = FundingCreated_clone(&orig_conv);
10546         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10547         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10548         long ret_ref = (long)ret_var.inner;
10549         if (ret_var.is_owned) {
10550                 ret_ref |= 1;
10551         }
10552         return ret_ref;
10553 }
10554
10555 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10556         LDKFundingCreated this_ptr_conv;
10557         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10558         this_ptr_conv.is_owned = false;
10559         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10560         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingCreated_get_temporary_channel_id(&this_ptr_conv));
10561         return ret_arr;
10562 }
10563
10564 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10565         LDKFundingCreated this_ptr_conv;
10566         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10567         this_ptr_conv.is_owned = false;
10568         LDKThirtyTwoBytes val_ref;
10569         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10570         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10571         FundingCreated_set_temporary_channel_id(&this_ptr_conv, val_ref);
10572 }
10573
10574 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1txid(JNIEnv * _env, jclass _b, jlong this_ptr) {
10575         LDKFundingCreated this_ptr_conv;
10576         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10577         this_ptr_conv.is_owned = false;
10578         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10579         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingCreated_get_funding_txid(&this_ptr_conv));
10580         return ret_arr;
10581 }
10582
10583 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1txid(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10584         LDKFundingCreated this_ptr_conv;
10585         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10586         this_ptr_conv.is_owned = false;
10587         LDKThirtyTwoBytes val_ref;
10588         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10589         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10590         FundingCreated_set_funding_txid(&this_ptr_conv, val_ref);
10591 }
10592
10593 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1output_1index(JNIEnv * _env, jclass _b, jlong this_ptr) {
10594         LDKFundingCreated this_ptr_conv;
10595         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10596         this_ptr_conv.is_owned = false;
10597         jshort ret_val = FundingCreated_get_funding_output_index(&this_ptr_conv);
10598         return ret_val;
10599 }
10600
10601 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1output_1index(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
10602         LDKFundingCreated this_ptr_conv;
10603         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10604         this_ptr_conv.is_owned = false;
10605         FundingCreated_set_funding_output_index(&this_ptr_conv, val);
10606 }
10607
10608 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
10609         LDKFundingCreated this_ptr_conv;
10610         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10611         this_ptr_conv.is_owned = false;
10612         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10613         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, FundingCreated_get_signature(&this_ptr_conv).compact_form);
10614         return arg_arr;
10615 }
10616
10617 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10618         LDKFundingCreated this_ptr_conv;
10619         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10620         this_ptr_conv.is_owned = false;
10621         LDKSignature val_ref;
10622         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10623         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10624         FundingCreated_set_signature(&this_ptr_conv, val_ref);
10625 }
10626
10627 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) {
10628         LDKThirtyTwoBytes temporary_channel_id_arg_ref;
10629         CHECK((*_env)->GetArrayLength (_env, temporary_channel_id_arg) == 32);
10630         (*_env)->GetByteArrayRegion (_env, temporary_channel_id_arg, 0, 32, temporary_channel_id_arg_ref.data);
10631         LDKThirtyTwoBytes funding_txid_arg_ref;
10632         CHECK((*_env)->GetArrayLength (_env, funding_txid_arg) == 32);
10633         (*_env)->GetByteArrayRegion (_env, funding_txid_arg, 0, 32, funding_txid_arg_ref.data);
10634         LDKSignature signature_arg_ref;
10635         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
10636         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10637         LDKFundingCreated ret_var = FundingCreated_new(temporary_channel_id_arg_ref, funding_txid_arg_ref, funding_output_index_arg, signature_arg_ref);
10638         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10639         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10640         long ret_ref = (long)ret_var.inner;
10641         if (ret_var.is_owned) {
10642                 ret_ref |= 1;
10643         }
10644         return ret_ref;
10645 }
10646
10647 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10648         LDKFundingSigned this_ptr_conv;
10649         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10650         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10651         FundingSigned_free(this_ptr_conv);
10652 }
10653
10654 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10655         LDKFundingSigned orig_conv;
10656         orig_conv.inner = (void*)(orig & (~1));
10657         orig_conv.is_owned = false;
10658         LDKFundingSigned ret_var = FundingSigned_clone(&orig_conv);
10659         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10660         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10661         long ret_ref = (long)ret_var.inner;
10662         if (ret_var.is_owned) {
10663                 ret_ref |= 1;
10664         }
10665         return ret_ref;
10666 }
10667
10668 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10669         LDKFundingSigned this_ptr_conv;
10670         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10671         this_ptr_conv.is_owned = false;
10672         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10673         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingSigned_get_channel_id(&this_ptr_conv));
10674         return ret_arr;
10675 }
10676
10677 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10678         LDKFundingSigned this_ptr_conv;
10679         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10680         this_ptr_conv.is_owned = false;
10681         LDKThirtyTwoBytes val_ref;
10682         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10683         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10684         FundingSigned_set_channel_id(&this_ptr_conv, val_ref);
10685 }
10686
10687 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
10688         LDKFundingSigned this_ptr_conv;
10689         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10690         this_ptr_conv.is_owned = false;
10691         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10692         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, FundingSigned_get_signature(&this_ptr_conv).compact_form);
10693         return arg_arr;
10694 }
10695
10696 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10697         LDKFundingSigned this_ptr_conv;
10698         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10699         this_ptr_conv.is_owned = false;
10700         LDKSignature val_ref;
10701         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10702         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10703         FundingSigned_set_signature(&this_ptr_conv, val_ref);
10704 }
10705
10706 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray signature_arg) {
10707         LDKThirtyTwoBytes channel_id_arg_ref;
10708         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
10709         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10710         LDKSignature signature_arg_ref;
10711         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
10712         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10713         LDKFundingSigned ret_var = FundingSigned_new(channel_id_arg_ref, signature_arg_ref);
10714         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10715         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10716         long ret_ref = (long)ret_var.inner;
10717         if (ret_var.is_owned) {
10718                 ret_ref |= 1;
10719         }
10720         return ret_ref;
10721 }
10722
10723 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10724         LDKFundingLocked this_ptr_conv;
10725         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10726         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10727         FundingLocked_free(this_ptr_conv);
10728 }
10729
10730 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10731         LDKFundingLocked orig_conv;
10732         orig_conv.inner = (void*)(orig & (~1));
10733         orig_conv.is_owned = false;
10734         LDKFundingLocked ret_var = FundingLocked_clone(&orig_conv);
10735         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10736         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10737         long ret_ref = (long)ret_var.inner;
10738         if (ret_var.is_owned) {
10739                 ret_ref |= 1;
10740         }
10741         return ret_ref;
10742 }
10743
10744 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10745         LDKFundingLocked this_ptr_conv;
10746         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10747         this_ptr_conv.is_owned = false;
10748         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10749         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingLocked_get_channel_id(&this_ptr_conv));
10750         return ret_arr;
10751 }
10752
10753 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10754         LDKFundingLocked this_ptr_conv;
10755         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10756         this_ptr_conv.is_owned = false;
10757         LDKThirtyTwoBytes val_ref;
10758         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10759         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10760         FundingLocked_set_channel_id(&this_ptr_conv, val_ref);
10761 }
10762
10763 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
10764         LDKFundingLocked this_ptr_conv;
10765         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10766         this_ptr_conv.is_owned = false;
10767         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
10768         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, FundingLocked_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
10769         return arg_arr;
10770 }
10771
10772 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1set_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10773         LDKFundingLocked this_ptr_conv;
10774         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10775         this_ptr_conv.is_owned = false;
10776         LDKPublicKey val_ref;
10777         CHECK((*_env)->GetArrayLength (_env, val) == 33);
10778         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
10779         FundingLocked_set_next_per_commitment_point(&this_ptr_conv, val_ref);
10780 }
10781
10782 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray next_per_commitment_point_arg) {
10783         LDKThirtyTwoBytes channel_id_arg_ref;
10784         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
10785         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10786         LDKPublicKey next_per_commitment_point_arg_ref;
10787         CHECK((*_env)->GetArrayLength (_env, next_per_commitment_point_arg) == 33);
10788         (*_env)->GetByteArrayRegion (_env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
10789         LDKFundingLocked ret_var = FundingLocked_new(channel_id_arg_ref, next_per_commitment_point_arg_ref);
10790         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10791         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10792         long ret_ref = (long)ret_var.inner;
10793         if (ret_var.is_owned) {
10794                 ret_ref |= 1;
10795         }
10796         return ret_ref;
10797 }
10798
10799 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10800         LDKShutdown this_ptr_conv;
10801         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10802         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10803         Shutdown_free(this_ptr_conv);
10804 }
10805
10806 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10807         LDKShutdown orig_conv;
10808         orig_conv.inner = (void*)(orig & (~1));
10809         orig_conv.is_owned = false;
10810         LDKShutdown ret_var = Shutdown_clone(&orig_conv);
10811         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10812         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10813         long ret_ref = (long)ret_var.inner;
10814         if (ret_var.is_owned) {
10815                 ret_ref |= 1;
10816         }
10817         return ret_ref;
10818 }
10819
10820 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10821         LDKShutdown this_ptr_conv;
10822         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10823         this_ptr_conv.is_owned = false;
10824         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10825         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *Shutdown_get_channel_id(&this_ptr_conv));
10826         return ret_arr;
10827 }
10828
10829 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10830         LDKShutdown this_ptr_conv;
10831         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10832         this_ptr_conv.is_owned = false;
10833         LDKThirtyTwoBytes val_ref;
10834         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10835         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10836         Shutdown_set_channel_id(&this_ptr_conv, val_ref);
10837 }
10838
10839 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1scriptpubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
10840         LDKShutdown this_ptr_conv;
10841         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10842         this_ptr_conv.is_owned = false;
10843         LDKu8slice arg_var = Shutdown_get_scriptpubkey(&this_ptr_conv);
10844         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
10845         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
10846         return arg_arr;
10847 }
10848
10849 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1scriptpubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10850         LDKShutdown this_ptr_conv;
10851         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10852         this_ptr_conv.is_owned = false;
10853         LDKCVec_u8Z val_ref;
10854         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
10855         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
10856         (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data);
10857         Shutdown_set_scriptpubkey(&this_ptr_conv, val_ref);
10858 }
10859
10860 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray scriptpubkey_arg) {
10861         LDKThirtyTwoBytes channel_id_arg_ref;
10862         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
10863         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10864         LDKCVec_u8Z scriptpubkey_arg_ref;
10865         scriptpubkey_arg_ref.datalen = (*_env)->GetArrayLength (_env, scriptpubkey_arg);
10866         scriptpubkey_arg_ref.data = MALLOC(scriptpubkey_arg_ref.datalen, "LDKCVec_u8Z Bytes");
10867         (*_env)->GetByteArrayRegion(_env, scriptpubkey_arg, 0, scriptpubkey_arg_ref.datalen, scriptpubkey_arg_ref.data);
10868         LDKShutdown ret_var = Shutdown_new(channel_id_arg_ref, scriptpubkey_arg_ref);
10869         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10870         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10871         long ret_ref = (long)ret_var.inner;
10872         if (ret_var.is_owned) {
10873                 ret_ref |= 1;
10874         }
10875         return ret_ref;
10876 }
10877
10878 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10879         LDKClosingSigned this_ptr_conv;
10880         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10881         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10882         ClosingSigned_free(this_ptr_conv);
10883 }
10884
10885 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10886         LDKClosingSigned orig_conv;
10887         orig_conv.inner = (void*)(orig & (~1));
10888         orig_conv.is_owned = false;
10889         LDKClosingSigned ret_var = ClosingSigned_clone(&orig_conv);
10890         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10891         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10892         long ret_ref = (long)ret_var.inner;
10893         if (ret_var.is_owned) {
10894                 ret_ref |= 1;
10895         }
10896         return ret_ref;
10897 }
10898
10899 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10900         LDKClosingSigned this_ptr_conv;
10901         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10902         this_ptr_conv.is_owned = false;
10903         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10904         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ClosingSigned_get_channel_id(&this_ptr_conv));
10905         return ret_arr;
10906 }
10907
10908 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10909         LDKClosingSigned this_ptr_conv;
10910         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10911         this_ptr_conv.is_owned = false;
10912         LDKThirtyTwoBytes val_ref;
10913         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10914         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10915         ClosingSigned_set_channel_id(&this_ptr_conv, val_ref);
10916 }
10917
10918 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1fee_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
10919         LDKClosingSigned this_ptr_conv;
10920         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10921         this_ptr_conv.is_owned = false;
10922         jlong ret_val = ClosingSigned_get_fee_satoshis(&this_ptr_conv);
10923         return ret_val;
10924 }
10925
10926 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1fee_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10927         LDKClosingSigned this_ptr_conv;
10928         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10929         this_ptr_conv.is_owned = false;
10930         ClosingSigned_set_fee_satoshis(&this_ptr_conv, val);
10931 }
10932
10933 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
10934         LDKClosingSigned this_ptr_conv;
10935         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10936         this_ptr_conv.is_owned = false;
10937         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10938         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ClosingSigned_get_signature(&this_ptr_conv).compact_form);
10939         return arg_arr;
10940 }
10941
10942 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10943         LDKClosingSigned this_ptr_conv;
10944         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10945         this_ptr_conv.is_owned = false;
10946         LDKSignature val_ref;
10947         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10948         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10949         ClosingSigned_set_signature(&this_ptr_conv, val_ref);
10950 }
10951
10952 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) {
10953         LDKThirtyTwoBytes channel_id_arg_ref;
10954         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
10955         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
10956         LDKSignature signature_arg_ref;
10957         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
10958         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10959         LDKClosingSigned ret_var = ClosingSigned_new(channel_id_arg_ref, fee_satoshis_arg, signature_arg_ref);
10960         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10961         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10962         long ret_ref = (long)ret_var.inner;
10963         if (ret_var.is_owned) {
10964                 ret_ref |= 1;
10965         }
10966         return ret_ref;
10967 }
10968
10969 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10970         LDKUpdateAddHTLC this_ptr_conv;
10971         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10972         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10973         UpdateAddHTLC_free(this_ptr_conv);
10974 }
10975
10976 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10977         LDKUpdateAddHTLC orig_conv;
10978         orig_conv.inner = (void*)(orig & (~1));
10979         orig_conv.is_owned = false;
10980         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_clone(&orig_conv);
10981         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10982         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10983         long ret_ref = (long)ret_var.inner;
10984         if (ret_var.is_owned) {
10985                 ret_ref |= 1;
10986         }
10987         return ret_ref;
10988 }
10989
10990 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10991         LDKUpdateAddHTLC this_ptr_conv;
10992         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10993         this_ptr_conv.is_owned = false;
10994         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10995         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateAddHTLC_get_channel_id(&this_ptr_conv));
10996         return ret_arr;
10997 }
10998
10999 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11000         LDKUpdateAddHTLC this_ptr_conv;
11001         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11002         this_ptr_conv.is_owned = false;
11003         LDKThirtyTwoBytes val_ref;
11004         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11005         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11006         UpdateAddHTLC_set_channel_id(&this_ptr_conv, val_ref);
11007 }
11008
11009 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11010         LDKUpdateAddHTLC this_ptr_conv;
11011         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11012         this_ptr_conv.is_owned = false;
11013         jlong ret_val = UpdateAddHTLC_get_htlc_id(&this_ptr_conv);
11014         return ret_val;
11015 }
11016
11017 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11018         LDKUpdateAddHTLC this_ptr_conv;
11019         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11020         this_ptr_conv.is_owned = false;
11021         UpdateAddHTLC_set_htlc_id(&this_ptr_conv, val);
11022 }
11023
11024 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
11025         LDKUpdateAddHTLC this_ptr_conv;
11026         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11027         this_ptr_conv.is_owned = false;
11028         jlong ret_val = UpdateAddHTLC_get_amount_msat(&this_ptr_conv);
11029         return ret_val;
11030 }
11031
11032 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11033         LDKUpdateAddHTLC this_ptr_conv;
11034         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11035         this_ptr_conv.is_owned = false;
11036         UpdateAddHTLC_set_amount_msat(&this_ptr_conv, val);
11037 }
11038
11039 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
11040         LDKUpdateAddHTLC this_ptr_conv;
11041         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11042         this_ptr_conv.is_owned = false;
11043         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11044         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateAddHTLC_get_payment_hash(&this_ptr_conv));
11045         return ret_arr;
11046 }
11047
11048 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11049         LDKUpdateAddHTLC this_ptr_conv;
11050         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11051         this_ptr_conv.is_owned = false;
11052         LDKThirtyTwoBytes val_ref;
11053         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11054         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11055         UpdateAddHTLC_set_payment_hash(&this_ptr_conv, val_ref);
11056 }
11057
11058 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr) {
11059         LDKUpdateAddHTLC this_ptr_conv;
11060         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11061         this_ptr_conv.is_owned = false;
11062         jint ret_val = UpdateAddHTLC_get_cltv_expiry(&this_ptr_conv);
11063         return ret_val;
11064 }
11065
11066 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
11067         LDKUpdateAddHTLC this_ptr_conv;
11068         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11069         this_ptr_conv.is_owned = false;
11070         UpdateAddHTLC_set_cltv_expiry(&this_ptr_conv, val);
11071 }
11072
11073 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11074         LDKUpdateFulfillHTLC this_ptr_conv;
11075         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11076         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11077         UpdateFulfillHTLC_free(this_ptr_conv);
11078 }
11079
11080 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11081         LDKUpdateFulfillHTLC orig_conv;
11082         orig_conv.inner = (void*)(orig & (~1));
11083         orig_conv.is_owned = false;
11084         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_clone(&orig_conv);
11085         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11086         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11087         long ret_ref = (long)ret_var.inner;
11088         if (ret_var.is_owned) {
11089                 ret_ref |= 1;
11090         }
11091         return ret_ref;
11092 }
11093
11094 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11095         LDKUpdateFulfillHTLC this_ptr_conv;
11096         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11097         this_ptr_conv.is_owned = false;
11098         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11099         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_channel_id(&this_ptr_conv));
11100         return ret_arr;
11101 }
11102
11103 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11104         LDKUpdateFulfillHTLC this_ptr_conv;
11105         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11106         this_ptr_conv.is_owned = false;
11107         LDKThirtyTwoBytes val_ref;
11108         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11109         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11110         UpdateFulfillHTLC_set_channel_id(&this_ptr_conv, val_ref);
11111 }
11112
11113 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11114         LDKUpdateFulfillHTLC this_ptr_conv;
11115         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11116         this_ptr_conv.is_owned = false;
11117         jlong ret_val = UpdateFulfillHTLC_get_htlc_id(&this_ptr_conv);
11118         return ret_val;
11119 }
11120
11121 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11122         LDKUpdateFulfillHTLC this_ptr_conv;
11123         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11124         this_ptr_conv.is_owned = false;
11125         UpdateFulfillHTLC_set_htlc_id(&this_ptr_conv, val);
11126 }
11127
11128 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1payment_1preimage(JNIEnv * _env, jclass _b, jlong this_ptr) {
11129         LDKUpdateFulfillHTLC this_ptr_conv;
11130         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11131         this_ptr_conv.is_owned = false;
11132         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11133         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_payment_preimage(&this_ptr_conv));
11134         return ret_arr;
11135 }
11136
11137 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1payment_1preimage(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11138         LDKUpdateFulfillHTLC this_ptr_conv;
11139         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11140         this_ptr_conv.is_owned = false;
11141         LDKThirtyTwoBytes val_ref;
11142         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11143         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11144         UpdateFulfillHTLC_set_payment_preimage(&this_ptr_conv, val_ref);
11145 }
11146
11147 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) {
11148         LDKThirtyTwoBytes channel_id_arg_ref;
11149         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
11150         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11151         LDKThirtyTwoBytes payment_preimage_arg_ref;
11152         CHECK((*_env)->GetArrayLength (_env, payment_preimage_arg) == 32);
11153         (*_env)->GetByteArrayRegion (_env, payment_preimage_arg, 0, 32, payment_preimage_arg_ref.data);
11154         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_new(channel_id_arg_ref, htlc_id_arg, payment_preimage_arg_ref);
11155         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11156         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11157         long ret_ref = (long)ret_var.inner;
11158         if (ret_var.is_owned) {
11159                 ret_ref |= 1;
11160         }
11161         return ret_ref;
11162 }
11163
11164 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11165         LDKUpdateFailHTLC this_ptr_conv;
11166         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11167         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11168         UpdateFailHTLC_free(this_ptr_conv);
11169 }
11170
11171 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11172         LDKUpdateFailHTLC orig_conv;
11173         orig_conv.inner = (void*)(orig & (~1));
11174         orig_conv.is_owned = false;
11175         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_clone(&orig_conv);
11176         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11177         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11178         long ret_ref = (long)ret_var.inner;
11179         if (ret_var.is_owned) {
11180                 ret_ref |= 1;
11181         }
11182         return ret_ref;
11183 }
11184
11185 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11186         LDKUpdateFailHTLC this_ptr_conv;
11187         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11188         this_ptr_conv.is_owned = false;
11189         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11190         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFailHTLC_get_channel_id(&this_ptr_conv));
11191         return ret_arr;
11192 }
11193
11194 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11195         LDKUpdateFailHTLC this_ptr_conv;
11196         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11197         this_ptr_conv.is_owned = false;
11198         LDKThirtyTwoBytes val_ref;
11199         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11200         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11201         UpdateFailHTLC_set_channel_id(&this_ptr_conv, val_ref);
11202 }
11203
11204 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11205         LDKUpdateFailHTLC this_ptr_conv;
11206         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11207         this_ptr_conv.is_owned = false;
11208         jlong ret_val = UpdateFailHTLC_get_htlc_id(&this_ptr_conv);
11209         return ret_val;
11210 }
11211
11212 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11213         LDKUpdateFailHTLC this_ptr_conv;
11214         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11215         this_ptr_conv.is_owned = false;
11216         UpdateFailHTLC_set_htlc_id(&this_ptr_conv, val);
11217 }
11218
11219 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11220         LDKUpdateFailMalformedHTLC this_ptr_conv;
11221         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11222         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11223         UpdateFailMalformedHTLC_free(this_ptr_conv);
11224 }
11225
11226 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11227         LDKUpdateFailMalformedHTLC orig_conv;
11228         orig_conv.inner = (void*)(orig & (~1));
11229         orig_conv.is_owned = false;
11230         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_clone(&orig_conv);
11231         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11232         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11233         long ret_ref = (long)ret_var.inner;
11234         if (ret_var.is_owned) {
11235                 ret_ref |= 1;
11236         }
11237         return ret_ref;
11238 }
11239
11240 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11241         LDKUpdateFailMalformedHTLC this_ptr_conv;
11242         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11243         this_ptr_conv.is_owned = false;
11244         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11245         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFailMalformedHTLC_get_channel_id(&this_ptr_conv));
11246         return ret_arr;
11247 }
11248
11249 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11250         LDKUpdateFailMalformedHTLC this_ptr_conv;
11251         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11252         this_ptr_conv.is_owned = false;
11253         LDKThirtyTwoBytes val_ref;
11254         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11255         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11256         UpdateFailMalformedHTLC_set_channel_id(&this_ptr_conv, val_ref);
11257 }
11258
11259 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11260         LDKUpdateFailMalformedHTLC this_ptr_conv;
11261         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11262         this_ptr_conv.is_owned = false;
11263         jlong ret_val = UpdateFailMalformedHTLC_get_htlc_id(&this_ptr_conv);
11264         return ret_val;
11265 }
11266
11267 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11268         LDKUpdateFailMalformedHTLC this_ptr_conv;
11269         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11270         this_ptr_conv.is_owned = false;
11271         UpdateFailMalformedHTLC_set_htlc_id(&this_ptr_conv, val);
11272 }
11273
11274 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1failure_1code(JNIEnv * _env, jclass _b, jlong this_ptr) {
11275         LDKUpdateFailMalformedHTLC this_ptr_conv;
11276         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11277         this_ptr_conv.is_owned = false;
11278         jshort ret_val = UpdateFailMalformedHTLC_get_failure_code(&this_ptr_conv);
11279         return ret_val;
11280 }
11281
11282 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1failure_1code(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
11283         LDKUpdateFailMalformedHTLC this_ptr_conv;
11284         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11285         this_ptr_conv.is_owned = false;
11286         UpdateFailMalformedHTLC_set_failure_code(&this_ptr_conv, val);
11287 }
11288
11289 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11290         LDKCommitmentSigned this_ptr_conv;
11291         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11292         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11293         CommitmentSigned_free(this_ptr_conv);
11294 }
11295
11296 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11297         LDKCommitmentSigned orig_conv;
11298         orig_conv.inner = (void*)(orig & (~1));
11299         orig_conv.is_owned = false;
11300         LDKCommitmentSigned ret_var = CommitmentSigned_clone(&orig_conv);
11301         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11302         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11303         long ret_ref = (long)ret_var.inner;
11304         if (ret_var.is_owned) {
11305                 ret_ref |= 1;
11306         }
11307         return ret_ref;
11308 }
11309
11310 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11311         LDKCommitmentSigned this_ptr_conv;
11312         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11313         this_ptr_conv.is_owned = false;
11314         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11315         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *CommitmentSigned_get_channel_id(&this_ptr_conv));
11316         return ret_arr;
11317 }
11318
11319 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11320         LDKCommitmentSigned this_ptr_conv;
11321         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11322         this_ptr_conv.is_owned = false;
11323         LDKThirtyTwoBytes val_ref;
11324         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11325         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11326         CommitmentSigned_set_channel_id(&this_ptr_conv, val_ref);
11327 }
11328
11329 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
11330         LDKCommitmentSigned this_ptr_conv;
11331         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11332         this_ptr_conv.is_owned = false;
11333         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
11334         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, CommitmentSigned_get_signature(&this_ptr_conv).compact_form);
11335         return arg_arr;
11336 }
11337
11338 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11339         LDKCommitmentSigned this_ptr_conv;
11340         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11341         this_ptr_conv.is_owned = false;
11342         LDKSignature val_ref;
11343         CHECK((*_env)->GetArrayLength (_env, val) == 64);
11344         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
11345         CommitmentSigned_set_signature(&this_ptr_conv, val_ref);
11346 }
11347
11348 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1htlc_1signatures(JNIEnv * _env, jclass _b, jlong this_ptr, jobjectArray val) {
11349         LDKCommitmentSigned this_ptr_conv;
11350         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11351         this_ptr_conv.is_owned = false;
11352         LDKCVec_SignatureZ val_constr;
11353         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
11354         if (val_constr.datalen > 0)
11355                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
11356         else
11357                 val_constr.data = NULL;
11358         for (size_t i = 0; i < val_constr.datalen; i++) {
11359                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, val, i);
11360                 LDKSignature arr_conv_8_ref;
11361                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
11362                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
11363                 val_constr.data[i] = arr_conv_8_ref;
11364         }
11365         CommitmentSigned_set_htlc_signatures(&this_ptr_conv, val_constr);
11366 }
11367
11368 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) {
11369         LDKThirtyTwoBytes channel_id_arg_ref;
11370         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
11371         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11372         LDKSignature signature_arg_ref;
11373         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
11374         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
11375         LDKCVec_SignatureZ htlc_signatures_arg_constr;
11376         htlc_signatures_arg_constr.datalen = (*_env)->GetArrayLength (_env, htlc_signatures_arg);
11377         if (htlc_signatures_arg_constr.datalen > 0)
11378                 htlc_signatures_arg_constr.data = MALLOC(htlc_signatures_arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
11379         else
11380                 htlc_signatures_arg_constr.data = NULL;
11381         for (size_t i = 0; i < htlc_signatures_arg_constr.datalen; i++) {
11382                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, htlc_signatures_arg, i);
11383                 LDKSignature arr_conv_8_ref;
11384                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
11385                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
11386                 htlc_signatures_arg_constr.data[i] = arr_conv_8_ref;
11387         }
11388         LDKCommitmentSigned ret_var = CommitmentSigned_new(channel_id_arg_ref, signature_arg_ref, htlc_signatures_arg_constr);
11389         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11390         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11391         long ret_ref = (long)ret_var.inner;
11392         if (ret_var.is_owned) {
11393                 ret_ref |= 1;
11394         }
11395         return ret_ref;
11396 }
11397
11398 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11399         LDKRevokeAndACK this_ptr_conv;
11400         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11401         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11402         RevokeAndACK_free(this_ptr_conv);
11403 }
11404
11405 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11406         LDKRevokeAndACK orig_conv;
11407         orig_conv.inner = (void*)(orig & (~1));
11408         orig_conv.is_owned = false;
11409         LDKRevokeAndACK ret_var = RevokeAndACK_clone(&orig_conv);
11410         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11411         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11412         long ret_ref = (long)ret_var.inner;
11413         if (ret_var.is_owned) {
11414                 ret_ref |= 1;
11415         }
11416         return ret_ref;
11417 }
11418
11419 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11420         LDKRevokeAndACK this_ptr_conv;
11421         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11422         this_ptr_conv.is_owned = false;
11423         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11424         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *RevokeAndACK_get_channel_id(&this_ptr_conv));
11425         return ret_arr;
11426 }
11427
11428 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11429         LDKRevokeAndACK this_ptr_conv;
11430         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11431         this_ptr_conv.is_owned = false;
11432         LDKThirtyTwoBytes val_ref;
11433         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11434         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11435         RevokeAndACK_set_channel_id(&this_ptr_conv, val_ref);
11436 }
11437
11438 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr) {
11439         LDKRevokeAndACK this_ptr_conv;
11440         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11441         this_ptr_conv.is_owned = false;
11442         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11443         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *RevokeAndACK_get_per_commitment_secret(&this_ptr_conv));
11444         return ret_arr;
11445 }
11446
11447 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11448         LDKRevokeAndACK this_ptr_conv;
11449         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11450         this_ptr_conv.is_owned = false;
11451         LDKThirtyTwoBytes val_ref;
11452         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11453         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11454         RevokeAndACK_set_per_commitment_secret(&this_ptr_conv, val_ref);
11455 }
11456
11457 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
11458         LDKRevokeAndACK this_ptr_conv;
11459         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11460         this_ptr_conv.is_owned = false;
11461         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
11462         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RevokeAndACK_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
11463         return arg_arr;
11464 }
11465
11466 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11467         LDKRevokeAndACK this_ptr_conv;
11468         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11469         this_ptr_conv.is_owned = false;
11470         LDKPublicKey val_ref;
11471         CHECK((*_env)->GetArrayLength (_env, val) == 33);
11472         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
11473         RevokeAndACK_set_next_per_commitment_point(&this_ptr_conv, val_ref);
11474 }
11475
11476 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) {
11477         LDKThirtyTwoBytes channel_id_arg_ref;
11478         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
11479         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11480         LDKThirtyTwoBytes per_commitment_secret_arg_ref;
11481         CHECK((*_env)->GetArrayLength (_env, per_commitment_secret_arg) == 32);
11482         (*_env)->GetByteArrayRegion (_env, per_commitment_secret_arg, 0, 32, per_commitment_secret_arg_ref.data);
11483         LDKPublicKey next_per_commitment_point_arg_ref;
11484         CHECK((*_env)->GetArrayLength (_env, next_per_commitment_point_arg) == 33);
11485         (*_env)->GetByteArrayRegion (_env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
11486         LDKRevokeAndACK ret_var = RevokeAndACK_new(channel_id_arg_ref, per_commitment_secret_arg_ref, next_per_commitment_point_arg_ref);
11487         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11488         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11489         long ret_ref = (long)ret_var.inner;
11490         if (ret_var.is_owned) {
11491                 ret_ref |= 1;
11492         }
11493         return ret_ref;
11494 }
11495
11496 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11497         LDKUpdateFee this_ptr_conv;
11498         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11499         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11500         UpdateFee_free(this_ptr_conv);
11501 }
11502
11503 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11504         LDKUpdateFee orig_conv;
11505         orig_conv.inner = (void*)(orig & (~1));
11506         orig_conv.is_owned = false;
11507         LDKUpdateFee ret_var = UpdateFee_clone(&orig_conv);
11508         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11509         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11510         long ret_ref = (long)ret_var.inner;
11511         if (ret_var.is_owned) {
11512                 ret_ref |= 1;
11513         }
11514         return ret_ref;
11515 }
11516
11517 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11518         LDKUpdateFee this_ptr_conv;
11519         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11520         this_ptr_conv.is_owned = false;
11521         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11522         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFee_get_channel_id(&this_ptr_conv));
11523         return ret_arr;
11524 }
11525
11526 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11527         LDKUpdateFee this_ptr_conv;
11528         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11529         this_ptr_conv.is_owned = false;
11530         LDKThirtyTwoBytes val_ref;
11531         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11532         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11533         UpdateFee_set_channel_id(&this_ptr_conv, val_ref);
11534 }
11535
11536 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr) {
11537         LDKUpdateFee this_ptr_conv;
11538         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11539         this_ptr_conv.is_owned = false;
11540         jint ret_val = UpdateFee_get_feerate_per_kw(&this_ptr_conv);
11541         return ret_val;
11542 }
11543
11544 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
11545         LDKUpdateFee this_ptr_conv;
11546         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11547         this_ptr_conv.is_owned = false;
11548         UpdateFee_set_feerate_per_kw(&this_ptr_conv, val);
11549 }
11550
11551 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jint feerate_per_kw_arg) {
11552         LDKThirtyTwoBytes channel_id_arg_ref;
11553         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
11554         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11555         LDKUpdateFee ret_var = UpdateFee_new(channel_id_arg_ref, feerate_per_kw_arg);
11556         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11557         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11558         long ret_ref = (long)ret_var.inner;
11559         if (ret_var.is_owned) {
11560                 ret_ref |= 1;
11561         }
11562         return ret_ref;
11563 }
11564
11565 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11566         LDKDataLossProtect this_ptr_conv;
11567         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11568         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11569         DataLossProtect_free(this_ptr_conv);
11570 }
11571
11572 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11573         LDKDataLossProtect orig_conv;
11574         orig_conv.inner = (void*)(orig & (~1));
11575         orig_conv.is_owned = false;
11576         LDKDataLossProtect ret_var = DataLossProtect_clone(&orig_conv);
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         return ret_ref;
11584 }
11585
11586 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1your_1last_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr) {
11587         LDKDataLossProtect this_ptr_conv;
11588         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11589         this_ptr_conv.is_owned = false;
11590         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11591         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *DataLossProtect_get_your_last_per_commitment_secret(&this_ptr_conv));
11592         return ret_arr;
11593 }
11594
11595 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1set_1your_1last_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11596         LDKDataLossProtect this_ptr_conv;
11597         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11598         this_ptr_conv.is_owned = false;
11599         LDKThirtyTwoBytes val_ref;
11600         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11601         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11602         DataLossProtect_set_your_last_per_commitment_secret(&this_ptr_conv, val_ref);
11603 }
11604
11605 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1my_1current_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
11606         LDKDataLossProtect this_ptr_conv;
11607         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11608         this_ptr_conv.is_owned = false;
11609         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
11610         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, DataLossProtect_get_my_current_per_commitment_point(&this_ptr_conv).compressed_form);
11611         return arg_arr;
11612 }
11613
11614 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1set_1my_1current_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11615         LDKDataLossProtect this_ptr_conv;
11616         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11617         this_ptr_conv.is_owned = false;
11618         LDKPublicKey val_ref;
11619         CHECK((*_env)->GetArrayLength (_env, val) == 33);
11620         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
11621         DataLossProtect_set_my_current_per_commitment_point(&this_ptr_conv, val_ref);
11622 }
11623
11624 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) {
11625         LDKThirtyTwoBytes your_last_per_commitment_secret_arg_ref;
11626         CHECK((*_env)->GetArrayLength (_env, your_last_per_commitment_secret_arg) == 32);
11627         (*_env)->GetByteArrayRegion (_env, your_last_per_commitment_secret_arg, 0, 32, your_last_per_commitment_secret_arg_ref.data);
11628         LDKPublicKey my_current_per_commitment_point_arg_ref;
11629         CHECK((*_env)->GetArrayLength (_env, my_current_per_commitment_point_arg) == 33);
11630         (*_env)->GetByteArrayRegion (_env, my_current_per_commitment_point_arg, 0, 33, my_current_per_commitment_point_arg_ref.compressed_form);
11631         LDKDataLossProtect ret_var = DataLossProtect_new(your_last_per_commitment_secret_arg_ref, my_current_per_commitment_point_arg_ref);
11632         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11633         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11634         long ret_ref = (long)ret_var.inner;
11635         if (ret_var.is_owned) {
11636                 ret_ref |= 1;
11637         }
11638         return ret_ref;
11639 }
11640
11641 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11642         LDKChannelReestablish this_ptr_conv;
11643         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11644         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11645         ChannelReestablish_free(this_ptr_conv);
11646 }
11647
11648 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11649         LDKChannelReestablish orig_conv;
11650         orig_conv.inner = (void*)(orig & (~1));
11651         orig_conv.is_owned = false;
11652         LDKChannelReestablish ret_var = ChannelReestablish_clone(&orig_conv);
11653         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11654         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11655         long ret_ref = (long)ret_var.inner;
11656         if (ret_var.is_owned) {
11657                 ret_ref |= 1;
11658         }
11659         return ret_ref;
11660 }
11661
11662 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11663         LDKChannelReestablish this_ptr_conv;
11664         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11665         this_ptr_conv.is_owned = false;
11666         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11667         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ChannelReestablish_get_channel_id(&this_ptr_conv));
11668         return ret_arr;
11669 }
11670
11671 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11672         LDKChannelReestablish this_ptr_conv;
11673         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11674         this_ptr_conv.is_owned = false;
11675         LDKThirtyTwoBytes val_ref;
11676         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11677         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11678         ChannelReestablish_set_channel_id(&this_ptr_conv, val_ref);
11679 }
11680
11681 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1local_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr) {
11682         LDKChannelReestablish this_ptr_conv;
11683         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11684         this_ptr_conv.is_owned = false;
11685         jlong ret_val = ChannelReestablish_get_next_local_commitment_number(&this_ptr_conv);
11686         return ret_val;
11687 }
11688
11689 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1next_1local_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11690         LDKChannelReestablish this_ptr_conv;
11691         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11692         this_ptr_conv.is_owned = false;
11693         ChannelReestablish_set_next_local_commitment_number(&this_ptr_conv, val);
11694 }
11695
11696 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1remote_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr) {
11697         LDKChannelReestablish this_ptr_conv;
11698         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11699         this_ptr_conv.is_owned = false;
11700         jlong ret_val = ChannelReestablish_get_next_remote_commitment_number(&this_ptr_conv);
11701         return ret_val;
11702 }
11703
11704 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1next_1remote_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11705         LDKChannelReestablish this_ptr_conv;
11706         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11707         this_ptr_conv.is_owned = false;
11708         ChannelReestablish_set_next_remote_commitment_number(&this_ptr_conv, val);
11709 }
11710
11711 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11712         LDKAnnouncementSignatures this_ptr_conv;
11713         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11714         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11715         AnnouncementSignatures_free(this_ptr_conv);
11716 }
11717
11718 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11719         LDKAnnouncementSignatures orig_conv;
11720         orig_conv.inner = (void*)(orig & (~1));
11721         orig_conv.is_owned = false;
11722         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_clone(&orig_conv);
11723         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11724         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11725         long ret_ref = (long)ret_var.inner;
11726         if (ret_var.is_owned) {
11727                 ret_ref |= 1;
11728         }
11729         return ret_ref;
11730 }
11731
11732 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11733         LDKAnnouncementSignatures this_ptr_conv;
11734         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11735         this_ptr_conv.is_owned = false;
11736         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11737         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *AnnouncementSignatures_get_channel_id(&this_ptr_conv));
11738         return ret_arr;
11739 }
11740
11741 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11742         LDKAnnouncementSignatures this_ptr_conv;
11743         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11744         this_ptr_conv.is_owned = false;
11745         LDKThirtyTwoBytes val_ref;
11746         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11747         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11748         AnnouncementSignatures_set_channel_id(&this_ptr_conv, val_ref);
11749 }
11750
11751 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11752         LDKAnnouncementSignatures this_ptr_conv;
11753         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11754         this_ptr_conv.is_owned = false;
11755         jlong ret_val = AnnouncementSignatures_get_short_channel_id(&this_ptr_conv);
11756         return ret_val;
11757 }
11758
11759 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11760         LDKAnnouncementSignatures this_ptr_conv;
11761         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11762         this_ptr_conv.is_owned = false;
11763         AnnouncementSignatures_set_short_channel_id(&this_ptr_conv, val);
11764 }
11765
11766 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1node_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
11767         LDKAnnouncementSignatures this_ptr_conv;
11768         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11769         this_ptr_conv.is_owned = false;
11770         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
11771         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, AnnouncementSignatures_get_node_signature(&this_ptr_conv).compact_form);
11772         return arg_arr;
11773 }
11774
11775 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1node_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11776         LDKAnnouncementSignatures this_ptr_conv;
11777         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11778         this_ptr_conv.is_owned = false;
11779         LDKSignature val_ref;
11780         CHECK((*_env)->GetArrayLength (_env, val) == 64);
11781         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
11782         AnnouncementSignatures_set_node_signature(&this_ptr_conv, val_ref);
11783 }
11784
11785 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1bitcoin_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
11786         LDKAnnouncementSignatures this_ptr_conv;
11787         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11788         this_ptr_conv.is_owned = false;
11789         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
11790         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, AnnouncementSignatures_get_bitcoin_signature(&this_ptr_conv).compact_form);
11791         return arg_arr;
11792 }
11793
11794 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1bitcoin_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11795         LDKAnnouncementSignatures this_ptr_conv;
11796         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11797         this_ptr_conv.is_owned = false;
11798         LDKSignature val_ref;
11799         CHECK((*_env)->GetArrayLength (_env, val) == 64);
11800         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
11801         AnnouncementSignatures_set_bitcoin_signature(&this_ptr_conv, val_ref);
11802 }
11803
11804 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) {
11805         LDKThirtyTwoBytes channel_id_arg_ref;
11806         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
11807         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
11808         LDKSignature node_signature_arg_ref;
11809         CHECK((*_env)->GetArrayLength (_env, node_signature_arg) == 64);
11810         (*_env)->GetByteArrayRegion (_env, node_signature_arg, 0, 64, node_signature_arg_ref.compact_form);
11811         LDKSignature bitcoin_signature_arg_ref;
11812         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_arg) == 64);
11813         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_arg, 0, 64, bitcoin_signature_arg_ref.compact_form);
11814         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_new(channel_id_arg_ref, short_channel_id_arg, node_signature_arg_ref, bitcoin_signature_arg_ref);
11815         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11816         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11817         long ret_ref = (long)ret_var.inner;
11818         if (ret_var.is_owned) {
11819                 ret_ref |= 1;
11820         }
11821         return ret_ref;
11822 }
11823
11824 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetAddress_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11825         LDKNetAddress this_ptr_conv = *(LDKNetAddress*)this_ptr;
11826         FREE((void*)this_ptr);
11827         NetAddress_free(this_ptr_conv);
11828 }
11829
11830 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetAddress_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11831         LDKNetAddress* orig_conv = (LDKNetAddress*)orig;
11832         LDKNetAddress *ret_copy = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress");
11833         *ret_copy = NetAddress_clone(orig_conv);
11834         long ret_ref = (long)ret_copy;
11835         return ret_ref;
11836 }
11837
11838 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NetAddress_1write(JNIEnv * _env, jclass _b, jlong obj) {
11839         LDKNetAddress* obj_conv = (LDKNetAddress*)obj;
11840         LDKCVec_u8Z arg_var = NetAddress_write(obj_conv);
11841         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11842         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11843         CVec_u8Z_free(arg_var);
11844         return arg_arr;
11845 }
11846
11847 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Result_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11848         LDKu8slice ser_ref;
11849         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11850         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11851         LDKCResult_CResult_NetAddressu8ZDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CResult_NetAddressu8ZDecodeErrorZ), "LDKCResult_CResult_NetAddressu8ZDecodeErrorZ");
11852         *ret_conv = Result_read(ser_ref);
11853         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11854         return (long)ret_conv;
11855 }
11856
11857 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11858         LDKUnsignedNodeAnnouncement this_ptr_conv;
11859         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11860         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11861         UnsignedNodeAnnouncement_free(this_ptr_conv);
11862 }
11863
11864 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11865         LDKUnsignedNodeAnnouncement orig_conv;
11866         orig_conv.inner = (void*)(orig & (~1));
11867         orig_conv.is_owned = false;
11868         LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_clone(&orig_conv);
11869         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11870         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11871         long ret_ref = (long)ret_var.inner;
11872         if (ret_var.is_owned) {
11873                 ret_ref |= 1;
11874         }
11875         return ret_ref;
11876 }
11877
11878 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
11879         LDKUnsignedNodeAnnouncement this_ptr_conv;
11880         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11881         this_ptr_conv.is_owned = false;
11882         LDKNodeFeatures ret_var = UnsignedNodeAnnouncement_get_features(&this_ptr_conv);
11883         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11884         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11885         long ret_ref = (long)ret_var.inner;
11886         if (ret_var.is_owned) {
11887                 ret_ref |= 1;
11888         }
11889         return ret_ref;
11890 }
11891
11892 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11893         LDKUnsignedNodeAnnouncement this_ptr_conv;
11894         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11895         this_ptr_conv.is_owned = false;
11896         LDKNodeFeatures val_conv;
11897         val_conv.inner = (void*)(val & (~1));
11898         val_conv.is_owned = (val & 1) || (val == 0);
11899         // Warning: we may need a move here but can't clone!
11900         UnsignedNodeAnnouncement_set_features(&this_ptr_conv, val_conv);
11901 }
11902
11903 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
11904         LDKUnsignedNodeAnnouncement this_ptr_conv;
11905         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11906         this_ptr_conv.is_owned = false;
11907         jint ret_val = UnsignedNodeAnnouncement_get_timestamp(&this_ptr_conv);
11908         return ret_val;
11909 }
11910
11911 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
11912         LDKUnsignedNodeAnnouncement this_ptr_conv;
11913         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11914         this_ptr_conv.is_owned = false;
11915         UnsignedNodeAnnouncement_set_timestamp(&this_ptr_conv, val);
11916 }
11917
11918 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
11919         LDKUnsignedNodeAnnouncement this_ptr_conv;
11920         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11921         this_ptr_conv.is_owned = false;
11922         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
11923         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedNodeAnnouncement_get_node_id(&this_ptr_conv).compressed_form);
11924         return arg_arr;
11925 }
11926
11927 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11928         LDKUnsignedNodeAnnouncement this_ptr_conv;
11929         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11930         this_ptr_conv.is_owned = false;
11931         LDKPublicKey val_ref;
11932         CHECK((*_env)->GetArrayLength (_env, val) == 33);
11933         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
11934         UnsignedNodeAnnouncement_set_node_id(&this_ptr_conv, val_ref);
11935 }
11936
11937 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr) {
11938         LDKUnsignedNodeAnnouncement this_ptr_conv;
11939         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11940         this_ptr_conv.is_owned = false;
11941         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 3);
11942         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 3, *UnsignedNodeAnnouncement_get_rgb(&this_ptr_conv));
11943         return ret_arr;
11944 }
11945
11946 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11947         LDKUnsignedNodeAnnouncement this_ptr_conv;
11948         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11949         this_ptr_conv.is_owned = false;
11950         LDKThreeBytes val_ref;
11951         CHECK((*_env)->GetArrayLength (_env, val) == 3);
11952         (*_env)->GetByteArrayRegion (_env, val, 0, 3, val_ref.data);
11953         UnsignedNodeAnnouncement_set_rgb(&this_ptr_conv, val_ref);
11954 }
11955
11956 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1alias(JNIEnv * _env, jclass _b, jlong this_ptr) {
11957         LDKUnsignedNodeAnnouncement this_ptr_conv;
11958         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11959         this_ptr_conv.is_owned = false;
11960         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
11961         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedNodeAnnouncement_get_alias(&this_ptr_conv));
11962         return ret_arr;
11963 }
11964
11965 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1alias(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
11966         LDKUnsignedNodeAnnouncement this_ptr_conv;
11967         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11968         this_ptr_conv.is_owned = false;
11969         LDKThirtyTwoBytes val_ref;
11970         CHECK((*_env)->GetArrayLength (_env, val) == 32);
11971         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
11972         UnsignedNodeAnnouncement_set_alias(&this_ptr_conv, val_ref);
11973 }
11974
11975 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1addresses(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
11976         LDKUnsignedNodeAnnouncement this_ptr_conv;
11977         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11978         this_ptr_conv.is_owned = false;
11979         LDKCVec_NetAddressZ val_constr;
11980         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
11981         if (val_constr.datalen > 0)
11982                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
11983         else
11984                 val_constr.data = NULL;
11985         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
11986         for (size_t m = 0; m < val_constr.datalen; m++) {
11987                 long arr_conv_12 = val_vals[m];
11988                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
11989                 FREE((void*)arr_conv_12);
11990                 val_constr.data[m] = arr_conv_12_conv;
11991         }
11992         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
11993         UnsignedNodeAnnouncement_set_addresses(&this_ptr_conv, val_constr);
11994 }
11995
11996 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11997         LDKNodeAnnouncement this_ptr_conv;
11998         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11999         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12000         NodeAnnouncement_free(this_ptr_conv);
12001 }
12002
12003 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12004         LDKNodeAnnouncement orig_conv;
12005         orig_conv.inner = (void*)(orig & (~1));
12006         orig_conv.is_owned = false;
12007         LDKNodeAnnouncement ret_var = NodeAnnouncement_clone(&orig_conv);
12008         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12009         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12010         long ret_ref = (long)ret_var.inner;
12011         if (ret_var.is_owned) {
12012                 ret_ref |= 1;
12013         }
12014         return ret_ref;
12015 }
12016
12017 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
12018         LDKNodeAnnouncement this_ptr_conv;
12019         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12020         this_ptr_conv.is_owned = false;
12021         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12022         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, NodeAnnouncement_get_signature(&this_ptr_conv).compact_form);
12023         return arg_arr;
12024 }
12025
12026 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12027         LDKNodeAnnouncement this_ptr_conv;
12028         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12029         this_ptr_conv.is_owned = false;
12030         LDKSignature val_ref;
12031         CHECK((*_env)->GetArrayLength (_env, val) == 64);
12032         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
12033         NodeAnnouncement_set_signature(&this_ptr_conv, val_ref);
12034 }
12035
12036 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
12037         LDKNodeAnnouncement this_ptr_conv;
12038         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12039         this_ptr_conv.is_owned = false;
12040         LDKUnsignedNodeAnnouncement ret_var = NodeAnnouncement_get_contents(&this_ptr_conv);
12041         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12042         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12043         long ret_ref = (long)ret_var.inner;
12044         if (ret_var.is_owned) {
12045                 ret_ref |= 1;
12046         }
12047         return ret_ref;
12048 }
12049
12050 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12051         LDKNodeAnnouncement this_ptr_conv;
12052         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12053         this_ptr_conv.is_owned = false;
12054         LDKUnsignedNodeAnnouncement val_conv;
12055         val_conv.inner = (void*)(val & (~1));
12056         val_conv.is_owned = (val & 1) || (val == 0);
12057         if (val_conv.inner != NULL)
12058                 val_conv = UnsignedNodeAnnouncement_clone(&val_conv);
12059         NodeAnnouncement_set_contents(&this_ptr_conv, val_conv);
12060 }
12061
12062 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1new(JNIEnv * _env, jclass _b, jbyteArray signature_arg, jlong contents_arg) {
12063         LDKSignature signature_arg_ref;
12064         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
12065         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
12066         LDKUnsignedNodeAnnouncement contents_arg_conv;
12067         contents_arg_conv.inner = (void*)(contents_arg & (~1));
12068         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
12069         if (contents_arg_conv.inner != NULL)
12070                 contents_arg_conv = UnsignedNodeAnnouncement_clone(&contents_arg_conv);
12071         LDKNodeAnnouncement ret_var = NodeAnnouncement_new(signature_arg_ref, contents_arg_conv);
12072         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12073         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12074         long ret_ref = (long)ret_var.inner;
12075         if (ret_var.is_owned) {
12076                 ret_ref |= 1;
12077         }
12078         return ret_ref;
12079 }
12080
12081 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12082         LDKUnsignedChannelAnnouncement this_ptr_conv;
12083         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12084         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12085         UnsignedChannelAnnouncement_free(this_ptr_conv);
12086 }
12087
12088 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12089         LDKUnsignedChannelAnnouncement orig_conv;
12090         orig_conv.inner = (void*)(orig & (~1));
12091         orig_conv.is_owned = false;
12092         LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_clone(&orig_conv);
12093         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12094         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12095         long ret_ref = (long)ret_var.inner;
12096         if (ret_var.is_owned) {
12097                 ret_ref |= 1;
12098         }
12099         return ret_ref;
12100 }
12101
12102 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
12103         LDKUnsignedChannelAnnouncement this_ptr_conv;
12104         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12105         this_ptr_conv.is_owned = false;
12106         LDKChannelFeatures ret_var = UnsignedChannelAnnouncement_get_features(&this_ptr_conv);
12107         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12108         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12109         long ret_ref = (long)ret_var.inner;
12110         if (ret_var.is_owned) {
12111                 ret_ref |= 1;
12112         }
12113         return ret_ref;
12114 }
12115
12116 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12117         LDKUnsignedChannelAnnouncement this_ptr_conv;
12118         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12119         this_ptr_conv.is_owned = false;
12120         LDKChannelFeatures val_conv;
12121         val_conv.inner = (void*)(val & (~1));
12122         val_conv.is_owned = (val & 1) || (val == 0);
12123         // Warning: we may need a move here but can't clone!
12124         UnsignedChannelAnnouncement_set_features(&this_ptr_conv, val_conv);
12125 }
12126
12127 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12128         LDKUnsignedChannelAnnouncement this_ptr_conv;
12129         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12130         this_ptr_conv.is_owned = false;
12131         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12132         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedChannelAnnouncement_get_chain_hash(&this_ptr_conv));
12133         return ret_arr;
12134 }
12135
12136 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12137         LDKUnsignedChannelAnnouncement this_ptr_conv;
12138         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12139         this_ptr_conv.is_owned = false;
12140         LDKThirtyTwoBytes val_ref;
12141         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12142         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12143         UnsignedChannelAnnouncement_set_chain_hash(&this_ptr_conv, val_ref);
12144 }
12145
12146 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
12147         LDKUnsignedChannelAnnouncement this_ptr_conv;
12148         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12149         this_ptr_conv.is_owned = false;
12150         jlong ret_val = UnsignedChannelAnnouncement_get_short_channel_id(&this_ptr_conv);
12151         return ret_val;
12152 }
12153
12154 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12155         LDKUnsignedChannelAnnouncement this_ptr_conv;
12156         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12157         this_ptr_conv.is_owned = false;
12158         UnsignedChannelAnnouncement_set_short_channel_id(&this_ptr_conv, val);
12159 }
12160
12161 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
12162         LDKUnsignedChannelAnnouncement this_ptr_conv;
12163         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12164         this_ptr_conv.is_owned = false;
12165         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12166         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_1(&this_ptr_conv).compressed_form);
12167         return arg_arr;
12168 }
12169
12170 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12171         LDKUnsignedChannelAnnouncement this_ptr_conv;
12172         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12173         this_ptr_conv.is_owned = false;
12174         LDKPublicKey val_ref;
12175         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12176         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12177         UnsignedChannelAnnouncement_set_node_id_1(&this_ptr_conv, val_ref);
12178 }
12179
12180 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
12181         LDKUnsignedChannelAnnouncement this_ptr_conv;
12182         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12183         this_ptr_conv.is_owned = false;
12184         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12185         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_2(&this_ptr_conv).compressed_form);
12186         return arg_arr;
12187 }
12188
12189 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12190         LDKUnsignedChannelAnnouncement this_ptr_conv;
12191         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12192         this_ptr_conv.is_owned = false;
12193         LDKPublicKey val_ref;
12194         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12195         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12196         UnsignedChannelAnnouncement_set_node_id_2(&this_ptr_conv, val_ref);
12197 }
12198
12199 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
12200         LDKUnsignedChannelAnnouncement this_ptr_conv;
12201         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12202         this_ptr_conv.is_owned = false;
12203         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12204         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_1(&this_ptr_conv).compressed_form);
12205         return arg_arr;
12206 }
12207
12208 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12209         LDKUnsignedChannelAnnouncement this_ptr_conv;
12210         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12211         this_ptr_conv.is_owned = false;
12212         LDKPublicKey val_ref;
12213         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12214         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12215         UnsignedChannelAnnouncement_set_bitcoin_key_1(&this_ptr_conv, val_ref);
12216 }
12217
12218 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
12219         LDKUnsignedChannelAnnouncement this_ptr_conv;
12220         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12221         this_ptr_conv.is_owned = false;
12222         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12223         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_2(&this_ptr_conv).compressed_form);
12224         return arg_arr;
12225 }
12226
12227 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12228         LDKUnsignedChannelAnnouncement this_ptr_conv;
12229         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12230         this_ptr_conv.is_owned = false;
12231         LDKPublicKey val_ref;
12232         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12233         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12234         UnsignedChannelAnnouncement_set_bitcoin_key_2(&this_ptr_conv, val_ref);
12235 }
12236
12237 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12238         LDKChannelAnnouncement this_ptr_conv;
12239         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12240         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12241         ChannelAnnouncement_free(this_ptr_conv);
12242 }
12243
12244 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12245         LDKChannelAnnouncement orig_conv;
12246         orig_conv.inner = (void*)(orig & (~1));
12247         orig_conv.is_owned = false;
12248         LDKChannelAnnouncement ret_var = ChannelAnnouncement_clone(&orig_conv);
12249         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12250         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12251         long ret_ref = (long)ret_var.inner;
12252         if (ret_var.is_owned) {
12253                 ret_ref |= 1;
12254         }
12255         return ret_ref;
12256 }
12257
12258 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
12259         LDKChannelAnnouncement this_ptr_conv;
12260         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12261         this_ptr_conv.is_owned = false;
12262         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12263         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_1(&this_ptr_conv).compact_form);
12264         return arg_arr;
12265 }
12266
12267 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12268         LDKChannelAnnouncement this_ptr_conv;
12269         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12270         this_ptr_conv.is_owned = false;
12271         LDKSignature val_ref;
12272         CHECK((*_env)->GetArrayLength (_env, val) == 64);
12273         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
12274         ChannelAnnouncement_set_node_signature_1(&this_ptr_conv, val_ref);
12275 }
12276
12277 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
12278         LDKChannelAnnouncement this_ptr_conv;
12279         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12280         this_ptr_conv.is_owned = false;
12281         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12282         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_2(&this_ptr_conv).compact_form);
12283         return arg_arr;
12284 }
12285
12286 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12287         LDKChannelAnnouncement this_ptr_conv;
12288         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12289         this_ptr_conv.is_owned = false;
12290         LDKSignature val_ref;
12291         CHECK((*_env)->GetArrayLength (_env, val) == 64);
12292         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
12293         ChannelAnnouncement_set_node_signature_2(&this_ptr_conv, val_ref);
12294 }
12295
12296 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
12297         LDKChannelAnnouncement this_ptr_conv;
12298         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12299         this_ptr_conv.is_owned = false;
12300         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12301         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_1(&this_ptr_conv).compact_form);
12302         return arg_arr;
12303 }
12304
12305 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12306         LDKChannelAnnouncement this_ptr_conv;
12307         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12308         this_ptr_conv.is_owned = false;
12309         LDKSignature val_ref;
12310         CHECK((*_env)->GetArrayLength (_env, val) == 64);
12311         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
12312         ChannelAnnouncement_set_bitcoin_signature_1(&this_ptr_conv, val_ref);
12313 }
12314
12315 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
12316         LDKChannelAnnouncement this_ptr_conv;
12317         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12318         this_ptr_conv.is_owned = false;
12319         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12320         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_2(&this_ptr_conv).compact_form);
12321         return arg_arr;
12322 }
12323
12324 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12325         LDKChannelAnnouncement this_ptr_conv;
12326         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12327         this_ptr_conv.is_owned = false;
12328         LDKSignature val_ref;
12329         CHECK((*_env)->GetArrayLength (_env, val) == 64);
12330         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
12331         ChannelAnnouncement_set_bitcoin_signature_2(&this_ptr_conv, val_ref);
12332 }
12333
12334 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
12335         LDKChannelAnnouncement this_ptr_conv;
12336         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12337         this_ptr_conv.is_owned = false;
12338         LDKUnsignedChannelAnnouncement ret_var = ChannelAnnouncement_get_contents(&this_ptr_conv);
12339         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12340         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12341         long ret_ref = (long)ret_var.inner;
12342         if (ret_var.is_owned) {
12343                 ret_ref |= 1;
12344         }
12345         return ret_ref;
12346 }
12347
12348 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12349         LDKChannelAnnouncement this_ptr_conv;
12350         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12351         this_ptr_conv.is_owned = false;
12352         LDKUnsignedChannelAnnouncement val_conv;
12353         val_conv.inner = (void*)(val & (~1));
12354         val_conv.is_owned = (val & 1) || (val == 0);
12355         if (val_conv.inner != NULL)
12356                 val_conv = UnsignedChannelAnnouncement_clone(&val_conv);
12357         ChannelAnnouncement_set_contents(&this_ptr_conv, val_conv);
12358 }
12359
12360 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) {
12361         LDKSignature node_signature_1_arg_ref;
12362         CHECK((*_env)->GetArrayLength (_env, node_signature_1_arg) == 64);
12363         (*_env)->GetByteArrayRegion (_env, node_signature_1_arg, 0, 64, node_signature_1_arg_ref.compact_form);
12364         LDKSignature node_signature_2_arg_ref;
12365         CHECK((*_env)->GetArrayLength (_env, node_signature_2_arg) == 64);
12366         (*_env)->GetByteArrayRegion (_env, node_signature_2_arg, 0, 64, node_signature_2_arg_ref.compact_form);
12367         LDKSignature bitcoin_signature_1_arg_ref;
12368         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_1_arg) == 64);
12369         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_1_arg, 0, 64, bitcoin_signature_1_arg_ref.compact_form);
12370         LDKSignature bitcoin_signature_2_arg_ref;
12371         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_2_arg) == 64);
12372         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_2_arg, 0, 64, bitcoin_signature_2_arg_ref.compact_form);
12373         LDKUnsignedChannelAnnouncement contents_arg_conv;
12374         contents_arg_conv.inner = (void*)(contents_arg & (~1));
12375         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
12376         if (contents_arg_conv.inner != NULL)
12377                 contents_arg_conv = UnsignedChannelAnnouncement_clone(&contents_arg_conv);
12378         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);
12379         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12380         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12381         long ret_ref = (long)ret_var.inner;
12382         if (ret_var.is_owned) {
12383                 ret_ref |= 1;
12384         }
12385         return ret_ref;
12386 }
12387
12388 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12389         LDKUnsignedChannelUpdate this_ptr_conv;
12390         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12391         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12392         UnsignedChannelUpdate_free(this_ptr_conv);
12393 }
12394
12395 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12396         LDKUnsignedChannelUpdate orig_conv;
12397         orig_conv.inner = (void*)(orig & (~1));
12398         orig_conv.is_owned = false;
12399         LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_clone(&orig_conv);
12400         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12401         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12402         long ret_ref = (long)ret_var.inner;
12403         if (ret_var.is_owned) {
12404                 ret_ref |= 1;
12405         }
12406         return ret_ref;
12407 }
12408
12409 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12410         LDKUnsignedChannelUpdate this_ptr_conv;
12411         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12412         this_ptr_conv.is_owned = false;
12413         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12414         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedChannelUpdate_get_chain_hash(&this_ptr_conv));
12415         return ret_arr;
12416 }
12417
12418 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12419         LDKUnsignedChannelUpdate this_ptr_conv;
12420         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12421         this_ptr_conv.is_owned = false;
12422         LDKThirtyTwoBytes val_ref;
12423         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12424         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12425         UnsignedChannelUpdate_set_chain_hash(&this_ptr_conv, val_ref);
12426 }
12427
12428 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
12429         LDKUnsignedChannelUpdate this_ptr_conv;
12430         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12431         this_ptr_conv.is_owned = false;
12432         jlong ret_val = UnsignedChannelUpdate_get_short_channel_id(&this_ptr_conv);
12433         return ret_val;
12434 }
12435
12436 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12437         LDKUnsignedChannelUpdate this_ptr_conv;
12438         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12439         this_ptr_conv.is_owned = false;
12440         UnsignedChannelUpdate_set_short_channel_id(&this_ptr_conv, val);
12441 }
12442
12443 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
12444         LDKUnsignedChannelUpdate this_ptr_conv;
12445         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12446         this_ptr_conv.is_owned = false;
12447         jint ret_val = UnsignedChannelUpdate_get_timestamp(&this_ptr_conv);
12448         return ret_val;
12449 }
12450
12451 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12452         LDKUnsignedChannelUpdate this_ptr_conv;
12453         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12454         this_ptr_conv.is_owned = false;
12455         UnsignedChannelUpdate_set_timestamp(&this_ptr_conv, val);
12456 }
12457
12458 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1flags(JNIEnv * _env, jclass _b, jlong this_ptr) {
12459         LDKUnsignedChannelUpdate this_ptr_conv;
12460         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12461         this_ptr_conv.is_owned = false;
12462         jbyte ret_val = UnsignedChannelUpdate_get_flags(&this_ptr_conv);
12463         return ret_val;
12464 }
12465
12466 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1flags(JNIEnv * _env, jclass _b, jlong this_ptr, jbyte val) {
12467         LDKUnsignedChannelUpdate this_ptr_conv;
12468         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12469         this_ptr_conv.is_owned = false;
12470         UnsignedChannelUpdate_set_flags(&this_ptr_conv, val);
12471 }
12472
12473 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
12474         LDKUnsignedChannelUpdate this_ptr_conv;
12475         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12476         this_ptr_conv.is_owned = false;
12477         jshort ret_val = UnsignedChannelUpdate_get_cltv_expiry_delta(&this_ptr_conv);
12478         return ret_val;
12479 }
12480
12481 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
12482         LDKUnsignedChannelUpdate this_ptr_conv;
12483         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12484         this_ptr_conv.is_owned = false;
12485         UnsignedChannelUpdate_set_cltv_expiry_delta(&this_ptr_conv, val);
12486 }
12487
12488 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
12489         LDKUnsignedChannelUpdate this_ptr_conv;
12490         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12491         this_ptr_conv.is_owned = false;
12492         jlong ret_val = UnsignedChannelUpdate_get_htlc_minimum_msat(&this_ptr_conv);
12493         return ret_val;
12494 }
12495
12496 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12497         LDKUnsignedChannelUpdate this_ptr_conv;
12498         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12499         this_ptr_conv.is_owned = false;
12500         UnsignedChannelUpdate_set_htlc_minimum_msat(&this_ptr_conv, val);
12501 }
12502
12503 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
12504         LDKUnsignedChannelUpdate this_ptr_conv;
12505         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12506         this_ptr_conv.is_owned = false;
12507         jint ret_val = UnsignedChannelUpdate_get_fee_base_msat(&this_ptr_conv);
12508         return ret_val;
12509 }
12510
12511 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12512         LDKUnsignedChannelUpdate this_ptr_conv;
12513         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12514         this_ptr_conv.is_owned = false;
12515         UnsignedChannelUpdate_set_fee_base_msat(&this_ptr_conv, val);
12516 }
12517
12518 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
12519         LDKUnsignedChannelUpdate this_ptr_conv;
12520         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12521         this_ptr_conv.is_owned = false;
12522         jint ret_val = UnsignedChannelUpdate_get_fee_proportional_millionths(&this_ptr_conv);
12523         return ret_val;
12524 }
12525
12526 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12527         LDKUnsignedChannelUpdate this_ptr_conv;
12528         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12529         this_ptr_conv.is_owned = false;
12530         UnsignedChannelUpdate_set_fee_proportional_millionths(&this_ptr_conv, val);
12531 }
12532
12533 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12534         LDKChannelUpdate this_ptr_conv;
12535         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12536         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12537         ChannelUpdate_free(this_ptr_conv);
12538 }
12539
12540 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12541         LDKChannelUpdate orig_conv;
12542         orig_conv.inner = (void*)(orig & (~1));
12543         orig_conv.is_owned = false;
12544         LDKChannelUpdate ret_var = ChannelUpdate_clone(&orig_conv);
12545         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12546         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12547         long ret_ref = (long)ret_var.inner;
12548         if (ret_var.is_owned) {
12549                 ret_ref |= 1;
12550         }
12551         return ret_ref;
12552 }
12553
12554 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
12555         LDKChannelUpdate this_ptr_conv;
12556         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12557         this_ptr_conv.is_owned = false;
12558         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12559         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelUpdate_get_signature(&this_ptr_conv).compact_form);
12560         return arg_arr;
12561 }
12562
12563 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12564         LDKChannelUpdate this_ptr_conv;
12565         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12566         this_ptr_conv.is_owned = false;
12567         LDKSignature val_ref;
12568         CHECK((*_env)->GetArrayLength (_env, val) == 64);
12569         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
12570         ChannelUpdate_set_signature(&this_ptr_conv, val_ref);
12571 }
12572
12573 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
12574         LDKChannelUpdate this_ptr_conv;
12575         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12576         this_ptr_conv.is_owned = false;
12577         LDKUnsignedChannelUpdate ret_var = ChannelUpdate_get_contents(&this_ptr_conv);
12578         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12579         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12580         long ret_ref = (long)ret_var.inner;
12581         if (ret_var.is_owned) {
12582                 ret_ref |= 1;
12583         }
12584         return ret_ref;
12585 }
12586
12587 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12588         LDKChannelUpdate this_ptr_conv;
12589         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12590         this_ptr_conv.is_owned = false;
12591         LDKUnsignedChannelUpdate val_conv;
12592         val_conv.inner = (void*)(val & (~1));
12593         val_conv.is_owned = (val & 1) || (val == 0);
12594         if (val_conv.inner != NULL)
12595                 val_conv = UnsignedChannelUpdate_clone(&val_conv);
12596         ChannelUpdate_set_contents(&this_ptr_conv, val_conv);
12597 }
12598
12599 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1new(JNIEnv * _env, jclass _b, jbyteArray signature_arg, jlong contents_arg) {
12600         LDKSignature signature_arg_ref;
12601         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
12602         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
12603         LDKUnsignedChannelUpdate contents_arg_conv;
12604         contents_arg_conv.inner = (void*)(contents_arg & (~1));
12605         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
12606         if (contents_arg_conv.inner != NULL)
12607                 contents_arg_conv = UnsignedChannelUpdate_clone(&contents_arg_conv);
12608         LDKChannelUpdate ret_var = ChannelUpdate_new(signature_arg_ref, contents_arg_conv);
12609         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12610         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12611         long ret_ref = (long)ret_var.inner;
12612         if (ret_var.is_owned) {
12613                 ret_ref |= 1;
12614         }
12615         return ret_ref;
12616 }
12617
12618 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12619         LDKQueryChannelRange this_ptr_conv;
12620         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12621         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12622         QueryChannelRange_free(this_ptr_conv);
12623 }
12624
12625 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12626         LDKQueryChannelRange orig_conv;
12627         orig_conv.inner = (void*)(orig & (~1));
12628         orig_conv.is_owned = false;
12629         LDKQueryChannelRange ret_var = QueryChannelRange_clone(&orig_conv);
12630         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12631         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12632         long ret_ref = (long)ret_var.inner;
12633         if (ret_var.is_owned) {
12634                 ret_ref |= 1;
12635         }
12636         return ret_ref;
12637 }
12638
12639 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12640         LDKQueryChannelRange this_ptr_conv;
12641         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12642         this_ptr_conv.is_owned = false;
12643         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12644         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *QueryChannelRange_get_chain_hash(&this_ptr_conv));
12645         return ret_arr;
12646 }
12647
12648 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12649         LDKQueryChannelRange this_ptr_conv;
12650         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12651         this_ptr_conv.is_owned = false;
12652         LDKThirtyTwoBytes val_ref;
12653         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12654         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12655         QueryChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
12656 }
12657
12658 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr) {
12659         LDKQueryChannelRange this_ptr_conv;
12660         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12661         this_ptr_conv.is_owned = false;
12662         jint ret_val = QueryChannelRange_get_first_blocknum(&this_ptr_conv);
12663         return ret_val;
12664 }
12665
12666 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12667         LDKQueryChannelRange this_ptr_conv;
12668         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12669         this_ptr_conv.is_owned = false;
12670         QueryChannelRange_set_first_blocknum(&this_ptr_conv, val);
12671 }
12672
12673 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr) {
12674         LDKQueryChannelRange this_ptr_conv;
12675         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12676         this_ptr_conv.is_owned = false;
12677         jint ret_val = QueryChannelRange_get_number_of_blocks(&this_ptr_conv);
12678         return ret_val;
12679 }
12680
12681 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12682         LDKQueryChannelRange this_ptr_conv;
12683         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12684         this_ptr_conv.is_owned = false;
12685         QueryChannelRange_set_number_of_blocks(&this_ptr_conv, val);
12686 }
12687
12688 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) {
12689         LDKThirtyTwoBytes chain_hash_arg_ref;
12690         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
12691         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12692         LDKQueryChannelRange ret_var = QueryChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg);
12693         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12694         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12695         long ret_ref = (long)ret_var.inner;
12696         if (ret_var.is_owned) {
12697                 ret_ref |= 1;
12698         }
12699         return ret_ref;
12700 }
12701
12702 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12703         LDKReplyChannelRange this_ptr_conv;
12704         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12705         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12706         ReplyChannelRange_free(this_ptr_conv);
12707 }
12708
12709 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12710         LDKReplyChannelRange orig_conv;
12711         orig_conv.inner = (void*)(orig & (~1));
12712         orig_conv.is_owned = false;
12713         LDKReplyChannelRange ret_var = ReplyChannelRange_clone(&orig_conv);
12714         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12715         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12716         long ret_ref = (long)ret_var.inner;
12717         if (ret_var.is_owned) {
12718                 ret_ref |= 1;
12719         }
12720         return ret_ref;
12721 }
12722
12723 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12724         LDKReplyChannelRange this_ptr_conv;
12725         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12726         this_ptr_conv.is_owned = false;
12727         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12728         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ReplyChannelRange_get_chain_hash(&this_ptr_conv));
12729         return ret_arr;
12730 }
12731
12732 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12733         LDKReplyChannelRange this_ptr_conv;
12734         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12735         this_ptr_conv.is_owned = false;
12736         LDKThirtyTwoBytes val_ref;
12737         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12738         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12739         ReplyChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
12740 }
12741
12742 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr) {
12743         LDKReplyChannelRange this_ptr_conv;
12744         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12745         this_ptr_conv.is_owned = false;
12746         jint ret_val = ReplyChannelRange_get_first_blocknum(&this_ptr_conv);
12747         return ret_val;
12748 }
12749
12750 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12751         LDKReplyChannelRange this_ptr_conv;
12752         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12753         this_ptr_conv.is_owned = false;
12754         ReplyChannelRange_set_first_blocknum(&this_ptr_conv, val);
12755 }
12756
12757 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr) {
12758         LDKReplyChannelRange this_ptr_conv;
12759         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12760         this_ptr_conv.is_owned = false;
12761         jint ret_val = ReplyChannelRange_get_number_of_blocks(&this_ptr_conv);
12762         return ret_val;
12763 }
12764
12765 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12766         LDKReplyChannelRange this_ptr_conv;
12767         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12768         this_ptr_conv.is_owned = false;
12769         ReplyChannelRange_set_number_of_blocks(&this_ptr_conv, val);
12770 }
12771
12772 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr) {
12773         LDKReplyChannelRange this_ptr_conv;
12774         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12775         this_ptr_conv.is_owned = false;
12776         jboolean ret_val = ReplyChannelRange_get_full_information(&this_ptr_conv);
12777         return ret_val;
12778 }
12779
12780 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
12781         LDKReplyChannelRange this_ptr_conv;
12782         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12783         this_ptr_conv.is_owned = false;
12784         ReplyChannelRange_set_full_information(&this_ptr_conv, val);
12785 }
12786
12787 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1short_1channel_1ids(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
12788         LDKReplyChannelRange this_ptr_conv;
12789         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12790         this_ptr_conv.is_owned = false;
12791         LDKCVec_u64Z val_constr;
12792         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
12793         if (val_constr.datalen > 0)
12794                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
12795         else
12796                 val_constr.data = NULL;
12797         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
12798         for (size_t g = 0; g < val_constr.datalen; g++) {
12799                 long arr_conv_6 = val_vals[g];
12800                 val_constr.data[g] = arr_conv_6;
12801         }
12802         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
12803         ReplyChannelRange_set_short_channel_ids(&this_ptr_conv, val_constr);
12804 }
12805
12806 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) {
12807         LDKThirtyTwoBytes chain_hash_arg_ref;
12808         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
12809         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12810         LDKCVec_u64Z short_channel_ids_arg_constr;
12811         short_channel_ids_arg_constr.datalen = (*_env)->GetArrayLength (_env, short_channel_ids_arg);
12812         if (short_channel_ids_arg_constr.datalen > 0)
12813                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
12814         else
12815                 short_channel_ids_arg_constr.data = NULL;
12816         long* short_channel_ids_arg_vals = (*_env)->GetLongArrayElements (_env, short_channel_ids_arg, NULL);
12817         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
12818                 long arr_conv_6 = short_channel_ids_arg_vals[g];
12819                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
12820         }
12821         (*_env)->ReleaseLongArrayElements (_env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
12822         LDKReplyChannelRange ret_var = ReplyChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg, full_information_arg, short_channel_ids_arg_constr);
12823         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12824         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12825         long ret_ref = (long)ret_var.inner;
12826         if (ret_var.is_owned) {
12827                 ret_ref |= 1;
12828         }
12829         return ret_ref;
12830 }
12831
12832 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12833         LDKQueryShortChannelIds this_ptr_conv;
12834         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12835         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12836         QueryShortChannelIds_free(this_ptr_conv);
12837 }
12838
12839 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12840         LDKQueryShortChannelIds orig_conv;
12841         orig_conv.inner = (void*)(orig & (~1));
12842         orig_conv.is_owned = false;
12843         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_clone(&orig_conv);
12844         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12845         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12846         long ret_ref = (long)ret_var.inner;
12847         if (ret_var.is_owned) {
12848                 ret_ref |= 1;
12849         }
12850         return ret_ref;
12851 }
12852
12853 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12854         LDKQueryShortChannelIds this_ptr_conv;
12855         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12856         this_ptr_conv.is_owned = false;
12857         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12858         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *QueryShortChannelIds_get_chain_hash(&this_ptr_conv));
12859         return ret_arr;
12860 }
12861
12862 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12863         LDKQueryShortChannelIds this_ptr_conv;
12864         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12865         this_ptr_conv.is_owned = false;
12866         LDKThirtyTwoBytes val_ref;
12867         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12868         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12869         QueryShortChannelIds_set_chain_hash(&this_ptr_conv, val_ref);
12870 }
12871
12872 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1short_1channel_1ids(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
12873         LDKQueryShortChannelIds this_ptr_conv;
12874         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12875         this_ptr_conv.is_owned = false;
12876         LDKCVec_u64Z val_constr;
12877         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
12878         if (val_constr.datalen > 0)
12879                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
12880         else
12881                 val_constr.data = NULL;
12882         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
12883         for (size_t g = 0; g < val_constr.datalen; g++) {
12884                 long arr_conv_6 = val_vals[g];
12885                 val_constr.data[g] = arr_conv_6;
12886         }
12887         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
12888         QueryShortChannelIds_set_short_channel_ids(&this_ptr_conv, val_constr);
12889 }
12890
12891 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1new(JNIEnv * _env, jclass _b, jbyteArray chain_hash_arg, jlongArray short_channel_ids_arg) {
12892         LDKThirtyTwoBytes chain_hash_arg_ref;
12893         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
12894         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12895         LDKCVec_u64Z short_channel_ids_arg_constr;
12896         short_channel_ids_arg_constr.datalen = (*_env)->GetArrayLength (_env, short_channel_ids_arg);
12897         if (short_channel_ids_arg_constr.datalen > 0)
12898                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
12899         else
12900                 short_channel_ids_arg_constr.data = NULL;
12901         long* short_channel_ids_arg_vals = (*_env)->GetLongArrayElements (_env, short_channel_ids_arg, NULL);
12902         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
12903                 long arr_conv_6 = short_channel_ids_arg_vals[g];
12904                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
12905         }
12906         (*_env)->ReleaseLongArrayElements (_env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
12907         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_new(chain_hash_arg_ref, short_channel_ids_arg_constr);
12908         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12909         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12910         long ret_ref = (long)ret_var.inner;
12911         if (ret_var.is_owned) {
12912                 ret_ref |= 1;
12913         }
12914         return ret_ref;
12915 }
12916
12917 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12918         LDKReplyShortChannelIdsEnd this_ptr_conv;
12919         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12920         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12921         ReplyShortChannelIdsEnd_free(this_ptr_conv);
12922 }
12923
12924 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12925         LDKReplyShortChannelIdsEnd orig_conv;
12926         orig_conv.inner = (void*)(orig & (~1));
12927         orig_conv.is_owned = false;
12928         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_clone(&orig_conv);
12929         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12930         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12931         long ret_ref = (long)ret_var.inner;
12932         if (ret_var.is_owned) {
12933                 ret_ref |= 1;
12934         }
12935         return ret_ref;
12936 }
12937
12938 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12939         LDKReplyShortChannelIdsEnd this_ptr_conv;
12940         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12941         this_ptr_conv.is_owned = false;
12942         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12943         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ReplyShortChannelIdsEnd_get_chain_hash(&this_ptr_conv));
12944         return ret_arr;
12945 }
12946
12947 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12948         LDKReplyShortChannelIdsEnd this_ptr_conv;
12949         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12950         this_ptr_conv.is_owned = false;
12951         LDKThirtyTwoBytes val_ref;
12952         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12953         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12954         ReplyShortChannelIdsEnd_set_chain_hash(&this_ptr_conv, val_ref);
12955 }
12956
12957 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr) {
12958         LDKReplyShortChannelIdsEnd this_ptr_conv;
12959         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12960         this_ptr_conv.is_owned = false;
12961         jboolean ret_val = ReplyShortChannelIdsEnd_get_full_information(&this_ptr_conv);
12962         return ret_val;
12963 }
12964
12965 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
12966         LDKReplyShortChannelIdsEnd this_ptr_conv;
12967         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12968         this_ptr_conv.is_owned = false;
12969         ReplyShortChannelIdsEnd_set_full_information(&this_ptr_conv, val);
12970 }
12971
12972 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1new(JNIEnv * _env, jclass _b, jbyteArray chain_hash_arg, jboolean full_information_arg) {
12973         LDKThirtyTwoBytes chain_hash_arg_ref;
12974         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
12975         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
12976         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_new(chain_hash_arg_ref, full_information_arg);
12977         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12978         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12979         long ret_ref = (long)ret_var.inner;
12980         if (ret_var.is_owned) {
12981                 ret_ref |= 1;
12982         }
12983         return ret_ref;
12984 }
12985
12986 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12987         LDKGossipTimestampFilter this_ptr_conv;
12988         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12989         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12990         GossipTimestampFilter_free(this_ptr_conv);
12991 }
12992
12993 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12994         LDKGossipTimestampFilter orig_conv;
12995         orig_conv.inner = (void*)(orig & (~1));
12996         orig_conv.is_owned = false;
12997         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_clone(&orig_conv);
12998         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12999         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13000         long ret_ref = (long)ret_var.inner;
13001         if (ret_var.is_owned) {
13002                 ret_ref |= 1;
13003         }
13004         return ret_ref;
13005 }
13006
13007 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
13008         LDKGossipTimestampFilter this_ptr_conv;
13009         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13010         this_ptr_conv.is_owned = false;
13011         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
13012         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *GossipTimestampFilter_get_chain_hash(&this_ptr_conv));
13013         return ret_arr;
13014 }
13015
13016 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13017         LDKGossipTimestampFilter this_ptr_conv;
13018         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13019         this_ptr_conv.is_owned = false;
13020         LDKThirtyTwoBytes val_ref;
13021         CHECK((*_env)->GetArrayLength (_env, val) == 32);
13022         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
13023         GossipTimestampFilter_set_chain_hash(&this_ptr_conv, val_ref);
13024 }
13025
13026 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1first_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
13027         LDKGossipTimestampFilter this_ptr_conv;
13028         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13029         this_ptr_conv.is_owned = false;
13030         jint ret_val = GossipTimestampFilter_get_first_timestamp(&this_ptr_conv);
13031         return ret_val;
13032 }
13033
13034 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1first_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13035         LDKGossipTimestampFilter this_ptr_conv;
13036         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13037         this_ptr_conv.is_owned = false;
13038         GossipTimestampFilter_set_first_timestamp(&this_ptr_conv, val);
13039 }
13040
13041 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1timestamp_1range(JNIEnv * _env, jclass _b, jlong this_ptr) {
13042         LDKGossipTimestampFilter this_ptr_conv;
13043         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13044         this_ptr_conv.is_owned = false;
13045         jint ret_val = GossipTimestampFilter_get_timestamp_range(&this_ptr_conv);
13046         return ret_val;
13047 }
13048
13049 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1timestamp_1range(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13050         LDKGossipTimestampFilter this_ptr_conv;
13051         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13052         this_ptr_conv.is_owned = false;
13053         GossipTimestampFilter_set_timestamp_range(&this_ptr_conv, val);
13054 }
13055
13056 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) {
13057         LDKThirtyTwoBytes chain_hash_arg_ref;
13058         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
13059         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
13060         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_new(chain_hash_arg_ref, first_timestamp_arg, timestamp_range_arg);
13061         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13062         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13063         long ret_ref = (long)ret_var.inner;
13064         if (ret_var.is_owned) {
13065                 ret_ref |= 1;
13066         }
13067         return ret_ref;
13068 }
13069
13070 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorAction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13071         LDKErrorAction this_ptr_conv = *(LDKErrorAction*)this_ptr;
13072         FREE((void*)this_ptr);
13073         ErrorAction_free(this_ptr_conv);
13074 }
13075
13076 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorAction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13077         LDKErrorAction* orig_conv = (LDKErrorAction*)orig;
13078         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
13079         *ret_copy = ErrorAction_clone(orig_conv);
13080         long ret_ref = (long)ret_copy;
13081         return ret_ref;
13082 }
13083
13084 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13085         LDKLightningError this_ptr_conv;
13086         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13087         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13088         LightningError_free(this_ptr_conv);
13089 }
13090
13091 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1err(JNIEnv * _env, jclass _b, jlong this_ptr) {
13092         LDKLightningError this_ptr_conv;
13093         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13094         this_ptr_conv.is_owned = false;
13095         LDKStr _str = LightningError_get_err(&this_ptr_conv);
13096         char* _buf = MALLOC(_str.len + 1, "str conv buf");
13097         memcpy(_buf, _str.chars, _str.len);
13098         _buf[_str.len] = 0;
13099         jstring _conv = (*_env)->NewStringUTF(_env, _str.chars);
13100         FREE(_buf);
13101         return _conv;
13102 }
13103
13104 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1err(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13105         LDKLightningError this_ptr_conv;
13106         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13107         this_ptr_conv.is_owned = false;
13108         LDKCVec_u8Z val_ref;
13109         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
13110         val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes");
13111         (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data);
13112         LightningError_set_err(&this_ptr_conv, val_ref);
13113 }
13114
13115 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1action(JNIEnv * _env, jclass _b, jlong this_ptr) {
13116         LDKLightningError this_ptr_conv;
13117         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13118         this_ptr_conv.is_owned = false;
13119         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
13120         *ret_copy = LightningError_get_action(&this_ptr_conv);
13121         long ret_ref = (long)ret_copy;
13122         return ret_ref;
13123 }
13124
13125 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1action(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13126         LDKLightningError this_ptr_conv;
13127         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13128         this_ptr_conv.is_owned = false;
13129         LDKErrorAction val_conv = *(LDKErrorAction*)val;
13130         FREE((void*)val);
13131         LightningError_set_action(&this_ptr_conv, val_conv);
13132 }
13133
13134 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LightningError_1new(JNIEnv * _env, jclass _b, jbyteArray err_arg, jlong action_arg) {
13135         LDKCVec_u8Z err_arg_ref;
13136         err_arg_ref.datalen = (*_env)->GetArrayLength (_env, err_arg);
13137         err_arg_ref.data = MALLOC(err_arg_ref.datalen, "LDKCVec_u8Z Bytes");
13138         (*_env)->GetByteArrayRegion(_env, err_arg, 0, err_arg_ref.datalen, err_arg_ref.data);
13139         LDKErrorAction action_arg_conv = *(LDKErrorAction*)action_arg;
13140         FREE((void*)action_arg);
13141         LDKLightningError ret_var = LightningError_new(err_arg_ref, action_arg_conv);
13142         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13143         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13144         long ret_ref = (long)ret_var.inner;
13145         if (ret_var.is_owned) {
13146                 ret_ref |= 1;
13147         }
13148         return ret_ref;
13149 }
13150
13151 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13152         LDKCommitmentUpdate this_ptr_conv;
13153         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13154         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13155         CommitmentUpdate_free(this_ptr_conv);
13156 }
13157
13158 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13159         LDKCommitmentUpdate orig_conv;
13160         orig_conv.inner = (void*)(orig & (~1));
13161         orig_conv.is_owned = false;
13162         LDKCommitmentUpdate ret_var = CommitmentUpdate_clone(&orig_conv);
13163         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13164         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13165         long ret_ref = (long)ret_var.inner;
13166         if (ret_var.is_owned) {
13167                 ret_ref |= 1;
13168         }
13169         return ret_ref;
13170 }
13171
13172 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1add_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
13173         LDKCommitmentUpdate this_ptr_conv;
13174         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13175         this_ptr_conv.is_owned = false;
13176         LDKCVec_UpdateAddHTLCZ val_constr;
13177         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
13178         if (val_constr.datalen > 0)
13179                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
13180         else
13181                 val_constr.data = NULL;
13182         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
13183         for (size_t p = 0; p < val_constr.datalen; p++) {
13184                 long arr_conv_15 = val_vals[p];
13185                 LDKUpdateAddHTLC arr_conv_15_conv;
13186                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
13187                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
13188                 if (arr_conv_15_conv.inner != NULL)
13189                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
13190                 val_constr.data[p] = arr_conv_15_conv;
13191         }
13192         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
13193         CommitmentUpdate_set_update_add_htlcs(&this_ptr_conv, val_constr);
13194 }
13195
13196 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fulfill_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
13197         LDKCommitmentUpdate this_ptr_conv;
13198         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13199         this_ptr_conv.is_owned = false;
13200         LDKCVec_UpdateFulfillHTLCZ val_constr;
13201         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
13202         if (val_constr.datalen > 0)
13203                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
13204         else
13205                 val_constr.data = NULL;
13206         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
13207         for (size_t t = 0; t < val_constr.datalen; t++) {
13208                 long arr_conv_19 = val_vals[t];
13209                 LDKUpdateFulfillHTLC arr_conv_19_conv;
13210                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
13211                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
13212                 if (arr_conv_19_conv.inner != NULL)
13213                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
13214                 val_constr.data[t] = arr_conv_19_conv;
13215         }
13216         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
13217         CommitmentUpdate_set_update_fulfill_htlcs(&this_ptr_conv, val_constr);
13218 }
13219
13220 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fail_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
13221         LDKCommitmentUpdate this_ptr_conv;
13222         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13223         this_ptr_conv.is_owned = false;
13224         LDKCVec_UpdateFailHTLCZ val_constr;
13225         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
13226         if (val_constr.datalen > 0)
13227                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
13228         else
13229                 val_constr.data = NULL;
13230         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
13231         for (size_t q = 0; q < val_constr.datalen; q++) {
13232                 long arr_conv_16 = val_vals[q];
13233                 LDKUpdateFailHTLC arr_conv_16_conv;
13234                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
13235                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
13236                 if (arr_conv_16_conv.inner != NULL)
13237                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
13238                 val_constr.data[q] = arr_conv_16_conv;
13239         }
13240         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
13241         CommitmentUpdate_set_update_fail_htlcs(&this_ptr_conv, val_constr);
13242 }
13243
13244 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fail_1malformed_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
13245         LDKCommitmentUpdate this_ptr_conv;
13246         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13247         this_ptr_conv.is_owned = false;
13248         LDKCVec_UpdateFailMalformedHTLCZ val_constr;
13249         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
13250         if (val_constr.datalen > 0)
13251                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
13252         else
13253                 val_constr.data = NULL;
13254         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
13255         for (size_t z = 0; z < val_constr.datalen; z++) {
13256                 long arr_conv_25 = val_vals[z];
13257                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
13258                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
13259                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
13260                 if (arr_conv_25_conv.inner != NULL)
13261                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
13262                 val_constr.data[z] = arr_conv_25_conv;
13263         }
13264         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
13265         CommitmentUpdate_set_update_fail_malformed_htlcs(&this_ptr_conv, val_constr);
13266 }
13267
13268 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1update_1fee(JNIEnv * _env, jclass _b, jlong this_ptr) {
13269         LDKCommitmentUpdate this_ptr_conv;
13270         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13271         this_ptr_conv.is_owned = false;
13272         LDKUpdateFee ret_var = CommitmentUpdate_get_update_fee(&this_ptr_conv);
13273         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13274         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13275         long ret_ref = (long)ret_var.inner;
13276         if (ret_var.is_owned) {
13277                 ret_ref |= 1;
13278         }
13279         return ret_ref;
13280 }
13281
13282 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fee(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13283         LDKCommitmentUpdate this_ptr_conv;
13284         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13285         this_ptr_conv.is_owned = false;
13286         LDKUpdateFee val_conv;
13287         val_conv.inner = (void*)(val & (~1));
13288         val_conv.is_owned = (val & 1) || (val == 0);
13289         if (val_conv.inner != NULL)
13290                 val_conv = UpdateFee_clone(&val_conv);
13291         CommitmentUpdate_set_update_fee(&this_ptr_conv, val_conv);
13292 }
13293
13294 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1commitment_1signed(JNIEnv * _env, jclass _b, jlong this_ptr) {
13295         LDKCommitmentUpdate this_ptr_conv;
13296         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13297         this_ptr_conv.is_owned = false;
13298         LDKCommitmentSigned ret_var = CommitmentUpdate_get_commitment_signed(&this_ptr_conv);
13299         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13300         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13301         long ret_ref = (long)ret_var.inner;
13302         if (ret_var.is_owned) {
13303                 ret_ref |= 1;
13304         }
13305         return ret_ref;
13306 }
13307
13308 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1commitment_1signed(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13309         LDKCommitmentUpdate this_ptr_conv;
13310         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13311         this_ptr_conv.is_owned = false;
13312         LDKCommitmentSigned val_conv;
13313         val_conv.inner = (void*)(val & (~1));
13314         val_conv.is_owned = (val & 1) || (val == 0);
13315         if (val_conv.inner != NULL)
13316                 val_conv = CommitmentSigned_clone(&val_conv);
13317         CommitmentUpdate_set_commitment_signed(&this_ptr_conv, val_conv);
13318 }
13319
13320 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) {
13321         LDKCVec_UpdateAddHTLCZ update_add_htlcs_arg_constr;
13322         update_add_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_add_htlcs_arg);
13323         if (update_add_htlcs_arg_constr.datalen > 0)
13324                 update_add_htlcs_arg_constr.data = MALLOC(update_add_htlcs_arg_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
13325         else
13326                 update_add_htlcs_arg_constr.data = NULL;
13327         long* update_add_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_add_htlcs_arg, NULL);
13328         for (size_t p = 0; p < update_add_htlcs_arg_constr.datalen; p++) {
13329                 long arr_conv_15 = update_add_htlcs_arg_vals[p];
13330                 LDKUpdateAddHTLC arr_conv_15_conv;
13331                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
13332                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
13333                 if (arr_conv_15_conv.inner != NULL)
13334                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
13335                 update_add_htlcs_arg_constr.data[p] = arr_conv_15_conv;
13336         }
13337         (*_env)->ReleaseLongArrayElements (_env, update_add_htlcs_arg, update_add_htlcs_arg_vals, 0);
13338         LDKCVec_UpdateFulfillHTLCZ update_fulfill_htlcs_arg_constr;
13339         update_fulfill_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fulfill_htlcs_arg);
13340         if (update_fulfill_htlcs_arg_constr.datalen > 0)
13341                 update_fulfill_htlcs_arg_constr.data = MALLOC(update_fulfill_htlcs_arg_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
13342         else
13343                 update_fulfill_htlcs_arg_constr.data = NULL;
13344         long* update_fulfill_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fulfill_htlcs_arg, NULL);
13345         for (size_t t = 0; t < update_fulfill_htlcs_arg_constr.datalen; t++) {
13346                 long arr_conv_19 = update_fulfill_htlcs_arg_vals[t];
13347                 LDKUpdateFulfillHTLC arr_conv_19_conv;
13348                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
13349                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
13350                 if (arr_conv_19_conv.inner != NULL)
13351                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
13352                 update_fulfill_htlcs_arg_constr.data[t] = arr_conv_19_conv;
13353         }
13354         (*_env)->ReleaseLongArrayElements (_env, update_fulfill_htlcs_arg, update_fulfill_htlcs_arg_vals, 0);
13355         LDKCVec_UpdateFailHTLCZ update_fail_htlcs_arg_constr;
13356         update_fail_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fail_htlcs_arg);
13357         if (update_fail_htlcs_arg_constr.datalen > 0)
13358                 update_fail_htlcs_arg_constr.data = MALLOC(update_fail_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
13359         else
13360                 update_fail_htlcs_arg_constr.data = NULL;
13361         long* update_fail_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fail_htlcs_arg, NULL);
13362         for (size_t q = 0; q < update_fail_htlcs_arg_constr.datalen; q++) {
13363                 long arr_conv_16 = update_fail_htlcs_arg_vals[q];
13364                 LDKUpdateFailHTLC arr_conv_16_conv;
13365                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
13366                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
13367                 if (arr_conv_16_conv.inner != NULL)
13368                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
13369                 update_fail_htlcs_arg_constr.data[q] = arr_conv_16_conv;
13370         }
13371         (*_env)->ReleaseLongArrayElements (_env, update_fail_htlcs_arg, update_fail_htlcs_arg_vals, 0);
13372         LDKCVec_UpdateFailMalformedHTLCZ update_fail_malformed_htlcs_arg_constr;
13373         update_fail_malformed_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fail_malformed_htlcs_arg);
13374         if (update_fail_malformed_htlcs_arg_constr.datalen > 0)
13375                 update_fail_malformed_htlcs_arg_constr.data = MALLOC(update_fail_malformed_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
13376         else
13377                 update_fail_malformed_htlcs_arg_constr.data = NULL;
13378         long* update_fail_malformed_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fail_malformed_htlcs_arg, NULL);
13379         for (size_t z = 0; z < update_fail_malformed_htlcs_arg_constr.datalen; z++) {
13380                 long arr_conv_25 = update_fail_malformed_htlcs_arg_vals[z];
13381                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
13382                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
13383                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
13384                 if (arr_conv_25_conv.inner != NULL)
13385                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
13386                 update_fail_malformed_htlcs_arg_constr.data[z] = arr_conv_25_conv;
13387         }
13388         (*_env)->ReleaseLongArrayElements (_env, update_fail_malformed_htlcs_arg, update_fail_malformed_htlcs_arg_vals, 0);
13389         LDKUpdateFee update_fee_arg_conv;
13390         update_fee_arg_conv.inner = (void*)(update_fee_arg & (~1));
13391         update_fee_arg_conv.is_owned = (update_fee_arg & 1) || (update_fee_arg == 0);
13392         if (update_fee_arg_conv.inner != NULL)
13393                 update_fee_arg_conv = UpdateFee_clone(&update_fee_arg_conv);
13394         LDKCommitmentSigned commitment_signed_arg_conv;
13395         commitment_signed_arg_conv.inner = (void*)(commitment_signed_arg & (~1));
13396         commitment_signed_arg_conv.is_owned = (commitment_signed_arg & 1) || (commitment_signed_arg == 0);
13397         if (commitment_signed_arg_conv.inner != NULL)
13398                 commitment_signed_arg_conv = CommitmentSigned_clone(&commitment_signed_arg_conv);
13399         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);
13400         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13401         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13402         long ret_ref = (long)ret_var.inner;
13403         if (ret_var.is_owned) {
13404                 ret_ref |= 1;
13405         }
13406         return ret_ref;
13407 }
13408
13409 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13410         LDKHTLCFailChannelUpdate this_ptr_conv = *(LDKHTLCFailChannelUpdate*)this_ptr;
13411         FREE((void*)this_ptr);
13412         HTLCFailChannelUpdate_free(this_ptr_conv);
13413 }
13414
13415 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13416         LDKHTLCFailChannelUpdate* orig_conv = (LDKHTLCFailChannelUpdate*)orig;
13417         LDKHTLCFailChannelUpdate *ret_copy = MALLOC(sizeof(LDKHTLCFailChannelUpdate), "LDKHTLCFailChannelUpdate");
13418         *ret_copy = HTLCFailChannelUpdate_clone(orig_conv);
13419         long ret_ref = (long)ret_copy;
13420         return ret_ref;
13421 }
13422
13423 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13424         LDKChannelMessageHandler this_ptr_conv = *(LDKChannelMessageHandler*)this_ptr;
13425         FREE((void*)this_ptr);
13426         ChannelMessageHandler_free(this_ptr_conv);
13427 }
13428
13429 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13430         LDKRoutingMessageHandler this_ptr_conv = *(LDKRoutingMessageHandler*)this_ptr;
13431         FREE((void*)this_ptr);
13432         RoutingMessageHandler_free(this_ptr_conv);
13433 }
13434
13435 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1write(JNIEnv * _env, jclass _b, jlong obj) {
13436         LDKAcceptChannel obj_conv;
13437         obj_conv.inner = (void*)(obj & (~1));
13438         obj_conv.is_owned = false;
13439         LDKCVec_u8Z arg_var = AcceptChannel_write(&obj_conv);
13440         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13441         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13442         CVec_u8Z_free(arg_var);
13443         return arg_arr;
13444 }
13445
13446 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13447         LDKu8slice ser_ref;
13448         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13449         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13450         LDKAcceptChannel ret_var = AcceptChannel_read(ser_ref);
13451         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13452         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13453         long ret_ref = (long)ret_var.inner;
13454         if (ret_var.is_owned) {
13455                 ret_ref |= 1;
13456         }
13457         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13458         return ret_ref;
13459 }
13460
13461 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1write(JNIEnv * _env, jclass _b, jlong obj) {
13462         LDKAnnouncementSignatures obj_conv;
13463         obj_conv.inner = (void*)(obj & (~1));
13464         obj_conv.is_owned = false;
13465         LDKCVec_u8Z arg_var = AnnouncementSignatures_write(&obj_conv);
13466         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13467         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13468         CVec_u8Z_free(arg_var);
13469         return arg_arr;
13470 }
13471
13472 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13473         LDKu8slice ser_ref;
13474         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13475         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13476         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_read(ser_ref);
13477         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13478         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13479         long ret_ref = (long)ret_var.inner;
13480         if (ret_var.is_owned) {
13481                 ret_ref |= 1;
13482         }
13483         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13484         return ret_ref;
13485 }
13486
13487 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1write(JNIEnv * _env, jclass _b, jlong obj) {
13488         LDKChannelReestablish obj_conv;
13489         obj_conv.inner = (void*)(obj & (~1));
13490         obj_conv.is_owned = false;
13491         LDKCVec_u8Z arg_var = ChannelReestablish_write(&obj_conv);
13492         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13493         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13494         CVec_u8Z_free(arg_var);
13495         return arg_arr;
13496 }
13497
13498 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13499         LDKu8slice ser_ref;
13500         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13501         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13502         LDKCResult_ChannelReestablishDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ChannelReestablishDecodeErrorZ), "LDKCResult_ChannelReestablishDecodeErrorZ");
13503         *ret_conv = ChannelReestablish_read(ser_ref);
13504         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13505         return (long)ret_conv;
13506 }
13507
13508 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
13509         LDKClosingSigned obj_conv;
13510         obj_conv.inner = (void*)(obj & (~1));
13511         obj_conv.is_owned = false;
13512         LDKCVec_u8Z arg_var = ClosingSigned_write(&obj_conv);
13513         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13514         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13515         CVec_u8Z_free(arg_var);
13516         return arg_arr;
13517 }
13518
13519 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13520         LDKu8slice ser_ref;
13521         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13522         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13523         LDKClosingSigned ret_var = ClosingSigned_read(ser_ref);
13524         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13525         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13526         long ret_ref = (long)ret_var.inner;
13527         if (ret_var.is_owned) {
13528                 ret_ref |= 1;
13529         }
13530         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13531         return ret_ref;
13532 }
13533
13534 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
13535         LDKCommitmentSigned obj_conv;
13536         obj_conv.inner = (void*)(obj & (~1));
13537         obj_conv.is_owned = false;
13538         LDKCVec_u8Z arg_var = CommitmentSigned_write(&obj_conv);
13539         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13540         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13541         CVec_u8Z_free(arg_var);
13542         return arg_arr;
13543 }
13544
13545 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13546         LDKu8slice ser_ref;
13547         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13548         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13549         LDKCommitmentSigned ret_var = CommitmentSigned_read(ser_ref);
13550         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13551         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13552         long ret_ref = (long)ret_var.inner;
13553         if (ret_var.is_owned) {
13554                 ret_ref |= 1;
13555         }
13556         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13557         return ret_ref;
13558 }
13559
13560 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1write(JNIEnv * _env, jclass _b, jlong obj) {
13561         LDKFundingCreated obj_conv;
13562         obj_conv.inner = (void*)(obj & (~1));
13563         obj_conv.is_owned = false;
13564         LDKCVec_u8Z arg_var = FundingCreated_write(&obj_conv);
13565         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13566         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13567         CVec_u8Z_free(arg_var);
13568         return arg_arr;
13569 }
13570
13571 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingCreated_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13572         LDKu8slice ser_ref;
13573         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13574         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13575         LDKFundingCreated ret_var = FundingCreated_read(ser_ref);
13576         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13577         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13578         long ret_ref = (long)ret_var.inner;
13579         if (ret_var.is_owned) {
13580                 ret_ref |= 1;
13581         }
13582         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13583         return ret_ref;
13584 }
13585
13586 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
13587         LDKFundingSigned obj_conv;
13588         obj_conv.inner = (void*)(obj & (~1));
13589         obj_conv.is_owned = false;
13590         LDKCVec_u8Z arg_var = FundingSigned_write(&obj_conv);
13591         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13592         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13593         CVec_u8Z_free(arg_var);
13594         return arg_arr;
13595 }
13596
13597 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13598         LDKu8slice ser_ref;
13599         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13600         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13601         LDKFundingSigned ret_var = FundingSigned_read(ser_ref);
13602         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13603         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13604         long ret_ref = (long)ret_var.inner;
13605         if (ret_var.is_owned) {
13606                 ret_ref |= 1;
13607         }
13608         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13609         return ret_ref;
13610 }
13611
13612 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1write(JNIEnv * _env, jclass _b, jlong obj) {
13613         LDKFundingLocked obj_conv;
13614         obj_conv.inner = (void*)(obj & (~1));
13615         obj_conv.is_owned = false;
13616         LDKCVec_u8Z arg_var = FundingLocked_write(&obj_conv);
13617         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13618         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13619         CVec_u8Z_free(arg_var);
13620         return arg_arr;
13621 }
13622
13623 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13624         LDKu8slice ser_ref;
13625         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13626         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13627         LDKFundingLocked ret_var = FundingLocked_read(ser_ref);
13628         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13629         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13630         long ret_ref = (long)ret_var.inner;
13631         if (ret_var.is_owned) {
13632                 ret_ref |= 1;
13633         }
13634         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13635         return ret_ref;
13636 }
13637
13638 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Init_1write(JNIEnv * _env, jclass _b, jlong obj) {
13639         LDKInit obj_conv;
13640         obj_conv.inner = (void*)(obj & (~1));
13641         obj_conv.is_owned = false;
13642         LDKCVec_u8Z arg_var = Init_write(&obj_conv);
13643         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13644         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13645         CVec_u8Z_free(arg_var);
13646         return arg_arr;
13647 }
13648
13649 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Init_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13650         LDKu8slice ser_ref;
13651         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13652         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13653         LDKCResult_InitDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_InitDecodeErrorZ), "LDKCResult_InitDecodeErrorZ");
13654         *ret_conv = Init_read(ser_ref);
13655         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13656         return (long)ret_conv;
13657 }
13658
13659 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1write(JNIEnv * _env, jclass _b, jlong obj) {
13660         LDKOpenChannel obj_conv;
13661         obj_conv.inner = (void*)(obj & (~1));
13662         obj_conv.is_owned = false;
13663         LDKCVec_u8Z arg_var = OpenChannel_write(&obj_conv);
13664         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13665         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13666         CVec_u8Z_free(arg_var);
13667         return arg_arr;
13668 }
13669
13670 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13671         LDKu8slice ser_ref;
13672         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13673         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13674         LDKOpenChannel ret_var = OpenChannel_read(ser_ref);
13675         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13676         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13677         long ret_ref = (long)ret_var.inner;
13678         if (ret_var.is_owned) {
13679                 ret_ref |= 1;
13680         }
13681         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13682         return ret_ref;
13683 }
13684
13685 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1write(JNIEnv * _env, jclass _b, jlong obj) {
13686         LDKRevokeAndACK obj_conv;
13687         obj_conv.inner = (void*)(obj & (~1));
13688         obj_conv.is_owned = false;
13689         LDKCVec_u8Z arg_var = RevokeAndACK_write(&obj_conv);
13690         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13691         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13692         CVec_u8Z_free(arg_var);
13693         return arg_arr;
13694 }
13695
13696 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13697         LDKu8slice ser_ref;
13698         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13699         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13700         LDKRevokeAndACK ret_var = RevokeAndACK_read(ser_ref);
13701         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13702         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13703         long ret_ref = (long)ret_var.inner;
13704         if (ret_var.is_owned) {
13705                 ret_ref |= 1;
13706         }
13707         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13708         return ret_ref;
13709 }
13710
13711 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1write(JNIEnv * _env, jclass _b, jlong obj) {
13712         LDKShutdown obj_conv;
13713         obj_conv.inner = (void*)(obj & (~1));
13714         obj_conv.is_owned = false;
13715         LDKCVec_u8Z arg_var = Shutdown_write(&obj_conv);
13716         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13717         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13718         CVec_u8Z_free(arg_var);
13719         return arg_arr;
13720 }
13721
13722 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13723         LDKu8slice ser_ref;
13724         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13725         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13726         LDKShutdown ret_var = Shutdown_read(ser_ref);
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         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13734         return ret_ref;
13735 }
13736
13737 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
13738         LDKUpdateFailHTLC obj_conv;
13739         obj_conv.inner = (void*)(obj & (~1));
13740         obj_conv.is_owned = false;
13741         LDKCVec_u8Z arg_var = UpdateFailHTLC_write(&obj_conv);
13742         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13743         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13744         CVec_u8Z_free(arg_var);
13745         return arg_arr;
13746 }
13747
13748 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13749         LDKu8slice ser_ref;
13750         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13751         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13752         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_read(ser_ref);
13753         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13754         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13755         long ret_ref = (long)ret_var.inner;
13756         if (ret_var.is_owned) {
13757                 ret_ref |= 1;
13758         }
13759         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13760         return ret_ref;
13761 }
13762
13763 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
13764         LDKUpdateFailMalformedHTLC obj_conv;
13765         obj_conv.inner = (void*)(obj & (~1));
13766         obj_conv.is_owned = false;
13767         LDKCVec_u8Z arg_var = UpdateFailMalformedHTLC_write(&obj_conv);
13768         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13769         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13770         CVec_u8Z_free(arg_var);
13771         return arg_arr;
13772 }
13773
13774 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13775         LDKu8slice ser_ref;
13776         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13777         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13778         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_read(ser_ref);
13779         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13780         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13781         long ret_ref = (long)ret_var.inner;
13782         if (ret_var.is_owned) {
13783                 ret_ref |= 1;
13784         }
13785         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13786         return ret_ref;
13787 }
13788
13789 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1write(JNIEnv * _env, jclass _b, jlong obj) {
13790         LDKUpdateFee obj_conv;
13791         obj_conv.inner = (void*)(obj & (~1));
13792         obj_conv.is_owned = false;
13793         LDKCVec_u8Z arg_var = UpdateFee_write(&obj_conv);
13794         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13795         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13796         CVec_u8Z_free(arg_var);
13797         return arg_arr;
13798 }
13799
13800 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13801         LDKu8slice ser_ref;
13802         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13803         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13804         LDKUpdateFee ret_var = UpdateFee_read(ser_ref);
13805         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13806         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13807         long ret_ref = (long)ret_var.inner;
13808         if (ret_var.is_owned) {
13809                 ret_ref |= 1;
13810         }
13811         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13812         return ret_ref;
13813 }
13814
13815 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
13816         LDKUpdateFulfillHTLC obj_conv;
13817         obj_conv.inner = (void*)(obj & (~1));
13818         obj_conv.is_owned = false;
13819         LDKCVec_u8Z arg_var = UpdateFulfillHTLC_write(&obj_conv);
13820         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13821         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13822         CVec_u8Z_free(arg_var);
13823         return arg_arr;
13824 }
13825
13826 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13827         LDKu8slice ser_ref;
13828         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13829         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13830         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_read(ser_ref);
13831         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13832         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13833         long ret_ref = (long)ret_var.inner;
13834         if (ret_var.is_owned) {
13835                 ret_ref |= 1;
13836         }
13837         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13838         return ret_ref;
13839 }
13840
13841 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
13842         LDKUpdateAddHTLC obj_conv;
13843         obj_conv.inner = (void*)(obj & (~1));
13844         obj_conv.is_owned = false;
13845         LDKCVec_u8Z arg_var = UpdateAddHTLC_write(&obj_conv);
13846         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13847         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13848         CVec_u8Z_free(arg_var);
13849         return arg_arr;
13850 }
13851
13852 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13853         LDKu8slice ser_ref;
13854         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13855         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13856         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_read(ser_ref);
13857         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13858         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13859         long ret_ref = (long)ret_var.inner;
13860         if (ret_var.is_owned) {
13861                 ret_ref |= 1;
13862         }
13863         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13864         return ret_ref;
13865 }
13866
13867 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Ping_1write(JNIEnv * _env, jclass _b, jlong obj) {
13868         LDKPing obj_conv;
13869         obj_conv.inner = (void*)(obj & (~1));
13870         obj_conv.is_owned = false;
13871         LDKCVec_u8Z arg_var = Ping_write(&obj_conv);
13872         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13873         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13874         CVec_u8Z_free(arg_var);
13875         return arg_arr;
13876 }
13877
13878 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13879         LDKu8slice ser_ref;
13880         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13881         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13882         LDKCResult_PingDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PingDecodeErrorZ), "LDKCResult_PingDecodeErrorZ");
13883         *ret_conv = Ping_read(ser_ref);
13884         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13885         return (long)ret_conv;
13886 }
13887
13888 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Pong_1write(JNIEnv * _env, jclass _b, jlong obj) {
13889         LDKPong obj_conv;
13890         obj_conv.inner = (void*)(obj & (~1));
13891         obj_conv.is_owned = false;
13892         LDKCVec_u8Z arg_var = Pong_write(&obj_conv);
13893         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13894         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13895         CVec_u8Z_free(arg_var);
13896         return arg_arr;
13897 }
13898
13899 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13900         LDKu8slice ser_ref;
13901         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13902         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13903         LDKCResult_PongDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PongDecodeErrorZ), "LDKCResult_PongDecodeErrorZ");
13904         *ret_conv = Pong_read(ser_ref);
13905         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13906         return (long)ret_conv;
13907 }
13908
13909 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
13910         LDKUnsignedChannelAnnouncement obj_conv;
13911         obj_conv.inner = (void*)(obj & (~1));
13912         obj_conv.is_owned = false;
13913         LDKCVec_u8Z arg_var = UnsignedChannelAnnouncement_write(&obj_conv);
13914         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13915         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13916         CVec_u8Z_free(arg_var);
13917         return arg_arr;
13918 }
13919
13920 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13921         LDKu8slice ser_ref;
13922         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13923         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13924         LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ), "LDKCResult_UnsignedChannelAnnouncementDecodeErrorZ");
13925         *ret_conv = UnsignedChannelAnnouncement_read(ser_ref);
13926         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13927         return (long)ret_conv;
13928 }
13929
13930 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
13931         LDKChannelAnnouncement obj_conv;
13932         obj_conv.inner = (void*)(obj & (~1));
13933         obj_conv.is_owned = false;
13934         LDKCVec_u8Z arg_var = ChannelAnnouncement_write(&obj_conv);
13935         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13936         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13937         CVec_u8Z_free(arg_var);
13938         return arg_arr;
13939 }
13940
13941 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13942         LDKu8slice ser_ref;
13943         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13944         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13945         LDKChannelAnnouncement ret_var = ChannelAnnouncement_read(ser_ref);
13946         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13947         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13948         long ret_ref = (long)ret_var.inner;
13949         if (ret_var.is_owned) {
13950                 ret_ref |= 1;
13951         }
13952         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13953         return ret_ref;
13954 }
13955
13956 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
13957         LDKUnsignedChannelUpdate obj_conv;
13958         obj_conv.inner = (void*)(obj & (~1));
13959         obj_conv.is_owned = false;
13960         LDKCVec_u8Z arg_var = UnsignedChannelUpdate_write(&obj_conv);
13961         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13962         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13963         CVec_u8Z_free(arg_var);
13964         return arg_arr;
13965 }
13966
13967 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13968         LDKu8slice ser_ref;
13969         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13970         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13971         LDKCResult_UnsignedChannelUpdateDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedChannelUpdateDecodeErrorZ), "LDKCResult_UnsignedChannelUpdateDecodeErrorZ");
13972         *ret_conv = UnsignedChannelUpdate_read(ser_ref);
13973         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13974         return (long)ret_conv;
13975 }
13976
13977 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
13978         LDKChannelUpdate obj_conv;
13979         obj_conv.inner = (void*)(obj & (~1));
13980         obj_conv.is_owned = false;
13981         LDKCVec_u8Z arg_var = ChannelUpdate_write(&obj_conv);
13982         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13983         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13984         CVec_u8Z_free(arg_var);
13985         return arg_arr;
13986 }
13987
13988 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13989         LDKu8slice ser_ref;
13990         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13991         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13992         LDKChannelUpdate ret_var = ChannelUpdate_read(ser_ref);
13993         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13994         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13995         long ret_ref = (long)ret_var.inner;
13996         if (ret_var.is_owned) {
13997                 ret_ref |= 1;
13998         }
13999         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14000         return ret_ref;
14001 }
14002
14003 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1write(JNIEnv * _env, jclass _b, jlong obj) {
14004         LDKErrorMessage obj_conv;
14005         obj_conv.inner = (void*)(obj & (~1));
14006         obj_conv.is_owned = false;
14007         LDKCVec_u8Z arg_var = ErrorMessage_write(&obj_conv);
14008         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14009         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14010         CVec_u8Z_free(arg_var);
14011         return arg_arr;
14012 }
14013
14014 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14015         LDKu8slice ser_ref;
14016         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14017         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14018         LDKCResult_ErrorMessageDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ErrorMessageDecodeErrorZ), "LDKCResult_ErrorMessageDecodeErrorZ");
14019         *ret_conv = ErrorMessage_read(ser_ref);
14020         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14021         return (long)ret_conv;
14022 }
14023
14024 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
14025         LDKUnsignedNodeAnnouncement obj_conv;
14026         obj_conv.inner = (void*)(obj & (~1));
14027         obj_conv.is_owned = false;
14028         LDKCVec_u8Z arg_var = UnsignedNodeAnnouncement_write(&obj_conv);
14029         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14030         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14031         CVec_u8Z_free(arg_var);
14032         return arg_arr;
14033 }
14034
14035 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14036         LDKu8slice ser_ref;
14037         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14038         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14039         LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ), "LDKCResult_UnsignedNodeAnnouncementDecodeErrorZ");
14040         *ret_conv = UnsignedNodeAnnouncement_read(ser_ref);
14041         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14042         return (long)ret_conv;
14043 }
14044
14045 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
14046         LDKNodeAnnouncement obj_conv;
14047         obj_conv.inner = (void*)(obj & (~1));
14048         obj_conv.is_owned = false;
14049         LDKCVec_u8Z arg_var = NodeAnnouncement_write(&obj_conv);
14050         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14051         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14052         CVec_u8Z_free(arg_var);
14053         return arg_arr;
14054 }
14055
14056 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14057         LDKu8slice ser_ref;
14058         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14059         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14060         LDKNodeAnnouncement ret_var = NodeAnnouncement_read(ser_ref);
14061         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14062         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14063         long ret_ref = (long)ret_var.inner;
14064         if (ret_var.is_owned) {
14065                 ret_ref |= 1;
14066         }
14067         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14068         return ret_ref;
14069 }
14070
14071 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14072         LDKu8slice ser_ref;
14073         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14074         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14075         LDKCResult_QueryShortChannelIdsDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryShortChannelIdsDecodeErrorZ), "LDKCResult_QueryShortChannelIdsDecodeErrorZ");
14076         *ret_conv = QueryShortChannelIds_read(ser_ref);
14077         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14078         return (long)ret_conv;
14079 }
14080
14081 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1write(JNIEnv * _env, jclass _b, jlong obj) {
14082         LDKQueryShortChannelIds obj_conv;
14083         obj_conv.inner = (void*)(obj & (~1));
14084         obj_conv.is_owned = false;
14085         LDKCVec_u8Z arg_var = QueryShortChannelIds_write(&obj_conv);
14086         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14087         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14088         CVec_u8Z_free(arg_var);
14089         return arg_arr;
14090 }
14091
14092 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14093         LDKu8slice ser_ref;
14094         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14095         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14096         LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ), "LDKCResult_ReplyShortChannelIdsEndDecodeErrorZ");
14097         *ret_conv = ReplyShortChannelIdsEnd_read(ser_ref);
14098         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14099         return (long)ret_conv;
14100 }
14101
14102 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1write(JNIEnv * _env, jclass _b, jlong obj) {
14103         LDKReplyShortChannelIdsEnd obj_conv;
14104         obj_conv.inner = (void*)(obj & (~1));
14105         obj_conv.is_owned = false;
14106         LDKCVec_u8Z arg_var = ReplyShortChannelIdsEnd_write(&obj_conv);
14107         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14108         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14109         CVec_u8Z_free(arg_var);
14110         return arg_arr;
14111 }
14112
14113 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14114         LDKu8slice ser_ref;
14115         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14116         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14117         LDKCResult_QueryChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_QueryChannelRangeDecodeErrorZ), "LDKCResult_QueryChannelRangeDecodeErrorZ");
14118         *ret_conv = QueryChannelRange_read(ser_ref);
14119         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14120         return (long)ret_conv;
14121 }
14122
14123 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1write(JNIEnv * _env, jclass _b, jlong obj) {
14124         LDKQueryChannelRange obj_conv;
14125         obj_conv.inner = (void*)(obj & (~1));
14126         obj_conv.is_owned = false;
14127         LDKCVec_u8Z arg_var = QueryChannelRange_write(&obj_conv);
14128         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14129         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14130         CVec_u8Z_free(arg_var);
14131         return arg_arr;
14132 }
14133
14134 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14135         LDKu8slice ser_ref;
14136         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14137         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14138         LDKCResult_ReplyChannelRangeDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_ReplyChannelRangeDecodeErrorZ), "LDKCResult_ReplyChannelRangeDecodeErrorZ");
14139         *ret_conv = ReplyChannelRange_read(ser_ref);
14140         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14141         return (long)ret_conv;
14142 }
14143
14144 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1write(JNIEnv * _env, jclass _b, jlong obj) {
14145         LDKReplyChannelRange obj_conv;
14146         obj_conv.inner = (void*)(obj & (~1));
14147         obj_conv.is_owned = false;
14148         LDKCVec_u8Z arg_var = ReplyChannelRange_write(&obj_conv);
14149         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14150         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14151         CVec_u8Z_free(arg_var);
14152         return arg_arr;
14153 }
14154
14155 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14156         LDKu8slice ser_ref;
14157         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14158         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14159         LDKCResult_GossipTimestampFilterDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_GossipTimestampFilterDecodeErrorZ), "LDKCResult_GossipTimestampFilterDecodeErrorZ");
14160         *ret_conv = GossipTimestampFilter_read(ser_ref);
14161         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14162         return (long)ret_conv;
14163 }
14164
14165 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1write(JNIEnv * _env, jclass _b, jlong obj) {
14166         LDKGossipTimestampFilter obj_conv;
14167         obj_conv.inner = (void*)(obj & (~1));
14168         obj_conv.is_owned = false;
14169         LDKCVec_u8Z arg_var = GossipTimestampFilter_write(&obj_conv);
14170         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14171         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14172         CVec_u8Z_free(arg_var);
14173         return arg_arr;
14174 }
14175
14176 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14177         LDKMessageHandler this_ptr_conv;
14178         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14179         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14180         MessageHandler_free(this_ptr_conv);
14181 }
14182
14183 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1chan_1handler(JNIEnv * _env, jclass _b, jlong this_ptr) {
14184         LDKMessageHandler this_ptr_conv;
14185         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14186         this_ptr_conv.is_owned = false;
14187         long ret_ret = (long)MessageHandler_get_chan_handler(&this_ptr_conv);
14188         return ret_ret;
14189 }
14190
14191 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1chan_1handler(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14192         LDKMessageHandler this_ptr_conv;
14193         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14194         this_ptr_conv.is_owned = false;
14195         LDKChannelMessageHandler val_conv = *(LDKChannelMessageHandler*)val;
14196         if (val_conv.free == LDKChannelMessageHandler_JCalls_free) {
14197                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14198                 LDKChannelMessageHandler_JCalls_clone(val_conv.this_arg);
14199         }
14200         MessageHandler_set_chan_handler(&this_ptr_conv, val_conv);
14201 }
14202
14203 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1route_1handler(JNIEnv * _env, jclass _b, jlong this_ptr) {
14204         LDKMessageHandler this_ptr_conv;
14205         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14206         this_ptr_conv.is_owned = false;
14207         long ret_ret = (long)MessageHandler_get_route_handler(&this_ptr_conv);
14208         return ret_ret;
14209 }
14210
14211 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1route_1handler(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14212         LDKMessageHandler this_ptr_conv;
14213         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14214         this_ptr_conv.is_owned = false;
14215         LDKRoutingMessageHandler val_conv = *(LDKRoutingMessageHandler*)val;
14216         if (val_conv.free == LDKRoutingMessageHandler_JCalls_free) {
14217                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14218                 LDKRoutingMessageHandler_JCalls_clone(val_conv.this_arg);
14219         }
14220         MessageHandler_set_route_handler(&this_ptr_conv, val_conv);
14221 }
14222
14223 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1new(JNIEnv * _env, jclass _b, jlong chan_handler_arg, jlong route_handler_arg) {
14224         LDKChannelMessageHandler chan_handler_arg_conv = *(LDKChannelMessageHandler*)chan_handler_arg;
14225         if (chan_handler_arg_conv.free == LDKChannelMessageHandler_JCalls_free) {
14226                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14227                 LDKChannelMessageHandler_JCalls_clone(chan_handler_arg_conv.this_arg);
14228         }
14229         LDKRoutingMessageHandler route_handler_arg_conv = *(LDKRoutingMessageHandler*)route_handler_arg;
14230         if (route_handler_arg_conv.free == LDKRoutingMessageHandler_JCalls_free) {
14231                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14232                 LDKRoutingMessageHandler_JCalls_clone(route_handler_arg_conv.this_arg);
14233         }
14234         LDKMessageHandler ret_var = MessageHandler_new(chan_handler_arg_conv, route_handler_arg_conv);
14235         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14236         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14237         long ret_ref = (long)ret_var.inner;
14238         if (ret_var.is_owned) {
14239                 ret_ref |= 1;
14240         }
14241         return ret_ref;
14242 }
14243
14244 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1clone(JNIEnv * _env, jclass _b, jlong orig) {
14245         LDKSocketDescriptor* orig_conv = (LDKSocketDescriptor*)orig;
14246         LDKSocketDescriptor* ret = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
14247         *ret = SocketDescriptor_clone(orig_conv);
14248         return (long)ret;
14249 }
14250
14251 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14252         LDKSocketDescriptor this_ptr_conv = *(LDKSocketDescriptor*)this_ptr;
14253         FREE((void*)this_ptr);
14254         SocketDescriptor_free(this_ptr_conv);
14255 }
14256
14257 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14258         LDKPeerHandleError this_ptr_conv;
14259         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14260         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14261         PeerHandleError_free(this_ptr_conv);
14262 }
14263
14264 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1get_1no_1connection_1possible(JNIEnv * _env, jclass _b, jlong this_ptr) {
14265         LDKPeerHandleError this_ptr_conv;
14266         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14267         this_ptr_conv.is_owned = false;
14268         jboolean ret_val = PeerHandleError_get_no_connection_possible(&this_ptr_conv);
14269         return ret_val;
14270 }
14271
14272 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1set_1no_1connection_1possible(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
14273         LDKPeerHandleError this_ptr_conv;
14274         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14275         this_ptr_conv.is_owned = false;
14276         PeerHandleError_set_no_connection_possible(&this_ptr_conv, val);
14277 }
14278
14279 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1new(JNIEnv * _env, jclass _b, jboolean no_connection_possible_arg) {
14280         LDKPeerHandleError ret_var = PeerHandleError_new(no_connection_possible_arg);
14281         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14282         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14283         long ret_ref = (long)ret_var.inner;
14284         if (ret_var.is_owned) {
14285                 ret_ref |= 1;
14286         }
14287         return ret_ref;
14288 }
14289
14290 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14291         LDKPeerManager this_ptr_conv;
14292         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14293         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14294         PeerManager_free(this_ptr_conv);
14295 }
14296
14297 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) {
14298         LDKMessageHandler message_handler_conv;
14299         message_handler_conv.inner = (void*)(message_handler & (~1));
14300         message_handler_conv.is_owned = (message_handler & 1) || (message_handler == 0);
14301         // Warning: we may need a move here but can't clone!
14302         LDKSecretKey our_node_secret_ref;
14303         CHECK((*_env)->GetArrayLength (_env, our_node_secret) == 32);
14304         (*_env)->GetByteArrayRegion (_env, our_node_secret, 0, 32, our_node_secret_ref.bytes);
14305         unsigned char ephemeral_random_data_arr[32];
14306         CHECK((*_env)->GetArrayLength (_env, ephemeral_random_data) == 32);
14307         (*_env)->GetByteArrayRegion (_env, ephemeral_random_data, 0, 32, ephemeral_random_data_arr);
14308         unsigned char (*ephemeral_random_data_ref)[32] = &ephemeral_random_data_arr;
14309         LDKLogger logger_conv = *(LDKLogger*)logger;
14310         if (logger_conv.free == LDKLogger_JCalls_free) {
14311                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14312                 LDKLogger_JCalls_clone(logger_conv.this_arg);
14313         }
14314         LDKPeerManager ret_var = PeerManager_new(message_handler_conv, our_node_secret_ref, ephemeral_random_data_ref, logger_conv);
14315         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14316         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14317         long ret_ref = (long)ret_var.inner;
14318         if (ret_var.is_owned) {
14319                 ret_ref |= 1;
14320         }
14321         return ret_ref;
14322 }
14323
14324 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_PeerManager_1get_1peer_1node_1ids(JNIEnv * _env, jclass _b, jlong this_arg) {
14325         LDKPeerManager this_arg_conv;
14326         this_arg_conv.inner = (void*)(this_arg & (~1));
14327         this_arg_conv.is_owned = false;
14328         LDKCVec_PublicKeyZ ret_var = PeerManager_get_peer_node_ids(&this_arg_conv);
14329         jobjectArray ret_arr = (*_env)->NewObjectArray(_env, ret_var.datalen, arr_of_B_clz, NULL);
14330         for (size_t i = 0; i < ret_var.datalen; i++) {
14331                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 33);
14332                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 33, ret_var.data[i].compressed_form);
14333                 (*_env)->SetObjectArrayElement(_env, ret_arr, i, arr_conv_8_arr);
14334         }
14335         FREE(ret_var.data);
14336         return ret_arr;
14337 }
14338
14339 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) {
14340         LDKPeerManager this_arg_conv;
14341         this_arg_conv.inner = (void*)(this_arg & (~1));
14342         this_arg_conv.is_owned = false;
14343         LDKPublicKey their_node_id_ref;
14344         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
14345         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
14346         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
14347         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
14348                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14349                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
14350         }
14351         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
14352         *ret_conv = PeerManager_new_outbound_connection(&this_arg_conv, their_node_id_ref, descriptor_conv);
14353         return (long)ret_conv;
14354 }
14355
14356 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1new_1inbound_1connection(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
14357         LDKPeerManager this_arg_conv;
14358         this_arg_conv.inner = (void*)(this_arg & (~1));
14359         this_arg_conv.is_owned = false;
14360         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
14361         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
14362                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
14363                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
14364         }
14365         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
14366         *ret_conv = PeerManager_new_inbound_connection(&this_arg_conv, descriptor_conv);
14367         return (long)ret_conv;
14368 }
14369
14370 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1write_1buffer_1space_1avail(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
14371         LDKPeerManager this_arg_conv;
14372         this_arg_conv.inner = (void*)(this_arg & (~1));
14373         this_arg_conv.is_owned = false;
14374         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
14375         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
14376         *ret_conv = PeerManager_write_buffer_space_avail(&this_arg_conv, descriptor_conv);
14377         return (long)ret_conv;
14378 }
14379
14380 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1read_1event(JNIEnv * _env, jclass _b, jlong this_arg, jlong peer_descriptor, jbyteArray data) {
14381         LDKPeerManager this_arg_conv;
14382         this_arg_conv.inner = (void*)(this_arg & (~1));
14383         this_arg_conv.is_owned = false;
14384         LDKSocketDescriptor* peer_descriptor_conv = (LDKSocketDescriptor*)peer_descriptor;
14385         LDKu8slice data_ref;
14386         data_ref.datalen = (*_env)->GetArrayLength (_env, data);
14387         data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL);
14388         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
14389         *ret_conv = PeerManager_read_event(&this_arg_conv, peer_descriptor_conv, data_ref);
14390         (*_env)->ReleaseByteArrayElements(_env, data, (int8_t*)data_ref.data, 0);
14391         return (long)ret_conv;
14392 }
14393
14394 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1process_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
14395         LDKPeerManager this_arg_conv;
14396         this_arg_conv.inner = (void*)(this_arg & (~1));
14397         this_arg_conv.is_owned = false;
14398         PeerManager_process_events(&this_arg_conv);
14399 }
14400
14401 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1socket_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
14402         LDKPeerManager this_arg_conv;
14403         this_arg_conv.inner = (void*)(this_arg & (~1));
14404         this_arg_conv.is_owned = false;
14405         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
14406         PeerManager_socket_disconnected(&this_arg_conv, descriptor_conv);
14407 }
14408
14409 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1timer_1tick_1occured(JNIEnv * _env, jclass _b, jlong this_arg) {
14410         LDKPeerManager this_arg_conv;
14411         this_arg_conv.inner = (void*)(this_arg & (~1));
14412         this_arg_conv.is_owned = false;
14413         PeerManager_timer_tick_occured(&this_arg_conv);
14414 }
14415
14416 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_build_1commitment_1secret(JNIEnv * _env, jclass _b, jbyteArray commitment_seed, jlong idx) {
14417         unsigned char commitment_seed_arr[32];
14418         CHECK((*_env)->GetArrayLength (_env, commitment_seed) == 32);
14419         (*_env)->GetByteArrayRegion (_env, commitment_seed, 0, 32, commitment_seed_arr);
14420         unsigned char (*commitment_seed_ref)[32] = &commitment_seed_arr;
14421         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
14422         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, build_commitment_secret(commitment_seed_ref, idx).data);
14423         return arg_arr;
14424 }
14425
14426 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_derive_1private_1key(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jbyteArray base_secret) {
14427         LDKPublicKey per_commitment_point_ref;
14428         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
14429         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14430         unsigned char base_secret_arr[32];
14431         CHECK((*_env)->GetArrayLength (_env, base_secret) == 32);
14432         (*_env)->GetByteArrayRegion (_env, base_secret, 0, 32, base_secret_arr);
14433         unsigned char (*base_secret_ref)[32] = &base_secret_arr;
14434         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
14435         *ret_conv = derive_private_key(per_commitment_point_ref, base_secret_ref);
14436         return (long)ret_conv;
14437 }
14438
14439 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_derive_1public_1key(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jbyteArray base_point) {
14440         LDKPublicKey per_commitment_point_ref;
14441         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
14442         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14443         LDKPublicKey base_point_ref;
14444         CHECK((*_env)->GetArrayLength (_env, base_point) == 33);
14445         (*_env)->GetByteArrayRegion (_env, base_point, 0, 33, base_point_ref.compressed_form);
14446         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
14447         *ret_conv = derive_public_key(per_commitment_point_ref, base_point_ref);
14448         return (long)ret_conv;
14449 }
14450
14451 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) {
14452         unsigned char per_commitment_secret_arr[32];
14453         CHECK((*_env)->GetArrayLength (_env, per_commitment_secret) == 32);
14454         (*_env)->GetByteArrayRegion (_env, per_commitment_secret, 0, 32, per_commitment_secret_arr);
14455         unsigned char (*per_commitment_secret_ref)[32] = &per_commitment_secret_arr;
14456         unsigned char countersignatory_revocation_base_secret_arr[32];
14457         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base_secret) == 32);
14458         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base_secret, 0, 32, countersignatory_revocation_base_secret_arr);
14459         unsigned char (*countersignatory_revocation_base_secret_ref)[32] = &countersignatory_revocation_base_secret_arr;
14460         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
14461         *ret_conv = derive_private_revocation_key(per_commitment_secret_ref, countersignatory_revocation_base_secret_ref);
14462         return (long)ret_conv;
14463 }
14464
14465 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) {
14466         LDKPublicKey per_commitment_point_ref;
14467         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
14468         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14469         LDKPublicKey countersignatory_revocation_base_point_ref;
14470         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base_point) == 33);
14471         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base_point, 0, 33, countersignatory_revocation_base_point_ref.compressed_form);
14472         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
14473         *ret_conv = derive_public_revocation_key(per_commitment_point_ref, countersignatory_revocation_base_point_ref);
14474         return (long)ret_conv;
14475 }
14476
14477 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14478         LDKTxCreationKeys this_ptr_conv;
14479         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14480         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14481         TxCreationKeys_free(this_ptr_conv);
14482 }
14483
14484 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
14485         LDKTxCreationKeys orig_conv;
14486         orig_conv.inner = (void*)(orig & (~1));
14487         orig_conv.is_owned = false;
14488         LDKTxCreationKeys ret_var = TxCreationKeys_clone(&orig_conv);
14489         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14490         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14491         long ret_ref = (long)ret_var.inner;
14492         if (ret_var.is_owned) {
14493                 ret_ref |= 1;
14494         }
14495         return ret_ref;
14496 }
14497
14498 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
14499         LDKTxCreationKeys this_ptr_conv;
14500         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14501         this_ptr_conv.is_owned = false;
14502         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14503         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_per_commitment_point(&this_ptr_conv).compressed_form);
14504         return arg_arr;
14505 }
14506
14507 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14508         LDKTxCreationKeys this_ptr_conv;
14509         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14510         this_ptr_conv.is_owned = false;
14511         LDKPublicKey val_ref;
14512         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14513         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14514         TxCreationKeys_set_per_commitment_point(&this_ptr_conv, val_ref);
14515 }
14516
14517 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1revocation_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
14518         LDKTxCreationKeys this_ptr_conv;
14519         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14520         this_ptr_conv.is_owned = false;
14521         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14522         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_revocation_key(&this_ptr_conv).compressed_form);
14523         return arg_arr;
14524 }
14525
14526 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1revocation_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14527         LDKTxCreationKeys this_ptr_conv;
14528         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14529         this_ptr_conv.is_owned = false;
14530         LDKPublicKey val_ref;
14531         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14532         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14533         TxCreationKeys_set_revocation_key(&this_ptr_conv, val_ref);
14534 }
14535
14536 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
14537         LDKTxCreationKeys this_ptr_conv;
14538         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14539         this_ptr_conv.is_owned = false;
14540         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14541         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_htlc_key(&this_ptr_conv).compressed_form);
14542         return arg_arr;
14543 }
14544
14545 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1broadcaster_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14546         LDKTxCreationKeys this_ptr_conv;
14547         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14548         this_ptr_conv.is_owned = false;
14549         LDKPublicKey val_ref;
14550         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14551         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14552         TxCreationKeys_set_broadcaster_htlc_key(&this_ptr_conv, val_ref);
14553 }
14554
14555 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1countersignatory_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
14556         LDKTxCreationKeys this_ptr_conv;
14557         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14558         this_ptr_conv.is_owned = false;
14559         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14560         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_countersignatory_htlc_key(&this_ptr_conv).compressed_form);
14561         return arg_arr;
14562 }
14563
14564 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1countersignatory_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14565         LDKTxCreationKeys this_ptr_conv;
14566         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14567         this_ptr_conv.is_owned = false;
14568         LDKPublicKey val_ref;
14569         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14570         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14571         TxCreationKeys_set_countersignatory_htlc_key(&this_ptr_conv, val_ref);
14572 }
14573
14574 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1delayed_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
14575         LDKTxCreationKeys this_ptr_conv;
14576         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14577         this_ptr_conv.is_owned = false;
14578         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14579         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_delayed_payment_key(&this_ptr_conv).compressed_form);
14580         return arg_arr;
14581 }
14582
14583 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1broadcaster_1delayed_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14584         LDKTxCreationKeys this_ptr_conv;
14585         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14586         this_ptr_conv.is_owned = false;
14587         LDKPublicKey val_ref;
14588         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14589         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14590         TxCreationKeys_set_broadcaster_delayed_payment_key(&this_ptr_conv, val_ref);
14591 }
14592
14593 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) {
14594         LDKPublicKey per_commitment_point_arg_ref;
14595         CHECK((*_env)->GetArrayLength (_env, per_commitment_point_arg) == 33);
14596         (*_env)->GetByteArrayRegion (_env, per_commitment_point_arg, 0, 33, per_commitment_point_arg_ref.compressed_form);
14597         LDKPublicKey revocation_key_arg_ref;
14598         CHECK((*_env)->GetArrayLength (_env, revocation_key_arg) == 33);
14599         (*_env)->GetByteArrayRegion (_env, revocation_key_arg, 0, 33, revocation_key_arg_ref.compressed_form);
14600         LDKPublicKey broadcaster_htlc_key_arg_ref;
14601         CHECK((*_env)->GetArrayLength (_env, broadcaster_htlc_key_arg) == 33);
14602         (*_env)->GetByteArrayRegion (_env, broadcaster_htlc_key_arg, 0, 33, broadcaster_htlc_key_arg_ref.compressed_form);
14603         LDKPublicKey countersignatory_htlc_key_arg_ref;
14604         CHECK((*_env)->GetArrayLength (_env, countersignatory_htlc_key_arg) == 33);
14605         (*_env)->GetByteArrayRegion (_env, countersignatory_htlc_key_arg, 0, 33, countersignatory_htlc_key_arg_ref.compressed_form);
14606         LDKPublicKey broadcaster_delayed_payment_key_arg_ref;
14607         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key_arg) == 33);
14608         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key_arg, 0, 33, broadcaster_delayed_payment_key_arg_ref.compressed_form);
14609         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);
14610         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14611         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14612         long ret_ref = (long)ret_var.inner;
14613         if (ret_var.is_owned) {
14614                 ret_ref |= 1;
14615         }
14616         return ret_ref;
14617 }
14618
14619 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
14620         LDKTxCreationKeys obj_conv;
14621         obj_conv.inner = (void*)(obj & (~1));
14622         obj_conv.is_owned = false;
14623         LDKCVec_u8Z arg_var = TxCreationKeys_write(&obj_conv);
14624         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14625         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14626         CVec_u8Z_free(arg_var);
14627         return arg_arr;
14628 }
14629
14630 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14631         LDKu8slice ser_ref;
14632         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14633         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14634         LDKTxCreationKeys ret_var = TxCreationKeys_read(ser_ref);
14635         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14636         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14637         long ret_ref = (long)ret_var.inner;
14638         if (ret_var.is_owned) {
14639                 ret_ref |= 1;
14640         }
14641         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14642         return ret_ref;
14643 }
14644
14645 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14646         LDKChannelPublicKeys this_ptr_conv;
14647         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14648         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14649         ChannelPublicKeys_free(this_ptr_conv);
14650 }
14651
14652 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
14653         LDKChannelPublicKeys orig_conv;
14654         orig_conv.inner = (void*)(orig & (~1));
14655         orig_conv.is_owned = false;
14656         LDKChannelPublicKeys ret_var = ChannelPublicKeys_clone(&orig_conv);
14657         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14658         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14659         long ret_ref = (long)ret_var.inner;
14660         if (ret_var.is_owned) {
14661                 ret_ref |= 1;
14662         }
14663         return ret_ref;
14664 }
14665
14666 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
14667         LDKChannelPublicKeys this_ptr_conv;
14668         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14669         this_ptr_conv.is_owned = false;
14670         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14671         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_funding_pubkey(&this_ptr_conv).compressed_form);
14672         return arg_arr;
14673 }
14674
14675 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14676         LDKChannelPublicKeys this_ptr_conv;
14677         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14678         this_ptr_conv.is_owned = false;
14679         LDKPublicKey val_ref;
14680         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14681         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14682         ChannelPublicKeys_set_funding_pubkey(&this_ptr_conv, val_ref);
14683 }
14684
14685 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
14686         LDKChannelPublicKeys this_ptr_conv;
14687         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14688         this_ptr_conv.is_owned = false;
14689         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14690         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_revocation_basepoint(&this_ptr_conv).compressed_form);
14691         return arg_arr;
14692 }
14693
14694 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14695         LDKChannelPublicKeys this_ptr_conv;
14696         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14697         this_ptr_conv.is_owned = false;
14698         LDKPublicKey val_ref;
14699         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14700         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14701         ChannelPublicKeys_set_revocation_basepoint(&this_ptr_conv, val_ref);
14702 }
14703
14704 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
14705         LDKChannelPublicKeys this_ptr_conv;
14706         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14707         this_ptr_conv.is_owned = false;
14708         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14709         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_payment_point(&this_ptr_conv).compressed_form);
14710         return arg_arr;
14711 }
14712
14713 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14714         LDKChannelPublicKeys this_ptr_conv;
14715         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14716         this_ptr_conv.is_owned = false;
14717         LDKPublicKey val_ref;
14718         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14719         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14720         ChannelPublicKeys_set_payment_point(&this_ptr_conv, val_ref);
14721 }
14722
14723 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
14724         LDKChannelPublicKeys this_ptr_conv;
14725         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14726         this_ptr_conv.is_owned = false;
14727         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14728         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
14729         return arg_arr;
14730 }
14731
14732 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14733         LDKChannelPublicKeys this_ptr_conv;
14734         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14735         this_ptr_conv.is_owned = false;
14736         LDKPublicKey val_ref;
14737         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14738         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14739         ChannelPublicKeys_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
14740 }
14741
14742 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
14743         LDKChannelPublicKeys this_ptr_conv;
14744         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14745         this_ptr_conv.is_owned = false;
14746         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
14747         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_htlc_basepoint(&this_ptr_conv).compressed_form);
14748         return arg_arr;
14749 }
14750
14751 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14752         LDKChannelPublicKeys this_ptr_conv;
14753         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14754         this_ptr_conv.is_owned = false;
14755         LDKPublicKey val_ref;
14756         CHECK((*_env)->GetArrayLength (_env, val) == 33);
14757         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
14758         ChannelPublicKeys_set_htlc_basepoint(&this_ptr_conv, val_ref);
14759 }
14760
14761 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) {
14762         LDKPublicKey funding_pubkey_arg_ref;
14763         CHECK((*_env)->GetArrayLength (_env, funding_pubkey_arg) == 33);
14764         (*_env)->GetByteArrayRegion (_env, funding_pubkey_arg, 0, 33, funding_pubkey_arg_ref.compressed_form);
14765         LDKPublicKey revocation_basepoint_arg_ref;
14766         CHECK((*_env)->GetArrayLength (_env, revocation_basepoint_arg) == 33);
14767         (*_env)->GetByteArrayRegion (_env, revocation_basepoint_arg, 0, 33, revocation_basepoint_arg_ref.compressed_form);
14768         LDKPublicKey payment_point_arg_ref;
14769         CHECK((*_env)->GetArrayLength (_env, payment_point_arg) == 33);
14770         (*_env)->GetByteArrayRegion (_env, payment_point_arg, 0, 33, payment_point_arg_ref.compressed_form);
14771         LDKPublicKey delayed_payment_basepoint_arg_ref;
14772         CHECK((*_env)->GetArrayLength (_env, delayed_payment_basepoint_arg) == 33);
14773         (*_env)->GetByteArrayRegion (_env, delayed_payment_basepoint_arg, 0, 33, delayed_payment_basepoint_arg_ref.compressed_form);
14774         LDKPublicKey htlc_basepoint_arg_ref;
14775         CHECK((*_env)->GetArrayLength (_env, htlc_basepoint_arg) == 33);
14776         (*_env)->GetByteArrayRegion (_env, htlc_basepoint_arg, 0, 33, htlc_basepoint_arg_ref.compressed_form);
14777         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);
14778         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14779         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14780         long ret_ref = (long)ret_var.inner;
14781         if (ret_var.is_owned) {
14782                 ret_ref |= 1;
14783         }
14784         return ret_ref;
14785 }
14786
14787 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
14788         LDKChannelPublicKeys obj_conv;
14789         obj_conv.inner = (void*)(obj & (~1));
14790         obj_conv.is_owned = false;
14791         LDKCVec_u8Z arg_var = ChannelPublicKeys_write(&obj_conv);
14792         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14793         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14794         CVec_u8Z_free(arg_var);
14795         return arg_arr;
14796 }
14797
14798 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14799         LDKu8slice ser_ref;
14800         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14801         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14802         LDKChannelPublicKeys ret_var = ChannelPublicKeys_read(ser_ref);
14803         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14804         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14805         long ret_ref = (long)ret_var.inner;
14806         if (ret_var.is_owned) {
14807                 ret_ref |= 1;
14808         }
14809         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14810         return ret_ref;
14811 }
14812
14813 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) {
14814         LDKPublicKey per_commitment_point_ref;
14815         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
14816         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14817         LDKPublicKey broadcaster_delayed_payment_base_ref;
14818         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_base) == 33);
14819         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_base, 0, 33, broadcaster_delayed_payment_base_ref.compressed_form);
14820         LDKPublicKey broadcaster_htlc_base_ref;
14821         CHECK((*_env)->GetArrayLength (_env, broadcaster_htlc_base) == 33);
14822         (*_env)->GetByteArrayRegion (_env, broadcaster_htlc_base, 0, 33, broadcaster_htlc_base_ref.compressed_form);
14823         LDKPublicKey countersignatory_revocation_base_ref;
14824         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base) == 33);
14825         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base, 0, 33, countersignatory_revocation_base_ref.compressed_form);
14826         LDKPublicKey countersignatory_htlc_base_ref;
14827         CHECK((*_env)->GetArrayLength (_env, countersignatory_htlc_base) == 33);
14828         (*_env)->GetByteArrayRegion (_env, countersignatory_htlc_base, 0, 33, countersignatory_htlc_base_ref.compressed_form);
14829         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
14830         *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);
14831         return (long)ret_conv;
14832 }
14833
14834 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1from_1channel_1static_1keys(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jlong broadcaster_keys, jlong countersignatory_keys) {
14835         LDKPublicKey per_commitment_point_ref;
14836         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
14837         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
14838         LDKChannelPublicKeys broadcaster_keys_conv;
14839         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
14840         broadcaster_keys_conv.is_owned = false;
14841         LDKChannelPublicKeys countersignatory_keys_conv;
14842         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
14843         countersignatory_keys_conv.is_owned = false;
14844         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
14845         *ret_conv = TxCreationKeys_from_channel_static_keys(per_commitment_point_ref, &broadcaster_keys_conv, &countersignatory_keys_conv);
14846         return (long)ret_conv;
14847 }
14848
14849 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) {
14850         LDKPublicKey revocation_key_ref;
14851         CHECK((*_env)->GetArrayLength (_env, revocation_key) == 33);
14852         (*_env)->GetByteArrayRegion (_env, revocation_key, 0, 33, revocation_key_ref.compressed_form);
14853         LDKPublicKey broadcaster_delayed_payment_key_ref;
14854         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key) == 33);
14855         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
14856         LDKCVec_u8Z arg_var = get_revokeable_redeemscript(revocation_key_ref, contest_delay, broadcaster_delayed_payment_key_ref);
14857         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14858         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14859         CVec_u8Z_free(arg_var);
14860         return arg_arr;
14861 }
14862
14863 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14864         LDKHTLCOutputInCommitment this_ptr_conv;
14865         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14866         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14867         HTLCOutputInCommitment_free(this_ptr_conv);
14868 }
14869
14870 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1clone(JNIEnv * _env, jclass _b, jlong orig) {
14871         LDKHTLCOutputInCommitment orig_conv;
14872         orig_conv.inner = (void*)(orig & (~1));
14873         orig_conv.is_owned = false;
14874         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_clone(&orig_conv);
14875         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14876         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14877         long ret_ref = (long)ret_var.inner;
14878         if (ret_var.is_owned) {
14879                 ret_ref |= 1;
14880         }
14881         return ret_ref;
14882 }
14883
14884 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1offered(JNIEnv * _env, jclass _b, jlong this_ptr) {
14885         LDKHTLCOutputInCommitment this_ptr_conv;
14886         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14887         this_ptr_conv.is_owned = false;
14888         jboolean ret_val = HTLCOutputInCommitment_get_offered(&this_ptr_conv);
14889         return ret_val;
14890 }
14891
14892 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1offered(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
14893         LDKHTLCOutputInCommitment this_ptr_conv;
14894         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14895         this_ptr_conv.is_owned = false;
14896         HTLCOutputInCommitment_set_offered(&this_ptr_conv, val);
14897 }
14898
14899 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
14900         LDKHTLCOutputInCommitment this_ptr_conv;
14901         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14902         this_ptr_conv.is_owned = false;
14903         jlong ret_val = HTLCOutputInCommitment_get_amount_msat(&this_ptr_conv);
14904         return ret_val;
14905 }
14906
14907 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14908         LDKHTLCOutputInCommitment this_ptr_conv;
14909         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14910         this_ptr_conv.is_owned = false;
14911         HTLCOutputInCommitment_set_amount_msat(&this_ptr_conv, val);
14912 }
14913
14914 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr) {
14915         LDKHTLCOutputInCommitment this_ptr_conv;
14916         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14917         this_ptr_conv.is_owned = false;
14918         jint ret_val = HTLCOutputInCommitment_get_cltv_expiry(&this_ptr_conv);
14919         return ret_val;
14920 }
14921
14922 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
14923         LDKHTLCOutputInCommitment this_ptr_conv;
14924         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14925         this_ptr_conv.is_owned = false;
14926         HTLCOutputInCommitment_set_cltv_expiry(&this_ptr_conv, val);
14927 }
14928
14929 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
14930         LDKHTLCOutputInCommitment this_ptr_conv;
14931         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14932         this_ptr_conv.is_owned = false;
14933         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
14934         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *HTLCOutputInCommitment_get_payment_hash(&this_ptr_conv));
14935         return ret_arr;
14936 }
14937
14938 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14939         LDKHTLCOutputInCommitment this_ptr_conv;
14940         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14941         this_ptr_conv.is_owned = false;
14942         LDKThirtyTwoBytes val_ref;
14943         CHECK((*_env)->GetArrayLength (_env, val) == 32);
14944         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
14945         HTLCOutputInCommitment_set_payment_hash(&this_ptr_conv, val_ref);
14946 }
14947
14948 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1write(JNIEnv * _env, jclass _b, jlong obj) {
14949         LDKHTLCOutputInCommitment obj_conv;
14950         obj_conv.inner = (void*)(obj & (~1));
14951         obj_conv.is_owned = false;
14952         LDKCVec_u8Z arg_var = HTLCOutputInCommitment_write(&obj_conv);
14953         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14954         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14955         CVec_u8Z_free(arg_var);
14956         return arg_arr;
14957 }
14958
14959 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14960         LDKu8slice ser_ref;
14961         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14962         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14963         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_read(ser_ref);
14964         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14965         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14966         long ret_ref = (long)ret_var.inner;
14967         if (ret_var.is_owned) {
14968                 ret_ref |= 1;
14969         }
14970         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14971         return ret_ref;
14972 }
14973
14974 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_get_1htlc_1redeemscript(JNIEnv * _env, jclass _b, jlong htlc, jlong keys) {
14975         LDKHTLCOutputInCommitment htlc_conv;
14976         htlc_conv.inner = (void*)(htlc & (~1));
14977         htlc_conv.is_owned = false;
14978         LDKTxCreationKeys keys_conv;
14979         keys_conv.inner = (void*)(keys & (~1));
14980         keys_conv.is_owned = false;
14981         LDKCVec_u8Z arg_var = get_htlc_redeemscript(&htlc_conv, &keys_conv);
14982         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14983         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14984         CVec_u8Z_free(arg_var);
14985         return arg_arr;
14986 }
14987
14988 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_make_1funding_1redeemscript(JNIEnv * _env, jclass _b, jbyteArray broadcaster, jbyteArray countersignatory) {
14989         LDKPublicKey broadcaster_ref;
14990         CHECK((*_env)->GetArrayLength (_env, broadcaster) == 33);
14991         (*_env)->GetByteArrayRegion (_env, broadcaster, 0, 33, broadcaster_ref.compressed_form);
14992         LDKPublicKey countersignatory_ref;
14993         CHECK((*_env)->GetArrayLength (_env, countersignatory) == 33);
14994         (*_env)->GetByteArrayRegion (_env, countersignatory, 0, 33, countersignatory_ref.compressed_form);
14995         LDKCVec_u8Z arg_var = make_funding_redeemscript(broadcaster_ref, countersignatory_ref);
14996         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14997         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14998         CVec_u8Z_free(arg_var);
14999         return arg_arr;
15000 }
15001
15002 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) {
15003         unsigned char prev_hash_arr[32];
15004         CHECK((*_env)->GetArrayLength (_env, prev_hash) == 32);
15005         (*_env)->GetByteArrayRegion (_env, prev_hash, 0, 32, prev_hash_arr);
15006         unsigned char (*prev_hash_ref)[32] = &prev_hash_arr;
15007         LDKHTLCOutputInCommitment htlc_conv;
15008         htlc_conv.inner = (void*)(htlc & (~1));
15009         htlc_conv.is_owned = false;
15010         LDKPublicKey broadcaster_delayed_payment_key_ref;
15011         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key) == 33);
15012         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
15013         LDKPublicKey revocation_key_ref;
15014         CHECK((*_env)->GetArrayLength (_env, revocation_key) == 33);
15015         (*_env)->GetByteArrayRegion (_env, revocation_key, 0, 33, revocation_key_ref.compressed_form);
15016         LDKTransaction arg_var = build_htlc_transaction(prev_hash_ref, feerate_per_kw, contest_delay, &htlc_conv, broadcaster_delayed_payment_key_ref, revocation_key_ref);
15017         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15018         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15019         Transaction_free(arg_var);
15020         return arg_arr;
15021 }
15022
15023 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15024         LDKChannelTransactionParameters this_ptr_conv;
15025         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15026         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15027         ChannelTransactionParameters_free(this_ptr_conv);
15028 }
15029
15030 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1clone(JNIEnv * _env, jclass _b, jlong orig) {
15031         LDKChannelTransactionParameters orig_conv;
15032         orig_conv.inner = (void*)(orig & (~1));
15033         orig_conv.is_owned = false;
15034         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_clone(&orig_conv);
15035         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15036         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15037         long ret_ref = (long)ret_var.inner;
15038         if (ret_var.is_owned) {
15039                 ret_ref |= 1;
15040         }
15041         return ret_ref;
15042 }
15043
15044 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1holder_1pubkeys(JNIEnv * _env, jclass _b, jlong this_ptr) {
15045         LDKChannelTransactionParameters this_ptr_conv;
15046         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15047         this_ptr_conv.is_owned = false;
15048         LDKChannelPublicKeys ret_var = ChannelTransactionParameters_get_holder_pubkeys(&this_ptr_conv);
15049         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15050         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15051         long ret_ref = (long)ret_var.inner;
15052         if (ret_var.is_owned) {
15053                 ret_ref |= 1;
15054         }
15055         return ret_ref;
15056 }
15057
15058 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1holder_1pubkeys(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15059         LDKChannelTransactionParameters this_ptr_conv;
15060         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15061         this_ptr_conv.is_owned = false;
15062         LDKChannelPublicKeys val_conv;
15063         val_conv.inner = (void*)(val & (~1));
15064         val_conv.is_owned = (val & 1) || (val == 0);
15065         if (val_conv.inner != NULL)
15066                 val_conv = ChannelPublicKeys_clone(&val_conv);
15067         ChannelTransactionParameters_set_holder_pubkeys(&this_ptr_conv, val_conv);
15068 }
15069
15070 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1holder_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
15071         LDKChannelTransactionParameters this_ptr_conv;
15072         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15073         this_ptr_conv.is_owned = false;
15074         jshort ret_val = ChannelTransactionParameters_get_holder_selected_contest_delay(&this_ptr_conv);
15075         return ret_val;
15076 }
15077
15078 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1holder_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
15079         LDKChannelTransactionParameters this_ptr_conv;
15080         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15081         this_ptr_conv.is_owned = false;
15082         ChannelTransactionParameters_set_holder_selected_contest_delay(&this_ptr_conv, val);
15083 }
15084
15085 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1is_1outbound_1from_1holder(JNIEnv * _env, jclass _b, jlong this_ptr) {
15086         LDKChannelTransactionParameters this_ptr_conv;
15087         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15088         this_ptr_conv.is_owned = false;
15089         jboolean ret_val = ChannelTransactionParameters_get_is_outbound_from_holder(&this_ptr_conv);
15090         return ret_val;
15091 }
15092
15093 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1is_1outbound_1from_1holder(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
15094         LDKChannelTransactionParameters this_ptr_conv;
15095         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15096         this_ptr_conv.is_owned = false;
15097         ChannelTransactionParameters_set_is_outbound_from_holder(&this_ptr_conv, val);
15098 }
15099
15100 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1counterparty_1parameters(JNIEnv * _env, jclass _b, jlong this_ptr) {
15101         LDKChannelTransactionParameters this_ptr_conv;
15102         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15103         this_ptr_conv.is_owned = false;
15104         LDKCounterpartyChannelTransactionParameters ret_var = ChannelTransactionParameters_get_counterparty_parameters(&this_ptr_conv);
15105         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15106         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15107         long ret_ref = (long)ret_var.inner;
15108         if (ret_var.is_owned) {
15109                 ret_ref |= 1;
15110         }
15111         return ret_ref;
15112 }
15113
15114 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1counterparty_1parameters(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15115         LDKChannelTransactionParameters this_ptr_conv;
15116         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15117         this_ptr_conv.is_owned = false;
15118         LDKCounterpartyChannelTransactionParameters val_conv;
15119         val_conv.inner = (void*)(val & (~1));
15120         val_conv.is_owned = (val & 1) || (val == 0);
15121         if (val_conv.inner != NULL)
15122                 val_conv = CounterpartyChannelTransactionParameters_clone(&val_conv);
15123         ChannelTransactionParameters_set_counterparty_parameters(&this_ptr_conv, val_conv);
15124 }
15125
15126 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1get_1funding_1outpoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
15127         LDKChannelTransactionParameters this_ptr_conv;
15128         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15129         this_ptr_conv.is_owned = false;
15130         LDKOutPoint ret_var = ChannelTransactionParameters_get_funding_outpoint(&this_ptr_conv);
15131         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15132         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15133         long ret_ref = (long)ret_var.inner;
15134         if (ret_var.is_owned) {
15135                 ret_ref |= 1;
15136         }
15137         return ret_ref;
15138 }
15139
15140 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1set_1funding_1outpoint(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15141         LDKChannelTransactionParameters this_ptr_conv;
15142         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15143         this_ptr_conv.is_owned = false;
15144         LDKOutPoint val_conv;
15145         val_conv.inner = (void*)(val & (~1));
15146         val_conv.is_owned = (val & 1) || (val == 0);
15147         if (val_conv.inner != NULL)
15148                 val_conv = OutPoint_clone(&val_conv);
15149         ChannelTransactionParameters_set_funding_outpoint(&this_ptr_conv, val_conv);
15150 }
15151
15152 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1new(JNIEnv * _env, jclass _b, jlong holder_pubkeys_arg, jshort holder_selected_contest_delay_arg, jboolean is_outbound_from_holder_arg, jlong counterparty_parameters_arg, jlong funding_outpoint_arg) {
15153         LDKChannelPublicKeys holder_pubkeys_arg_conv;
15154         holder_pubkeys_arg_conv.inner = (void*)(holder_pubkeys_arg & (~1));
15155         holder_pubkeys_arg_conv.is_owned = (holder_pubkeys_arg & 1) || (holder_pubkeys_arg == 0);
15156         if (holder_pubkeys_arg_conv.inner != NULL)
15157                 holder_pubkeys_arg_conv = ChannelPublicKeys_clone(&holder_pubkeys_arg_conv);
15158         LDKCounterpartyChannelTransactionParameters counterparty_parameters_arg_conv;
15159         counterparty_parameters_arg_conv.inner = (void*)(counterparty_parameters_arg & (~1));
15160         counterparty_parameters_arg_conv.is_owned = (counterparty_parameters_arg & 1) || (counterparty_parameters_arg == 0);
15161         if (counterparty_parameters_arg_conv.inner != NULL)
15162                 counterparty_parameters_arg_conv = CounterpartyChannelTransactionParameters_clone(&counterparty_parameters_arg_conv);
15163         LDKOutPoint funding_outpoint_arg_conv;
15164         funding_outpoint_arg_conv.inner = (void*)(funding_outpoint_arg & (~1));
15165         funding_outpoint_arg_conv.is_owned = (funding_outpoint_arg & 1) || (funding_outpoint_arg == 0);
15166         if (funding_outpoint_arg_conv.inner != NULL)
15167                 funding_outpoint_arg_conv = OutPoint_clone(&funding_outpoint_arg_conv);
15168         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_new(holder_pubkeys_arg_conv, holder_selected_contest_delay_arg, is_outbound_from_holder_arg, counterparty_parameters_arg_conv, funding_outpoint_arg_conv);
15169         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15170         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15171         long ret_ref = (long)ret_var.inner;
15172         if (ret_var.is_owned) {
15173                 ret_ref |= 1;
15174         }
15175         return ret_ref;
15176 }
15177
15178 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15179         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15180         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15181         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15182         CounterpartyChannelTransactionParameters_free(this_ptr_conv);
15183 }
15184
15185 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1clone(JNIEnv * _env, jclass _b, jlong orig) {
15186         LDKCounterpartyChannelTransactionParameters orig_conv;
15187         orig_conv.inner = (void*)(orig & (~1));
15188         orig_conv.is_owned = false;
15189         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_clone(&orig_conv);
15190         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15191         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15192         long ret_ref = (long)ret_var.inner;
15193         if (ret_var.is_owned) {
15194                 ret_ref |= 1;
15195         }
15196         return ret_ref;
15197 }
15198
15199 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1get_1pubkeys(JNIEnv * _env, jclass _b, jlong this_ptr) {
15200         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15201         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15202         this_ptr_conv.is_owned = false;
15203         LDKChannelPublicKeys ret_var = CounterpartyChannelTransactionParameters_get_pubkeys(&this_ptr_conv);
15204         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15205         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15206         long ret_ref = (long)ret_var.inner;
15207         if (ret_var.is_owned) {
15208                 ret_ref |= 1;
15209         }
15210         return ret_ref;
15211 }
15212
15213 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1set_1pubkeys(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15214         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15215         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15216         this_ptr_conv.is_owned = false;
15217         LDKChannelPublicKeys val_conv;
15218         val_conv.inner = (void*)(val & (~1));
15219         val_conv.is_owned = (val & 1) || (val == 0);
15220         if (val_conv.inner != NULL)
15221                 val_conv = ChannelPublicKeys_clone(&val_conv);
15222         CounterpartyChannelTransactionParameters_set_pubkeys(&this_ptr_conv, val_conv);
15223 }
15224
15225 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1get_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
15226         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15227         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15228         this_ptr_conv.is_owned = false;
15229         jshort ret_val = CounterpartyChannelTransactionParameters_get_selected_contest_delay(&this_ptr_conv);
15230         return ret_val;
15231 }
15232
15233 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1set_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
15234         LDKCounterpartyChannelTransactionParameters this_ptr_conv;
15235         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15236         this_ptr_conv.is_owned = false;
15237         CounterpartyChannelTransactionParameters_set_selected_contest_delay(&this_ptr_conv, val);
15238 }
15239
15240 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1new(JNIEnv * _env, jclass _b, jlong pubkeys_arg, jshort selected_contest_delay_arg) {
15241         LDKChannelPublicKeys pubkeys_arg_conv;
15242         pubkeys_arg_conv.inner = (void*)(pubkeys_arg & (~1));
15243         pubkeys_arg_conv.is_owned = (pubkeys_arg & 1) || (pubkeys_arg == 0);
15244         if (pubkeys_arg_conv.inner != NULL)
15245                 pubkeys_arg_conv = ChannelPublicKeys_clone(&pubkeys_arg_conv);
15246         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_new(pubkeys_arg_conv, selected_contest_delay_arg);
15247         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15248         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15249         long ret_ref = (long)ret_var.inner;
15250         if (ret_var.is_owned) {
15251                 ret_ref |= 1;
15252         }
15253         return ret_ref;
15254 }
15255
15256 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1is_1populated(JNIEnv * _env, jclass _b, jlong this_arg) {
15257         LDKChannelTransactionParameters this_arg_conv;
15258         this_arg_conv.inner = (void*)(this_arg & (~1));
15259         this_arg_conv.is_owned = false;
15260         jboolean ret_val = ChannelTransactionParameters_is_populated(&this_arg_conv);
15261         return ret_val;
15262 }
15263
15264 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1as_1holder_1broadcastable(JNIEnv * _env, jclass _b, jlong this_arg) {
15265         LDKChannelTransactionParameters this_arg_conv;
15266         this_arg_conv.inner = (void*)(this_arg & (~1));
15267         this_arg_conv.is_owned = false;
15268         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_holder_broadcastable(&this_arg_conv);
15269         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15270         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15271         long ret_ref = (long)ret_var.inner;
15272         if (ret_var.is_owned) {
15273                 ret_ref |= 1;
15274         }
15275         return ret_ref;
15276 }
15277
15278 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1as_1counterparty_1broadcastable(JNIEnv * _env, jclass _b, jlong this_arg) {
15279         LDKChannelTransactionParameters this_arg_conv;
15280         this_arg_conv.inner = (void*)(this_arg & (~1));
15281         this_arg_conv.is_owned = false;
15282         LDKDirectedChannelTransactionParameters ret_var = ChannelTransactionParameters_as_counterparty_broadcastable(&this_arg_conv);
15283         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15284         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15285         long ret_ref = (long)ret_var.inner;
15286         if (ret_var.is_owned) {
15287                 ret_ref |= 1;
15288         }
15289         return ret_ref;
15290 }
15291
15292 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1write(JNIEnv * _env, jclass _b, jlong obj) {
15293         LDKCounterpartyChannelTransactionParameters obj_conv;
15294         obj_conv.inner = (void*)(obj & (~1));
15295         obj_conv.is_owned = false;
15296         LDKCVec_u8Z arg_var = CounterpartyChannelTransactionParameters_write(&obj_conv);
15297         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15298         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15299         CVec_u8Z_free(arg_var);
15300         return arg_arr;
15301 }
15302
15303 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CounterpartyChannelTransactionParameters_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
15304         LDKu8slice ser_ref;
15305         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
15306         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
15307         LDKCounterpartyChannelTransactionParameters ret_var = CounterpartyChannelTransactionParameters_read(ser_ref);
15308         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15309         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15310         long ret_ref = (long)ret_var.inner;
15311         if (ret_var.is_owned) {
15312                 ret_ref |= 1;
15313         }
15314         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
15315         return ret_ref;
15316 }
15317
15318 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1write(JNIEnv * _env, jclass _b, jlong obj) {
15319         LDKChannelTransactionParameters obj_conv;
15320         obj_conv.inner = (void*)(obj & (~1));
15321         obj_conv.is_owned = false;
15322         LDKCVec_u8Z arg_var = ChannelTransactionParameters_write(&obj_conv);
15323         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15324         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15325         CVec_u8Z_free(arg_var);
15326         return arg_arr;
15327 }
15328
15329 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelTransactionParameters_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
15330         LDKu8slice ser_ref;
15331         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
15332         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
15333         LDKChannelTransactionParameters ret_var = ChannelTransactionParameters_read(ser_ref);
15334         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15335         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15336         long ret_ref = (long)ret_var.inner;
15337         if (ret_var.is_owned) {
15338                 ret_ref |= 1;
15339         }
15340         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
15341         return ret_ref;
15342 }
15343
15344 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15345         LDKDirectedChannelTransactionParameters this_ptr_conv;
15346         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15347         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15348         DirectedChannelTransactionParameters_free(this_ptr_conv);
15349 }
15350
15351 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1broadcaster_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
15352         LDKDirectedChannelTransactionParameters this_arg_conv;
15353         this_arg_conv.inner = (void*)(this_arg & (~1));
15354         this_arg_conv.is_owned = false;
15355         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_broadcaster_pubkeys(&this_arg_conv);
15356         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15357         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15358         long ret_ref = (long)ret_var.inner;
15359         if (ret_var.is_owned) {
15360                 ret_ref |= 1;
15361         }
15362         return ret_ref;
15363 }
15364
15365 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1countersignatory_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
15366         LDKDirectedChannelTransactionParameters this_arg_conv;
15367         this_arg_conv.inner = (void*)(this_arg & (~1));
15368         this_arg_conv.is_owned = false;
15369         LDKChannelPublicKeys ret_var = DirectedChannelTransactionParameters_countersignatory_pubkeys(&this_arg_conv);
15370         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15371         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15372         long ret_ref = (long)ret_var.inner;
15373         if (ret_var.is_owned) {
15374                 ret_ref |= 1;
15375         }
15376         return ret_ref;
15377 }
15378
15379 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_arg) {
15380         LDKDirectedChannelTransactionParameters this_arg_conv;
15381         this_arg_conv.inner = (void*)(this_arg & (~1));
15382         this_arg_conv.is_owned = false;
15383         jshort ret_val = DirectedChannelTransactionParameters_contest_delay(&this_arg_conv);
15384         return ret_val;
15385 }
15386
15387 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1is_1outbound(JNIEnv * _env, jclass _b, jlong this_arg) {
15388         LDKDirectedChannelTransactionParameters this_arg_conv;
15389         this_arg_conv.inner = (void*)(this_arg & (~1));
15390         this_arg_conv.is_owned = false;
15391         jboolean ret_val = DirectedChannelTransactionParameters_is_outbound(&this_arg_conv);
15392         return ret_val;
15393 }
15394
15395 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectedChannelTransactionParameters_1funding_1outpoint(JNIEnv * _env, jclass _b, jlong this_arg) {
15396         LDKDirectedChannelTransactionParameters this_arg_conv;
15397         this_arg_conv.inner = (void*)(this_arg & (~1));
15398         this_arg_conv.is_owned = false;
15399         LDKOutPoint ret_var = DirectedChannelTransactionParameters_funding_outpoint(&this_arg_conv);
15400         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15401         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15402         long ret_ref = (long)ret_var.inner;
15403         if (ret_var.is_owned) {
15404                 ret_ref |= 1;
15405         }
15406         return ret_ref;
15407 }
15408
15409 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15410         LDKHolderCommitmentTransaction this_ptr_conv;
15411         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15412         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15413         HolderCommitmentTransaction_free(this_ptr_conv);
15414 }
15415
15416 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
15417         LDKHolderCommitmentTransaction orig_conv;
15418         orig_conv.inner = (void*)(orig & (~1));
15419         orig_conv.is_owned = false;
15420         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_clone(&orig_conv);
15421         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15422         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15423         long ret_ref = (long)ret_var.inner;
15424         if (ret_var.is_owned) {
15425                 ret_ref |= 1;
15426         }
15427         return ret_ref;
15428 }
15429
15430 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1counterparty_1sig(JNIEnv * _env, jclass _b, jlong this_ptr) {
15431         LDKHolderCommitmentTransaction this_ptr_conv;
15432         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15433         this_ptr_conv.is_owned = false;
15434         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
15435         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, HolderCommitmentTransaction_get_counterparty_sig(&this_ptr_conv).compact_form);
15436         return arg_arr;
15437 }
15438
15439 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1counterparty_1sig(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
15440         LDKHolderCommitmentTransaction this_ptr_conv;
15441         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15442         this_ptr_conv.is_owned = false;
15443         LDKSignature val_ref;
15444         CHECK((*_env)->GetArrayLength (_env, val) == 64);
15445         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
15446         HolderCommitmentTransaction_set_counterparty_sig(&this_ptr_conv, val_ref);
15447 }
15448
15449 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1counterparty_1htlc_1sigs(JNIEnv * _env, jclass _b, jlong this_ptr, jobjectArray val) {
15450         LDKHolderCommitmentTransaction this_ptr_conv;
15451         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15452         this_ptr_conv.is_owned = false;
15453         LDKCVec_SignatureZ val_constr;
15454         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
15455         if (val_constr.datalen > 0)
15456                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
15457         else
15458                 val_constr.data = NULL;
15459         for (size_t i = 0; i < val_constr.datalen; i++) {
15460                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, val, i);
15461                 LDKSignature arr_conv_8_ref;
15462                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
15463                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
15464                 val_constr.data[i] = arr_conv_8_ref;
15465         }
15466         HolderCommitmentTransaction_set_counterparty_htlc_sigs(&this_ptr_conv, val_constr);
15467 }
15468
15469 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1write(JNIEnv * _env, jclass _b, jlong obj) {
15470         LDKHolderCommitmentTransaction obj_conv;
15471         obj_conv.inner = (void*)(obj & (~1));
15472         obj_conv.is_owned = false;
15473         LDKCVec_u8Z arg_var = HolderCommitmentTransaction_write(&obj_conv);
15474         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15475         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15476         CVec_u8Z_free(arg_var);
15477         return arg_arr;
15478 }
15479
15480 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
15481         LDKu8slice ser_ref;
15482         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
15483         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
15484         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_read(ser_ref);
15485         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15486         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15487         long ret_ref = (long)ret_var.inner;
15488         if (ret_var.is_owned) {
15489                 ret_ref |= 1;
15490         }
15491         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
15492         return ret_ref;
15493 }
15494
15495 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1new(JNIEnv * _env, jclass _b, jlong commitment_tx, jbyteArray counterparty_sig, jobjectArray counterparty_htlc_sigs, jbyteArray holder_funding_key, jbyteArray counterparty_funding_key) {
15496         LDKCommitmentTransaction commitment_tx_conv;
15497         commitment_tx_conv.inner = (void*)(commitment_tx & (~1));
15498         commitment_tx_conv.is_owned = (commitment_tx & 1) || (commitment_tx == 0);
15499         if (commitment_tx_conv.inner != NULL)
15500                 commitment_tx_conv = CommitmentTransaction_clone(&commitment_tx_conv);
15501         LDKSignature counterparty_sig_ref;
15502         CHECK((*_env)->GetArrayLength (_env, counterparty_sig) == 64);
15503         (*_env)->GetByteArrayRegion (_env, counterparty_sig, 0, 64, counterparty_sig_ref.compact_form);
15504         LDKCVec_SignatureZ counterparty_htlc_sigs_constr;
15505         counterparty_htlc_sigs_constr.datalen = (*_env)->GetArrayLength (_env, counterparty_htlc_sigs);
15506         if (counterparty_htlc_sigs_constr.datalen > 0)
15507                 counterparty_htlc_sigs_constr.data = MALLOC(counterparty_htlc_sigs_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
15508         else
15509                 counterparty_htlc_sigs_constr.data = NULL;
15510         for (size_t i = 0; i < counterparty_htlc_sigs_constr.datalen; i++) {
15511                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, counterparty_htlc_sigs, i);
15512                 LDKSignature arr_conv_8_ref;
15513                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
15514                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
15515                 counterparty_htlc_sigs_constr.data[i] = arr_conv_8_ref;
15516         }
15517         LDKPublicKey holder_funding_key_ref;
15518         CHECK((*_env)->GetArrayLength (_env, holder_funding_key) == 33);
15519         (*_env)->GetByteArrayRegion (_env, holder_funding_key, 0, 33, holder_funding_key_ref.compressed_form);
15520         LDKPublicKey counterparty_funding_key_ref;
15521         CHECK((*_env)->GetArrayLength (_env, counterparty_funding_key) == 33);
15522         (*_env)->GetByteArrayRegion (_env, counterparty_funding_key, 0, 33, counterparty_funding_key_ref.compressed_form);
15523         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_new(commitment_tx_conv, counterparty_sig_ref, counterparty_htlc_sigs_constr, holder_funding_key_ref, counterparty_funding_key_ref);
15524         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15525         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15526         long ret_ref = (long)ret_var.inner;
15527         if (ret_var.is_owned) {
15528                 ret_ref |= 1;
15529         }
15530         return ret_ref;
15531 }
15532
15533 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15534         LDKBuiltCommitmentTransaction this_ptr_conv;
15535         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15536         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15537         BuiltCommitmentTransaction_free(this_ptr_conv);
15538 }
15539
15540 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
15541         LDKBuiltCommitmentTransaction orig_conv;
15542         orig_conv.inner = (void*)(orig & (~1));
15543         orig_conv.is_owned = false;
15544         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_clone(&orig_conv);
15545         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15546         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15547         long ret_ref = (long)ret_var.inner;
15548         if (ret_var.is_owned) {
15549                 ret_ref |= 1;
15550         }
15551         return ret_ref;
15552 }
15553
15554 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1get_1transaction(JNIEnv * _env, jclass _b, jlong this_ptr) {
15555         LDKBuiltCommitmentTransaction this_ptr_conv;
15556         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15557         this_ptr_conv.is_owned = false;
15558         LDKTransaction arg_var = BuiltCommitmentTransaction_get_transaction(&this_ptr_conv);
15559         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15560         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15561         Transaction_free(arg_var);
15562         return arg_arr;
15563 }
15564
15565 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1set_1transaction(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
15566         LDKBuiltCommitmentTransaction this_ptr_conv;
15567         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15568         this_ptr_conv.is_owned = false;
15569         LDKTransaction val_ref;
15570         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
15571         val_ref.data = MALLOC(val_ref.datalen, "LDKTransaction Bytes");
15572         (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data);
15573         val_ref.data_is_owned = true;
15574         BuiltCommitmentTransaction_set_transaction(&this_ptr_conv, val_ref);
15575 }
15576
15577 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1get_1txid(JNIEnv * _env, jclass _b, jlong this_ptr) {
15578         LDKBuiltCommitmentTransaction this_ptr_conv;
15579         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15580         this_ptr_conv.is_owned = false;
15581         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
15582         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *BuiltCommitmentTransaction_get_txid(&this_ptr_conv));
15583         return ret_arr;
15584 }
15585
15586 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1set_1txid(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
15587         LDKBuiltCommitmentTransaction this_ptr_conv;
15588         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15589         this_ptr_conv.is_owned = false;
15590         LDKThirtyTwoBytes val_ref;
15591         CHECK((*_env)->GetArrayLength (_env, val) == 32);
15592         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
15593         BuiltCommitmentTransaction_set_txid(&this_ptr_conv, val_ref);
15594 }
15595
15596 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1new(JNIEnv * _env, jclass _b, jbyteArray transaction_arg, jbyteArray txid_arg) {
15597         LDKTransaction transaction_arg_ref;
15598         transaction_arg_ref.datalen = (*_env)->GetArrayLength (_env, transaction_arg);
15599         transaction_arg_ref.data = MALLOC(transaction_arg_ref.datalen, "LDKTransaction Bytes");
15600         (*_env)->GetByteArrayRegion(_env, transaction_arg, 0, transaction_arg_ref.datalen, transaction_arg_ref.data);
15601         transaction_arg_ref.data_is_owned = true;
15602         LDKThirtyTwoBytes txid_arg_ref;
15603         CHECK((*_env)->GetArrayLength (_env, txid_arg) == 32);
15604         (*_env)->GetByteArrayRegion (_env, txid_arg, 0, 32, txid_arg_ref.data);
15605         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_new(transaction_arg_ref, txid_arg_ref);
15606         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15607         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15608         long ret_ref = (long)ret_var.inner;
15609         if (ret_var.is_owned) {
15610                 ret_ref |= 1;
15611         }
15612         return ret_ref;
15613 }
15614
15615 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1write(JNIEnv * _env, jclass _b, jlong obj) {
15616         LDKBuiltCommitmentTransaction obj_conv;
15617         obj_conv.inner = (void*)(obj & (~1));
15618         obj_conv.is_owned = false;
15619         LDKCVec_u8Z arg_var = BuiltCommitmentTransaction_write(&obj_conv);
15620         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15621         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15622         CVec_u8Z_free(arg_var);
15623         return arg_arr;
15624 }
15625
15626 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
15627         LDKu8slice ser_ref;
15628         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
15629         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
15630         LDKBuiltCommitmentTransaction ret_var = BuiltCommitmentTransaction_read(ser_ref);
15631         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15632         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15633         long ret_ref = (long)ret_var.inner;
15634         if (ret_var.is_owned) {
15635                 ret_ref |= 1;
15636         }
15637         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
15638         return ret_ref;
15639 }
15640
15641 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1get_1sighash_1all(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray funding_redeemscript, jlong channel_value_satoshis) {
15642         LDKBuiltCommitmentTransaction this_arg_conv;
15643         this_arg_conv.inner = (void*)(this_arg & (~1));
15644         this_arg_conv.is_owned = false;
15645         LDKu8slice funding_redeemscript_ref;
15646         funding_redeemscript_ref.datalen = (*_env)->GetArrayLength (_env, funding_redeemscript);
15647         funding_redeemscript_ref.data = (*_env)->GetByteArrayElements (_env, funding_redeemscript, NULL);
15648         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
15649         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, BuiltCommitmentTransaction_get_sighash_all(&this_arg_conv, funding_redeemscript_ref, channel_value_satoshis).data);
15650         (*_env)->ReleaseByteArrayElements(_env, funding_redeemscript, (int8_t*)funding_redeemscript_ref.data, 0);
15651         return arg_arr;
15652 }
15653
15654 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_BuiltCommitmentTransaction_1sign(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray funding_key, jbyteArray funding_redeemscript, jlong channel_value_satoshis) {
15655         LDKBuiltCommitmentTransaction this_arg_conv;
15656         this_arg_conv.inner = (void*)(this_arg & (~1));
15657         this_arg_conv.is_owned = false;
15658         unsigned char funding_key_arr[32];
15659         CHECK((*_env)->GetArrayLength (_env, funding_key) == 32);
15660         (*_env)->GetByteArrayRegion (_env, funding_key, 0, 32, funding_key_arr);
15661         unsigned char (*funding_key_ref)[32] = &funding_key_arr;
15662         LDKu8slice funding_redeemscript_ref;
15663         funding_redeemscript_ref.datalen = (*_env)->GetArrayLength (_env, funding_redeemscript);
15664         funding_redeemscript_ref.data = (*_env)->GetByteArrayElements (_env, funding_redeemscript, NULL);
15665         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
15666         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, BuiltCommitmentTransaction_sign(&this_arg_conv, funding_key_ref, funding_redeemscript_ref, channel_value_satoshis).compact_form);
15667         (*_env)->ReleaseByteArrayElements(_env, funding_redeemscript, (int8_t*)funding_redeemscript_ref.data, 0);
15668         return arg_arr;
15669 }
15670
15671 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15672         LDKCommitmentTransaction this_ptr_conv;
15673         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15674         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15675         CommitmentTransaction_free(this_ptr_conv);
15676 }
15677
15678 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
15679         LDKCommitmentTransaction orig_conv;
15680         orig_conv.inner = (void*)(orig & (~1));
15681         orig_conv.is_owned = false;
15682         LDKCommitmentTransaction ret_var = CommitmentTransaction_clone(&orig_conv);
15683         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15684         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15685         long ret_ref = (long)ret_var.inner;
15686         if (ret_var.is_owned) {
15687                 ret_ref |= 1;
15688         }
15689         return ret_ref;
15690 }
15691
15692 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1write(JNIEnv * _env, jclass _b, jlong obj) {
15693         LDKCommitmentTransaction obj_conv;
15694         obj_conv.inner = (void*)(obj & (~1));
15695         obj_conv.is_owned = false;
15696         LDKCVec_u8Z arg_var = CommitmentTransaction_write(&obj_conv);
15697         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
15698         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
15699         CVec_u8Z_free(arg_var);
15700         return arg_arr;
15701 }
15702
15703 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
15704         LDKu8slice ser_ref;
15705         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
15706         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
15707         LDKCommitmentTransaction ret_var = CommitmentTransaction_read(ser_ref);
15708         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15709         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15710         long ret_ref = (long)ret_var.inner;
15711         if (ret_var.is_owned) {
15712                 ret_ref |= 1;
15713         }
15714         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
15715         return ret_ref;
15716 }
15717
15718 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_arg) {
15719         LDKCommitmentTransaction this_arg_conv;
15720         this_arg_conv.inner = (void*)(this_arg & (~1));
15721         this_arg_conv.is_owned = false;
15722         jlong ret_val = CommitmentTransaction_commitment_number(&this_arg_conv);
15723         return ret_val;
15724 }
15725
15726 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1to_1broadcaster_1value_1sat(JNIEnv * _env, jclass _b, jlong this_arg) {
15727         LDKCommitmentTransaction this_arg_conv;
15728         this_arg_conv.inner = (void*)(this_arg & (~1));
15729         this_arg_conv.is_owned = false;
15730         jlong ret_val = CommitmentTransaction_to_broadcaster_value_sat(&this_arg_conv);
15731         return ret_val;
15732 }
15733
15734 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1to_1countersignatory_1value_1sat(JNIEnv * _env, jclass _b, jlong this_arg) {
15735         LDKCommitmentTransaction this_arg_conv;
15736         this_arg_conv.inner = (void*)(this_arg & (~1));
15737         this_arg_conv.is_owned = false;
15738         jlong ret_val = CommitmentTransaction_to_countersignatory_value_sat(&this_arg_conv);
15739         return ret_val;
15740 }
15741
15742 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_arg) {
15743         LDKCommitmentTransaction this_arg_conv;
15744         this_arg_conv.inner = (void*)(this_arg & (~1));
15745         this_arg_conv.is_owned = false;
15746         jint ret_val = CommitmentTransaction_feerate_per_kw(&this_arg_conv);
15747         return ret_val;
15748 }
15749
15750 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1trust(JNIEnv * _env, jclass _b, jlong this_arg) {
15751         LDKCommitmentTransaction this_arg_conv;
15752         this_arg_conv.inner = (void*)(this_arg & (~1));
15753         this_arg_conv.is_owned = false;
15754         LDKTrustedCommitmentTransaction ret_var = CommitmentTransaction_trust(&this_arg_conv);
15755         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15756         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15757         long ret_ref = (long)ret_var.inner;
15758         if (ret_var.is_owned) {
15759                 ret_ref |= 1;
15760         }
15761         return ret_ref;
15762 }
15763
15764 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentTransaction_1verify(JNIEnv * _env, jclass _b, jlong this_arg, jlong channel_parameters, jlong broadcaster_keys, jlong countersignatory_keys) {
15765         LDKCommitmentTransaction this_arg_conv;
15766         this_arg_conv.inner = (void*)(this_arg & (~1));
15767         this_arg_conv.is_owned = false;
15768         LDKDirectedChannelTransactionParameters channel_parameters_conv;
15769         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
15770         channel_parameters_conv.is_owned = false;
15771         LDKChannelPublicKeys broadcaster_keys_conv;
15772         broadcaster_keys_conv.inner = (void*)(broadcaster_keys & (~1));
15773         broadcaster_keys_conv.is_owned = false;
15774         LDKChannelPublicKeys countersignatory_keys_conv;
15775         countersignatory_keys_conv.inner = (void*)(countersignatory_keys & (~1));
15776         countersignatory_keys_conv.is_owned = false;
15777         LDKCResult_TrustedCommitmentTransactionNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_TrustedCommitmentTransactionNoneZ), "LDKCResult_TrustedCommitmentTransactionNoneZ");
15778         *ret_conv = CommitmentTransaction_verify(&this_arg_conv, &channel_parameters_conv, &broadcaster_keys_conv, &countersignatory_keys_conv);
15779         return (long)ret_conv;
15780 }
15781
15782 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15783         LDKTrustedCommitmentTransaction this_ptr_conv;
15784         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15785         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15786         TrustedCommitmentTransaction_free(this_ptr_conv);
15787 }
15788
15789 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1txid(JNIEnv * _env, jclass _b, jlong this_arg) {
15790         LDKTrustedCommitmentTransaction this_arg_conv;
15791         this_arg_conv.inner = (void*)(this_arg & (~1));
15792         this_arg_conv.is_owned = false;
15793         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
15794         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, TrustedCommitmentTransaction_txid(&this_arg_conv).data);
15795         return arg_arr;
15796 }
15797
15798 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1built_1transaction(JNIEnv * _env, jclass _b, jlong this_arg) {
15799         LDKTrustedCommitmentTransaction this_arg_conv;
15800         this_arg_conv.inner = (void*)(this_arg & (~1));
15801         this_arg_conv.is_owned = false;
15802         LDKBuiltCommitmentTransaction ret_var = TrustedCommitmentTransaction_built_transaction(&this_arg_conv);
15803         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15804         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15805         long ret_ref = (long)ret_var.inner;
15806         if (ret_var.is_owned) {
15807                 ret_ref |= 1;
15808         }
15809         return ret_ref;
15810 }
15811
15812 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1keys(JNIEnv * _env, jclass _b, jlong this_arg) {
15813         LDKTrustedCommitmentTransaction this_arg_conv;
15814         this_arg_conv.inner = (void*)(this_arg & (~1));
15815         this_arg_conv.is_owned = false;
15816         LDKTxCreationKeys ret_var = TrustedCommitmentTransaction_keys(&this_arg_conv);
15817         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15818         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15819         long ret_ref = (long)ret_var.inner;
15820         if (ret_var.is_owned) {
15821                 ret_ref |= 1;
15822         }
15823         return ret_ref;
15824 }
15825
15826 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TrustedCommitmentTransaction_1get_1htlc_1sigs(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray htlc_base_key, jlong channel_parameters) {
15827         LDKTrustedCommitmentTransaction this_arg_conv;
15828         this_arg_conv.inner = (void*)(this_arg & (~1));
15829         this_arg_conv.is_owned = false;
15830         unsigned char htlc_base_key_arr[32];
15831         CHECK((*_env)->GetArrayLength (_env, htlc_base_key) == 32);
15832         (*_env)->GetByteArrayRegion (_env, htlc_base_key, 0, 32, htlc_base_key_arr);
15833         unsigned char (*htlc_base_key_ref)[32] = &htlc_base_key_arr;
15834         LDKDirectedChannelTransactionParameters channel_parameters_conv;
15835         channel_parameters_conv.inner = (void*)(channel_parameters & (~1));
15836         channel_parameters_conv.is_owned = false;
15837         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
15838         *ret_conv = TrustedCommitmentTransaction_get_htlc_sigs(&this_arg_conv, htlc_base_key_ref, &channel_parameters_conv);
15839         return (long)ret_conv;
15840 }
15841
15842 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_get_1commitment_1transaction_1number_1obscure_1factor(JNIEnv * _env, jclass _b, jbyteArray broadcaster_payment_basepoint, jbyteArray countersignatory_payment_basepoint, jboolean outbound_from_broadcaster) {
15843         LDKPublicKey broadcaster_payment_basepoint_ref;
15844         CHECK((*_env)->GetArrayLength (_env, broadcaster_payment_basepoint) == 33);
15845         (*_env)->GetByteArrayRegion (_env, broadcaster_payment_basepoint, 0, 33, broadcaster_payment_basepoint_ref.compressed_form);
15846         LDKPublicKey countersignatory_payment_basepoint_ref;
15847         CHECK((*_env)->GetArrayLength (_env, countersignatory_payment_basepoint) == 33);
15848         (*_env)->GetByteArrayRegion (_env, countersignatory_payment_basepoint, 0, 33, countersignatory_payment_basepoint_ref.compressed_form);
15849         jlong ret_val = get_commitment_transaction_number_obscure_factor(broadcaster_payment_basepoint_ref, countersignatory_payment_basepoint_ref, outbound_from_broadcaster);
15850         return ret_val;
15851 }
15852
15853 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InitFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15854         LDKInitFeatures this_ptr_conv;
15855         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15856         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15857         InitFeatures_free(this_ptr_conv);
15858 }
15859
15860 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15861         LDKNodeFeatures this_ptr_conv;
15862         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15863         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15864         NodeFeatures_free(this_ptr_conv);
15865 }
15866
15867 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15868         LDKChannelFeatures this_ptr_conv;
15869         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15870         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15871         ChannelFeatures_free(this_ptr_conv);
15872 }
15873
15874 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
15875         LDKRouteHop this_ptr_conv;
15876         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15877         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
15878         RouteHop_free(this_ptr_conv);
15879 }
15880
15881 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1clone(JNIEnv * _env, jclass _b, jlong orig) {
15882         LDKRouteHop orig_conv;
15883         orig_conv.inner = (void*)(orig & (~1));
15884         orig_conv.is_owned = false;
15885         LDKRouteHop ret_var = RouteHop_clone(&orig_conv);
15886         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15887         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15888         long ret_ref = (long)ret_var.inner;
15889         if (ret_var.is_owned) {
15890                 ret_ref |= 1;
15891         }
15892         return ret_ref;
15893 }
15894
15895 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
15896         LDKRouteHop this_ptr_conv;
15897         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15898         this_ptr_conv.is_owned = false;
15899         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
15900         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RouteHop_get_pubkey(&this_ptr_conv).compressed_form);
15901         return arg_arr;
15902 }
15903
15904 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
15905         LDKRouteHop this_ptr_conv;
15906         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15907         this_ptr_conv.is_owned = false;
15908         LDKPublicKey val_ref;
15909         CHECK((*_env)->GetArrayLength (_env, val) == 33);
15910         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
15911         RouteHop_set_pubkey(&this_ptr_conv, val_ref);
15912 }
15913
15914 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1node_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
15915         LDKRouteHop this_ptr_conv;
15916         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15917         this_ptr_conv.is_owned = false;
15918         LDKNodeFeatures ret_var = RouteHop_get_node_features(&this_ptr_conv);
15919         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15920         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15921         long ret_ref = (long)ret_var.inner;
15922         if (ret_var.is_owned) {
15923                 ret_ref |= 1;
15924         }
15925         return ret_ref;
15926 }
15927
15928 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1node_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15929         LDKRouteHop this_ptr_conv;
15930         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15931         this_ptr_conv.is_owned = false;
15932         LDKNodeFeatures val_conv;
15933         val_conv.inner = (void*)(val & (~1));
15934         val_conv.is_owned = (val & 1) || (val == 0);
15935         // Warning: we may need a move here but can't clone!
15936         RouteHop_set_node_features(&this_ptr_conv, val_conv);
15937 }
15938
15939 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
15940         LDKRouteHop this_ptr_conv;
15941         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15942         this_ptr_conv.is_owned = false;
15943         jlong ret_val = RouteHop_get_short_channel_id(&this_ptr_conv);
15944         return ret_val;
15945 }
15946
15947 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15948         LDKRouteHop this_ptr_conv;
15949         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15950         this_ptr_conv.is_owned = false;
15951         RouteHop_set_short_channel_id(&this_ptr_conv, val);
15952 }
15953
15954 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1channel_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
15955         LDKRouteHop this_ptr_conv;
15956         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15957         this_ptr_conv.is_owned = false;
15958         LDKChannelFeatures ret_var = RouteHop_get_channel_features(&this_ptr_conv);
15959         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
15960         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
15961         long ret_ref = (long)ret_var.inner;
15962         if (ret_var.is_owned) {
15963                 ret_ref |= 1;
15964         }
15965         return ret_ref;
15966 }
15967
15968 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1channel_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15969         LDKRouteHop this_ptr_conv;
15970         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15971         this_ptr_conv.is_owned = false;
15972         LDKChannelFeatures val_conv;
15973         val_conv.inner = (void*)(val & (~1));
15974         val_conv.is_owned = (val & 1) || (val == 0);
15975         // Warning: we may need a move here but can't clone!
15976         RouteHop_set_channel_features(&this_ptr_conv, val_conv);
15977 }
15978
15979 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1fee_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
15980         LDKRouteHop this_ptr_conv;
15981         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15982         this_ptr_conv.is_owned = false;
15983         jlong ret_val = RouteHop_get_fee_msat(&this_ptr_conv);
15984         return ret_val;
15985 }
15986
15987 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1fee_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
15988         LDKRouteHop this_ptr_conv;
15989         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15990         this_ptr_conv.is_owned = false;
15991         RouteHop_set_fee_msat(&this_ptr_conv, val);
15992 }
15993
15994 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
15995         LDKRouteHop this_ptr_conv;
15996         this_ptr_conv.inner = (void*)(this_ptr & (~1));
15997         this_ptr_conv.is_owned = false;
15998         jint ret_val = RouteHop_get_cltv_expiry_delta(&this_ptr_conv);
15999         return ret_val;
16000 }
16001
16002 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
16003         LDKRouteHop this_ptr_conv;
16004         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16005         this_ptr_conv.is_owned = false;
16006         RouteHop_set_cltv_expiry_delta(&this_ptr_conv, val);
16007 }
16008
16009 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) {
16010         LDKPublicKey pubkey_arg_ref;
16011         CHECK((*_env)->GetArrayLength (_env, pubkey_arg) == 33);
16012         (*_env)->GetByteArrayRegion (_env, pubkey_arg, 0, 33, pubkey_arg_ref.compressed_form);
16013         LDKNodeFeatures node_features_arg_conv;
16014         node_features_arg_conv.inner = (void*)(node_features_arg & (~1));
16015         node_features_arg_conv.is_owned = (node_features_arg & 1) || (node_features_arg == 0);
16016         // Warning: we may need a move here but can't clone!
16017         LDKChannelFeatures channel_features_arg_conv;
16018         channel_features_arg_conv.inner = (void*)(channel_features_arg & (~1));
16019         channel_features_arg_conv.is_owned = (channel_features_arg & 1) || (channel_features_arg == 0);
16020         // Warning: we may need a move here but can't clone!
16021         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);
16022         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16023         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16024         long ret_ref = (long)ret_var.inner;
16025         if (ret_var.is_owned) {
16026                 ret_ref |= 1;
16027         }
16028         return ret_ref;
16029 }
16030
16031 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16032         LDKRoute this_ptr_conv;
16033         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16034         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16035         Route_free(this_ptr_conv);
16036 }
16037
16038 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1clone(JNIEnv * _env, jclass _b, jlong orig) {
16039         LDKRoute orig_conv;
16040         orig_conv.inner = (void*)(orig & (~1));
16041         orig_conv.is_owned = false;
16042         LDKRoute ret_var = Route_clone(&orig_conv);
16043         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16044         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16045         long ret_ref = (long)ret_var.inner;
16046         if (ret_var.is_owned) {
16047                 ret_ref |= 1;
16048         }
16049         return ret_ref;
16050 }
16051
16052 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1set_1paths(JNIEnv * _env, jclass _b, jlong this_ptr, jobjectArray val) {
16053         LDKRoute this_ptr_conv;
16054         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16055         this_ptr_conv.is_owned = false;
16056         LDKCVec_CVec_RouteHopZZ val_constr;
16057         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
16058         if (val_constr.datalen > 0)
16059                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
16060         else
16061                 val_constr.data = NULL;
16062         for (size_t m = 0; m < val_constr.datalen; m++) {
16063                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, val, m);
16064                 LDKCVec_RouteHopZ arr_conv_12_constr;
16065                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
16066                 if (arr_conv_12_constr.datalen > 0)
16067                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
16068                 else
16069                         arr_conv_12_constr.data = NULL;
16070                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
16071                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
16072                         long arr_conv_10 = arr_conv_12_vals[k];
16073                         LDKRouteHop arr_conv_10_conv;
16074                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
16075                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
16076                         if (arr_conv_10_conv.inner != NULL)
16077                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
16078                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
16079                 }
16080                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
16081                 val_constr.data[m] = arr_conv_12_constr;
16082         }
16083         Route_set_paths(&this_ptr_conv, val_constr);
16084 }
16085
16086 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1new(JNIEnv * _env, jclass _b, jobjectArray paths_arg) {
16087         LDKCVec_CVec_RouteHopZZ paths_arg_constr;
16088         paths_arg_constr.datalen = (*_env)->GetArrayLength (_env, paths_arg);
16089         if (paths_arg_constr.datalen > 0)
16090                 paths_arg_constr.data = MALLOC(paths_arg_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
16091         else
16092                 paths_arg_constr.data = NULL;
16093         for (size_t m = 0; m < paths_arg_constr.datalen; m++) {
16094                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, paths_arg, m);
16095                 LDKCVec_RouteHopZ arr_conv_12_constr;
16096                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
16097                 if (arr_conv_12_constr.datalen > 0)
16098                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
16099                 else
16100                         arr_conv_12_constr.data = NULL;
16101                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
16102                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
16103                         long arr_conv_10 = arr_conv_12_vals[k];
16104                         LDKRouteHop arr_conv_10_conv;
16105                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
16106                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
16107                         if (arr_conv_10_conv.inner != NULL)
16108                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
16109                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
16110                 }
16111                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
16112                 paths_arg_constr.data[m] = arr_conv_12_constr;
16113         }
16114         LDKRoute ret_var = Route_new(paths_arg_constr);
16115         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16116         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16117         long ret_ref = (long)ret_var.inner;
16118         if (ret_var.is_owned) {
16119                 ret_ref |= 1;
16120         }
16121         return ret_ref;
16122 }
16123
16124 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Route_1write(JNIEnv * _env, jclass _b, jlong obj) {
16125         LDKRoute obj_conv;
16126         obj_conv.inner = (void*)(obj & (~1));
16127         obj_conv.is_owned = false;
16128         LDKCVec_u8Z arg_var = Route_write(&obj_conv);
16129         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
16130         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
16131         CVec_u8Z_free(arg_var);
16132         return arg_arr;
16133 }
16134
16135 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
16136         LDKu8slice ser_ref;
16137         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
16138         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
16139         LDKCResult_RouteDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteDecodeErrorZ), "LDKCResult_RouteDecodeErrorZ");
16140         *ret_conv = Route_read(ser_ref);
16141         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
16142         return (long)ret_conv;
16143 }
16144
16145 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16146         LDKRouteHint this_ptr_conv;
16147         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16148         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16149         RouteHint_free(this_ptr_conv);
16150 }
16151
16152 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1clone(JNIEnv * _env, jclass _b, jlong orig) {
16153         LDKRouteHint orig_conv;
16154         orig_conv.inner = (void*)(orig & (~1));
16155         orig_conv.is_owned = false;
16156         LDKRouteHint ret_var = RouteHint_clone(&orig_conv);
16157         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16158         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16159         long ret_ref = (long)ret_var.inner;
16160         if (ret_var.is_owned) {
16161                 ret_ref |= 1;
16162         }
16163         return ret_ref;
16164 }
16165
16166 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1src_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
16167         LDKRouteHint this_ptr_conv;
16168         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16169         this_ptr_conv.is_owned = false;
16170         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
16171         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RouteHint_get_src_node_id(&this_ptr_conv).compressed_form);
16172         return arg_arr;
16173 }
16174
16175 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1src_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
16176         LDKRouteHint this_ptr_conv;
16177         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16178         this_ptr_conv.is_owned = false;
16179         LDKPublicKey val_ref;
16180         CHECK((*_env)->GetArrayLength (_env, val) == 33);
16181         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
16182         RouteHint_set_src_node_id(&this_ptr_conv, val_ref);
16183 }
16184
16185 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
16186         LDKRouteHint this_ptr_conv;
16187         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16188         this_ptr_conv.is_owned = false;
16189         jlong ret_val = RouteHint_get_short_channel_id(&this_ptr_conv);
16190         return ret_val;
16191 }
16192
16193 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16194         LDKRouteHint this_ptr_conv;
16195         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16196         this_ptr_conv.is_owned = false;
16197         RouteHint_set_short_channel_id(&this_ptr_conv, val);
16198 }
16199
16200 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1fees(JNIEnv * _env, jclass _b, jlong this_ptr) {
16201         LDKRouteHint this_ptr_conv;
16202         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16203         this_ptr_conv.is_owned = false;
16204         LDKRoutingFees ret_var = RouteHint_get_fees(&this_ptr_conv);
16205         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16206         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16207         long ret_ref = (long)ret_var.inner;
16208         if (ret_var.is_owned) {
16209                 ret_ref |= 1;
16210         }
16211         return ret_ref;
16212 }
16213
16214 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1fees(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16215         LDKRouteHint this_ptr_conv;
16216         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16217         this_ptr_conv.is_owned = false;
16218         LDKRoutingFees val_conv;
16219         val_conv.inner = (void*)(val & (~1));
16220         val_conv.is_owned = (val & 1) || (val == 0);
16221         if (val_conv.inner != NULL)
16222                 val_conv = RoutingFees_clone(&val_conv);
16223         RouteHint_set_fees(&this_ptr_conv, val_conv);
16224 }
16225
16226 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
16227         LDKRouteHint this_ptr_conv;
16228         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16229         this_ptr_conv.is_owned = false;
16230         jshort ret_val = RouteHint_get_cltv_expiry_delta(&this_ptr_conv);
16231         return ret_val;
16232 }
16233
16234 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
16235         LDKRouteHint this_ptr_conv;
16236         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16237         this_ptr_conv.is_owned = false;
16238         RouteHint_set_cltv_expiry_delta(&this_ptr_conv, val);
16239 }
16240
16241 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
16242         LDKRouteHint this_ptr_conv;
16243         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16244         this_ptr_conv.is_owned = false;
16245         jlong ret_val = RouteHint_get_htlc_minimum_msat(&this_ptr_conv);
16246         return ret_val;
16247 }
16248
16249 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16250         LDKRouteHint this_ptr_conv;
16251         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16252         this_ptr_conv.is_owned = false;
16253         RouteHint_set_htlc_minimum_msat(&this_ptr_conv, val);
16254 }
16255
16256 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) {
16257         LDKPublicKey src_node_id_arg_ref;
16258         CHECK((*_env)->GetArrayLength (_env, src_node_id_arg) == 33);
16259         (*_env)->GetByteArrayRegion (_env, src_node_id_arg, 0, 33, src_node_id_arg_ref.compressed_form);
16260         LDKRoutingFees fees_arg_conv;
16261         fees_arg_conv.inner = (void*)(fees_arg & (~1));
16262         fees_arg_conv.is_owned = (fees_arg & 1) || (fees_arg == 0);
16263         if (fees_arg_conv.inner != NULL)
16264                 fees_arg_conv = RoutingFees_clone(&fees_arg_conv);
16265         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);
16266         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16267         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16268         long ret_ref = (long)ret_var.inner;
16269         if (ret_var.is_owned) {
16270                 ret_ref |= 1;
16271         }
16272         return ret_ref;
16273 }
16274
16275 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) {
16276         LDKPublicKey our_node_id_ref;
16277         CHECK((*_env)->GetArrayLength (_env, our_node_id) == 33);
16278         (*_env)->GetByteArrayRegion (_env, our_node_id, 0, 33, our_node_id_ref.compressed_form);
16279         LDKNetworkGraph network_conv;
16280         network_conv.inner = (void*)(network & (~1));
16281         network_conv.is_owned = false;
16282         LDKPublicKey target_ref;
16283         CHECK((*_env)->GetArrayLength (_env, target) == 33);
16284         (*_env)->GetByteArrayRegion (_env, target, 0, 33, target_ref.compressed_form);
16285         LDKCVec_ChannelDetailsZ first_hops_constr;
16286         first_hops_constr.datalen = (*_env)->GetArrayLength (_env, first_hops);
16287         if (first_hops_constr.datalen > 0)
16288                 first_hops_constr.data = MALLOC(first_hops_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
16289         else
16290                 first_hops_constr.data = NULL;
16291         long* first_hops_vals = (*_env)->GetLongArrayElements (_env, first_hops, NULL);
16292         for (size_t q = 0; q < first_hops_constr.datalen; q++) {
16293                 long arr_conv_16 = first_hops_vals[q];
16294                 LDKChannelDetails arr_conv_16_conv;
16295                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
16296                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
16297                 first_hops_constr.data[q] = arr_conv_16_conv;
16298         }
16299         (*_env)->ReleaseLongArrayElements (_env, first_hops, first_hops_vals, 0);
16300         LDKCVec_RouteHintZ last_hops_constr;
16301         last_hops_constr.datalen = (*_env)->GetArrayLength (_env, last_hops);
16302         if (last_hops_constr.datalen > 0)
16303                 last_hops_constr.data = MALLOC(last_hops_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
16304         else
16305                 last_hops_constr.data = NULL;
16306         long* last_hops_vals = (*_env)->GetLongArrayElements (_env, last_hops, NULL);
16307         for (size_t l = 0; l < last_hops_constr.datalen; l++) {
16308                 long arr_conv_11 = last_hops_vals[l];
16309                 LDKRouteHint arr_conv_11_conv;
16310                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
16311                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
16312                 if (arr_conv_11_conv.inner != NULL)
16313                         arr_conv_11_conv = RouteHint_clone(&arr_conv_11_conv);
16314                 last_hops_constr.data[l] = arr_conv_11_conv;
16315         }
16316         (*_env)->ReleaseLongArrayElements (_env, last_hops, last_hops_vals, 0);
16317         LDKLogger logger_conv = *(LDKLogger*)logger;
16318         if (logger_conv.free == LDKLogger_JCalls_free) {
16319                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
16320                 LDKLogger_JCalls_clone(logger_conv.this_arg);
16321         }
16322         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
16323         *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);
16324         FREE(first_hops_constr.data);
16325         return (long)ret_conv;
16326 }
16327
16328 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16329         LDKNetworkGraph this_ptr_conv;
16330         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16331         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16332         NetworkGraph_free(this_ptr_conv);
16333 }
16334
16335 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16336         LDKLockedNetworkGraph this_ptr_conv;
16337         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16338         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16339         LockedNetworkGraph_free(this_ptr_conv);
16340 }
16341
16342 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16343         LDKNetGraphMsgHandler this_ptr_conv;
16344         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16345         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16346         NetGraphMsgHandler_free(this_ptr_conv);
16347 }
16348
16349 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1new(JNIEnv * _env, jclass _b, jbyteArray genesis_hash, jlong chain_access, jlong logger) {
16350         LDKThirtyTwoBytes genesis_hash_ref;
16351         CHECK((*_env)->GetArrayLength (_env, genesis_hash) == 32);
16352         (*_env)->GetByteArrayRegion (_env, genesis_hash, 0, 32, genesis_hash_ref.data);
16353         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
16354         LDKLogger logger_conv = *(LDKLogger*)logger;
16355         if (logger_conv.free == LDKLogger_JCalls_free) {
16356                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
16357                 LDKLogger_JCalls_clone(logger_conv.this_arg);
16358         }
16359         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_new(genesis_hash_ref, chain_access_conv, logger_conv);
16360         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16361         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16362         long ret_ref = (long)ret_var.inner;
16363         if (ret_var.is_owned) {
16364                 ret_ref |= 1;
16365         }
16366         return ret_ref;
16367 }
16368
16369 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1from_1net_1graph(JNIEnv * _env, jclass _b, jlong chain_access, jlong logger, jlong network_graph) {
16370         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
16371         LDKLogger logger_conv = *(LDKLogger*)logger;
16372         if (logger_conv.free == LDKLogger_JCalls_free) {
16373                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
16374                 LDKLogger_JCalls_clone(logger_conv.this_arg);
16375         }
16376         LDKNetworkGraph network_graph_conv;
16377         network_graph_conv.inner = (void*)(network_graph & (~1));
16378         network_graph_conv.is_owned = (network_graph & 1) || (network_graph == 0);
16379         // Warning: we may need a move here but can't clone!
16380         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_from_net_graph(chain_access_conv, logger_conv, network_graph_conv);
16381         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16382         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16383         long ret_ref = (long)ret_var.inner;
16384         if (ret_var.is_owned) {
16385                 ret_ref |= 1;
16386         }
16387         return ret_ref;
16388 }
16389
16390 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1read_1locked_1graph(JNIEnv * _env, jclass _b, jlong this_arg) {
16391         LDKNetGraphMsgHandler this_arg_conv;
16392         this_arg_conv.inner = (void*)(this_arg & (~1));
16393         this_arg_conv.is_owned = false;
16394         LDKLockedNetworkGraph ret_var = NetGraphMsgHandler_read_locked_graph(&this_arg_conv);
16395         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16396         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16397         long ret_ref = (long)ret_var.inner;
16398         if (ret_var.is_owned) {
16399                 ret_ref |= 1;
16400         }
16401         return ret_ref;
16402 }
16403
16404 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1graph(JNIEnv * _env, jclass _b, jlong this_arg) {
16405         LDKLockedNetworkGraph this_arg_conv;
16406         this_arg_conv.inner = (void*)(this_arg & (~1));
16407         this_arg_conv.is_owned = false;
16408         LDKNetworkGraph ret_var = LockedNetworkGraph_graph(&this_arg_conv);
16409         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16410         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16411         long ret_ref = (long)ret_var.inner;
16412         if (ret_var.is_owned) {
16413                 ret_ref |= 1;
16414         }
16415         return ret_ref;
16416 }
16417
16418 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1as_1RoutingMessageHandler(JNIEnv * _env, jclass _b, jlong this_arg) {
16419         LDKNetGraphMsgHandler this_arg_conv;
16420         this_arg_conv.inner = (void*)(this_arg & (~1));
16421         this_arg_conv.is_owned = false;
16422         LDKRoutingMessageHandler* ret = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
16423         *ret = NetGraphMsgHandler_as_RoutingMessageHandler(&this_arg_conv);
16424         return (long)ret;
16425 }
16426
16427 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1as_1MessageSendEventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
16428         LDKNetGraphMsgHandler this_arg_conv;
16429         this_arg_conv.inner = (void*)(this_arg & (~1));
16430         this_arg_conv.is_owned = false;
16431         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
16432         *ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&this_arg_conv);
16433         return (long)ret;
16434 }
16435
16436 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16437         LDKDirectionalChannelInfo this_ptr_conv;
16438         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16439         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16440         DirectionalChannelInfo_free(this_ptr_conv);
16441 }
16442
16443 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr) {
16444         LDKDirectionalChannelInfo this_ptr_conv;
16445         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16446         this_ptr_conv.is_owned = false;
16447         jint ret_val = DirectionalChannelInfo_get_last_update(&this_ptr_conv);
16448         return ret_val;
16449 }
16450
16451 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
16452         LDKDirectionalChannelInfo this_ptr_conv;
16453         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16454         this_ptr_conv.is_owned = false;
16455         DirectionalChannelInfo_set_last_update(&this_ptr_conv, val);
16456 }
16457
16458 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1enabled(JNIEnv * _env, jclass _b, jlong this_ptr) {
16459         LDKDirectionalChannelInfo this_ptr_conv;
16460         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16461         this_ptr_conv.is_owned = false;
16462         jboolean ret_val = DirectionalChannelInfo_get_enabled(&this_ptr_conv);
16463         return ret_val;
16464 }
16465
16466 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1enabled(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
16467         LDKDirectionalChannelInfo this_ptr_conv;
16468         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16469         this_ptr_conv.is_owned = false;
16470         DirectionalChannelInfo_set_enabled(&this_ptr_conv, val);
16471 }
16472
16473 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
16474         LDKDirectionalChannelInfo this_ptr_conv;
16475         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16476         this_ptr_conv.is_owned = false;
16477         jshort ret_val = DirectionalChannelInfo_get_cltv_expiry_delta(&this_ptr_conv);
16478         return ret_val;
16479 }
16480
16481 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
16482         LDKDirectionalChannelInfo this_ptr_conv;
16483         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16484         this_ptr_conv.is_owned = false;
16485         DirectionalChannelInfo_set_cltv_expiry_delta(&this_ptr_conv, val);
16486 }
16487
16488 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
16489         LDKDirectionalChannelInfo this_ptr_conv;
16490         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16491         this_ptr_conv.is_owned = false;
16492         jlong ret_val = DirectionalChannelInfo_get_htlc_minimum_msat(&this_ptr_conv);
16493         return ret_val;
16494 }
16495
16496 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16497         LDKDirectionalChannelInfo this_ptr_conv;
16498         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16499         this_ptr_conv.is_owned = false;
16500         DirectionalChannelInfo_set_htlc_minimum_msat(&this_ptr_conv, val);
16501 }
16502
16503 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1fees(JNIEnv * _env, jclass _b, jlong this_ptr) {
16504         LDKDirectionalChannelInfo this_ptr_conv;
16505         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16506         this_ptr_conv.is_owned = false;
16507         LDKRoutingFees ret_var = DirectionalChannelInfo_get_fees(&this_ptr_conv);
16508         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16509         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16510         long ret_ref = (long)ret_var.inner;
16511         if (ret_var.is_owned) {
16512                 ret_ref |= 1;
16513         }
16514         return ret_ref;
16515 }
16516
16517 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1fees(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16518         LDKDirectionalChannelInfo this_ptr_conv;
16519         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16520         this_ptr_conv.is_owned = false;
16521         LDKRoutingFees val_conv;
16522         val_conv.inner = (void*)(val & (~1));
16523         val_conv.is_owned = (val & 1) || (val == 0);
16524         if (val_conv.inner != NULL)
16525                 val_conv = RoutingFees_clone(&val_conv);
16526         DirectionalChannelInfo_set_fees(&this_ptr_conv, val_conv);
16527 }
16528
16529 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
16530         LDKDirectionalChannelInfo this_ptr_conv;
16531         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16532         this_ptr_conv.is_owned = false;
16533         LDKChannelUpdate ret_var = DirectionalChannelInfo_get_last_update_message(&this_ptr_conv);
16534         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16535         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16536         long ret_ref = (long)ret_var.inner;
16537         if (ret_var.is_owned) {
16538                 ret_ref |= 1;
16539         }
16540         return ret_ref;
16541 }
16542
16543 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16544         LDKDirectionalChannelInfo this_ptr_conv;
16545         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16546         this_ptr_conv.is_owned = false;
16547         LDKChannelUpdate val_conv;
16548         val_conv.inner = (void*)(val & (~1));
16549         val_conv.is_owned = (val & 1) || (val == 0);
16550         if (val_conv.inner != NULL)
16551                 val_conv = ChannelUpdate_clone(&val_conv);
16552         DirectionalChannelInfo_set_last_update_message(&this_ptr_conv, val_conv);
16553 }
16554
16555 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
16556         LDKDirectionalChannelInfo obj_conv;
16557         obj_conv.inner = (void*)(obj & (~1));
16558         obj_conv.is_owned = false;
16559         LDKCVec_u8Z arg_var = DirectionalChannelInfo_write(&obj_conv);
16560         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
16561         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
16562         CVec_u8Z_free(arg_var);
16563         return arg_arr;
16564 }
16565
16566 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
16567         LDKu8slice ser_ref;
16568         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
16569         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
16570         LDKDirectionalChannelInfo ret_var = DirectionalChannelInfo_read(ser_ref);
16571         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16572         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16573         long ret_ref = (long)ret_var.inner;
16574         if (ret_var.is_owned) {
16575                 ret_ref |= 1;
16576         }
16577         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
16578         return ret_ref;
16579 }
16580
16581 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16582         LDKChannelInfo this_ptr_conv;
16583         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16584         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16585         ChannelInfo_free(this_ptr_conv);
16586 }
16587
16588 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
16589         LDKChannelInfo this_ptr_conv;
16590         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16591         this_ptr_conv.is_owned = false;
16592         LDKChannelFeatures ret_var = ChannelInfo_get_features(&this_ptr_conv);
16593         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16594         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16595         long ret_ref = (long)ret_var.inner;
16596         if (ret_var.is_owned) {
16597                 ret_ref |= 1;
16598         }
16599         return ret_ref;
16600 }
16601
16602 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16603         LDKChannelInfo this_ptr_conv;
16604         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16605         this_ptr_conv.is_owned = false;
16606         LDKChannelFeatures val_conv;
16607         val_conv.inner = (void*)(val & (~1));
16608         val_conv.is_owned = (val & 1) || (val == 0);
16609         // Warning: we may need a move here but can't clone!
16610         ChannelInfo_set_features(&this_ptr_conv, val_conv);
16611 }
16612
16613 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1one(JNIEnv * _env, jclass _b, jlong this_ptr) {
16614         LDKChannelInfo this_ptr_conv;
16615         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16616         this_ptr_conv.is_owned = false;
16617         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
16618         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelInfo_get_node_one(&this_ptr_conv).compressed_form);
16619         return arg_arr;
16620 }
16621
16622 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1one(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
16623         LDKChannelInfo this_ptr_conv;
16624         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16625         this_ptr_conv.is_owned = false;
16626         LDKPublicKey val_ref;
16627         CHECK((*_env)->GetArrayLength (_env, val) == 33);
16628         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
16629         ChannelInfo_set_node_one(&this_ptr_conv, val_ref);
16630 }
16631
16632 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1one_1to_1two(JNIEnv * _env, jclass _b, jlong this_ptr) {
16633         LDKChannelInfo this_ptr_conv;
16634         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16635         this_ptr_conv.is_owned = false;
16636         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_one_to_two(&this_ptr_conv);
16637         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16638         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16639         long ret_ref = (long)ret_var.inner;
16640         if (ret_var.is_owned) {
16641                 ret_ref |= 1;
16642         }
16643         return ret_ref;
16644 }
16645
16646 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1one_1to_1two(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16647         LDKChannelInfo this_ptr_conv;
16648         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16649         this_ptr_conv.is_owned = false;
16650         LDKDirectionalChannelInfo val_conv;
16651         val_conv.inner = (void*)(val & (~1));
16652         val_conv.is_owned = (val & 1) || (val == 0);
16653         // Warning: we may need a move here but can't clone!
16654         ChannelInfo_set_one_to_two(&this_ptr_conv, val_conv);
16655 }
16656
16657 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1two(JNIEnv * _env, jclass _b, jlong this_ptr) {
16658         LDKChannelInfo this_ptr_conv;
16659         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16660         this_ptr_conv.is_owned = false;
16661         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
16662         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelInfo_get_node_two(&this_ptr_conv).compressed_form);
16663         return arg_arr;
16664 }
16665
16666 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1two(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
16667         LDKChannelInfo this_ptr_conv;
16668         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16669         this_ptr_conv.is_owned = false;
16670         LDKPublicKey val_ref;
16671         CHECK((*_env)->GetArrayLength (_env, val) == 33);
16672         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
16673         ChannelInfo_set_node_two(&this_ptr_conv, val_ref);
16674 }
16675
16676 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1two_1to_1one(JNIEnv * _env, jclass _b, jlong this_ptr) {
16677         LDKChannelInfo this_ptr_conv;
16678         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16679         this_ptr_conv.is_owned = false;
16680         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_two_to_one(&this_ptr_conv);
16681         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16682         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16683         long ret_ref = (long)ret_var.inner;
16684         if (ret_var.is_owned) {
16685                 ret_ref |= 1;
16686         }
16687         return ret_ref;
16688 }
16689
16690 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1two_1to_1one(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16691         LDKChannelInfo this_ptr_conv;
16692         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16693         this_ptr_conv.is_owned = false;
16694         LDKDirectionalChannelInfo val_conv;
16695         val_conv.inner = (void*)(val & (~1));
16696         val_conv.is_owned = (val & 1) || (val == 0);
16697         // Warning: we may need a move here but can't clone!
16698         ChannelInfo_set_two_to_one(&this_ptr_conv, val_conv);
16699 }
16700
16701 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
16702         LDKChannelInfo this_ptr_conv;
16703         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16704         this_ptr_conv.is_owned = false;
16705         LDKChannelAnnouncement ret_var = ChannelInfo_get_announcement_message(&this_ptr_conv);
16706         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16707         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16708         long ret_ref = (long)ret_var.inner;
16709         if (ret_var.is_owned) {
16710                 ret_ref |= 1;
16711         }
16712         return ret_ref;
16713 }
16714
16715 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16716         LDKChannelInfo this_ptr_conv;
16717         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16718         this_ptr_conv.is_owned = false;
16719         LDKChannelAnnouncement val_conv;
16720         val_conv.inner = (void*)(val & (~1));
16721         val_conv.is_owned = (val & 1) || (val == 0);
16722         if (val_conv.inner != NULL)
16723                 val_conv = ChannelAnnouncement_clone(&val_conv);
16724         ChannelInfo_set_announcement_message(&this_ptr_conv, val_conv);
16725 }
16726
16727 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
16728         LDKChannelInfo obj_conv;
16729         obj_conv.inner = (void*)(obj & (~1));
16730         obj_conv.is_owned = false;
16731         LDKCVec_u8Z arg_var = ChannelInfo_write(&obj_conv);
16732         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
16733         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
16734         CVec_u8Z_free(arg_var);
16735         return arg_arr;
16736 }
16737
16738 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
16739         LDKu8slice ser_ref;
16740         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
16741         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
16742         LDKChannelInfo ret_var = ChannelInfo_read(ser_ref);
16743         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16744         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16745         long ret_ref = (long)ret_var.inner;
16746         if (ret_var.is_owned) {
16747                 ret_ref |= 1;
16748         }
16749         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
16750         return ret_ref;
16751 }
16752
16753 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16754         LDKRoutingFees this_ptr_conv;
16755         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16756         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16757         RoutingFees_free(this_ptr_conv);
16758 }
16759
16760 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1clone(JNIEnv * _env, jclass _b, jlong orig) {
16761         LDKRoutingFees orig_conv;
16762         orig_conv.inner = (void*)(orig & (~1));
16763         orig_conv.is_owned = false;
16764         LDKRoutingFees ret_var = RoutingFees_clone(&orig_conv);
16765         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16766         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16767         long ret_ref = (long)ret_var.inner;
16768         if (ret_var.is_owned) {
16769                 ret_ref |= 1;
16770         }
16771         return ret_ref;
16772 }
16773
16774 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
16775         LDKRoutingFees this_ptr_conv;
16776         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16777         this_ptr_conv.is_owned = false;
16778         jint ret_val = RoutingFees_get_base_msat(&this_ptr_conv);
16779         return ret_val;
16780 }
16781
16782 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
16783         LDKRoutingFees this_ptr_conv;
16784         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16785         this_ptr_conv.is_owned = false;
16786         RoutingFees_set_base_msat(&this_ptr_conv, val);
16787 }
16788
16789 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
16790         LDKRoutingFees this_ptr_conv;
16791         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16792         this_ptr_conv.is_owned = false;
16793         jint ret_val = RoutingFees_get_proportional_millionths(&this_ptr_conv);
16794         return ret_val;
16795 }
16796
16797 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
16798         LDKRoutingFees this_ptr_conv;
16799         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16800         this_ptr_conv.is_owned = false;
16801         RoutingFees_set_proportional_millionths(&this_ptr_conv, val);
16802 }
16803
16804 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1new(JNIEnv * _env, jclass _b, jint base_msat_arg, jint proportional_millionths_arg) {
16805         LDKRoutingFees ret_var = RoutingFees_new(base_msat_arg, proportional_millionths_arg);
16806         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16807         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16808         long ret_ref = (long)ret_var.inner;
16809         if (ret_var.is_owned) {
16810                 ret_ref |= 1;
16811         }
16812         return ret_ref;
16813 }
16814
16815 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
16816         LDKu8slice ser_ref;
16817         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
16818         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
16819         LDKCResult_RoutingFeesDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RoutingFeesDecodeErrorZ), "LDKCResult_RoutingFeesDecodeErrorZ");
16820         *ret_conv = RoutingFees_read(ser_ref);
16821         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
16822         return (long)ret_conv;
16823 }
16824
16825 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RoutingFees_1write(JNIEnv * _env, jclass _b, jlong obj) {
16826         LDKRoutingFees obj_conv;
16827         obj_conv.inner = (void*)(obj & (~1));
16828         obj_conv.is_owned = false;
16829         LDKCVec_u8Z arg_var = RoutingFees_write(&obj_conv);
16830         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
16831         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
16832         CVec_u8Z_free(arg_var);
16833         return arg_arr;
16834 }
16835
16836 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
16837         LDKNodeAnnouncementInfo this_ptr_conv;
16838         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16839         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
16840         NodeAnnouncementInfo_free(this_ptr_conv);
16841 }
16842
16843 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
16844         LDKNodeAnnouncementInfo this_ptr_conv;
16845         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16846         this_ptr_conv.is_owned = false;
16847         LDKNodeFeatures ret_var = NodeAnnouncementInfo_get_features(&this_ptr_conv);
16848         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16849         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16850         long ret_ref = (long)ret_var.inner;
16851         if (ret_var.is_owned) {
16852                 ret_ref |= 1;
16853         }
16854         return ret_ref;
16855 }
16856
16857 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16858         LDKNodeAnnouncementInfo this_ptr_conv;
16859         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16860         this_ptr_conv.is_owned = false;
16861         LDKNodeFeatures val_conv;
16862         val_conv.inner = (void*)(val & (~1));
16863         val_conv.is_owned = (val & 1) || (val == 0);
16864         // Warning: we may need a move here but can't clone!
16865         NodeAnnouncementInfo_set_features(&this_ptr_conv, val_conv);
16866 }
16867
16868 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr) {
16869         LDKNodeAnnouncementInfo this_ptr_conv;
16870         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16871         this_ptr_conv.is_owned = false;
16872         jint ret_val = NodeAnnouncementInfo_get_last_update(&this_ptr_conv);
16873         return ret_val;
16874 }
16875
16876 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
16877         LDKNodeAnnouncementInfo this_ptr_conv;
16878         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16879         this_ptr_conv.is_owned = false;
16880         NodeAnnouncementInfo_set_last_update(&this_ptr_conv, val);
16881 }
16882
16883 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr) {
16884         LDKNodeAnnouncementInfo this_ptr_conv;
16885         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16886         this_ptr_conv.is_owned = false;
16887         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 3);
16888         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 3, *NodeAnnouncementInfo_get_rgb(&this_ptr_conv));
16889         return ret_arr;
16890 }
16891
16892 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
16893         LDKNodeAnnouncementInfo this_ptr_conv;
16894         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16895         this_ptr_conv.is_owned = false;
16896         LDKThreeBytes val_ref;
16897         CHECK((*_env)->GetArrayLength (_env, val) == 3);
16898         (*_env)->GetByteArrayRegion (_env, val, 0, 3, val_ref.data);
16899         NodeAnnouncementInfo_set_rgb(&this_ptr_conv, val_ref);
16900 }
16901
16902 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1alias(JNIEnv * _env, jclass _b, jlong this_ptr) {
16903         LDKNodeAnnouncementInfo this_ptr_conv;
16904         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16905         this_ptr_conv.is_owned = false;
16906         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
16907         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *NodeAnnouncementInfo_get_alias(&this_ptr_conv));
16908         return ret_arr;
16909 }
16910
16911 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1alias(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
16912         LDKNodeAnnouncementInfo this_ptr_conv;
16913         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16914         this_ptr_conv.is_owned = false;
16915         LDKThirtyTwoBytes val_ref;
16916         CHECK((*_env)->GetArrayLength (_env, val) == 32);
16917         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
16918         NodeAnnouncementInfo_set_alias(&this_ptr_conv, val_ref);
16919 }
16920
16921 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1addresses(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
16922         LDKNodeAnnouncementInfo this_ptr_conv;
16923         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16924         this_ptr_conv.is_owned = false;
16925         LDKCVec_NetAddressZ val_constr;
16926         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
16927         if (val_constr.datalen > 0)
16928                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
16929         else
16930                 val_constr.data = NULL;
16931         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
16932         for (size_t m = 0; m < val_constr.datalen; m++) {
16933                 long arr_conv_12 = val_vals[m];
16934                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
16935                 FREE((void*)arr_conv_12);
16936                 val_constr.data[m] = arr_conv_12_conv;
16937         }
16938         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
16939         NodeAnnouncementInfo_set_addresses(&this_ptr_conv, val_constr);
16940 }
16941
16942 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
16943         LDKNodeAnnouncementInfo this_ptr_conv;
16944         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16945         this_ptr_conv.is_owned = false;
16946         LDKNodeAnnouncement ret_var = NodeAnnouncementInfo_get_announcement_message(&this_ptr_conv);
16947         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
16948         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
16949         long ret_ref = (long)ret_var.inner;
16950         if (ret_var.is_owned) {
16951                 ret_ref |= 1;
16952         }
16953         return ret_ref;
16954 }
16955
16956 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
16957         LDKNodeAnnouncementInfo this_ptr_conv;
16958         this_ptr_conv.inner = (void*)(this_ptr & (~1));
16959         this_ptr_conv.is_owned = false;
16960         LDKNodeAnnouncement val_conv;
16961         val_conv.inner = (void*)(val & (~1));
16962         val_conv.is_owned = (val & 1) || (val == 0);
16963         if (val_conv.inner != NULL)
16964                 val_conv = NodeAnnouncement_clone(&val_conv);
16965         NodeAnnouncementInfo_set_announcement_message(&this_ptr_conv, val_conv);
16966 }
16967
16968 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) {
16969         LDKNodeFeatures features_arg_conv;
16970         features_arg_conv.inner = (void*)(features_arg & (~1));
16971         features_arg_conv.is_owned = (features_arg & 1) || (features_arg == 0);
16972         // Warning: we may need a move here but can't clone!
16973         LDKThreeBytes rgb_arg_ref;
16974         CHECK((*_env)->GetArrayLength (_env, rgb_arg) == 3);
16975         (*_env)->GetByteArrayRegion (_env, rgb_arg, 0, 3, rgb_arg_ref.data);
16976         LDKThirtyTwoBytes alias_arg_ref;
16977         CHECK((*_env)->GetArrayLength (_env, alias_arg) == 32);
16978         (*_env)->GetByteArrayRegion (_env, alias_arg, 0, 32, alias_arg_ref.data);
16979         LDKCVec_NetAddressZ addresses_arg_constr;
16980         addresses_arg_constr.datalen = (*_env)->GetArrayLength (_env, addresses_arg);
16981         if (addresses_arg_constr.datalen > 0)
16982                 addresses_arg_constr.data = MALLOC(addresses_arg_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
16983         else
16984                 addresses_arg_constr.data = NULL;
16985         long* addresses_arg_vals = (*_env)->GetLongArrayElements (_env, addresses_arg, NULL);
16986         for (size_t m = 0; m < addresses_arg_constr.datalen; m++) {
16987                 long arr_conv_12 = addresses_arg_vals[m];
16988                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
16989                 FREE((void*)arr_conv_12);
16990                 addresses_arg_constr.data[m] = arr_conv_12_conv;
16991         }
16992         (*_env)->ReleaseLongArrayElements (_env, addresses_arg, addresses_arg_vals, 0);
16993         LDKNodeAnnouncement announcement_message_arg_conv;
16994         announcement_message_arg_conv.inner = (void*)(announcement_message_arg & (~1));
16995         announcement_message_arg_conv.is_owned = (announcement_message_arg & 1) || (announcement_message_arg == 0);
16996         if (announcement_message_arg_conv.inner != NULL)
16997                 announcement_message_arg_conv = NodeAnnouncement_clone(&announcement_message_arg_conv);
16998         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_new(features_arg_conv, last_update_arg, rgb_arg_ref, alias_arg_ref, addresses_arg_constr, announcement_message_arg_conv);
16999         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
17000         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
17001         long ret_ref = (long)ret_var.inner;
17002         if (ret_var.is_owned) {
17003                 ret_ref |= 1;
17004         }
17005         return ret_ref;
17006 }
17007
17008 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
17009         LDKNodeAnnouncementInfo obj_conv;
17010         obj_conv.inner = (void*)(obj & (~1));
17011         obj_conv.is_owned = false;
17012         LDKCVec_u8Z arg_var = NodeAnnouncementInfo_write(&obj_conv);
17013         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
17014         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
17015         CVec_u8Z_free(arg_var);
17016         return arg_arr;
17017 }
17018
17019 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
17020         LDKu8slice ser_ref;
17021         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
17022         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
17023         LDKCResult_NodeAnnouncementInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeAnnouncementInfoDecodeErrorZ), "LDKCResult_NodeAnnouncementInfoDecodeErrorZ");
17024         *ret_conv = NodeAnnouncementInfo_read(ser_ref);
17025         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
17026         return (long)ret_conv;
17027 }
17028
17029 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
17030         LDKNodeInfo this_ptr_conv;
17031         this_ptr_conv.inner = (void*)(this_ptr & (~1));
17032         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
17033         NodeInfo_free(this_ptr_conv);
17034 }
17035
17036 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1channels(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
17037         LDKNodeInfo this_ptr_conv;
17038         this_ptr_conv.inner = (void*)(this_ptr & (~1));
17039         this_ptr_conv.is_owned = false;
17040         LDKCVec_u64Z val_constr;
17041         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
17042         if (val_constr.datalen > 0)
17043                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
17044         else
17045                 val_constr.data = NULL;
17046         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
17047         for (size_t g = 0; g < val_constr.datalen; g++) {
17048                 long arr_conv_6 = val_vals[g];
17049                 val_constr.data[g] = arr_conv_6;
17050         }
17051         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
17052         NodeInfo_set_channels(&this_ptr_conv, val_constr);
17053 }
17054
17055 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1lowest_1inbound_1channel_1fees(JNIEnv * _env, jclass _b, jlong this_ptr) {
17056         LDKNodeInfo this_ptr_conv;
17057         this_ptr_conv.inner = (void*)(this_ptr & (~1));
17058         this_ptr_conv.is_owned = false;
17059         LDKRoutingFees ret_var = NodeInfo_get_lowest_inbound_channel_fees(&this_ptr_conv);
17060         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
17061         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
17062         long ret_ref = (long)ret_var.inner;
17063         if (ret_var.is_owned) {
17064                 ret_ref |= 1;
17065         }
17066         return ret_ref;
17067 }
17068
17069 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1lowest_1inbound_1channel_1fees(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
17070         LDKNodeInfo this_ptr_conv;
17071         this_ptr_conv.inner = (void*)(this_ptr & (~1));
17072         this_ptr_conv.is_owned = false;
17073         LDKRoutingFees val_conv;
17074         val_conv.inner = (void*)(val & (~1));
17075         val_conv.is_owned = (val & 1) || (val == 0);
17076         if (val_conv.inner != NULL)
17077                 val_conv = RoutingFees_clone(&val_conv);
17078         NodeInfo_set_lowest_inbound_channel_fees(&this_ptr_conv, val_conv);
17079 }
17080
17081 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1announcement_1info(JNIEnv * _env, jclass _b, jlong this_ptr) {
17082         LDKNodeInfo this_ptr_conv;
17083         this_ptr_conv.inner = (void*)(this_ptr & (~1));
17084         this_ptr_conv.is_owned = false;
17085         LDKNodeAnnouncementInfo ret_var = NodeInfo_get_announcement_info(&this_ptr_conv);
17086         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
17087         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
17088         long ret_ref = (long)ret_var.inner;
17089         if (ret_var.is_owned) {
17090                 ret_ref |= 1;
17091         }
17092         return ret_ref;
17093 }
17094
17095 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1announcement_1info(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
17096         LDKNodeInfo this_ptr_conv;
17097         this_ptr_conv.inner = (void*)(this_ptr & (~1));
17098         this_ptr_conv.is_owned = false;
17099         LDKNodeAnnouncementInfo val_conv;
17100         val_conv.inner = (void*)(val & (~1));
17101         val_conv.is_owned = (val & 1) || (val == 0);
17102         // Warning: we may need a move here but can't clone!
17103         NodeInfo_set_announcement_info(&this_ptr_conv, val_conv);
17104 }
17105
17106 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) {
17107         LDKCVec_u64Z channels_arg_constr;
17108         channels_arg_constr.datalen = (*_env)->GetArrayLength (_env, channels_arg);
17109         if (channels_arg_constr.datalen > 0)
17110                 channels_arg_constr.data = MALLOC(channels_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
17111         else
17112                 channels_arg_constr.data = NULL;
17113         long* channels_arg_vals = (*_env)->GetLongArrayElements (_env, channels_arg, NULL);
17114         for (size_t g = 0; g < channels_arg_constr.datalen; g++) {
17115                 long arr_conv_6 = channels_arg_vals[g];
17116                 channels_arg_constr.data[g] = arr_conv_6;
17117         }
17118         (*_env)->ReleaseLongArrayElements (_env, channels_arg, channels_arg_vals, 0);
17119         LDKRoutingFees lowest_inbound_channel_fees_arg_conv;
17120         lowest_inbound_channel_fees_arg_conv.inner = (void*)(lowest_inbound_channel_fees_arg & (~1));
17121         lowest_inbound_channel_fees_arg_conv.is_owned = (lowest_inbound_channel_fees_arg & 1) || (lowest_inbound_channel_fees_arg == 0);
17122         if (lowest_inbound_channel_fees_arg_conv.inner != NULL)
17123                 lowest_inbound_channel_fees_arg_conv = RoutingFees_clone(&lowest_inbound_channel_fees_arg_conv);
17124         LDKNodeAnnouncementInfo announcement_info_arg_conv;
17125         announcement_info_arg_conv.inner = (void*)(announcement_info_arg & (~1));
17126         announcement_info_arg_conv.is_owned = (announcement_info_arg & 1) || (announcement_info_arg == 0);
17127         // Warning: we may need a move here but can't clone!
17128         LDKNodeInfo ret_var = NodeInfo_new(channels_arg_constr, lowest_inbound_channel_fees_arg_conv, announcement_info_arg_conv);
17129         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
17130         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
17131         long ret_ref = (long)ret_var.inner;
17132         if (ret_var.is_owned) {
17133                 ret_ref |= 1;
17134         }
17135         return ret_ref;
17136 }
17137
17138 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
17139         LDKNodeInfo obj_conv;
17140         obj_conv.inner = (void*)(obj & (~1));
17141         obj_conv.is_owned = false;
17142         LDKCVec_u8Z arg_var = NodeInfo_write(&obj_conv);
17143         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
17144         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
17145         CVec_u8Z_free(arg_var);
17146         return arg_arr;
17147 }
17148
17149 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
17150         LDKu8slice ser_ref;
17151         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
17152         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
17153         LDKCResult_NodeInfoDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NodeInfoDecodeErrorZ), "LDKCResult_NodeInfoDecodeErrorZ");
17154         *ret_conv = NodeInfo_read(ser_ref);
17155         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
17156         return (long)ret_conv;
17157 }
17158
17159 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1write(JNIEnv * _env, jclass _b, jlong obj) {
17160         LDKNetworkGraph obj_conv;
17161         obj_conv.inner = (void*)(obj & (~1));
17162         obj_conv.is_owned = false;
17163         LDKCVec_u8Z arg_var = NetworkGraph_write(&obj_conv);
17164         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
17165         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
17166         CVec_u8Z_free(arg_var);
17167         return arg_arr;
17168 }
17169
17170 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
17171         LDKu8slice ser_ref;
17172         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
17173         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
17174         LDKCResult_NetworkGraphDecodeErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NetworkGraphDecodeErrorZ), "LDKCResult_NetworkGraphDecodeErrorZ");
17175         *ret_conv = NetworkGraph_read(ser_ref);
17176         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
17177         return (long)ret_conv;
17178 }
17179
17180 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1new(JNIEnv * _env, jclass _b, jbyteArray genesis_hash) {
17181         LDKThirtyTwoBytes genesis_hash_ref;
17182         CHECK((*_env)->GetArrayLength (_env, genesis_hash) == 32);
17183         (*_env)->GetByteArrayRegion (_env, genesis_hash, 0, 32, genesis_hash_ref.data);
17184         LDKNetworkGraph ret_var = NetworkGraph_new(genesis_hash_ref);
17185         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
17186         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
17187         long ret_ref = (long)ret_var.inner;
17188         if (ret_var.is_owned) {
17189                 ret_ref |= 1;
17190         }
17191         return ret_ref;
17192 }
17193
17194 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1node_1from_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
17195         LDKNetworkGraph this_arg_conv;
17196         this_arg_conv.inner = (void*)(this_arg & (~1));
17197         this_arg_conv.is_owned = false;
17198         LDKNodeAnnouncement msg_conv;
17199         msg_conv.inner = (void*)(msg & (~1));
17200         msg_conv.is_owned = false;
17201         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17202         *ret_conv = NetworkGraph_update_node_from_announcement(&this_arg_conv, &msg_conv);
17203         return (long)ret_conv;
17204 }
17205
17206 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1node_1from_1unsigned_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
17207         LDKNetworkGraph this_arg_conv;
17208         this_arg_conv.inner = (void*)(this_arg & (~1));
17209         this_arg_conv.is_owned = false;
17210         LDKUnsignedNodeAnnouncement msg_conv;
17211         msg_conv.inner = (void*)(msg & (~1));
17212         msg_conv.is_owned = false;
17213         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17214         *ret_conv = NetworkGraph_update_node_from_unsigned_announcement(&this_arg_conv, &msg_conv);
17215         return (long)ret_conv;
17216 }
17217
17218 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel_1from_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg, jlong chain_access) {
17219         LDKNetworkGraph this_arg_conv;
17220         this_arg_conv.inner = (void*)(this_arg & (~1));
17221         this_arg_conv.is_owned = false;
17222         LDKChannelAnnouncement msg_conv;
17223         msg_conv.inner = (void*)(msg & (~1));
17224         msg_conv.is_owned = false;
17225         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
17226         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17227         *ret_conv = NetworkGraph_update_channel_from_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
17228         return (long)ret_conv;
17229 }
17230
17231 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel_1from_1unsigned_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg, jlong chain_access) {
17232         LDKNetworkGraph this_arg_conv;
17233         this_arg_conv.inner = (void*)(this_arg & (~1));
17234         this_arg_conv.is_owned = false;
17235         LDKUnsignedChannelAnnouncement msg_conv;
17236         msg_conv.inner = (void*)(msg & (~1));
17237         msg_conv.is_owned = false;
17238         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
17239         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17240         *ret_conv = NetworkGraph_update_channel_from_unsigned_announcement(&this_arg_conv, &msg_conv, chain_access_conv);
17241         return (long)ret_conv;
17242 }
17243
17244 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) {
17245         LDKNetworkGraph this_arg_conv;
17246         this_arg_conv.inner = (void*)(this_arg & (~1));
17247         this_arg_conv.is_owned = false;
17248         NetworkGraph_close_channel_from_update(&this_arg_conv, short_channel_id, is_permanent);
17249 }
17250
17251 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
17252         LDKNetworkGraph this_arg_conv;
17253         this_arg_conv.inner = (void*)(this_arg & (~1));
17254         this_arg_conv.is_owned = false;
17255         LDKChannelUpdate msg_conv;
17256         msg_conv.inner = (void*)(msg & (~1));
17257         msg_conv.is_owned = false;
17258         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17259         *ret_conv = NetworkGraph_update_channel(&this_arg_conv, &msg_conv);
17260         return (long)ret_conv;
17261 }
17262
17263 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1update_1channel_1unsigned(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
17264         LDKNetworkGraph this_arg_conv;
17265         this_arg_conv.inner = (void*)(this_arg & (~1));
17266         this_arg_conv.is_owned = false;
17267         LDKUnsignedChannelUpdate msg_conv;
17268         msg_conv.inner = (void*)(msg & (~1));
17269         msg_conv.is_owned = false;
17270         LDKCResult_NoneLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneLightningErrorZ), "LDKCResult_NoneLightningErrorZ");
17271         *ret_conv = NetworkGraph_update_channel_unsigned(&this_arg_conv, &msg_conv);
17272         return (long)ret_conv;
17273 }
17274