Finish compacting giant type-conversion-strings if tree, updating to new upstream...
[ldk-java] / src / main / jni / bindings.c
1 #include "org_ldk_impl_bindings.h"
2 #include <rust_types.h>
3 #include <lightning.h>
4 #include <string.h>
5 #include <stdatomic.h>
6 #include <assert.h>
7 // Always run a, then assert it is true:
8 #define DO_ASSERT(a) do { bool _assert_val = (a); assert(_assert_val); } while(0)
9 // Assert a is true or do nothing
10 #define CHECK(a) DO_ASSERT(a)
11
12 // Running a leak check across all the allocations and frees of the JDK is a mess,
13 // so instead we implement our own naive leak checker here, relying on the -wrap
14 // linker option to wrap malloc/calloc/realloc/free, tracking everyhing allocated
15 // and free'd in Rust or C across the generated bindings shared library.
16 #include <threads.h>
17 #include <execinfo.h>
18 #include <unistd.h>
19 static mtx_t allocation_mtx;
20
21 void __attribute__((constructor)) init_mtx() {
22         DO_ASSERT(mtx_init(&allocation_mtx, mtx_plain) == thrd_success);
23 }
24
25 #define BT_MAX 128
26 typedef struct allocation {
27         struct allocation* next;
28         void* ptr;
29         const char* struct_name;
30         void* bt[BT_MAX];
31         int bt_len;
32 } allocation;
33 static allocation* allocation_ll = NULL;
34
35 void* __real_malloc(size_t len);
36 void* __real_calloc(size_t nmemb, size_t len);
37 static void new_allocation(void* res, const char* struct_name) {
38         allocation* new_alloc = __real_malloc(sizeof(allocation));
39         new_alloc->ptr = res;
40         new_alloc->struct_name = struct_name;
41         new_alloc->bt_len = backtrace(new_alloc->bt, BT_MAX);
42         DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
43         new_alloc->next = allocation_ll;
44         allocation_ll = new_alloc;
45         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
46 }
47 static void* MALLOC(size_t len, const char* struct_name) {
48         void* res = __real_malloc(len);
49         new_allocation(res, struct_name);
50         return res;
51 }
52 void __real_free(void* ptr);
53 static void alloc_freed(void* ptr) {
54         allocation* p = NULL;
55         DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
56         allocation* it = allocation_ll;
57         while (it->ptr != ptr) {
58                 p = it; it = it->next;
59                 if (it == NULL) {
60                         fprintf(stderr, "Tried to free unknown pointer %p at:\n", ptr);
61                         void* bt[BT_MAX];
62                         int bt_len = backtrace(bt, BT_MAX);
63                         backtrace_symbols_fd(bt, bt_len, STDERR_FILENO);
64                         fprintf(stderr, "\n\n");
65                         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
66                         return; // addrsan should catch malloc-unknown and print more info than we have
67                 }
68         }
69         if (p) { p->next = it->next; } else { allocation_ll = it->next; }
70         DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
71         DO_ASSERT(it->ptr == ptr);
72         __real_free(it);
73 }
74 static void FREE(void* ptr) {
75         if ((long)ptr < 1024) return; // Rust loves to create pointers to the NULL page for dummys
76         alloc_freed(ptr);
77         __real_free(ptr);
78 }
79
80 void* __wrap_malloc(size_t len) {
81         void* res = __real_malloc(len);
82         new_allocation(res, "malloc call");
83         return res;
84 }
85 void* __wrap_calloc(size_t nmemb, size_t len) {
86         void* res = __real_calloc(nmemb, len);
87         new_allocation(res, "calloc call");
88         return res;
89 }
90 void __wrap_free(void* ptr) {
91         alloc_freed(ptr);
92         __real_free(ptr);
93 }
94
95 void* __real_realloc(void* ptr, size_t newlen);
96 void* __wrap_realloc(void* ptr, size_t len) {
97         alloc_freed(ptr);
98         void* res = __real_realloc(ptr, len);
99         new_allocation(res, "realloc call");
100         return res;
101 }
102 void __wrap_reallocarray(void* ptr, size_t new_sz) {
103         // Rust doesn't seem to use reallocarray currently
104         assert(false);
105 }
106
107 void __attribute__((destructor)) check_leaks() {
108         for (allocation* a = allocation_ll; a != NULL; a = a->next) {
109                 fprintf(stderr, "%s %p remains:\n", a->struct_name, a->ptr);
110                 backtrace_symbols_fd(a->bt, a->bt_len, STDERR_FILENO);
111                 fprintf(stderr, "\n\n");
112         }
113         DO_ASSERT(allocation_ll == NULL);
114 }
115
116 static jmethodID ordinal_meth = NULL;
117 static jmethodID slicedef_meth = NULL;
118 static jclass slicedef_cls = NULL;
119 JNIEXPORT void Java_org_ldk_impl_bindings_init(JNIEnv * env, jclass _b, jclass enum_class, jclass slicedef_class) {
120         ordinal_meth = (*env)->GetMethodID(env, enum_class, "ordinal", "()I");
121         CHECK(ordinal_meth != NULL);
122         slicedef_meth = (*env)->GetMethodID(env, slicedef_class, "<init>", "(JJJ)V");
123         CHECK(slicedef_meth != NULL);
124         slicedef_cls = (*env)->NewGlobalRef(env, slicedef_class);
125         CHECK(slicedef_cls != NULL);
126 }
127
128 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_deref_1bool (JNIEnv * env, jclass _a, jlong ptr) {
129         return *((bool*)ptr);
130 }
131 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_deref_1long (JNIEnv * env, jclass _a, jlong ptr) {
132         return *((long*)ptr);
133 }
134 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_free_1heap_1ptr (JNIEnv * env, jclass _a, jlong ptr) {
135         FREE((void*)ptr);
136 }
137 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_read_1bytes (JNIEnv * _env, jclass _b, jlong ptr, jlong len) {
138         jbyteArray ret_arr = (*_env)->NewByteArray(_env, len);
139         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, len, (unsigned char*)ptr);
140         return ret_arr;
141 }
142 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_get_1u8_1slice_1bytes (JNIEnv * _env, jclass _b, jlong slice_ptr) {
143         LDKu8slice *slice = (LDKu8slice*)slice_ptr;
144         jbyteArray ret_arr = (*_env)->NewByteArray(_env, slice->datalen);
145         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, slice->datalen, slice->data);
146         return ret_arr;
147 }
148 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec (JNIEnv * _env, jclass _b, jbyteArray bytes) {
149         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "LDKCVec_u8");
150         vec->datalen = (*_env)->GetArrayLength(_env, bytes);
151         vec->data = (uint8_t*)MALLOC(vec->datalen, "LDKCVec_u8Z Bytes");
152         (*_env)->GetByteArrayRegion (_env, bytes, 0, vec->datalen, vec->data);
153         return (long)vec;
154 }
155 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data (JNIEnv * env, jclass _b, jbyteArray bytes) {
156         LDKTransaction *txdata = (LDKTransaction*)MALLOC(sizeof(LDKTransaction), "LDKTransaction");
157         txdata->datalen = (*env)->GetArrayLength(env, bytes);
158         txdata->data = (uint8_t*)MALLOC(txdata->datalen, "Tx Data Bytes");
159         txdata->data_is_owned = false;
160         (*env)->GetByteArrayRegion (env, bytes, 0, txdata->datalen, txdata->data);
161         return (long)txdata;
162 }
163 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_txpointer_1free (JNIEnv * env, jclass _b, jlong ptr) {
164         LDKTransaction *tx = (LDKTransaction*)ptr;
165         tx->data_is_owned = true;
166         Transaction_free(*tx);
167         FREE((void*)ptr);
168 }
169 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) {
170         // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
171         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically");
172         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically");
173         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically");
174         _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_C2Tuple_usizeTransactionZZ, datalen), "Vec<*> needs to be mapped identically");
175         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
176         return (long)vec->datalen;
177 }
178 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec (JNIEnv * _env, jclass _b) {
179         // Check sizes of a few Vec types are all consistent as we're meant to be generic across types
180         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_SignatureZ), "Vec<*> needs to be mapped identically");
181         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_MessageSendEventZ), "Vec<*> needs to be mapped identically");
182         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_EventZ), "Vec<*> needs to be mapped identically");
183         _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "Vec<*> needs to be mapped identically");
184         LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "Empty LDKCVec");
185         vec->data = NULL;
186         vec->datalen = 0;
187         return (long)vec;
188 }
189
190 // We assume that CVec_u8Z and u8slice are the same size and layout (and thus pointers to the two can be mixed)
191 _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKu8slice), "Vec<u8> and [u8] need to have been mapped identically");
192 _Static_assert(offsetof(LDKCVec_u8Z, data) == offsetof(LDKu8slice, data), "Vec<u8> and [u8] need to have been mapped identically");
193 _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen), "Vec<u8> and [u8] need to have been mapped identically");
194
195 static inline LDKAccessError LDKAccessError_from_java(JNIEnv *env, jclass val) {
196         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
197                 case 0: return LDKAccessError_UnknownChain;
198                 case 1: return LDKAccessError_UnknownTx;
199         }
200         abort();
201 }
202 static jclass LDKAccessError_class = NULL;
203 static jfieldID LDKAccessError_LDKAccessError_UnknownChain = NULL;
204 static jfieldID LDKAccessError_LDKAccessError_UnknownTx = NULL;
205 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKAccessError_init (JNIEnv * env, jclass clz) {
206         LDKAccessError_class = (*env)->NewGlobalRef(env, clz);
207         CHECK(LDKAccessError_class != NULL);
208         LDKAccessError_LDKAccessError_UnknownChain = (*env)->GetStaticFieldID(env, LDKAccessError_class, "LDKAccessError_UnknownChain", "Lorg/ldk/enums/LDKAccessError;");
209         CHECK(LDKAccessError_LDKAccessError_UnknownChain != NULL);
210         LDKAccessError_LDKAccessError_UnknownTx = (*env)->GetStaticFieldID(env, LDKAccessError_class, "LDKAccessError_UnknownTx", "Lorg/ldk/enums/LDKAccessError;");
211         CHECK(LDKAccessError_LDKAccessError_UnknownTx != NULL);
212 }
213 static inline jclass LDKAccessError_to_java(JNIEnv *env, LDKAccessError val) {
214         switch (val) {
215                 case LDKAccessError_UnknownChain:
216                         return (*env)->GetStaticObjectField(env, LDKAccessError_class, LDKAccessError_LDKAccessError_UnknownChain);
217                 case LDKAccessError_UnknownTx:
218                         return (*env)->GetStaticObjectField(env, LDKAccessError_class, LDKAccessError_LDKAccessError_UnknownTx);
219                 default: abort();
220         }
221 }
222
223 static inline LDKChannelMonitorUpdateErr LDKChannelMonitorUpdateErr_from_java(JNIEnv *env, jclass val) {
224         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
225                 case 0: return LDKChannelMonitorUpdateErr_TemporaryFailure;
226                 case 1: return LDKChannelMonitorUpdateErr_PermanentFailure;
227         }
228         abort();
229 }
230 static jclass LDKChannelMonitorUpdateErr_class = NULL;
231 static jfieldID LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure = NULL;
232 static jfieldID LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure = NULL;
233 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKChannelMonitorUpdateErr_init (JNIEnv * env, jclass clz) {
234         LDKChannelMonitorUpdateErr_class = (*env)->NewGlobalRef(env, clz);
235         CHECK(LDKChannelMonitorUpdateErr_class != NULL);
236         LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure = (*env)->GetStaticFieldID(env, LDKChannelMonitorUpdateErr_class, "LDKChannelMonitorUpdateErr_TemporaryFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
237         CHECK(LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure != NULL);
238         LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure = (*env)->GetStaticFieldID(env, LDKChannelMonitorUpdateErr_class, "LDKChannelMonitorUpdateErr_PermanentFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
239         CHECK(LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure != NULL);
240 }
241 static inline jclass LDKChannelMonitorUpdateErr_to_java(JNIEnv *env, LDKChannelMonitorUpdateErr val) {
242         switch (val) {
243                 case LDKChannelMonitorUpdateErr_TemporaryFailure:
244                         return (*env)->GetStaticObjectField(env, LDKChannelMonitorUpdateErr_class, LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_TemporaryFailure);
245                 case LDKChannelMonitorUpdateErr_PermanentFailure:
246                         return (*env)->GetStaticObjectField(env, LDKChannelMonitorUpdateErr_class, LDKChannelMonitorUpdateErr_LDKChannelMonitorUpdateErr_PermanentFailure);
247                 default: abort();
248         }
249 }
250
251 static inline LDKConfirmationTarget LDKConfirmationTarget_from_java(JNIEnv *env, jclass val) {
252         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
253                 case 0: return LDKConfirmationTarget_Background;
254                 case 1: return LDKConfirmationTarget_Normal;
255                 case 2: return LDKConfirmationTarget_HighPriority;
256         }
257         abort();
258 }
259 static jclass LDKConfirmationTarget_class = NULL;
260 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_Background = NULL;
261 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_Normal = NULL;
262 static jfieldID LDKConfirmationTarget_LDKConfirmationTarget_HighPriority = NULL;
263 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKConfirmationTarget_init (JNIEnv * env, jclass clz) {
264         LDKConfirmationTarget_class = (*env)->NewGlobalRef(env, clz);
265         CHECK(LDKConfirmationTarget_class != NULL);
266         LDKConfirmationTarget_LDKConfirmationTarget_Background = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_Background", "Lorg/ldk/enums/LDKConfirmationTarget;");
267         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_Background != NULL);
268         LDKConfirmationTarget_LDKConfirmationTarget_Normal = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_Normal", "Lorg/ldk/enums/LDKConfirmationTarget;");
269         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_Normal != NULL);
270         LDKConfirmationTarget_LDKConfirmationTarget_HighPriority = (*env)->GetStaticFieldID(env, LDKConfirmationTarget_class, "LDKConfirmationTarget_HighPriority", "Lorg/ldk/enums/LDKConfirmationTarget;");
271         CHECK(LDKConfirmationTarget_LDKConfirmationTarget_HighPriority != NULL);
272 }
273 static inline jclass LDKConfirmationTarget_to_java(JNIEnv *env, LDKConfirmationTarget val) {
274         switch (val) {
275                 case LDKConfirmationTarget_Background:
276                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_Background);
277                 case LDKConfirmationTarget_Normal:
278                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_Normal);
279                 case LDKConfirmationTarget_HighPriority:
280                         return (*env)->GetStaticObjectField(env, LDKConfirmationTarget_class, LDKConfirmationTarget_LDKConfirmationTarget_HighPriority);
281                 default: abort();
282         }
283 }
284
285 static inline LDKLevel LDKLevel_from_java(JNIEnv *env, jclass val) {
286         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
287                 case 0: return LDKLevel_Off;
288                 case 1: return LDKLevel_Error;
289                 case 2: return LDKLevel_Warn;
290                 case 3: return LDKLevel_Info;
291                 case 4: return LDKLevel_Debug;
292                 case 5: return LDKLevel_Trace;
293         }
294         abort();
295 }
296 static jclass LDKLevel_class = NULL;
297 static jfieldID LDKLevel_LDKLevel_Off = NULL;
298 static jfieldID LDKLevel_LDKLevel_Error = NULL;
299 static jfieldID LDKLevel_LDKLevel_Warn = NULL;
300 static jfieldID LDKLevel_LDKLevel_Info = NULL;
301 static jfieldID LDKLevel_LDKLevel_Debug = NULL;
302 static jfieldID LDKLevel_LDKLevel_Trace = NULL;
303 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKLevel_init (JNIEnv * env, jclass clz) {
304         LDKLevel_class = (*env)->NewGlobalRef(env, clz);
305         CHECK(LDKLevel_class != NULL);
306         LDKLevel_LDKLevel_Off = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Off", "Lorg/ldk/enums/LDKLevel;");
307         CHECK(LDKLevel_LDKLevel_Off != NULL);
308         LDKLevel_LDKLevel_Error = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Error", "Lorg/ldk/enums/LDKLevel;");
309         CHECK(LDKLevel_LDKLevel_Error != NULL);
310         LDKLevel_LDKLevel_Warn = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Warn", "Lorg/ldk/enums/LDKLevel;");
311         CHECK(LDKLevel_LDKLevel_Warn != NULL);
312         LDKLevel_LDKLevel_Info = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Info", "Lorg/ldk/enums/LDKLevel;");
313         CHECK(LDKLevel_LDKLevel_Info != NULL);
314         LDKLevel_LDKLevel_Debug = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Debug", "Lorg/ldk/enums/LDKLevel;");
315         CHECK(LDKLevel_LDKLevel_Debug != NULL);
316         LDKLevel_LDKLevel_Trace = (*env)->GetStaticFieldID(env, LDKLevel_class, "LDKLevel_Trace", "Lorg/ldk/enums/LDKLevel;");
317         CHECK(LDKLevel_LDKLevel_Trace != NULL);
318 }
319 static inline jclass LDKLevel_to_java(JNIEnv *env, LDKLevel val) {
320         switch (val) {
321                 case LDKLevel_Off:
322                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Off);
323                 case LDKLevel_Error:
324                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Error);
325                 case LDKLevel_Warn:
326                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Warn);
327                 case LDKLevel_Info:
328                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Info);
329                 case LDKLevel_Debug:
330                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Debug);
331                 case LDKLevel_Trace:
332                         return (*env)->GetStaticObjectField(env, LDKLevel_class, LDKLevel_LDKLevel_Trace);
333                 default: abort();
334         }
335 }
336
337 static inline LDKNetwork LDKNetwork_from_java(JNIEnv *env, jclass val) {
338         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
339                 case 0: return LDKNetwork_Bitcoin;
340                 case 1: return LDKNetwork_Testnet;
341                 case 2: return LDKNetwork_Regtest;
342         }
343         abort();
344 }
345 static jclass LDKNetwork_class = NULL;
346 static jfieldID LDKNetwork_LDKNetwork_Bitcoin = NULL;
347 static jfieldID LDKNetwork_LDKNetwork_Testnet = NULL;
348 static jfieldID LDKNetwork_LDKNetwork_Regtest = NULL;
349 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKNetwork_init (JNIEnv * env, jclass clz) {
350         LDKNetwork_class = (*env)->NewGlobalRef(env, clz);
351         CHECK(LDKNetwork_class != NULL);
352         LDKNetwork_LDKNetwork_Bitcoin = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Bitcoin", "Lorg/ldk/enums/LDKNetwork;");
353         CHECK(LDKNetwork_LDKNetwork_Bitcoin != NULL);
354         LDKNetwork_LDKNetwork_Testnet = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Testnet", "Lorg/ldk/enums/LDKNetwork;");
355         CHECK(LDKNetwork_LDKNetwork_Testnet != NULL);
356         LDKNetwork_LDKNetwork_Regtest = (*env)->GetStaticFieldID(env, LDKNetwork_class, "LDKNetwork_Regtest", "Lorg/ldk/enums/LDKNetwork;");
357         CHECK(LDKNetwork_LDKNetwork_Regtest != NULL);
358 }
359 static inline jclass LDKNetwork_to_java(JNIEnv *env, LDKNetwork val) {
360         switch (val) {
361                 case LDKNetwork_Bitcoin:
362                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Bitcoin);
363                 case LDKNetwork_Testnet:
364                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Testnet);
365                 case LDKNetwork_Regtest:
366                         return (*env)->GetStaticObjectField(env, LDKNetwork_class, LDKNetwork_LDKNetwork_Regtest);
367                 default: abort();
368         }
369 }
370
371 static inline LDKSecp256k1Error LDKSecp256k1Error_from_java(JNIEnv *env, jclass val) {
372         switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
373                 case 0: return LDKSecp256k1Error_IncorrectSignature;
374                 case 1: return LDKSecp256k1Error_InvalidMessage;
375                 case 2: return LDKSecp256k1Error_InvalidPublicKey;
376                 case 3: return LDKSecp256k1Error_InvalidSignature;
377                 case 4: return LDKSecp256k1Error_InvalidSecretKey;
378                 case 5: return LDKSecp256k1Error_InvalidRecoveryId;
379                 case 6: return LDKSecp256k1Error_InvalidTweak;
380                 case 7: return LDKSecp256k1Error_NotEnoughMemory;
381                 case 8: return LDKSecp256k1Error_CallbackPanicked;
382         }
383         abort();
384 }
385 static jclass LDKSecp256k1Error_class = NULL;
386 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature = NULL;
387 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage = NULL;
388 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey = NULL;
389 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature = NULL;
390 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey = NULL;
391 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId = NULL;
392 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak = NULL;
393 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory = NULL;
394 static jfieldID LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked = NULL;
395 JNIEXPORT void JNICALL Java_org_ldk_enums_LDKSecp256k1Error_init (JNIEnv * env, jclass clz) {
396         LDKSecp256k1Error_class = (*env)->NewGlobalRef(env, clz);
397         CHECK(LDKSecp256k1Error_class != NULL);
398         LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_IncorrectSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
399         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature != NULL);
400         LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidMessage", "Lorg/ldk/enums/LDKSecp256k1Error;");
401         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage != NULL);
402         LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidPublicKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
403         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey != NULL);
404         LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
405         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature != NULL);
406         LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidSecretKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
407         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey != NULL);
408         LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidRecoveryId", "Lorg/ldk/enums/LDKSecp256k1Error;");
409         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId != NULL);
410         LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_InvalidTweak", "Lorg/ldk/enums/LDKSecp256k1Error;");
411         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak != NULL);
412         LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_NotEnoughMemory", "Lorg/ldk/enums/LDKSecp256k1Error;");
413         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory != NULL);
414         LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked = (*env)->GetStaticFieldID(env, LDKSecp256k1Error_class, "LDKSecp256k1Error_CallbackPanicked", "Lorg/ldk/enums/LDKSecp256k1Error;");
415         CHECK(LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked != NULL);
416 }
417 static inline jclass LDKSecp256k1Error_to_java(JNIEnv *env, LDKSecp256k1Error val) {
418         switch (val) {
419                 case LDKSecp256k1Error_IncorrectSignature:
420                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_IncorrectSignature);
421                 case LDKSecp256k1Error_InvalidMessage:
422                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidMessage);
423                 case LDKSecp256k1Error_InvalidPublicKey:
424                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidPublicKey);
425                 case LDKSecp256k1Error_InvalidSignature:
426                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidSignature);
427                 case LDKSecp256k1Error_InvalidSecretKey:
428                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidSecretKey);
429                 case LDKSecp256k1Error_InvalidRecoveryId:
430                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidRecoveryId);
431                 case LDKSecp256k1Error_InvalidTweak:
432                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_InvalidTweak);
433                 case LDKSecp256k1Error_NotEnoughMemory:
434                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_NotEnoughMemory);
435                 case LDKSecp256k1Error_CallbackPanicked:
436                         return (*env)->GetStaticObjectField(env, LDKSecp256k1Error_class, LDKSecp256k1Error_LDKSecp256k1Error_CallbackPanicked);
437                 default: abort();
438         }
439 }
440
441 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u8_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
442         LDKCVecTempl_u8 *vec = (LDKCVecTempl_u8*)ptr;
443         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(uint8_t));
444 }
445 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u8_1new(JNIEnv *env, jclass _b, jbyteArray elems){
446         LDKCVecTempl_u8 *ret = MALLOC(sizeof(LDKCVecTempl_u8), "LDKCVecTempl_u8");
447         ret->datalen = (*env)->GetArrayLength(env, elems);
448         if (ret->datalen == 0) {
449                 ret->data = NULL;
450         } else {
451                 ret->data = MALLOC(sizeof(uint8_t) * ret->datalen, "LDKCVecTempl_u8 Data");
452                 jbyte *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
453                 for (size_t i = 0; i < ret->datalen; i++) {
454                         ret->data[i] = java_elems[i];
455                 }
456                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
457         }
458         return (long)ret;
459 }
460 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1usize_1_1Transaction_1new(JNIEnv *_env, jclass _b, jlong a, jlong b) {
461         LDKC2TupleTempl_usize__Transaction* ret = MALLOC(sizeof(LDKC2TupleTempl_usize__Transaction), "LDKC2TupleTempl_usize__Transaction");
462         ret->a = a;
463         LDKTransaction b_conv = *(LDKTransaction*)b;
464         ret->b = b_conv;
465         return (long)ret;
466 }
467 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
468         return ((LDKCResult_NoneChannelMonitorUpdateErrZ*)arg)->result_ok;
469 }
470 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
471         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
472         CHECK(val->result_ok);
473         return *val->contents.result;
474 }
475 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
476         LDKCResult_NoneChannelMonitorUpdateErrZ *val = (LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
477         CHECK(!val->result_ok);
478         jclass err_conv = LDKChannelMonitorUpdateErr_to_java(_env, (*val->contents.err));
479         return err_conv;
480 }
481 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
482         return ((LDKCResult_NoneMonitorUpdateErrorZ*)arg)->result_ok;
483 }
484 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
485         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
486         CHECK(val->result_ok);
487         return *val->contents.result;
488 }
489 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdateErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
490         LDKCResult_NoneMonitorUpdateErrorZ *val = (LDKCResult_NoneMonitorUpdateErrorZ*)arg;
491         CHECK(!val->result_ok);
492         LDKMonitorUpdateError err_var = (*val->contents.err);
493         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
494         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
495         long err_ref = (long)err_var.inner & ~1;
496         return err_ref;
497 }
498 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1OutPoint_1_1CVec_1u8Z_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) {
499         LDKC2TupleTempl_OutPoint__CVec_u8Z* ret = MALLOC(sizeof(LDKC2TupleTempl_OutPoint__CVec_u8Z), "LDKC2TupleTempl_OutPoint__CVec_u8Z");
500         LDKOutPoint a_conv;
501         a_conv.inner = (void*)(a & (~1));
502         a_conv.is_owned = (a & 1) || (a == 0);
503         if (a_conv.inner != NULL)
504                 a_conv = OutPoint_clone(&a_conv);
505         ret->a = a_conv;
506         LDKCVec_u8Z b_ref;
507         b_ref.data = (*_env)->GetByteArrayElements (_env, b, NULL);
508         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
509         ret->b = b_ref;
510         //TODO: Really need to call (*_env)->ReleaseByteArrayElements(_env, b, (int8_t*)b_ref.data, 0); here
511         return (long)ret;
512 }
513 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1TxOut_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
514         LDKCVecTempl_TxOut *vec = (LDKCVecTempl_TxOut*)ptr;
515         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKTxOut));
516 }
517 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1TxOut_1new(JNIEnv *env, jclass _b, jlongArray elems){
518         LDKCVecTempl_TxOut *ret = MALLOC(sizeof(LDKCVecTempl_TxOut), "LDKCVecTempl_TxOut");
519         ret->datalen = (*env)->GetArrayLength(env, elems);
520         if (ret->datalen == 0) {
521                 ret->data = NULL;
522         } else {
523                 ret->data = MALLOC(sizeof(LDKTxOut) * ret->datalen, "LDKCVecTempl_TxOut Data");
524                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
525                 for (size_t i = 0; i < ret->datalen; i++) {
526                         jlong arr_elem = java_elems[i];
527                         LDKTxOut arr_elem_conv = *(LDKTxOut*)arr_elem;
528                         FREE((void*)arr_elem);
529                         ret->data[i] = arr_elem_conv;
530                 }
531                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
532         }
533         return (long)ret;
534 }
535 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1ThirtyTwoBytes_1_1CVecTempl_1TxOut_1new(JNIEnv *_env, jclass _b, jbyteArray a, jlongArray b) {
536         LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut* ret = MALLOC(sizeof(LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut), "LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut");
537         LDKThirtyTwoBytes a_ref;
538         CHECK((*_env)->GetArrayLength (_env, a) == 32);
539         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
540         ret->a = a_ref;
541         LDKCVecTempl_TxOut b_constr;
542         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
543         if (b_constr.datalen > 0)
544                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKTxOut), "LDKCVecTempl_TxOut Elements");
545         else
546                 b_constr.data = NULL;
547         long* b_vals = (*_env)->GetLongArrayElements (_env, b, NULL);
548         for (size_t h = 0; h < b_constr.datalen; h++) {
549                 long arr_conv_7 = b_vals[h];
550                 LDKTxOut arr_conv_7_conv = *(LDKTxOut*)arr_conv_7;
551                 FREE((void*)arr_conv_7);
552                 b_constr.data[h] = arr_conv_7_conv;
553         }
554         (*_env)->ReleaseLongArrayElements (_env, b, b_vals, 0);
555         ret->b = b_constr;
556         return (long)ret;
557 }
558 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1u64_1_1u64_1new(JNIEnv *_env, jclass _b, jlong a, jlong b) {
559         LDKC2TupleTempl_u64__u64* ret = MALLOC(sizeof(LDKC2TupleTempl_u64__u64), "LDKC2TupleTempl_u64__u64");
560         ret->a = a;
561         ret->b = b;
562         return (long)ret;
563 }
564 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Signature_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
565         LDKCVecTempl_Signature *vec = (LDKCVecTempl_Signature*)ptr;
566         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKSignature));
567 }
568 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1Signature_1_1CVecTempl_1Signature_1new(JNIEnv *_env, jclass _b, jbyteArray a, jobjectArray b) {
569         LDKC2TupleTempl_Signature__CVecTempl_Signature* ret = MALLOC(sizeof(LDKC2TupleTempl_Signature__CVecTempl_Signature), "LDKC2TupleTempl_Signature__CVecTempl_Signature");
570         LDKSignature a_ref;
571         CHECK((*_env)->GetArrayLength (_env, a) == 64);
572         (*_env)->GetByteArrayRegion (_env, a, 0, 64, a_ref.compact_form);
573         ret->a = a_ref;
574         LDKCVecTempl_Signature b_constr;
575         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
576         if (b_constr.datalen > 0)
577                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVecTempl_Signature Elements");
578         else
579                 b_constr.data = NULL;
580         for (size_t i = 0; i < b_constr.datalen; i++) {
581                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, b, i);
582                 LDKSignature arr_conv_8_ref;
583                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
584                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
585                 b_constr.data[i] = arr_conv_8_ref;
586         }
587         ret->b = b_constr;
588         return (long)ret;
589 }
590 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
591         return ((LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg)->result_ok;
592 }
593 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
594         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
595         CHECK(val->result_ok);
596         long res_ref = (long)&(*val->contents.result);
597         return res_ref;
598 }
599 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
600         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ *val = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
601         CHECK(!val->result_ok);
602         return *val->contents.err;
603 }
604 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
605         return ((LDKCResult_SignatureNoneZ*)arg)->result_ok;
606 }
607 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
608         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
609         CHECK(val->result_ok);
610         jbyteArray res_arr = (*_env)->NewByteArray(_env, 64);
611         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 64, (*val->contents.result).compact_form);
612         return res_arr;
613 }
614 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SignatureNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
615         LDKCResult_SignatureNoneZ *val = (LDKCResult_SignatureNoneZ*)arg;
616         CHECK(!val->result_ok);
617         return *val->contents.err;
618 }
619 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
620         return ((LDKCResult_CVec_SignatureZNoneZ*)arg)->result_ok;
621 }
622 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
623         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
624         CHECK(val->result_ok);
625         LDKCVecTempl_Signature res_var = (*val->contents.result);
626         jobjectArray res_arr = (*_env)->NewObjectArray(_env, res_var.datalen, NULL, NULL);
627         for (size_t i = 0; i < res_var.datalen; i++) {
628                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 64);
629                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 64, res_var.data[i].compact_form);
630                 (*_env)->SetObjectArrayElement(_env, res_arr, i, arr_conv_8_arr);
631         }
632         return res_arr;
633 }
634 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
635         LDKCResult_CVec_SignatureZNoneZ *val = (LDKCResult_CVec_SignatureZNoneZ*)arg;
636         CHECK(!val->result_ok);
637         return *val->contents.err;
638 }
639 static jclass LDKAPIError_APIMisuseError_class = NULL;
640 static jmethodID LDKAPIError_APIMisuseError_meth = NULL;
641 static jclass LDKAPIError_FeeRateTooHigh_class = NULL;
642 static jmethodID LDKAPIError_FeeRateTooHigh_meth = NULL;
643 static jclass LDKAPIError_RouteError_class = NULL;
644 static jmethodID LDKAPIError_RouteError_meth = NULL;
645 static jclass LDKAPIError_ChannelUnavailable_class = NULL;
646 static jmethodID LDKAPIError_ChannelUnavailable_meth = NULL;
647 static jclass LDKAPIError_MonitorUpdateFailed_class = NULL;
648 static jmethodID LDKAPIError_MonitorUpdateFailed_meth = NULL;
649 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKAPIError_init (JNIEnv * env, jclass _a) {
650         LDKAPIError_APIMisuseError_class =
651                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$APIMisuseError;"));
652         CHECK(LDKAPIError_APIMisuseError_class != NULL);
653         LDKAPIError_APIMisuseError_meth = (*env)->GetMethodID(env, LDKAPIError_APIMisuseError_class, "<init>", "([B)V");
654         CHECK(LDKAPIError_APIMisuseError_meth != NULL);
655         LDKAPIError_FeeRateTooHigh_class =
656                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$FeeRateTooHigh;"));
657         CHECK(LDKAPIError_FeeRateTooHigh_class != NULL);
658         LDKAPIError_FeeRateTooHigh_meth = (*env)->GetMethodID(env, LDKAPIError_FeeRateTooHigh_class, "<init>", "([BI)V");
659         CHECK(LDKAPIError_FeeRateTooHigh_meth != NULL);
660         LDKAPIError_RouteError_class =
661                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$RouteError;"));
662         CHECK(LDKAPIError_RouteError_class != NULL);
663         LDKAPIError_RouteError_meth = (*env)->GetMethodID(env, LDKAPIError_RouteError_class, "<init>", "(Ljava/lang/String;)V");
664         CHECK(LDKAPIError_RouteError_meth != NULL);
665         LDKAPIError_ChannelUnavailable_class =
666                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$ChannelUnavailable;"));
667         CHECK(LDKAPIError_ChannelUnavailable_class != NULL);
668         LDKAPIError_ChannelUnavailable_meth = (*env)->GetMethodID(env, LDKAPIError_ChannelUnavailable_class, "<init>", "([B)V");
669         CHECK(LDKAPIError_ChannelUnavailable_meth != NULL);
670         LDKAPIError_MonitorUpdateFailed_class =
671                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAPIError$MonitorUpdateFailed;"));
672         CHECK(LDKAPIError_MonitorUpdateFailed_class != NULL);
673         LDKAPIError_MonitorUpdateFailed_meth = (*env)->GetMethodID(env, LDKAPIError_MonitorUpdateFailed_class, "<init>", "()V");
674         CHECK(LDKAPIError_MonitorUpdateFailed_meth != NULL);
675 }
676 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAPIError_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
677         LDKAPIError *obj = (LDKAPIError*)ptr;
678         switch(obj->tag) {
679                 case LDKAPIError_APIMisuseError: {
680                         LDKCVec_u8Z err_var = obj->api_misuse_error.err;
681                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
682                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
683                         return (*_env)->NewObject(_env, LDKAPIError_APIMisuseError_class, LDKAPIError_APIMisuseError_meth, err_arr);
684                 }
685                 case LDKAPIError_FeeRateTooHigh: {
686                         LDKCVec_u8Z err_var = obj->fee_rate_too_high.err;
687                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
688                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
689                         return (*_env)->NewObject(_env, LDKAPIError_FeeRateTooHigh_class, LDKAPIError_FeeRateTooHigh_meth, err_arr, obj->fee_rate_too_high.feerate);
690                 }
691                 case LDKAPIError_RouteError: {
692                         LDKStr err_str = obj->route_error.err;
693                         char* err_buf = MALLOC(err_str.len + 1, "str conv buf");
694                         memcpy(err_buf, err_str.chars, err_str.len);
695                         err_buf[err_str.len] = 0;
696                         jstring err_conv = (*_env)->NewStringUTF(_env, err_str.chars);
697                         FREE(err_buf);
698                         return (*_env)->NewObject(_env, LDKAPIError_RouteError_class, LDKAPIError_RouteError_meth, err_conv);
699                 }
700                 case LDKAPIError_ChannelUnavailable: {
701                         LDKCVec_u8Z err_var = obj->channel_unavailable.err;
702                         jbyteArray err_arr = (*_env)->NewByteArray(_env, err_var.datalen);
703                         (*_env)->SetByteArrayRegion(_env, err_arr, 0, err_var.datalen, err_var.data);
704                         return (*_env)->NewObject(_env, LDKAPIError_ChannelUnavailable_class, LDKAPIError_ChannelUnavailable_meth, err_arr);
705                 }
706                 case LDKAPIError_MonitorUpdateFailed: {
707                         return (*_env)->NewObject(_env, LDKAPIError_MonitorUpdateFailed_class, LDKAPIError_MonitorUpdateFailed_meth);
708                 }
709                 default: abort();
710         }
711 }
712 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
713         return ((LDKCResult_NoneAPIErrorZ*)arg)->result_ok;
714 }
715 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
716         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
717         CHECK(val->result_ok);
718         return *val->contents.result;
719 }
720 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneAPIErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
721         LDKCResult_NoneAPIErrorZ *val = (LDKCResult_NoneAPIErrorZ*)arg;
722         CHECK(!val->result_ok);
723         long err_ref = (long)&(*val->contents.err);
724         return err_ref;
725 }
726 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
727         return ((LDKCResult_NonePaymentSendFailureZ*)arg)->result_ok;
728 }
729 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
730         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
731         CHECK(val->result_ok);
732         return *val->contents.result;
733 }
734 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFailureZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
735         LDKCResult_NonePaymentSendFailureZ *val = (LDKCResult_NonePaymentSendFailureZ*)arg;
736         CHECK(!val->result_ok);
737         LDKPaymentSendFailure err_var = (*val->contents.err);
738         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
739         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
740         long err_ref = (long)err_var.inner & ~1;
741         return err_ref;
742 }
743 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3TupleTempl_1ChannelAnnouncement_1_1ChannelUpdate_1_1ChannelUpdate_1new(JNIEnv *_env, jclass _b, jlong a, jlong b, jlong c) {
744         LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate* ret = MALLOC(sizeof(LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate), "LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate");
745         LDKChannelAnnouncement a_conv;
746         a_conv.inner = (void*)(a & (~1));
747         a_conv.is_owned = (a & 1) || (a == 0);
748         if (a_conv.inner != NULL)
749                 a_conv = ChannelAnnouncement_clone(&a_conv);
750         ret->a = a_conv;
751         LDKChannelUpdate b_conv;
752         b_conv.inner = (void*)(b & (~1));
753         b_conv.is_owned = (b & 1) || (b == 0);
754         if (b_conv.inner != NULL)
755                 b_conv = ChannelUpdate_clone(&b_conv);
756         ret->b = b_conv;
757         LDKChannelUpdate c_conv;
758         c_conv.inner = (void*)(c & (~1));
759         c_conv.is_owned = (c & 1) || (c == 0);
760         if (c_conv.inner != NULL)
761                 c_conv = ChannelUpdate_clone(&c_conv);
762         ret->c = c_conv;
763         return (long)ret;
764 }
765 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
766         return ((LDKCResult_NonePeerHandleErrorZ*)arg)->result_ok;
767 }
768 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
769         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
770         CHECK(val->result_ok);
771         return *val->contents.result;
772 }
773 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
774         LDKCResult_NonePeerHandleErrorZ *val = (LDKCResult_NonePeerHandleErrorZ*)arg;
775         CHECK(!val->result_ok);
776         LDKPeerHandleError err_var = (*val->contents.err);
777         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
778         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
779         long err_ref = (long)err_var.inner & ~1;
780         return err_ref;
781 }
782 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1HTLCOutputInCommitment_1_1Signature_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) {
783         LDKC2TupleTempl_HTLCOutputInCommitment__Signature* ret = MALLOC(sizeof(LDKC2TupleTempl_HTLCOutputInCommitment__Signature), "LDKC2TupleTempl_HTLCOutputInCommitment__Signature");
784         LDKHTLCOutputInCommitment a_conv;
785         a_conv.inner = (void*)(a & (~1));
786         a_conv.is_owned = (a & 1) || (a == 0);
787         if (a_conv.inner != NULL)
788                 a_conv = HTLCOutputInCommitment_clone(&a_conv);
789         ret->a = a_conv;
790         LDKSignature b_ref;
791         CHECK((*_env)->GetArrayLength (_env, b) == 64);
792         (*_env)->GetByteArrayRegion (_env, b, 0, 64, b_ref.compact_form);
793         ret->b = b_ref;
794         return (long)ret;
795 }
796 static jclass LDKSpendableOutputDescriptor_StaticOutput_class = NULL;
797 static jmethodID LDKSpendableOutputDescriptor_StaticOutput_meth = NULL;
798 static jclass LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class = NULL;
799 static jmethodID LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = NULL;
800 static jclass LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class = NULL;
801 static jmethodID LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = NULL;
802 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKSpendableOutputDescriptor_init (JNIEnv * env, jclass _a) {
803         LDKSpendableOutputDescriptor_StaticOutput_class =
804                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$StaticOutput;"));
805         CHECK(LDKSpendableOutputDescriptor_StaticOutput_class != NULL);
806         LDKSpendableOutputDescriptor_StaticOutput_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_StaticOutput_class, "<init>", "(JJ)V");
807         CHECK(LDKSpendableOutputDescriptor_StaticOutput_meth != NULL);
808         LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class =
809                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$DynamicOutputP2WSH;"));
810         CHECK(LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class != NULL);
811         LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class, "<init>", "(J[BSJJ[B)V");
812         CHECK(LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth != NULL);
813         LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class =
814                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSpendableOutputDescriptor$StaticOutputCounterpartyPayment;"));
815         CHECK(LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class != NULL);
816         LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth = (*env)->GetMethodID(env, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class, "<init>", "(JJJ)V");
817         CHECK(LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth != NULL);
818 }
819 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSpendableOutputDescriptor_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
820         LDKSpendableOutputDescriptor *obj = (LDKSpendableOutputDescriptor*)ptr;
821         switch(obj->tag) {
822                 case LDKSpendableOutputDescriptor_StaticOutput: {
823                         LDKOutPoint outpoint_var = obj->static_output.outpoint;
824                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
825                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
826                         long outpoint_ref = (long)outpoint_var.inner & ~1;
827                         long output_ref = (long)&obj->static_output.output;
828                         return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_StaticOutput_class, LDKSpendableOutputDescriptor_StaticOutput_meth, outpoint_ref, output_ref);
829                 }
830                 case LDKSpendableOutputDescriptor_DynamicOutputP2WSH: {
831                         LDKOutPoint outpoint_var = obj->dynamic_output_p2wsh.outpoint;
832                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
833                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
834                         long outpoint_ref = (long)outpoint_var.inner & ~1;
835                         jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33);
836                         (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, obj->dynamic_output_p2wsh.per_commitment_point.compressed_form);
837                         long output_ref = (long)&obj->dynamic_output_p2wsh.output;
838                         long key_derivation_params_ref = (long)&obj->dynamic_output_p2wsh.key_derivation_params;
839                         jbyteArray revocation_pubkey_arr = (*_env)->NewByteArray(_env, 33);
840                         (*_env)->SetByteArrayRegion(_env, revocation_pubkey_arr, 0, 33, obj->dynamic_output_p2wsh.revocation_pubkey.compressed_form);
841                         return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_class, LDKSpendableOutputDescriptor_DynamicOutputP2WSH_meth, outpoint_ref, per_commitment_point_arr, obj->dynamic_output_p2wsh.to_self_delay, output_ref, key_derivation_params_ref, revocation_pubkey_arr);
842                 }
843                 case LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment: {
844                         LDKOutPoint outpoint_var = obj->static_output_counterparty_payment.outpoint;
845                         CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
846                         CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
847                         long outpoint_ref = (long)outpoint_var.inner & ~1;
848                         long output_ref = (long)&obj->static_output_counterparty_payment.output;
849                         long key_derivation_params_ref = (long)&obj->static_output_counterparty_payment.key_derivation_params;
850                         return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth, outpoint_ref, output_ref, key_derivation_params_ref);
851                 }
852                 default: abort();
853         }
854 }
855 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1SpendableOutputDescriptor_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
856         LDKCVecTempl_SpendableOutputDescriptor *vec = (LDKCVecTempl_SpendableOutputDescriptor*)ptr;
857         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKSpendableOutputDescriptor));
858 }
859 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1SpendableOutputDescriptor_1new(JNIEnv *env, jclass _b, jlongArray elems){
860         LDKCVecTempl_SpendableOutputDescriptor *ret = MALLOC(sizeof(LDKCVecTempl_SpendableOutputDescriptor), "LDKCVecTempl_SpendableOutputDescriptor");
861         ret->datalen = (*env)->GetArrayLength(env, elems);
862         if (ret->datalen == 0) {
863                 ret->data = NULL;
864         } else {
865                 ret->data = MALLOC(sizeof(LDKSpendableOutputDescriptor) * ret->datalen, "LDKCVecTempl_SpendableOutputDescriptor Data");
866                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
867                 for (size_t i = 0; i < ret->datalen; i++) {
868                         jlong arr_elem = java_elems[i];
869                         LDKSpendableOutputDescriptor arr_elem_conv = *(LDKSpendableOutputDescriptor*)arr_elem;
870                         FREE((void*)arr_elem);
871                         ret->data[i] = arr_elem_conv;
872                 }
873                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
874         }
875         return (long)ret;
876 }
877 static jclass LDKEvent_FundingGenerationReady_class = NULL;
878 static jmethodID LDKEvent_FundingGenerationReady_meth = NULL;
879 static jclass LDKEvent_FundingBroadcastSafe_class = NULL;
880 static jmethodID LDKEvent_FundingBroadcastSafe_meth = NULL;
881 static jclass LDKEvent_PaymentReceived_class = NULL;
882 static jmethodID LDKEvent_PaymentReceived_meth = NULL;
883 static jclass LDKEvent_PaymentSent_class = NULL;
884 static jmethodID LDKEvent_PaymentSent_meth = NULL;
885 static jclass LDKEvent_PaymentFailed_class = NULL;
886 static jmethodID LDKEvent_PaymentFailed_meth = NULL;
887 static jclass LDKEvent_PendingHTLCsForwardable_class = NULL;
888 static jmethodID LDKEvent_PendingHTLCsForwardable_meth = NULL;
889 static jclass LDKEvent_SpendableOutputs_class = NULL;
890 static jmethodID LDKEvent_SpendableOutputs_meth = NULL;
891 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKEvent_init (JNIEnv * env, jclass _a) {
892         LDKEvent_FundingGenerationReady_class =
893                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$FundingGenerationReady;"));
894         CHECK(LDKEvent_FundingGenerationReady_class != NULL);
895         LDKEvent_FundingGenerationReady_meth = (*env)->GetMethodID(env, LDKEvent_FundingGenerationReady_class, "<init>", "([BJ[BJ)V");
896         CHECK(LDKEvent_FundingGenerationReady_meth != NULL);
897         LDKEvent_FundingBroadcastSafe_class =
898                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$FundingBroadcastSafe;"));
899         CHECK(LDKEvent_FundingBroadcastSafe_class != NULL);
900         LDKEvent_FundingBroadcastSafe_meth = (*env)->GetMethodID(env, LDKEvent_FundingBroadcastSafe_class, "<init>", "(JJ)V");
901         CHECK(LDKEvent_FundingBroadcastSafe_meth != NULL);
902         LDKEvent_PaymentReceived_class =
903                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentReceived;"));
904         CHECK(LDKEvent_PaymentReceived_class != NULL);
905         LDKEvent_PaymentReceived_meth = (*env)->GetMethodID(env, LDKEvent_PaymentReceived_class, "<init>", "([B[BJ)V");
906         CHECK(LDKEvent_PaymentReceived_meth != NULL);
907         LDKEvent_PaymentSent_class =
908                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentSent;"));
909         CHECK(LDKEvent_PaymentSent_class != NULL);
910         LDKEvent_PaymentSent_meth = (*env)->GetMethodID(env, LDKEvent_PaymentSent_class, "<init>", "([B)V");
911         CHECK(LDKEvent_PaymentSent_meth != NULL);
912         LDKEvent_PaymentFailed_class =
913                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PaymentFailed;"));
914         CHECK(LDKEvent_PaymentFailed_class != NULL);
915         LDKEvent_PaymentFailed_meth = (*env)->GetMethodID(env, LDKEvent_PaymentFailed_class, "<init>", "([BZ)V");
916         CHECK(LDKEvent_PaymentFailed_meth != NULL);
917         LDKEvent_PendingHTLCsForwardable_class =
918                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$PendingHTLCsForwardable;"));
919         CHECK(LDKEvent_PendingHTLCsForwardable_class != NULL);
920         LDKEvent_PendingHTLCsForwardable_meth = (*env)->GetMethodID(env, LDKEvent_PendingHTLCsForwardable_class, "<init>", "(J)V");
921         CHECK(LDKEvent_PendingHTLCsForwardable_meth != NULL);
922         LDKEvent_SpendableOutputs_class =
923                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKEvent$SpendableOutputs;"));
924         CHECK(LDKEvent_SpendableOutputs_class != NULL);
925         LDKEvent_SpendableOutputs_meth = (*env)->GetMethodID(env, LDKEvent_SpendableOutputs_class, "<init>", "([J)V");
926         CHECK(LDKEvent_SpendableOutputs_meth != NULL);
927 }
928 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEvent_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
929         LDKEvent *obj = (LDKEvent*)ptr;
930         switch(obj->tag) {
931                 case LDKEvent_FundingGenerationReady: {
932                         jbyteArray temporary_channel_id_arr = (*_env)->NewByteArray(_env, 32);
933                         (*_env)->SetByteArrayRegion(_env, temporary_channel_id_arr, 0, 32, obj->funding_generation_ready.temporary_channel_id.data);
934                         LDKCVec_u8Z output_script_var = obj->funding_generation_ready.output_script;
935                         jbyteArray output_script_arr = (*_env)->NewByteArray(_env, output_script_var.datalen);
936                         (*_env)->SetByteArrayRegion(_env, output_script_arr, 0, output_script_var.datalen, output_script_var.data);
937                         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);
938                 }
939                 case LDKEvent_FundingBroadcastSafe: {
940                         LDKOutPoint funding_txo_var = obj->funding_broadcast_safe.funding_txo;
941                         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
942                         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
943                         long funding_txo_ref = (long)funding_txo_var.inner & ~1;
944                         return (*_env)->NewObject(_env, LDKEvent_FundingBroadcastSafe_class, LDKEvent_FundingBroadcastSafe_meth, funding_txo_ref, obj->funding_broadcast_safe.user_channel_id);
945                 }
946                 case LDKEvent_PaymentReceived: {
947                         jbyteArray payment_hash_arr = (*_env)->NewByteArray(_env, 32);
948                         (*_env)->SetByteArrayRegion(_env, payment_hash_arr, 0, 32, obj->payment_received.payment_hash.data);
949                         jbyteArray payment_secret_arr = (*_env)->NewByteArray(_env, 32);
950                         (*_env)->SetByteArrayRegion(_env, payment_secret_arr, 0, 32, obj->payment_received.payment_secret.data);
951                         return (*_env)->NewObject(_env, LDKEvent_PaymentReceived_class, LDKEvent_PaymentReceived_meth, payment_hash_arr, payment_secret_arr, obj->payment_received.amt);
952                 }
953                 case LDKEvent_PaymentSent: {
954                         jbyteArray payment_preimage_arr = (*_env)->NewByteArray(_env, 32);
955                         (*_env)->SetByteArrayRegion(_env, payment_preimage_arr, 0, 32, obj->payment_sent.payment_preimage.data);
956                         return (*_env)->NewObject(_env, LDKEvent_PaymentSent_class, LDKEvent_PaymentSent_meth, payment_preimage_arr);
957                 }
958                 case LDKEvent_PaymentFailed: {
959                         jbyteArray payment_hash_arr = (*_env)->NewByteArray(_env, 32);
960                         (*_env)->SetByteArrayRegion(_env, payment_hash_arr, 0, 32, obj->payment_failed.payment_hash.data);
961                         return (*_env)->NewObject(_env, LDKEvent_PaymentFailed_class, LDKEvent_PaymentFailed_meth, payment_hash_arr, obj->payment_failed.rejected_by_dest);
962                 }
963                 case LDKEvent_PendingHTLCsForwardable: {
964                         return (*_env)->NewObject(_env, LDKEvent_PendingHTLCsForwardable_class, LDKEvent_PendingHTLCsForwardable_meth, obj->pending_htl_cs_forwardable.time_forwardable);
965                 }
966                 case LDKEvent_SpendableOutputs: {
967                         LDKCVec_SpendableOutputDescriptorZ outputs_var = obj->spendable_outputs.outputs;
968                         jlongArray outputs_arr = (*_env)->NewLongArray(_env, outputs_var.datalen);
969                         jlong *outputs_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, outputs_arr, NULL);
970                         for (size_t b = 0; b < outputs_var.datalen; b++) {
971                                 long arr_conv_27_ref = (long)&outputs_var.data[b];
972                                 outputs_arr_ptr[b] = arr_conv_27_ref;
973                         }
974                         (*_env)->ReleasePrimitiveArrayCritical(_env, outputs_arr, outputs_arr_ptr, 0);
975                         return (*_env)->NewObject(_env, LDKEvent_SpendableOutputs_class, LDKEvent_SpendableOutputs_meth, outputs_arr);
976                 }
977                 default: abort();
978         }
979 }
980 static jclass LDKErrorAction_DisconnectPeer_class = NULL;
981 static jmethodID LDKErrorAction_DisconnectPeer_meth = NULL;
982 static jclass LDKErrorAction_IgnoreError_class = NULL;
983 static jmethodID LDKErrorAction_IgnoreError_meth = NULL;
984 static jclass LDKErrorAction_SendErrorMessage_class = NULL;
985 static jmethodID LDKErrorAction_SendErrorMessage_meth = NULL;
986 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKErrorAction_init (JNIEnv * env, jclass _a) {
987         LDKErrorAction_DisconnectPeer_class =
988                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$DisconnectPeer;"));
989         CHECK(LDKErrorAction_DisconnectPeer_class != NULL);
990         LDKErrorAction_DisconnectPeer_meth = (*env)->GetMethodID(env, LDKErrorAction_DisconnectPeer_class, "<init>", "(J)V");
991         CHECK(LDKErrorAction_DisconnectPeer_meth != NULL);
992         LDKErrorAction_IgnoreError_class =
993                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$IgnoreError;"));
994         CHECK(LDKErrorAction_IgnoreError_class != NULL);
995         LDKErrorAction_IgnoreError_meth = (*env)->GetMethodID(env, LDKErrorAction_IgnoreError_class, "<init>", "()V");
996         CHECK(LDKErrorAction_IgnoreError_meth != NULL);
997         LDKErrorAction_SendErrorMessage_class =
998                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKErrorAction$SendErrorMessage;"));
999         CHECK(LDKErrorAction_SendErrorMessage_class != NULL);
1000         LDKErrorAction_SendErrorMessage_meth = (*env)->GetMethodID(env, LDKErrorAction_SendErrorMessage_class, "<init>", "(J)V");
1001         CHECK(LDKErrorAction_SendErrorMessage_meth != NULL);
1002 }
1003 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKErrorAction_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
1004         LDKErrorAction *obj = (LDKErrorAction*)ptr;
1005         switch(obj->tag) {
1006                 case LDKErrorAction_DisconnectPeer: {
1007                         LDKErrorMessage msg_var = obj->disconnect_peer.msg;
1008                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1009                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1010                         long msg_ref = (long)msg_var.inner & ~1;
1011                         return (*_env)->NewObject(_env, LDKErrorAction_DisconnectPeer_class, LDKErrorAction_DisconnectPeer_meth, msg_ref);
1012                 }
1013                 case LDKErrorAction_IgnoreError: {
1014                         return (*_env)->NewObject(_env, LDKErrorAction_IgnoreError_class, LDKErrorAction_IgnoreError_meth);
1015                 }
1016                 case LDKErrorAction_SendErrorMessage: {
1017                         LDKErrorMessage msg_var = obj->send_error_message.msg;
1018                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1019                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1020                         long msg_ref = (long)msg_var.inner & ~1;
1021                         return (*_env)->NewObject(_env, LDKErrorAction_SendErrorMessage_class, LDKErrorAction_SendErrorMessage_meth, msg_ref);
1022                 }
1023                 default: abort();
1024         }
1025 }
1026 static jclass LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class = NULL;
1027 static jmethodID LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = NULL;
1028 static jclass LDKHTLCFailChannelUpdate_ChannelClosed_class = NULL;
1029 static jmethodID LDKHTLCFailChannelUpdate_ChannelClosed_meth = NULL;
1030 static jclass LDKHTLCFailChannelUpdate_NodeFailure_class = NULL;
1031 static jmethodID LDKHTLCFailChannelUpdate_NodeFailure_meth = NULL;
1032 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKHTLCFailChannelUpdate_init (JNIEnv * env, jclass _a) {
1033         LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class =
1034                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$ChannelUpdateMessage;"));
1035         CHECK(LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class != NULL);
1036         LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class, "<init>", "(J)V");
1037         CHECK(LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth != NULL);
1038         LDKHTLCFailChannelUpdate_ChannelClosed_class =
1039                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$ChannelClosed;"));
1040         CHECK(LDKHTLCFailChannelUpdate_ChannelClosed_class != NULL);
1041         LDKHTLCFailChannelUpdate_ChannelClosed_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_ChannelClosed_class, "<init>", "(JZ)V");
1042         CHECK(LDKHTLCFailChannelUpdate_ChannelClosed_meth != NULL);
1043         LDKHTLCFailChannelUpdate_NodeFailure_class =
1044                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKHTLCFailChannelUpdate$NodeFailure;"));
1045         CHECK(LDKHTLCFailChannelUpdate_NodeFailure_class != NULL);
1046         LDKHTLCFailChannelUpdate_NodeFailure_meth = (*env)->GetMethodID(env, LDKHTLCFailChannelUpdate_NodeFailure_class, "<init>", "([BZ)V");
1047         CHECK(LDKHTLCFailChannelUpdate_NodeFailure_meth != NULL);
1048 }
1049 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKHTLCFailChannelUpdate_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
1050         LDKHTLCFailChannelUpdate *obj = (LDKHTLCFailChannelUpdate*)ptr;
1051         switch(obj->tag) {
1052                 case LDKHTLCFailChannelUpdate_ChannelUpdateMessage: {
1053                         LDKChannelUpdate msg_var = obj->channel_update_message.msg;
1054                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1055                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1056                         long msg_ref = (long)msg_var.inner & ~1;
1057                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth, msg_ref);
1058                 }
1059                 case LDKHTLCFailChannelUpdate_ChannelClosed: {
1060                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_ChannelClosed_class, LDKHTLCFailChannelUpdate_ChannelClosed_meth, obj->channel_closed.short_channel_id, obj->channel_closed.is_permanent);
1061                 }
1062                 case LDKHTLCFailChannelUpdate_NodeFailure: {
1063                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1064                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->node_failure.node_id.compressed_form);
1065                         return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_NodeFailure_class, LDKHTLCFailChannelUpdate_NodeFailure_meth, node_id_arr, obj->node_failure.is_permanent);
1066                 }
1067                 default: abort();
1068         }
1069 }
1070 static jclass LDKMessageSendEvent_SendAcceptChannel_class = NULL;
1071 static jmethodID LDKMessageSendEvent_SendAcceptChannel_meth = NULL;
1072 static jclass LDKMessageSendEvent_SendOpenChannel_class = NULL;
1073 static jmethodID LDKMessageSendEvent_SendOpenChannel_meth = NULL;
1074 static jclass LDKMessageSendEvent_SendFundingCreated_class = NULL;
1075 static jmethodID LDKMessageSendEvent_SendFundingCreated_meth = NULL;
1076 static jclass LDKMessageSendEvent_SendFundingSigned_class = NULL;
1077 static jmethodID LDKMessageSendEvent_SendFundingSigned_meth = NULL;
1078 static jclass LDKMessageSendEvent_SendFundingLocked_class = NULL;
1079 static jmethodID LDKMessageSendEvent_SendFundingLocked_meth = NULL;
1080 static jclass LDKMessageSendEvent_SendAnnouncementSignatures_class = NULL;
1081 static jmethodID LDKMessageSendEvent_SendAnnouncementSignatures_meth = NULL;
1082 static jclass LDKMessageSendEvent_UpdateHTLCs_class = NULL;
1083 static jmethodID LDKMessageSendEvent_UpdateHTLCs_meth = NULL;
1084 static jclass LDKMessageSendEvent_SendRevokeAndACK_class = NULL;
1085 static jmethodID LDKMessageSendEvent_SendRevokeAndACK_meth = NULL;
1086 static jclass LDKMessageSendEvent_SendClosingSigned_class = NULL;
1087 static jmethodID LDKMessageSendEvent_SendClosingSigned_meth = NULL;
1088 static jclass LDKMessageSendEvent_SendShutdown_class = NULL;
1089 static jmethodID LDKMessageSendEvent_SendShutdown_meth = NULL;
1090 static jclass LDKMessageSendEvent_SendChannelReestablish_class = NULL;
1091 static jmethodID LDKMessageSendEvent_SendChannelReestablish_meth = NULL;
1092 static jclass LDKMessageSendEvent_BroadcastChannelAnnouncement_class = NULL;
1093 static jmethodID LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = NULL;
1094 static jclass LDKMessageSendEvent_BroadcastNodeAnnouncement_class = NULL;
1095 static jmethodID LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = NULL;
1096 static jclass LDKMessageSendEvent_BroadcastChannelUpdate_class = NULL;
1097 static jmethodID LDKMessageSendEvent_BroadcastChannelUpdate_meth = NULL;
1098 static jclass LDKMessageSendEvent_HandleError_class = NULL;
1099 static jmethodID LDKMessageSendEvent_HandleError_meth = NULL;
1100 static jclass LDKMessageSendEvent_PaymentFailureNetworkUpdate_class = NULL;
1101 static jmethodID LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = NULL;
1102 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKMessageSendEvent_init (JNIEnv * env, jclass _a) {
1103         LDKMessageSendEvent_SendAcceptChannel_class =
1104                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendAcceptChannel;"));
1105         CHECK(LDKMessageSendEvent_SendAcceptChannel_class != NULL);
1106         LDKMessageSendEvent_SendAcceptChannel_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendAcceptChannel_class, "<init>", "([BJ)V");
1107         CHECK(LDKMessageSendEvent_SendAcceptChannel_meth != NULL);
1108         LDKMessageSendEvent_SendOpenChannel_class =
1109                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendOpenChannel;"));
1110         CHECK(LDKMessageSendEvent_SendOpenChannel_class != NULL);
1111         LDKMessageSendEvent_SendOpenChannel_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendOpenChannel_class, "<init>", "([BJ)V");
1112         CHECK(LDKMessageSendEvent_SendOpenChannel_meth != NULL);
1113         LDKMessageSendEvent_SendFundingCreated_class =
1114                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingCreated;"));
1115         CHECK(LDKMessageSendEvent_SendFundingCreated_class != NULL);
1116         LDKMessageSendEvent_SendFundingCreated_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingCreated_class, "<init>", "([BJ)V");
1117         CHECK(LDKMessageSendEvent_SendFundingCreated_meth != NULL);
1118         LDKMessageSendEvent_SendFundingSigned_class =
1119                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingSigned;"));
1120         CHECK(LDKMessageSendEvent_SendFundingSigned_class != NULL);
1121         LDKMessageSendEvent_SendFundingSigned_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingSigned_class, "<init>", "([BJ)V");
1122         CHECK(LDKMessageSendEvent_SendFundingSigned_meth != NULL);
1123         LDKMessageSendEvent_SendFundingLocked_class =
1124                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendFundingLocked;"));
1125         CHECK(LDKMessageSendEvent_SendFundingLocked_class != NULL);
1126         LDKMessageSendEvent_SendFundingLocked_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendFundingLocked_class, "<init>", "([BJ)V");
1127         CHECK(LDKMessageSendEvent_SendFundingLocked_meth != NULL);
1128         LDKMessageSendEvent_SendAnnouncementSignatures_class =
1129                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendAnnouncementSignatures;"));
1130         CHECK(LDKMessageSendEvent_SendAnnouncementSignatures_class != NULL);
1131         LDKMessageSendEvent_SendAnnouncementSignatures_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendAnnouncementSignatures_class, "<init>", "([BJ)V");
1132         CHECK(LDKMessageSendEvent_SendAnnouncementSignatures_meth != NULL);
1133         LDKMessageSendEvent_UpdateHTLCs_class =
1134                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$UpdateHTLCs;"));
1135         CHECK(LDKMessageSendEvent_UpdateHTLCs_class != NULL);
1136         LDKMessageSendEvent_UpdateHTLCs_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_UpdateHTLCs_class, "<init>", "([BJ)V");
1137         CHECK(LDKMessageSendEvent_UpdateHTLCs_meth != NULL);
1138         LDKMessageSendEvent_SendRevokeAndACK_class =
1139                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendRevokeAndACK;"));
1140         CHECK(LDKMessageSendEvent_SendRevokeAndACK_class != NULL);
1141         LDKMessageSendEvent_SendRevokeAndACK_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendRevokeAndACK_class, "<init>", "([BJ)V");
1142         CHECK(LDKMessageSendEvent_SendRevokeAndACK_meth != NULL);
1143         LDKMessageSendEvent_SendClosingSigned_class =
1144                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendClosingSigned;"));
1145         CHECK(LDKMessageSendEvent_SendClosingSigned_class != NULL);
1146         LDKMessageSendEvent_SendClosingSigned_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendClosingSigned_class, "<init>", "([BJ)V");
1147         CHECK(LDKMessageSendEvent_SendClosingSigned_meth != NULL);
1148         LDKMessageSendEvent_SendShutdown_class =
1149                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendShutdown;"));
1150         CHECK(LDKMessageSendEvent_SendShutdown_class != NULL);
1151         LDKMessageSendEvent_SendShutdown_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendShutdown_class, "<init>", "([BJ)V");
1152         CHECK(LDKMessageSendEvent_SendShutdown_meth != NULL);
1153         LDKMessageSendEvent_SendChannelReestablish_class =
1154                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$SendChannelReestablish;"));
1155         CHECK(LDKMessageSendEvent_SendChannelReestablish_class != NULL);
1156         LDKMessageSendEvent_SendChannelReestablish_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_SendChannelReestablish_class, "<init>", "([BJ)V");
1157         CHECK(LDKMessageSendEvent_SendChannelReestablish_meth != NULL);
1158         LDKMessageSendEvent_BroadcastChannelAnnouncement_class =
1159                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastChannelAnnouncement;"));
1160         CHECK(LDKMessageSendEvent_BroadcastChannelAnnouncement_class != NULL);
1161         LDKMessageSendEvent_BroadcastChannelAnnouncement_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastChannelAnnouncement_class, "<init>", "(JJ)V");
1162         CHECK(LDKMessageSendEvent_BroadcastChannelAnnouncement_meth != NULL);
1163         LDKMessageSendEvent_BroadcastNodeAnnouncement_class =
1164                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastNodeAnnouncement;"));
1165         CHECK(LDKMessageSendEvent_BroadcastNodeAnnouncement_class != NULL);
1166         LDKMessageSendEvent_BroadcastNodeAnnouncement_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastNodeAnnouncement_class, "<init>", "(J)V");
1167         CHECK(LDKMessageSendEvent_BroadcastNodeAnnouncement_meth != NULL);
1168         LDKMessageSendEvent_BroadcastChannelUpdate_class =
1169                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$BroadcastChannelUpdate;"));
1170         CHECK(LDKMessageSendEvent_BroadcastChannelUpdate_class != NULL);
1171         LDKMessageSendEvent_BroadcastChannelUpdate_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_BroadcastChannelUpdate_class, "<init>", "(J)V");
1172         CHECK(LDKMessageSendEvent_BroadcastChannelUpdate_meth != NULL);
1173         LDKMessageSendEvent_HandleError_class =
1174                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$HandleError;"));
1175         CHECK(LDKMessageSendEvent_HandleError_class != NULL);
1176         LDKMessageSendEvent_HandleError_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_HandleError_class, "<init>", "([BJ)V");
1177         CHECK(LDKMessageSendEvent_HandleError_meth != NULL);
1178         LDKMessageSendEvent_PaymentFailureNetworkUpdate_class =
1179                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKMessageSendEvent$PaymentFailureNetworkUpdate;"));
1180         CHECK(LDKMessageSendEvent_PaymentFailureNetworkUpdate_class != NULL);
1181         LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth = (*env)->GetMethodID(env, LDKMessageSendEvent_PaymentFailureNetworkUpdate_class, "<init>", "(J)V");
1182         CHECK(LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth != NULL);
1183 }
1184 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
1185         LDKMessageSendEvent *obj = (LDKMessageSendEvent*)ptr;
1186         switch(obj->tag) {
1187                 case LDKMessageSendEvent_SendAcceptChannel: {
1188                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1189                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_accept_channel.node_id.compressed_form);
1190                         LDKAcceptChannel msg_var = obj->send_accept_channel.msg;
1191                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1192                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1193                         long msg_ref = (long)msg_var.inner & ~1;
1194                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendAcceptChannel_class, LDKMessageSendEvent_SendAcceptChannel_meth, node_id_arr, msg_ref);
1195                 }
1196                 case LDKMessageSendEvent_SendOpenChannel: {
1197                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1198                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_open_channel.node_id.compressed_form);
1199                         LDKOpenChannel msg_var = obj->send_open_channel.msg;
1200                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1201                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1202                         long msg_ref = (long)msg_var.inner & ~1;
1203                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendOpenChannel_class, LDKMessageSendEvent_SendOpenChannel_meth, node_id_arr, msg_ref);
1204                 }
1205                 case LDKMessageSendEvent_SendFundingCreated: {
1206                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1207                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_created.node_id.compressed_form);
1208                         LDKFundingCreated msg_var = obj->send_funding_created.msg;
1209                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1210                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1211                         long msg_ref = (long)msg_var.inner & ~1;
1212                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingCreated_class, LDKMessageSendEvent_SendFundingCreated_meth, node_id_arr, msg_ref);
1213                 }
1214                 case LDKMessageSendEvent_SendFundingSigned: {
1215                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1216                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_signed.node_id.compressed_form);
1217                         LDKFundingSigned msg_var = obj->send_funding_signed.msg;
1218                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1219                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1220                         long msg_ref = (long)msg_var.inner & ~1;
1221                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingSigned_class, LDKMessageSendEvent_SendFundingSigned_meth, node_id_arr, msg_ref);
1222                 }
1223                 case LDKMessageSendEvent_SendFundingLocked: {
1224                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1225                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_funding_locked.node_id.compressed_form);
1226                         LDKFundingLocked msg_var = obj->send_funding_locked.msg;
1227                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1228                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1229                         long msg_ref = (long)msg_var.inner & ~1;
1230                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingLocked_class, LDKMessageSendEvent_SendFundingLocked_meth, node_id_arr, msg_ref);
1231                 }
1232                 case LDKMessageSendEvent_SendAnnouncementSignatures: {
1233                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1234                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_announcement_signatures.node_id.compressed_form);
1235                         LDKAnnouncementSignatures msg_var = obj->send_announcement_signatures.msg;
1236                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1237                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1238                         long msg_ref = (long)msg_var.inner & ~1;
1239                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendAnnouncementSignatures_class, LDKMessageSendEvent_SendAnnouncementSignatures_meth, node_id_arr, msg_ref);
1240                 }
1241                 case LDKMessageSendEvent_UpdateHTLCs: {
1242                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1243                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->update_htl_cs.node_id.compressed_form);
1244                         LDKCommitmentUpdate updates_var = obj->update_htl_cs.updates;
1245                         CHECK((((long)updates_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1246                         CHECK((((long)&updates_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1247                         long updates_ref = (long)updates_var.inner & ~1;
1248                         return (*_env)->NewObject(_env, LDKMessageSendEvent_UpdateHTLCs_class, LDKMessageSendEvent_UpdateHTLCs_meth, node_id_arr, updates_ref);
1249                 }
1250                 case LDKMessageSendEvent_SendRevokeAndACK: {
1251                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1252                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_revoke_and_ack.node_id.compressed_form);
1253                         LDKRevokeAndACK msg_var = obj->send_revoke_and_ack.msg;
1254                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1255                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1256                         long msg_ref = (long)msg_var.inner & ~1;
1257                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendRevokeAndACK_class, LDKMessageSendEvent_SendRevokeAndACK_meth, node_id_arr, msg_ref);
1258                 }
1259                 case LDKMessageSendEvent_SendClosingSigned: {
1260                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1261                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_closing_signed.node_id.compressed_form);
1262                         LDKClosingSigned msg_var = obj->send_closing_signed.msg;
1263                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1264                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1265                         long msg_ref = (long)msg_var.inner & ~1;
1266                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendClosingSigned_class, LDKMessageSendEvent_SendClosingSigned_meth, node_id_arr, msg_ref);
1267                 }
1268                 case LDKMessageSendEvent_SendShutdown: {
1269                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1270                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_shutdown.node_id.compressed_form);
1271                         LDKShutdown msg_var = obj->send_shutdown.msg;
1272                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1273                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1274                         long msg_ref = (long)msg_var.inner & ~1;
1275                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendShutdown_class, LDKMessageSendEvent_SendShutdown_meth, node_id_arr, msg_ref);
1276                 }
1277                 case LDKMessageSendEvent_SendChannelReestablish: {
1278                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1279                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->send_channel_reestablish.node_id.compressed_form);
1280                         LDKChannelReestablish msg_var = obj->send_channel_reestablish.msg;
1281                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1282                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1283                         long msg_ref = (long)msg_var.inner & ~1;
1284                         return (*_env)->NewObject(_env, LDKMessageSendEvent_SendChannelReestablish_class, LDKMessageSendEvent_SendChannelReestablish_meth, node_id_arr, msg_ref);
1285                 }
1286                 case LDKMessageSendEvent_BroadcastChannelAnnouncement: {
1287                         LDKChannelAnnouncement msg_var = obj->broadcast_channel_announcement.msg;
1288                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1289                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1290                         long msg_ref = (long)msg_var.inner & ~1;
1291                         LDKChannelUpdate update_msg_var = obj->broadcast_channel_announcement.update_msg;
1292                         CHECK((((long)update_msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1293                         CHECK((((long)&update_msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1294                         long update_msg_ref = (long)update_msg_var.inner & ~1;
1295                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastChannelAnnouncement_class, LDKMessageSendEvent_BroadcastChannelAnnouncement_meth, msg_ref, update_msg_ref);
1296                 }
1297                 case LDKMessageSendEvent_BroadcastNodeAnnouncement: {
1298                         LDKNodeAnnouncement msg_var = obj->broadcast_node_announcement.msg;
1299                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1300                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1301                         long msg_ref = (long)msg_var.inner & ~1;
1302                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastNodeAnnouncement_class, LDKMessageSendEvent_BroadcastNodeAnnouncement_meth, msg_ref);
1303                 }
1304                 case LDKMessageSendEvent_BroadcastChannelUpdate: {
1305                         LDKChannelUpdate msg_var = obj->broadcast_channel_update.msg;
1306                         CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1307                         CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1308                         long msg_ref = (long)msg_var.inner & ~1;
1309                         return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastChannelUpdate_class, LDKMessageSendEvent_BroadcastChannelUpdate_meth, msg_ref);
1310                 }
1311                 case LDKMessageSendEvent_HandleError: {
1312                         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
1313                         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, obj->handle_error.node_id.compressed_form);
1314                         long action_ref = (long)&obj->handle_error.action;
1315                         return (*_env)->NewObject(_env, LDKMessageSendEvent_HandleError_class, LDKMessageSendEvent_HandleError_meth, node_id_arr, action_ref);
1316                 }
1317                 case LDKMessageSendEvent_PaymentFailureNetworkUpdate: {
1318                         long update_ref = (long)&obj->payment_failure_network_update.update;
1319                         return (*_env)->NewObject(_env, LDKMessageSendEvent_PaymentFailureNetworkUpdate_class, LDKMessageSendEvent_PaymentFailureNetworkUpdate_meth, update_ref);
1320                 }
1321                 default: abort();
1322         }
1323 }
1324 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MessageSendEvent_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1325         LDKCVecTempl_MessageSendEvent *vec = (LDKCVecTempl_MessageSendEvent*)ptr;
1326         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKMessageSendEvent));
1327 }
1328 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MessageSendEvent_1new(JNIEnv *env, jclass _b, jlongArray elems){
1329         LDKCVecTempl_MessageSendEvent *ret = MALLOC(sizeof(LDKCVecTempl_MessageSendEvent), "LDKCVecTempl_MessageSendEvent");
1330         ret->datalen = (*env)->GetArrayLength(env, elems);
1331         if (ret->datalen == 0) {
1332                 ret->data = NULL;
1333         } else {
1334                 ret->data = MALLOC(sizeof(LDKMessageSendEvent) * ret->datalen, "LDKCVecTempl_MessageSendEvent Data");
1335                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1336                 for (size_t i = 0; i < ret->datalen; i++) {
1337                         jlong arr_elem = java_elems[i];
1338                         LDKMessageSendEvent arr_elem_conv = *(LDKMessageSendEvent*)arr_elem;
1339                         FREE((void*)arr_elem);
1340                         ret->data[i] = arr_elem_conv;
1341                 }
1342                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1343         }
1344         return (long)ret;
1345 }
1346 typedef struct LDKMessageSendEventsProvider_JCalls {
1347         atomic_size_t refcnt;
1348         JavaVM *vm;
1349         jweak o;
1350         jmethodID get_and_clear_pending_msg_events_meth;
1351 } LDKMessageSendEventsProvider_JCalls;
1352 LDKCVec_MessageSendEventZ get_and_clear_pending_msg_events_jcall(const void* this_arg) {
1353         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
1354         JNIEnv *_env;
1355         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1356         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1357         CHECK(obj != NULL);
1358         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_and_clear_pending_msg_events_meth);
1359         LDKCVec_MessageSendEventZ arg_constr;
1360         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
1361         if (arg_constr.datalen > 0)
1362                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
1363         else
1364                 arg_constr.data = NULL;
1365         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
1366         for (size_t s = 0; s < arg_constr.datalen; s++) {
1367                 long arr_conv_18 = arg_vals[s];
1368                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
1369                 FREE((void*)arr_conv_18);
1370                 arg_constr.data[s] = arr_conv_18_conv;
1371         }
1372         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
1373         return arg_constr;
1374 }
1375 static void LDKMessageSendEventsProvider_JCalls_free(void* this_arg) {
1376         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
1377         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1378                 JNIEnv *env;
1379                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1380                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1381                 FREE(j_calls);
1382         }
1383 }
1384 static void* LDKMessageSendEventsProvider_JCalls_clone(const void* this_arg) {
1385         LDKMessageSendEventsProvider_JCalls *j_calls = (LDKMessageSendEventsProvider_JCalls*) this_arg;
1386         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1387         return (void*) this_arg;
1388 }
1389 static inline LDKMessageSendEventsProvider LDKMessageSendEventsProvider_init (JNIEnv * env, jclass _a, jobject o) {
1390         jclass c = (*env)->GetObjectClass(env, o);
1391         CHECK(c != NULL);
1392         LDKMessageSendEventsProvider_JCalls *calls = MALLOC(sizeof(LDKMessageSendEventsProvider_JCalls), "LDKMessageSendEventsProvider_JCalls");
1393         atomic_init(&calls->refcnt, 1);
1394         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1395         calls->o = (*env)->NewWeakGlobalRef(env, o);
1396         calls->get_and_clear_pending_msg_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_msg_events", "()[J");
1397         CHECK(calls->get_and_clear_pending_msg_events_meth != NULL);
1398
1399         LDKMessageSendEventsProvider ret = {
1400                 .this_arg = (void*) calls,
1401                 .get_and_clear_pending_msg_events = get_and_clear_pending_msg_events_jcall,
1402                 .free = LDKMessageSendEventsProvider_JCalls_free,
1403         };
1404         return ret;
1405 }
1406 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1new (JNIEnv * env, jclass _a, jobject o) {
1407         LDKMessageSendEventsProvider *res_ptr = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
1408         *res_ptr = LDKMessageSendEventsProvider_init(env, _a, o);
1409         return (long)res_ptr;
1410 }
1411 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1412         jobject ret = (*env)->NewLocalRef(env, ((LDKMessageSendEventsProvider_JCalls*)val)->o);
1413         CHECK(ret != NULL);
1414         return ret;
1415 }
1416 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1get_1and_1clear_1pending_1msg_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
1417         LDKMessageSendEventsProvider* this_arg_conv = (LDKMessageSendEventsProvider*)this_arg;
1418         LDKCVec_MessageSendEventZ ret_var = (this_arg_conv->get_and_clear_pending_msg_events)(this_arg_conv->this_arg);
1419         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
1420         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
1421         for (size_t s = 0; s < ret_var.datalen; s++) {
1422                 LDKMessageSendEvent *arr_conv_18_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
1423                 *arr_conv_18_copy = MessageSendEvent_clone(&ret_var.data[s]);
1424                 long arr_conv_18_ref = (long)arr_conv_18_copy;
1425                 ret_arr_ptr[s] = arr_conv_18_ref;
1426         }
1427         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
1428         CVec_MessageSendEventZ_free(ret_var);
1429         return ret_arr;
1430 }
1431
1432 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Event_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1433         LDKCVecTempl_Event *vec = (LDKCVecTempl_Event*)ptr;
1434         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKEvent));
1435 }
1436 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Event_1new(JNIEnv *env, jclass _b, jlongArray elems){
1437         LDKCVecTempl_Event *ret = MALLOC(sizeof(LDKCVecTempl_Event), "LDKCVecTempl_Event");
1438         ret->datalen = (*env)->GetArrayLength(env, elems);
1439         if (ret->datalen == 0) {
1440                 ret->data = NULL;
1441         } else {
1442                 ret->data = MALLOC(sizeof(LDKEvent) * ret->datalen, "LDKCVecTempl_Event Data");
1443                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1444                 for (size_t i = 0; i < ret->datalen; i++) {
1445                         jlong arr_elem = java_elems[i];
1446                         LDKEvent arr_elem_conv = *(LDKEvent*)arr_elem;
1447                         FREE((void*)arr_elem);
1448                         ret->data[i] = arr_elem_conv;
1449                 }
1450                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1451         }
1452         return (long)ret;
1453 }
1454 typedef struct LDKEventsProvider_JCalls {
1455         atomic_size_t refcnt;
1456         JavaVM *vm;
1457         jweak o;
1458         jmethodID get_and_clear_pending_events_meth;
1459 } LDKEventsProvider_JCalls;
1460 LDKCVec_EventZ get_and_clear_pending_events_jcall(const void* this_arg) {
1461         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
1462         JNIEnv *_env;
1463         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1464         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1465         CHECK(obj != NULL);
1466         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_and_clear_pending_events_meth);
1467         LDKCVec_EventZ arg_constr;
1468         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
1469         if (arg_constr.datalen > 0)
1470                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
1471         else
1472                 arg_constr.data = NULL;
1473         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
1474         for (size_t h = 0; h < arg_constr.datalen; h++) {
1475                 long arr_conv_7 = arg_vals[h];
1476                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
1477                 FREE((void*)arr_conv_7);
1478                 arg_constr.data[h] = arr_conv_7_conv;
1479         }
1480         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
1481         return arg_constr;
1482 }
1483 static void LDKEventsProvider_JCalls_free(void* this_arg) {
1484         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
1485         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1486                 JNIEnv *env;
1487                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1488                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1489                 FREE(j_calls);
1490         }
1491 }
1492 static void* LDKEventsProvider_JCalls_clone(const void* this_arg) {
1493         LDKEventsProvider_JCalls *j_calls = (LDKEventsProvider_JCalls*) this_arg;
1494         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1495         return (void*) this_arg;
1496 }
1497 static inline LDKEventsProvider LDKEventsProvider_init (JNIEnv * env, jclass _a, jobject o) {
1498         jclass c = (*env)->GetObjectClass(env, o);
1499         CHECK(c != NULL);
1500         LDKEventsProvider_JCalls *calls = MALLOC(sizeof(LDKEventsProvider_JCalls), "LDKEventsProvider_JCalls");
1501         atomic_init(&calls->refcnt, 1);
1502         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1503         calls->o = (*env)->NewWeakGlobalRef(env, o);
1504         calls->get_and_clear_pending_events_meth = (*env)->GetMethodID(env, c, "get_and_clear_pending_events", "()[J");
1505         CHECK(calls->get_and_clear_pending_events_meth != NULL);
1506
1507         LDKEventsProvider ret = {
1508                 .this_arg = (void*) calls,
1509                 .get_and_clear_pending_events = get_and_clear_pending_events_jcall,
1510                 .free = LDKEventsProvider_JCalls_free,
1511         };
1512         return ret;
1513 }
1514 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1new (JNIEnv * env, jclass _a, jobject o) {
1515         LDKEventsProvider *res_ptr = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
1516         *res_ptr = LDKEventsProvider_init(env, _a, o);
1517         return (long)res_ptr;
1518 }
1519 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1520         jobject ret = (*env)->NewLocalRef(env, ((LDKEventsProvider_JCalls*)val)->o);
1521         CHECK(ret != NULL);
1522         return ret;
1523 }
1524 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_EventsProvider_1get_1and_1clear_1pending_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
1525         LDKEventsProvider* this_arg_conv = (LDKEventsProvider*)this_arg;
1526         LDKCVec_EventZ ret_var = (this_arg_conv->get_and_clear_pending_events)(this_arg_conv->this_arg);
1527         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
1528         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
1529         for (size_t h = 0; h < ret_var.datalen; h++) {
1530                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
1531                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
1532                 long arr_conv_7_ref = (long)arr_conv_7_copy;
1533                 ret_arr_ptr[h] = arr_conv_7_ref;
1534         }
1535         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
1536         CVec_EventZ_free(ret_var);
1537         return ret_arr;
1538 }
1539
1540 typedef struct LDKLogger_JCalls {
1541         atomic_size_t refcnt;
1542         JavaVM *vm;
1543         jweak o;
1544         jmethodID log_meth;
1545 } LDKLogger_JCalls;
1546 void log_jcall(const void* this_arg, const char *record) {
1547         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
1548         JNIEnv *_env;
1549         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1550         jstring record_conv = (*_env)->NewStringUTF(_env, record);
1551         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1552         CHECK(obj != NULL);
1553         return (*_env)->CallVoidMethod(_env, obj, j_calls->log_meth, record_conv);
1554 }
1555 static void LDKLogger_JCalls_free(void* this_arg) {
1556         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
1557         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1558                 JNIEnv *env;
1559                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1560                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1561                 FREE(j_calls);
1562         }
1563 }
1564 static void* LDKLogger_JCalls_clone(const void* this_arg) {
1565         LDKLogger_JCalls *j_calls = (LDKLogger_JCalls*) this_arg;
1566         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1567         return (void*) this_arg;
1568 }
1569 static inline LDKLogger LDKLogger_init (JNIEnv * env, jclass _a, jobject o) {
1570         jclass c = (*env)->GetObjectClass(env, o);
1571         CHECK(c != NULL);
1572         LDKLogger_JCalls *calls = MALLOC(sizeof(LDKLogger_JCalls), "LDKLogger_JCalls");
1573         atomic_init(&calls->refcnt, 1);
1574         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1575         calls->o = (*env)->NewWeakGlobalRef(env, o);
1576         calls->log_meth = (*env)->GetMethodID(env, c, "log", "(Ljava/lang/String;)V");
1577         CHECK(calls->log_meth != NULL);
1578
1579         LDKLogger ret = {
1580                 .this_arg = (void*) calls,
1581                 .log = log_jcall,
1582                 .free = LDKLogger_JCalls_free,
1583         };
1584         return ret;
1585 }
1586 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKLogger_1new (JNIEnv * env, jclass _a, jobject o) {
1587         LDKLogger *res_ptr = MALLOC(sizeof(LDKLogger), "LDKLogger");
1588         *res_ptr = LDKLogger_init(env, _a, o);
1589         return (long)res_ptr;
1590 }
1591 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKLogger_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1592         jobject ret = (*env)->NewLocalRef(env, ((LDKLogger_JCalls*)val)->o);
1593         CHECK(ret != NULL);
1594         return ret;
1595 }
1596 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
1597         return ((LDKCResult_TxOutAccessErrorZ*)arg)->result_ok;
1598 }
1599 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
1600         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
1601         CHECK(val->result_ok);
1602         long res_ref = (long)&(*val->contents.result);
1603         return res_ref;
1604 }
1605 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxOutAccessErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
1606         LDKCResult_TxOutAccessErrorZ *val = (LDKCResult_TxOutAccessErrorZ*)arg;
1607         CHECK(!val->result_ok);
1608         jclass err_conv = LDKAccessError_to_java(_env, (*val->contents.err));
1609         return err_conv;
1610 }
1611 typedef struct LDKAccess_JCalls {
1612         atomic_size_t refcnt;
1613         JavaVM *vm;
1614         jweak o;
1615         jmethodID get_utxo_meth;
1616 } LDKAccess_JCalls;
1617 LDKCResult_TxOutAccessErrorZ get_utxo_jcall(const void* this_arg, const uint8_t (*genesis_hash)[32], uint64_t short_channel_id) {
1618         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
1619         JNIEnv *_env;
1620         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1621         jbyteArray genesis_hash_arr = (*_env)->NewByteArray(_env, 32);
1622         (*_env)->SetByteArrayRegion(_env, genesis_hash_arr, 0, 32, *genesis_hash);
1623         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1624         CHECK(obj != NULL);
1625         LDKCResult_TxOutAccessErrorZ* ret = (LDKCResult_TxOutAccessErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->get_utxo_meth, genesis_hash_arr, short_channel_id);
1626         LDKCResult_TxOutAccessErrorZ ret_conv = *(LDKCResult_TxOutAccessErrorZ*)ret;
1627         FREE((void*)ret);
1628         return ret_conv;
1629 }
1630 static void LDKAccess_JCalls_free(void* this_arg) {
1631         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
1632         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1633                 JNIEnv *env;
1634                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1635                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1636                 FREE(j_calls);
1637         }
1638 }
1639 static void* LDKAccess_JCalls_clone(const void* this_arg) {
1640         LDKAccess_JCalls *j_calls = (LDKAccess_JCalls*) this_arg;
1641         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1642         return (void*) this_arg;
1643 }
1644 static inline LDKAccess LDKAccess_init (JNIEnv * env, jclass _a, jobject o) {
1645         jclass c = (*env)->GetObjectClass(env, o);
1646         CHECK(c != NULL);
1647         LDKAccess_JCalls *calls = MALLOC(sizeof(LDKAccess_JCalls), "LDKAccess_JCalls");
1648         atomic_init(&calls->refcnt, 1);
1649         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1650         calls->o = (*env)->NewWeakGlobalRef(env, o);
1651         calls->get_utxo_meth = (*env)->GetMethodID(env, c, "get_utxo", "([BJ)J");
1652         CHECK(calls->get_utxo_meth != NULL);
1653
1654         LDKAccess ret = {
1655                 .this_arg = (void*) calls,
1656                 .get_utxo = get_utxo_jcall,
1657                 .free = LDKAccess_JCalls_free,
1658         };
1659         return ret;
1660 }
1661 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKAccess_1new (JNIEnv * env, jclass _a, jobject o) {
1662         LDKAccess *res_ptr = MALLOC(sizeof(LDKAccess), "LDKAccess");
1663         *res_ptr = LDKAccess_init(env, _a, o);
1664         return (long)res_ptr;
1665 }
1666 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAccess_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1667         jobject ret = (*env)->NewLocalRef(env, ((LDKAccess_JCalls*)val)->o);
1668         CHECK(ret != NULL);
1669         return ret;
1670 }
1671 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) {
1672         LDKAccess* this_arg_conv = (LDKAccess*)this_arg;
1673         unsigned char genesis_hash_arr[32];
1674         CHECK((*_env)->GetArrayLength (_env, genesis_hash) == 32);
1675         (*_env)->GetByteArrayRegion (_env, genesis_hash, 0, 32, genesis_hash_arr);
1676         unsigned char (*genesis_hash_ref)[32] = &genesis_hash_arr;
1677         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
1678         *ret_conv = (this_arg_conv->get_utxo)(this_arg_conv->this_arg, genesis_hash_ref, short_channel_id);
1679         return (long)ret_conv;
1680 }
1681
1682 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1HTLCOutputInCommitment_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
1683         LDKCVecTempl_HTLCOutputInCommitment *vec = (LDKCVecTempl_HTLCOutputInCommitment*)ptr;
1684         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
1685         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
1686         for (size_t i = 0; i < vec->datalen; i++) {
1687                 CHECK((((long)vec->data[i].inner) & 1) == 0);
1688                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
1689         }
1690         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
1691         return ret;
1692 }
1693 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1HTLCOutputInCommitment_1new(JNIEnv *env, jclass _b, jlongArray elems){
1694         LDKCVecTempl_HTLCOutputInCommitment *ret = MALLOC(sizeof(LDKCVecTempl_HTLCOutputInCommitment), "LDKCVecTempl_HTLCOutputInCommitment");
1695         ret->datalen = (*env)->GetArrayLength(env, elems);
1696         if (ret->datalen == 0) {
1697                 ret->data = NULL;
1698         } else {
1699                 ret->data = MALLOC(sizeof(LDKHTLCOutputInCommitment) * ret->datalen, "LDKCVecTempl_HTLCOutputInCommitment Data");
1700                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
1701                 for (size_t i = 0; i < ret->datalen; i++) {
1702                         jlong arr_elem = java_elems[i];
1703                         LDKHTLCOutputInCommitment arr_elem_conv;
1704                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
1705                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
1706                         if (arr_elem_conv.inner != NULL)
1707                                 arr_elem_conv = HTLCOutputInCommitment_clone(&arr_elem_conv);
1708                         ret->data[i] = arr_elem_conv;
1709                 }
1710                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
1711         }
1712         return (long)ret;
1713 }
1714 typedef struct LDKChannelKeys_JCalls {
1715         atomic_size_t refcnt;
1716         JavaVM *vm;
1717         jweak o;
1718         jmethodID get_per_commitment_point_meth;
1719         jmethodID release_commitment_secret_meth;
1720         jmethodID key_derivation_params_meth;
1721         jmethodID sign_counterparty_commitment_meth;
1722         jmethodID sign_holder_commitment_meth;
1723         jmethodID sign_holder_commitment_htlc_transactions_meth;
1724         jmethodID sign_justice_transaction_meth;
1725         jmethodID sign_counterparty_htlc_transaction_meth;
1726         jmethodID sign_closing_transaction_meth;
1727         jmethodID sign_channel_announcement_meth;
1728         jmethodID on_accept_meth;
1729 } LDKChannelKeys_JCalls;
1730 LDKPublicKey get_per_commitment_point_jcall(const void* this_arg, uint64_t idx) {
1731         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1732         JNIEnv *_env;
1733         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1734         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1735         CHECK(obj != NULL);
1736         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_per_commitment_point_meth, idx);
1737         LDKPublicKey arg_ref;
1738         CHECK((*_env)->GetArrayLength (_env, arg) == 33);
1739         (*_env)->GetByteArrayRegion (_env, arg, 0, 33, arg_ref.compressed_form);
1740         return arg_ref;
1741 }
1742 LDKThirtyTwoBytes release_commitment_secret_jcall(const void* this_arg, uint64_t idx) {
1743         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1744         JNIEnv *_env;
1745         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1746         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1747         CHECK(obj != NULL);
1748         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->release_commitment_secret_meth, idx);
1749         LDKThirtyTwoBytes arg_ref;
1750         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
1751         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.data);
1752         return arg_ref;
1753 }
1754 LDKC2Tuple_u64u64Z key_derivation_params_jcall(const void* this_arg) {
1755         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1756         JNIEnv *_env;
1757         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1758         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1759         CHECK(obj != NULL);
1760         LDKC2Tuple_u64u64Z* ret = (LDKC2Tuple_u64u64Z*)(*_env)->CallLongMethod(_env, obj, j_calls->key_derivation_params_meth);
1761         LDKC2Tuple_u64u64Z ret_conv = *(LDKC2Tuple_u64u64Z*)ret;
1762         FREE((void*)ret);
1763         return ret_conv;
1764 }
1765 LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment_jcall(const void* this_arg, uint32_t feerate_per_kw, LDKTransaction commitment_tx, const LDKPreCalculatedTxCreationKeys *keys, LDKCVec_HTLCOutputInCommitmentZ htlcs) {
1766         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1767         JNIEnv *_env;
1768         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1769         LDKTransaction *commitment_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
1770         *commitment_tx_copy = commitment_tx;
1771         long commitment_tx_ref = (long)commitment_tx_copy;
1772         long ret_keys = (long)keys;
1773         LDKCVec_HTLCOutputInCommitmentZ htlcs_var = htlcs;
1774         jlongArray htlcs_arr = (*_env)->NewLongArray(_env, htlcs_var.datalen);
1775         jlong *htlcs_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, htlcs_arr, NULL);
1776         for (size_t y = 0; y < htlcs_var.datalen; y++) {
1777                 LDKHTLCOutputInCommitment arr_conv_24_var = htlcs_var.data[y];
1778                 CHECK((((long)arr_conv_24_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
1779                 CHECK((((long)&arr_conv_24_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
1780                 long arr_conv_24_ref = (long)arr_conv_24_var.inner;
1781                 if (arr_conv_24_var.is_owned) {
1782                         arr_conv_24_ref |= 1;
1783                 }
1784                 htlcs_arr_ptr[y] = arr_conv_24_ref;
1785         }
1786         (*_env)->ReleasePrimitiveArrayCritical(_env, htlcs_arr, htlcs_arr_ptr, 0);
1787         FREE(htlcs_var.data);
1788         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1789         CHECK(obj != NULL);
1790         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_counterparty_commitment_meth, feerate_per_kw, commitment_tx_ref, ret_keys, htlcs_arr);
1791         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)ret;
1792         FREE((void*)ret);
1793         return ret_conv;
1794 }
1795 LDKCResult_SignatureNoneZ sign_holder_commitment_jcall(const void* this_arg, const LDKHolderCommitmentTransaction *holder_commitment_tx) {
1796         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1797         JNIEnv *_env;
1798         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1799         long ret_holder_commitment_tx = (long)holder_commitment_tx;
1800         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1801         CHECK(obj != NULL);
1802         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_holder_commitment_meth, ret_holder_commitment_tx);
1803         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1804         FREE((void*)ret);
1805         return ret_conv;
1806 }
1807 LDKCResult_CVec_SignatureZNoneZ sign_holder_commitment_htlc_transactions_jcall(const void* this_arg, const LDKHolderCommitmentTransaction *holder_commitment_tx) {
1808         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1809         JNIEnv *_env;
1810         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1811         long ret_holder_commitment_tx = (long)holder_commitment_tx;
1812         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1813         CHECK(obj != NULL);
1814         LDKCResult_CVec_SignatureZNoneZ* ret = (LDKCResult_CVec_SignatureZNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_holder_commitment_htlc_transactions_meth, ret_holder_commitment_tx);
1815         LDKCResult_CVec_SignatureZNoneZ ret_conv = *(LDKCResult_CVec_SignatureZNoneZ*)ret;
1816         FREE((void*)ret);
1817         return ret_conv;
1818 }
1819 LDKCResult_SignatureNoneZ sign_justice_transaction_jcall(const void* this_arg, LDKTransaction justice_tx, uintptr_t input, uint64_t amount, const uint8_t (*per_commitment_key)[32], const LDKHTLCOutputInCommitment *htlc) {
1820         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1821         JNIEnv *_env;
1822         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1823         LDKTransaction *justice_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
1824         *justice_tx_copy = justice_tx;
1825         long justice_tx_ref = (long)justice_tx_copy;
1826         jbyteArray per_commitment_key_arr = (*_env)->NewByteArray(_env, 32);
1827         (*_env)->SetByteArrayRegion(_env, per_commitment_key_arr, 0, 32, *per_commitment_key);
1828         long ret_htlc = (long)htlc;
1829         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1830         CHECK(obj != NULL);
1831         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_justice_transaction_meth, justice_tx_ref, input, amount, per_commitment_key_arr, ret_htlc);
1832         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1833         FREE((void*)ret);
1834         return ret_conv;
1835 }
1836 LDKCResult_SignatureNoneZ sign_counterparty_htlc_transaction_jcall(const void* this_arg, LDKTransaction htlc_tx, uintptr_t input, uint64_t amount, LDKPublicKey per_commitment_point, const LDKHTLCOutputInCommitment *htlc) {
1837         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1838         JNIEnv *_env;
1839         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1840         LDKTransaction *htlc_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
1841         *htlc_tx_copy = htlc_tx;
1842         long htlc_tx_ref = (long)htlc_tx_copy;
1843         jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33);
1844         (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, per_commitment_point.compressed_form);
1845         long ret_htlc = (long)htlc;
1846         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1847         CHECK(obj != NULL);
1848         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_counterparty_htlc_transaction_meth, htlc_tx_ref, input, amount, per_commitment_point_arr, ret_htlc);
1849         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1850         FREE((void*)ret);
1851         return ret_conv;
1852 }
1853 LDKCResult_SignatureNoneZ sign_closing_transaction_jcall(const void* this_arg, LDKTransaction closing_tx) {
1854         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1855         JNIEnv *_env;
1856         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1857         LDKTransaction *closing_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
1858         *closing_tx_copy = closing_tx;
1859         long closing_tx_ref = (long)closing_tx_copy;
1860         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1861         CHECK(obj != NULL);
1862         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_closing_transaction_meth, closing_tx_ref);
1863         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1864         FREE((void*)ret);
1865         return ret_conv;
1866 }
1867 LDKCResult_SignatureNoneZ sign_channel_announcement_jcall(const void* this_arg, const LDKUnsignedChannelAnnouncement *msg) {
1868         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1869         JNIEnv *_env;
1870         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1871         long ret_msg = (long)msg;
1872         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1873         CHECK(obj != NULL);
1874         LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_channel_announcement_meth, ret_msg);
1875         LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret;
1876         FREE((void*)ret);
1877         return ret_conv;
1878 }
1879 void on_accept_jcall(void* this_arg, const LDKChannelPublicKeys *channel_points, uint16_t counterparty_selected_contest_delay, uint16_t holder_selected_contest_delay) {
1880         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1881         JNIEnv *_env;
1882         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
1883         long ret_channel_points = (long)channel_points;
1884         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
1885         CHECK(obj != NULL);
1886         return (*_env)->CallVoidMethod(_env, obj, j_calls->on_accept_meth, ret_channel_points, counterparty_selected_contest_delay, holder_selected_contest_delay);
1887 }
1888 static void LDKChannelKeys_JCalls_free(void* this_arg) {
1889         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1890         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
1891                 JNIEnv *env;
1892                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
1893                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
1894                 FREE(j_calls);
1895         }
1896 }
1897 static void* LDKChannelKeys_JCalls_clone(const void* this_arg) {
1898         LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
1899         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
1900         return (void*) this_arg;
1901 }
1902 static inline LDKChannelKeys LDKChannelKeys_init (JNIEnv * env, jclass _a, jobject o, jlong pubkeys) {
1903         jclass c = (*env)->GetObjectClass(env, o);
1904         CHECK(c != NULL);
1905         LDKChannelKeys_JCalls *calls = MALLOC(sizeof(LDKChannelKeys_JCalls), "LDKChannelKeys_JCalls");
1906         atomic_init(&calls->refcnt, 1);
1907         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
1908         calls->o = (*env)->NewWeakGlobalRef(env, o);
1909         calls->get_per_commitment_point_meth = (*env)->GetMethodID(env, c, "get_per_commitment_point", "(J)[B");
1910         CHECK(calls->get_per_commitment_point_meth != NULL);
1911         calls->release_commitment_secret_meth = (*env)->GetMethodID(env, c, "release_commitment_secret", "(J)[B");
1912         CHECK(calls->release_commitment_secret_meth != NULL);
1913         calls->key_derivation_params_meth = (*env)->GetMethodID(env, c, "key_derivation_params", "()J");
1914         CHECK(calls->key_derivation_params_meth != NULL);
1915         calls->sign_counterparty_commitment_meth = (*env)->GetMethodID(env, c, "sign_counterparty_commitment", "(IJJ[J)J");
1916         CHECK(calls->sign_counterparty_commitment_meth != NULL);
1917         calls->sign_holder_commitment_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment", "(J)J");
1918         CHECK(calls->sign_holder_commitment_meth != NULL);
1919         calls->sign_holder_commitment_htlc_transactions_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment_htlc_transactions", "(J)J");
1920         CHECK(calls->sign_holder_commitment_htlc_transactions_meth != NULL);
1921         calls->sign_justice_transaction_meth = (*env)->GetMethodID(env, c, "sign_justice_transaction", "(JJJ[BJ)J");
1922         CHECK(calls->sign_justice_transaction_meth != NULL);
1923         calls->sign_counterparty_htlc_transaction_meth = (*env)->GetMethodID(env, c, "sign_counterparty_htlc_transaction", "(JJJ[BJ)J");
1924         CHECK(calls->sign_counterparty_htlc_transaction_meth != NULL);
1925         calls->sign_closing_transaction_meth = (*env)->GetMethodID(env, c, "sign_closing_transaction", "(J)J");
1926         CHECK(calls->sign_closing_transaction_meth != NULL);
1927         calls->sign_channel_announcement_meth = (*env)->GetMethodID(env, c, "sign_channel_announcement", "(J)J");
1928         CHECK(calls->sign_channel_announcement_meth != NULL);
1929         calls->on_accept_meth = (*env)->GetMethodID(env, c, "on_accept", "(JSS)V");
1930         CHECK(calls->on_accept_meth != NULL);
1931
1932         LDKChannelPublicKeys pubkeys_conv;
1933         pubkeys_conv.inner = (void*)(pubkeys & (~1));
1934         pubkeys_conv.is_owned = (pubkeys & 1) || (pubkeys == 0);
1935         if (pubkeys_conv.inner != NULL)
1936                 pubkeys_conv = ChannelPublicKeys_clone(&pubkeys_conv);
1937
1938         LDKChannelKeys ret = {
1939                 .this_arg = (void*) calls,
1940                 .get_per_commitment_point = get_per_commitment_point_jcall,
1941                 .release_commitment_secret = release_commitment_secret_jcall,
1942                 .key_derivation_params = key_derivation_params_jcall,
1943                 .sign_counterparty_commitment = sign_counterparty_commitment_jcall,
1944                 .sign_holder_commitment = sign_holder_commitment_jcall,
1945                 .sign_holder_commitment_htlc_transactions = sign_holder_commitment_htlc_transactions_jcall,
1946                 .sign_justice_transaction = sign_justice_transaction_jcall,
1947                 .sign_counterparty_htlc_transaction = sign_counterparty_htlc_transaction_jcall,
1948                 .sign_closing_transaction = sign_closing_transaction_jcall,
1949                 .sign_channel_announcement = sign_channel_announcement_jcall,
1950                 .on_accept = on_accept_jcall,
1951                 .clone = LDKChannelKeys_JCalls_clone,
1952                 .free = LDKChannelKeys_JCalls_free,
1953                 .pubkeys = pubkeys_conv,
1954                 .set_pubkeys = NULL,
1955         };
1956         return ret;
1957 }
1958 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1new (JNIEnv * env, jclass _a, jobject o, jlong pubkeys) {
1959         LDKChannelKeys *res_ptr = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
1960         *res_ptr = LDKChannelKeys_init(env, _a, o, pubkeys);
1961         return (long)res_ptr;
1962 }
1963 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
1964         jobject ret = (*env)->NewLocalRef(env, ((LDKChannelKeys_JCalls*)val)->o);
1965         CHECK(ret != NULL);
1966         return ret;
1967 }
1968 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_arg, jlong idx) {
1969         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1970         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
1971         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (this_arg_conv->get_per_commitment_point)(this_arg_conv->this_arg, idx).compressed_form);
1972         return arg_arr;
1973 }
1974
1975 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1release_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_arg, jlong idx) {
1976         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1977         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
1978         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->release_commitment_secret)(this_arg_conv->this_arg, idx).data);
1979         return arg_arr;
1980 }
1981
1982 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1key_1derivation_1params(JNIEnv * _env, jclass _b, jlong this_arg) {
1983         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1984         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
1985         *ret_ref = (this_arg_conv->key_derivation_params)(this_arg_conv->this_arg);
1986         return (long)ret_ref;
1987 }
1988
1989 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jint feerate_per_kw, jlong commitment_tx, jlong keys, jlongArray htlcs) {
1990         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
1991         LDKTransaction commitment_tx_conv = *(LDKTransaction*)commitment_tx;
1992         LDKPreCalculatedTxCreationKeys keys_conv;
1993         keys_conv.inner = (void*)(keys & (~1));
1994         keys_conv.is_owned = (keys & 1) || (keys == 0);
1995         LDKCVec_HTLCOutputInCommitmentZ htlcs_constr;
1996         htlcs_constr.datalen = (*_env)->GetArrayLength (_env, htlcs);
1997         if (htlcs_constr.datalen > 0)
1998                 htlcs_constr.data = MALLOC(htlcs_constr.datalen * sizeof(LDKHTLCOutputInCommitment), "LDKCVec_HTLCOutputInCommitmentZ Elements");
1999         else
2000                 htlcs_constr.data = NULL;
2001         long* htlcs_vals = (*_env)->GetLongArrayElements (_env, htlcs, NULL);
2002         for (size_t y = 0; y < htlcs_constr.datalen; y++) {
2003                 long arr_conv_24 = htlcs_vals[y];
2004                 LDKHTLCOutputInCommitment arr_conv_24_conv;
2005                 arr_conv_24_conv.inner = (void*)(arr_conv_24 & (~1));
2006                 arr_conv_24_conv.is_owned = (arr_conv_24 & 1) || (arr_conv_24 == 0);
2007                 if (arr_conv_24_conv.inner != NULL)
2008                         arr_conv_24_conv = HTLCOutputInCommitment_clone(&arr_conv_24_conv);
2009                 htlcs_constr.data[y] = arr_conv_24_conv;
2010         }
2011         (*_env)->ReleaseLongArrayElements (_env, htlcs, htlcs_vals, 0);
2012         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
2013         *ret_conv = (this_arg_conv->sign_counterparty_commitment)(this_arg_conv->this_arg, feerate_per_kw, commitment_tx_conv, &keys_conv, htlcs_constr);
2014         return (long)ret_conv;
2015 }
2016
2017 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jlong holder_commitment_tx) {
2018         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2019         LDKHolderCommitmentTransaction holder_commitment_tx_conv;
2020         holder_commitment_tx_conv.inner = (void*)(holder_commitment_tx & (~1));
2021         holder_commitment_tx_conv.is_owned = (holder_commitment_tx & 1) || (holder_commitment_tx == 0);
2022         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2023         *ret_conv = (this_arg_conv->sign_holder_commitment)(this_arg_conv->this_arg, &holder_commitment_tx_conv);
2024         return (long)ret_conv;
2025 }
2026
2027 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1commitment_1htlc_1transactions(JNIEnv * _env, jclass _b, jlong this_arg, jlong holder_commitment_tx) {
2028         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2029         LDKHolderCommitmentTransaction holder_commitment_tx_conv;
2030         holder_commitment_tx_conv.inner = (void*)(holder_commitment_tx & (~1));
2031         holder_commitment_tx_conv.is_owned = (holder_commitment_tx & 1) || (holder_commitment_tx == 0);
2032         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
2033         *ret_conv = (this_arg_conv->sign_holder_commitment_htlc_transactions)(this_arg_conv->this_arg, &holder_commitment_tx_conv);
2034         return (long)ret_conv;
2035 }
2036
2037 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1justice_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong justice_tx, jlong input, jlong amount, jbyteArray per_commitment_key, jlong htlc) {
2038         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2039         LDKTransaction justice_tx_conv = *(LDKTransaction*)justice_tx;
2040         unsigned char per_commitment_key_arr[32];
2041         CHECK((*_env)->GetArrayLength (_env, per_commitment_key) == 32);
2042         (*_env)->GetByteArrayRegion (_env, per_commitment_key, 0, 32, per_commitment_key_arr);
2043         unsigned char (*per_commitment_key_ref)[32] = &per_commitment_key_arr;
2044         LDKHTLCOutputInCommitment htlc_conv;
2045         htlc_conv.inner = (void*)(htlc & (~1));
2046         htlc_conv.is_owned = (htlc & 1) || (htlc == 0);
2047         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2048         *ret_conv = (this_arg_conv->sign_justice_transaction)(this_arg_conv->this_arg, justice_tx_conv, input, amount, per_commitment_key_ref, &htlc_conv);
2049         return (long)ret_conv;
2050 }
2051
2052 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1htlc_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong htlc_tx, jlong input, jlong amount, jbyteArray per_commitment_point, jlong htlc) {
2053         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2054         LDKTransaction htlc_tx_conv = *(LDKTransaction*)htlc_tx;
2055         LDKPublicKey per_commitment_point_ref;
2056         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
2057         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
2058         LDKHTLCOutputInCommitment htlc_conv;
2059         htlc_conv.inner = (void*)(htlc & (~1));
2060         htlc_conv.is_owned = (htlc & 1) || (htlc == 0);
2061         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2062         *ret_conv = (this_arg_conv->sign_counterparty_htlc_transaction)(this_arg_conv->this_arg, htlc_tx_conv, input, amount, per_commitment_point_ref, &htlc_conv);
2063         return (long)ret_conv;
2064 }
2065
2066 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1closing_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong closing_tx) {
2067         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2068         LDKTransaction closing_tx_conv = *(LDKTransaction*)closing_tx;
2069         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2070         *ret_conv = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_conv);
2071         return (long)ret_conv;
2072 }
2073
2074 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1channel_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
2075         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2076         LDKUnsignedChannelAnnouncement msg_conv;
2077         msg_conv.inner = (void*)(msg & (~1));
2078         msg_conv.is_owned = (msg & 1) || (msg == 0);
2079         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
2080         *ret_conv = (this_arg_conv->sign_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
2081         return (long)ret_conv;
2082 }
2083
2084 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1on_1accept(JNIEnv * _env, jclass _b, jlong this_arg, jlong channel_points, jshort counterparty_selected_contest_delay, jshort holder_selected_contest_delay) {
2085         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2086         LDKChannelPublicKeys channel_points_conv;
2087         channel_points_conv.inner = (void*)(channel_points & (~1));
2088         channel_points_conv.is_owned = (channel_points & 1) || (channel_points == 0);
2089         (this_arg_conv->on_accept)(this_arg_conv->this_arg, &channel_points_conv, counterparty_selected_contest_delay, holder_selected_contest_delay);
2090 }
2091
2092 LDKChannelPublicKeys LDKChannelKeys_set_get_pubkeys(LDKChannelKeys* this_arg) {
2093         if (this_arg->set_pubkeys != NULL)
2094                 this_arg->set_pubkeys(this_arg);
2095         return this_arg->pubkeys;
2096 }
2097 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
2098         LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
2099         LDKChannelPublicKeys ret_var = LDKChannelKeys_set_get_pubkeys(this_arg_conv);
2100         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2101         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2102         long ret_ref = (long)ret_var.inner;
2103         if (ret_var.is_owned) {
2104                 ret_ref |= 1;
2105         }
2106         return ret_ref;
2107 }
2108
2109 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MonitorEvent_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2110         LDKCVecTempl_MonitorEvent *vec = (LDKCVecTempl_MonitorEvent*)ptr;
2111         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
2112         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
2113         for (size_t i = 0; i < vec->datalen; i++) {
2114                 CHECK((((long)vec->data[i].inner) & 1) == 0);
2115                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
2116         }
2117         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
2118         return ret;
2119 }
2120 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MonitorEvent_1new(JNIEnv *env, jclass _b, jlongArray elems){
2121         LDKCVecTempl_MonitorEvent *ret = MALLOC(sizeof(LDKCVecTempl_MonitorEvent), "LDKCVecTempl_MonitorEvent");
2122         ret->datalen = (*env)->GetArrayLength(env, elems);
2123         if (ret->datalen == 0) {
2124                 ret->data = NULL;
2125         } else {
2126                 ret->data = MALLOC(sizeof(LDKMonitorEvent) * ret->datalen, "LDKCVecTempl_MonitorEvent Data");
2127                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2128                 for (size_t i = 0; i < ret->datalen; i++) {
2129                         jlong arr_elem = java_elems[i];
2130                         LDKMonitorEvent arr_elem_conv;
2131                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2132                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2133                         if (arr_elem_conv.inner != NULL)
2134                                 arr_elem_conv = MonitorEvent_clone(&arr_elem_conv);
2135                         ret->data[i] = arr_elem_conv;
2136                 }
2137                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2138         }
2139         return (long)ret;
2140 }
2141 typedef struct LDKWatch_JCalls {
2142         atomic_size_t refcnt;
2143         JavaVM *vm;
2144         jweak o;
2145         jmethodID watch_channel_meth;
2146         jmethodID update_channel_meth;
2147         jmethodID release_pending_monitor_events_meth;
2148 } LDKWatch_JCalls;
2149 LDKCResult_NoneChannelMonitorUpdateErrZ watch_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitor monitor) {
2150         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2151         JNIEnv *_env;
2152         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2153         LDKOutPoint funding_txo_var = funding_txo;
2154         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2155         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2156         long funding_txo_ref = (long)funding_txo_var.inner;
2157         if (funding_txo_var.is_owned) {
2158                 funding_txo_ref |= 1;
2159         }
2160         LDKChannelMonitor monitor_var = monitor;
2161         CHECK((((long)monitor_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2162         CHECK((((long)&monitor_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2163         long monitor_ref = (long)monitor_var.inner;
2164         if (monitor_var.is_owned) {
2165                 monitor_ref |= 1;
2166         }
2167         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2168         CHECK(obj != NULL);
2169         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->watch_channel_meth, funding_txo_ref, monitor_ref);
2170         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2171         FREE((void*)ret);
2172         return ret_conv;
2173 }
2174 LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_jcall(const void* this_arg, LDKOutPoint funding_txo, LDKChannelMonitorUpdate update) {
2175         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2176         JNIEnv *_env;
2177         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2178         LDKOutPoint funding_txo_var = funding_txo;
2179         CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2180         CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2181         long funding_txo_ref = (long)funding_txo_var.inner;
2182         if (funding_txo_var.is_owned) {
2183                 funding_txo_ref |= 1;
2184         }
2185         LDKChannelMonitorUpdate update_var = update;
2186         CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2187         CHECK((((long)&update_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2188         long update_ref = (long)update_var.inner;
2189         if (update_var.is_owned) {
2190                 update_ref |= 1;
2191         }
2192         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2193         CHECK(obj != NULL);
2194         LDKCResult_NoneChannelMonitorUpdateErrZ* ret = (LDKCResult_NoneChannelMonitorUpdateErrZ*)(*_env)->CallLongMethod(_env, obj, j_calls->update_channel_meth, funding_txo_ref, update_ref);
2195         LDKCResult_NoneChannelMonitorUpdateErrZ ret_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)ret;
2196         FREE((void*)ret);
2197         return ret_conv;
2198 }
2199 LDKCVec_MonitorEventZ release_pending_monitor_events_jcall(const void* this_arg) {
2200         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2201         JNIEnv *_env;
2202         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2203         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2204         CHECK(obj != NULL);
2205         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->release_pending_monitor_events_meth);
2206         LDKCVec_MonitorEventZ arg_constr;
2207         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
2208         if (arg_constr.datalen > 0)
2209                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
2210         else
2211                 arg_constr.data = NULL;
2212         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
2213         for (size_t o = 0; o < arg_constr.datalen; o++) {
2214                 long arr_conv_14 = arg_vals[o];
2215                 LDKMonitorEvent arr_conv_14_conv;
2216                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
2217                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
2218                 if (arr_conv_14_conv.inner != NULL)
2219                         arr_conv_14_conv = MonitorEvent_clone(&arr_conv_14_conv);
2220                 arg_constr.data[o] = arr_conv_14_conv;
2221         }
2222         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
2223         return arg_constr;
2224 }
2225 static void LDKWatch_JCalls_free(void* this_arg) {
2226         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2227         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2228                 JNIEnv *env;
2229                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2230                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2231                 FREE(j_calls);
2232         }
2233 }
2234 static void* LDKWatch_JCalls_clone(const void* this_arg) {
2235         LDKWatch_JCalls *j_calls = (LDKWatch_JCalls*) this_arg;
2236         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2237         return (void*) this_arg;
2238 }
2239 static inline LDKWatch LDKWatch_init (JNIEnv * env, jclass _a, jobject o) {
2240         jclass c = (*env)->GetObjectClass(env, o);
2241         CHECK(c != NULL);
2242         LDKWatch_JCalls *calls = MALLOC(sizeof(LDKWatch_JCalls), "LDKWatch_JCalls");
2243         atomic_init(&calls->refcnt, 1);
2244         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2245         calls->o = (*env)->NewWeakGlobalRef(env, o);
2246         calls->watch_channel_meth = (*env)->GetMethodID(env, c, "watch_channel", "(JJ)J");
2247         CHECK(calls->watch_channel_meth != NULL);
2248         calls->update_channel_meth = (*env)->GetMethodID(env, c, "update_channel", "(JJ)J");
2249         CHECK(calls->update_channel_meth != NULL);
2250         calls->release_pending_monitor_events_meth = (*env)->GetMethodID(env, c, "release_pending_monitor_events", "()[J");
2251         CHECK(calls->release_pending_monitor_events_meth != NULL);
2252
2253         LDKWatch ret = {
2254                 .this_arg = (void*) calls,
2255                 .watch_channel = watch_channel_jcall,
2256                 .update_channel = update_channel_jcall,
2257                 .release_pending_monitor_events = release_pending_monitor_events_jcall,
2258                 .free = LDKWatch_JCalls_free,
2259         };
2260         return ret;
2261 }
2262 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKWatch_1new (JNIEnv * env, jclass _a, jobject o) {
2263         LDKWatch *res_ptr = MALLOC(sizeof(LDKWatch), "LDKWatch");
2264         *res_ptr = LDKWatch_init(env, _a, o);
2265         return (long)res_ptr;
2266 }
2267 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKWatch_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2268         jobject ret = (*env)->NewLocalRef(env, ((LDKWatch_JCalls*)val)->o);
2269         CHECK(ret != NULL);
2270         return ret;
2271 }
2272 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Watch_1watch_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong funding_txo, jlong monitor) {
2273         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2274         LDKOutPoint funding_txo_conv;
2275         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2276         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2277         if (funding_txo_conv.inner != NULL)
2278                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2279         LDKChannelMonitor monitor_conv;
2280         monitor_conv.inner = (void*)(monitor & (~1));
2281         monitor_conv.is_owned = (monitor & 1) || (monitor == 0);
2282         // Warning: we may need a move here but can't clone!
2283         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2284         *ret_conv = (this_arg_conv->watch_channel)(this_arg_conv->this_arg, funding_txo_conv, monitor_conv);
2285         return (long)ret_conv;
2286 }
2287
2288 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Watch_1update_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong funding_txo, jlong update) {
2289         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2290         LDKOutPoint funding_txo_conv;
2291         funding_txo_conv.inner = (void*)(funding_txo & (~1));
2292         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
2293         if (funding_txo_conv.inner != NULL)
2294                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
2295         LDKChannelMonitorUpdate update_conv;
2296         update_conv.inner = (void*)(update & (~1));
2297         update_conv.is_owned = (update & 1) || (update == 0);
2298         if (update_conv.inner != NULL)
2299                 update_conv = ChannelMonitorUpdate_clone(&update_conv);
2300         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
2301         *ret_conv = (this_arg_conv->update_channel)(this_arg_conv->this_arg, funding_txo_conv, update_conv);
2302         return (long)ret_conv;
2303 }
2304
2305 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_Watch_1release_1pending_1monitor_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
2306         LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
2307         LDKCVec_MonitorEventZ ret_var = (this_arg_conv->release_pending_monitor_events)(this_arg_conv->this_arg);
2308         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
2309         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
2310         for (size_t o = 0; o < ret_var.datalen; o++) {
2311                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
2312                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2313                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2314                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
2315                 if (arr_conv_14_var.is_owned) {
2316                         arr_conv_14_ref |= 1;
2317                 }
2318                 ret_arr_ptr[o] = arr_conv_14_ref;
2319         }
2320         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
2321         FREE(ret_var.data);
2322         return ret_arr;
2323 }
2324
2325 typedef struct LDKFilter_JCalls {
2326         atomic_size_t refcnt;
2327         JavaVM *vm;
2328         jweak o;
2329         jmethodID register_tx_meth;
2330         jmethodID register_output_meth;
2331 } LDKFilter_JCalls;
2332 void register_tx_jcall(const void* this_arg, const uint8_t (*txid)[32], LDKu8slice script_pubkey) {
2333         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
2334         JNIEnv *_env;
2335         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2336         jbyteArray txid_arr = (*_env)->NewByteArray(_env, 32);
2337         (*_env)->SetByteArrayRegion(_env, txid_arr, 0, 32, *txid);
2338         LDKu8slice script_pubkey_var = script_pubkey;
2339         jbyteArray script_pubkey_arr = (*_env)->NewByteArray(_env, script_pubkey_var.datalen);
2340         (*_env)->SetByteArrayRegion(_env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
2341         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2342         CHECK(obj != NULL);
2343         return (*_env)->CallVoidMethod(_env, obj, j_calls->register_tx_meth, txid_arr, script_pubkey_arr);
2344 }
2345 void register_output_jcall(const void* this_arg, const LDKOutPoint *outpoint, LDKu8slice script_pubkey) {
2346         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
2347         JNIEnv *_env;
2348         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2349         long ret_outpoint = (long)outpoint;
2350         LDKu8slice script_pubkey_var = script_pubkey;
2351         jbyteArray script_pubkey_arr = (*_env)->NewByteArray(_env, script_pubkey_var.datalen);
2352         (*_env)->SetByteArrayRegion(_env, script_pubkey_arr, 0, script_pubkey_var.datalen, script_pubkey_var.data);
2353         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2354         CHECK(obj != NULL);
2355         return (*_env)->CallVoidMethod(_env, obj, j_calls->register_output_meth, ret_outpoint, script_pubkey_arr);
2356 }
2357 static void LDKFilter_JCalls_free(void* this_arg) {
2358         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
2359         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2360                 JNIEnv *env;
2361                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2362                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2363                 FREE(j_calls);
2364         }
2365 }
2366 static void* LDKFilter_JCalls_clone(const void* this_arg) {
2367         LDKFilter_JCalls *j_calls = (LDKFilter_JCalls*) this_arg;
2368         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2369         return (void*) this_arg;
2370 }
2371 static inline LDKFilter LDKFilter_init (JNIEnv * env, jclass _a, jobject o) {
2372         jclass c = (*env)->GetObjectClass(env, o);
2373         CHECK(c != NULL);
2374         LDKFilter_JCalls *calls = MALLOC(sizeof(LDKFilter_JCalls), "LDKFilter_JCalls");
2375         atomic_init(&calls->refcnt, 1);
2376         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2377         calls->o = (*env)->NewWeakGlobalRef(env, o);
2378         calls->register_tx_meth = (*env)->GetMethodID(env, c, "register_tx", "([B[B)V");
2379         CHECK(calls->register_tx_meth != NULL);
2380         calls->register_output_meth = (*env)->GetMethodID(env, c, "register_output", "(J[B)V");
2381         CHECK(calls->register_output_meth != NULL);
2382
2383         LDKFilter ret = {
2384                 .this_arg = (void*) calls,
2385                 .register_tx = register_tx_jcall,
2386                 .register_output = register_output_jcall,
2387                 .free = LDKFilter_JCalls_free,
2388         };
2389         return ret;
2390 }
2391 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFilter_1new (JNIEnv * env, jclass _a, jobject o) {
2392         LDKFilter *res_ptr = MALLOC(sizeof(LDKFilter), "LDKFilter");
2393         *res_ptr = LDKFilter_init(env, _a, o);
2394         return (long)res_ptr;
2395 }
2396 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFilter_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2397         jobject ret = (*env)->NewLocalRef(env, ((LDKFilter_JCalls*)val)->o);
2398         CHECK(ret != NULL);
2399         return ret;
2400 }
2401 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1tx(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray txid, jbyteArray script_pubkey) {
2402         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
2403         unsigned char txid_arr[32];
2404         CHECK((*_env)->GetArrayLength (_env, txid) == 32);
2405         (*_env)->GetByteArrayRegion (_env, txid, 0, 32, txid_arr);
2406         unsigned char (*txid_ref)[32] = &txid_arr;
2407         LDKu8slice script_pubkey_ref;
2408         script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL);
2409         script_pubkey_ref.datalen = (*_env)->GetArrayLength (_env, script_pubkey);
2410         (this_arg_conv->register_tx)(this_arg_conv->this_arg, txid_ref, script_pubkey_ref);
2411         (*_env)->ReleaseByteArrayElements(_env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
2412 }
2413
2414 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1output(JNIEnv * _env, jclass _b, jlong this_arg, jlong outpoint, jbyteArray script_pubkey) {
2415         LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
2416         LDKOutPoint outpoint_conv;
2417         outpoint_conv.inner = (void*)(outpoint & (~1));
2418         outpoint_conv.is_owned = (outpoint & 1) || (outpoint == 0);
2419         LDKu8slice script_pubkey_ref;
2420         script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL);
2421         script_pubkey_ref.datalen = (*_env)->GetArrayLength (_env, script_pubkey);
2422         (this_arg_conv->register_output)(this_arg_conv->this_arg, &outpoint_conv, script_pubkey_ref);
2423         (*_env)->ReleaseByteArrayElements(_env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0);
2424 }
2425
2426 typedef struct LDKBroadcasterInterface_JCalls {
2427         atomic_size_t refcnt;
2428         JavaVM *vm;
2429         jweak o;
2430         jmethodID broadcast_transaction_meth;
2431 } LDKBroadcasterInterface_JCalls;
2432 void broadcast_transaction_jcall(const void* this_arg, LDKTransaction tx) {
2433         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2434         JNIEnv *_env;
2435         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2436         LDKTransaction *tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
2437         *tx_copy = tx;
2438         long tx_ref = (long)tx_copy;
2439         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2440         CHECK(obj != NULL);
2441         return (*_env)->CallVoidMethod(_env, obj, j_calls->broadcast_transaction_meth, tx_ref);
2442 }
2443 static void LDKBroadcasterInterface_JCalls_free(void* this_arg) {
2444         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2445         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2446                 JNIEnv *env;
2447                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2448                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2449                 FREE(j_calls);
2450         }
2451 }
2452 static void* LDKBroadcasterInterface_JCalls_clone(const void* this_arg) {
2453         LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
2454         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2455         return (void*) this_arg;
2456 }
2457 static inline LDKBroadcasterInterface LDKBroadcasterInterface_init (JNIEnv * env, jclass _a, jobject o) {
2458         jclass c = (*env)->GetObjectClass(env, o);
2459         CHECK(c != NULL);
2460         LDKBroadcasterInterface_JCalls *calls = MALLOC(sizeof(LDKBroadcasterInterface_JCalls), "LDKBroadcasterInterface_JCalls");
2461         atomic_init(&calls->refcnt, 1);
2462         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2463         calls->o = (*env)->NewWeakGlobalRef(env, o);
2464         calls->broadcast_transaction_meth = (*env)->GetMethodID(env, c, "broadcast_transaction", "(J)V");
2465         CHECK(calls->broadcast_transaction_meth != NULL);
2466
2467         LDKBroadcasterInterface ret = {
2468                 .this_arg = (void*) calls,
2469                 .broadcast_transaction = broadcast_transaction_jcall,
2470                 .free = LDKBroadcasterInterface_JCalls_free,
2471         };
2472         return ret;
2473 }
2474 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1new (JNIEnv * env, jclass _a, jobject o) {
2475         LDKBroadcasterInterface *res_ptr = MALLOC(sizeof(LDKBroadcasterInterface), "LDKBroadcasterInterface");
2476         *res_ptr = LDKBroadcasterInterface_init(env, _a, o);
2477         return (long)res_ptr;
2478 }
2479 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2480         jobject ret = (*env)->NewLocalRef(env, ((LDKBroadcasterInterface_JCalls*)val)->o);
2481         CHECK(ret != NULL);
2482         return ret;
2483 }
2484 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1broadcast_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong tx) {
2485         LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg;
2486         LDKTransaction tx_conv = *(LDKTransaction*)tx;
2487         (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_conv);
2488 }
2489
2490 typedef struct LDKFeeEstimator_JCalls {
2491         atomic_size_t refcnt;
2492         JavaVM *vm;
2493         jweak o;
2494         jmethodID get_est_sat_per_1000_weight_meth;
2495 } LDKFeeEstimator_JCalls;
2496 uint32_t get_est_sat_per_1000_weight_jcall(const void* this_arg, LDKConfirmationTarget confirmation_target) {
2497         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2498         JNIEnv *_env;
2499         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2500         jclass confirmation_target_conv = LDKConfirmationTarget_to_java(_env, confirmation_target);
2501         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2502         CHECK(obj != NULL);
2503         return (*_env)->CallIntMethod(_env, obj, j_calls->get_est_sat_per_1000_weight_meth, confirmation_target_conv);
2504 }
2505 static void LDKFeeEstimator_JCalls_free(void* this_arg) {
2506         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2507         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2508                 JNIEnv *env;
2509                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2510                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2511                 FREE(j_calls);
2512         }
2513 }
2514 static void* LDKFeeEstimator_JCalls_clone(const void* this_arg) {
2515         LDKFeeEstimator_JCalls *j_calls = (LDKFeeEstimator_JCalls*) this_arg;
2516         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2517         return (void*) this_arg;
2518 }
2519 static inline LDKFeeEstimator LDKFeeEstimator_init (JNIEnv * env, jclass _a, jobject o) {
2520         jclass c = (*env)->GetObjectClass(env, o);
2521         CHECK(c != NULL);
2522         LDKFeeEstimator_JCalls *calls = MALLOC(sizeof(LDKFeeEstimator_JCalls), "LDKFeeEstimator_JCalls");
2523         atomic_init(&calls->refcnt, 1);
2524         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2525         calls->o = (*env)->NewWeakGlobalRef(env, o);
2526         calls->get_est_sat_per_1000_weight_meth = (*env)->GetMethodID(env, c, "get_est_sat_per_1000_weight", "(Lorg/ldk/enums/LDKConfirmationTarget;)I");
2527         CHECK(calls->get_est_sat_per_1000_weight_meth != NULL);
2528
2529         LDKFeeEstimator ret = {
2530                 .this_arg = (void*) calls,
2531                 .get_est_sat_per_1000_weight = get_est_sat_per_1000_weight_jcall,
2532                 .free = LDKFeeEstimator_JCalls_free,
2533         };
2534         return ret;
2535 }
2536 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1new (JNIEnv * env, jclass _a, jobject o) {
2537         LDKFeeEstimator *res_ptr = MALLOC(sizeof(LDKFeeEstimator), "LDKFeeEstimator");
2538         *res_ptr = LDKFeeEstimator_init(env, _a, o);
2539         return (long)res_ptr;
2540 }
2541 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2542         jobject ret = (*env)->NewLocalRef(env, ((LDKFeeEstimator_JCalls*)val)->o);
2543         CHECK(ret != NULL);
2544         return ret;
2545 }
2546 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) {
2547         LDKFeeEstimator* this_arg_conv = (LDKFeeEstimator*)this_arg;
2548         LDKConfirmationTarget confirmation_target_conv = LDKConfirmationTarget_from_java(_env, confirmation_target);
2549         jint ret_val = (this_arg_conv->get_est_sat_per_1000_weight)(this_arg_conv->this_arg, confirmation_target_conv);
2550         return ret_val;
2551 }
2552
2553 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1usize_1_1Transaction_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2554         LDKCVecTempl_C2TupleTempl_usize__Transaction *vec = (LDKCVecTempl_C2TupleTempl_usize__Transaction*)ptr;
2555         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2TupleTempl_usize__Transaction));
2556 }
2557 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1usize_1_1Transaction_1new(JNIEnv *env, jclass _b, jlongArray elems){
2558         LDKCVecTempl_C2TupleTempl_usize__Transaction *ret = MALLOC(sizeof(LDKCVecTempl_C2TupleTempl_usize__Transaction), "LDKCVecTempl_C2TupleTempl_usize__Transaction");
2559         ret->datalen = (*env)->GetArrayLength(env, elems);
2560         if (ret->datalen == 0) {
2561                 ret->data = NULL;
2562         } else {
2563                 ret->data = MALLOC(sizeof(LDKC2TupleTempl_usize__Transaction) * ret->datalen, "LDKCVecTempl_C2TupleTempl_usize__Transaction Data");
2564                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2565                 for (size_t i = 0; i < ret->datalen; i++) {
2566                         jlong arr_elem = java_elems[i];
2567                         LDKC2TupleTempl_usize__Transaction arr_elem_conv = *(LDKC2TupleTempl_usize__Transaction*)arr_elem;
2568                         FREE((void*)arr_elem);
2569                         ret->data[i] = arr_elem_conv;
2570                 }
2571                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2572         }
2573         return (long)ret;
2574 }
2575 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Transaction_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2576         LDKCVecTempl_Transaction *vec = (LDKCVecTempl_Transaction*)ptr;
2577         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKTransaction));
2578 }
2579 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Transaction_1new(JNIEnv *env, jclass _b, jlongArray elems){
2580         LDKCVecTempl_Transaction *ret = MALLOC(sizeof(LDKCVecTempl_Transaction), "LDKCVecTempl_Transaction");
2581         ret->datalen = (*env)->GetArrayLength(env, elems);
2582         if (ret->datalen == 0) {
2583                 ret->data = NULL;
2584         } else {
2585                 ret->data = MALLOC(sizeof(LDKTransaction) * ret->datalen, "LDKCVecTempl_Transaction Data");
2586                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2587                 for (size_t i = 0; i < ret->datalen; i++) {
2588                         jlong arr_elem = java_elems[i];
2589                         LDKTransaction arr_elem_conv = *(LDKTransaction*)arr_elem;
2590                         ret->data[i] = arr_elem_conv;
2591                 }
2592                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2593         }
2594         return (long)ret;
2595 }
2596 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1ThirtyTwoBytes_1_1CVecTempl_1TxOut_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2597         LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut *vec = (LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut*)ptr;
2598         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut));
2599 }
2600 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1ThirtyTwoBytes_1_1CVecTempl_1TxOut_1new(JNIEnv *env, jclass _b, jlongArray elems){
2601         LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut *ret = MALLOC(sizeof(LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut), "LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut");
2602         ret->datalen = (*env)->GetArrayLength(env, elems);
2603         if (ret->datalen == 0) {
2604                 ret->data = NULL;
2605         } else {
2606                 ret->data = MALLOC(sizeof(LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut) * ret->datalen, "LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut Data");
2607                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2608                 for (size_t i = 0; i < ret->datalen; i++) {
2609                         jlong arr_elem = java_elems[i];
2610                         LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut arr_elem_conv = *(LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut*)arr_elem;
2611                         FREE((void*)arr_elem);
2612                         ret->data[i] = arr_elem_conv;
2613                 }
2614                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2615         }
2616         return (long)ret;
2617 }
2618 typedef struct LDKKeysInterface_JCalls {
2619         atomic_size_t refcnt;
2620         JavaVM *vm;
2621         jweak o;
2622         jmethodID get_node_secret_meth;
2623         jmethodID get_destination_script_meth;
2624         jmethodID get_shutdown_pubkey_meth;
2625         jmethodID get_channel_keys_meth;
2626         jmethodID get_secure_random_bytes_meth;
2627 } LDKKeysInterface_JCalls;
2628 LDKSecretKey get_node_secret_jcall(const void* this_arg) {
2629         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2630         JNIEnv *_env;
2631         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2632         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2633         CHECK(obj != NULL);
2634         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_node_secret_meth);
2635         LDKSecretKey arg_ref;
2636         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
2637         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.bytes);
2638         return arg_ref;
2639 }
2640 LDKCVec_u8Z get_destination_script_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_destination_script_meth);
2647         LDKCVec_u8Z arg_ref;
2648         arg_ref.data = (*_env)->GetByteArrayElements (_env, arg, NULL);
2649         arg_ref.datalen = (*_env)->GetArrayLength (_env, arg);
2650         return arg_ref;
2651 }
2652 LDKPublicKey get_shutdown_pubkey_jcall(const void* this_arg) {
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         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_shutdown_pubkey_meth);
2659         LDKPublicKey arg_ref;
2660         CHECK((*_env)->GetArrayLength (_env, arg) == 33);
2661         (*_env)->GetByteArrayRegion (_env, arg, 0, 33, arg_ref.compressed_form);
2662         return arg_ref;
2663 }
2664 LDKChannelKeys get_channel_keys_jcall(const void* this_arg, bool inbound, uint64_t channel_value_satoshis) {
2665         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2666         JNIEnv *_env;
2667         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2668         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2669         CHECK(obj != NULL);
2670         LDKChannelKeys* ret = (LDKChannelKeys*)(*_env)->CallLongMethod(_env, obj, j_calls->get_channel_keys_meth, inbound, channel_value_satoshis);
2671         LDKChannelKeys ret_conv = *(LDKChannelKeys*)ret;
2672         if (ret_conv.free == LDKChannelKeys_JCalls_free) {
2673                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
2674                 LDKChannelKeys_JCalls_clone(ret_conv.this_arg);
2675         }
2676         return ret_conv;
2677 }
2678 LDKThirtyTwoBytes get_secure_random_bytes_jcall(const void* this_arg) {
2679         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2680         JNIEnv *_env;
2681         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2682         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2683         CHECK(obj != NULL);
2684         jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_secure_random_bytes_meth);
2685         LDKThirtyTwoBytes arg_ref;
2686         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
2687         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.data);
2688         return arg_ref;
2689 }
2690 static void LDKKeysInterface_JCalls_free(void* this_arg) {
2691         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2692         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
2693                 JNIEnv *env;
2694                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
2695                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
2696                 FREE(j_calls);
2697         }
2698 }
2699 static void* LDKKeysInterface_JCalls_clone(const void* this_arg) {
2700         LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
2701         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
2702         return (void*) this_arg;
2703 }
2704 static inline LDKKeysInterface LDKKeysInterface_init (JNIEnv * env, jclass _a, jobject o) {
2705         jclass c = (*env)->GetObjectClass(env, o);
2706         CHECK(c != NULL);
2707         LDKKeysInterface_JCalls *calls = MALLOC(sizeof(LDKKeysInterface_JCalls), "LDKKeysInterface_JCalls");
2708         atomic_init(&calls->refcnt, 1);
2709         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
2710         calls->o = (*env)->NewWeakGlobalRef(env, o);
2711         calls->get_node_secret_meth = (*env)->GetMethodID(env, c, "get_node_secret", "()[B");
2712         CHECK(calls->get_node_secret_meth != NULL);
2713         calls->get_destination_script_meth = (*env)->GetMethodID(env, c, "get_destination_script", "()[B");
2714         CHECK(calls->get_destination_script_meth != NULL);
2715         calls->get_shutdown_pubkey_meth = (*env)->GetMethodID(env, c, "get_shutdown_pubkey", "()[B");
2716         CHECK(calls->get_shutdown_pubkey_meth != NULL);
2717         calls->get_channel_keys_meth = (*env)->GetMethodID(env, c, "get_channel_keys", "(ZJ)J");
2718         CHECK(calls->get_channel_keys_meth != NULL);
2719         calls->get_secure_random_bytes_meth = (*env)->GetMethodID(env, c, "get_secure_random_bytes", "()[B");
2720         CHECK(calls->get_secure_random_bytes_meth != NULL);
2721
2722         LDKKeysInterface ret = {
2723                 .this_arg = (void*) calls,
2724                 .get_node_secret = get_node_secret_jcall,
2725                 .get_destination_script = get_destination_script_jcall,
2726                 .get_shutdown_pubkey = get_shutdown_pubkey_jcall,
2727                 .get_channel_keys = get_channel_keys_jcall,
2728                 .get_secure_random_bytes = get_secure_random_bytes_jcall,
2729                 .free = LDKKeysInterface_JCalls_free,
2730         };
2731         return ret;
2732 }
2733 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1new (JNIEnv * env, jclass _a, jobject o) {
2734         LDKKeysInterface *res_ptr = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
2735         *res_ptr = LDKKeysInterface_init(env, _a, o);
2736         return (long)res_ptr;
2737 }
2738 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
2739         jobject ret = (*env)->NewLocalRef(env, ((LDKKeysInterface_JCalls*)val)->o);
2740         CHECK(ret != NULL);
2741         return ret;
2742 }
2743 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1node_1secret(JNIEnv * _env, jclass _b, jlong this_arg) {
2744         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2745         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
2746         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->get_node_secret)(this_arg_conv->this_arg).bytes);
2747         return arg_arr;
2748 }
2749
2750 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1destination_1script(JNIEnv * _env, jclass _b, jlong this_arg) {
2751         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2752         LDKCVec_u8Z arg_var = (this_arg_conv->get_destination_script)(this_arg_conv->this_arg);
2753         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
2754         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
2755         CVec_u8Z_free(arg_var);
2756         return arg_arr;
2757 }
2758
2759 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_arg) {
2760         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2761         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
2762         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (this_arg_conv->get_shutdown_pubkey)(this_arg_conv->this_arg).compressed_form);
2763         return arg_arr;
2764 }
2765
2766 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) {
2767         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2768         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
2769         *ret = (this_arg_conv->get_channel_keys)(this_arg_conv->this_arg, inbound, channel_value_satoshis);
2770         return (long)ret;
2771 }
2772
2773 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1get_1secure_1random_1bytes(JNIEnv * _env, jclass _b, jlong this_arg) {
2774         LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
2775         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
2776         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->get_secure_random_bytes)(this_arg_conv->this_arg).data);
2777         return arg_arr;
2778 }
2779
2780 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1ChannelDetails_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2781         LDKCVecTempl_ChannelDetails *vec = (LDKCVecTempl_ChannelDetails*)ptr;
2782         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
2783         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
2784         for (size_t i = 0; i < vec->datalen; i++) {
2785                 CHECK((((long)vec->data[i].inner) & 1) == 0);
2786                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
2787         }
2788         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
2789         return ret;
2790 }
2791 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1ChannelDetails_1new(JNIEnv *env, jclass _b, jlongArray elems){
2792         LDKCVecTempl_ChannelDetails *ret = MALLOC(sizeof(LDKCVecTempl_ChannelDetails), "LDKCVecTempl_ChannelDetails");
2793         ret->datalen = (*env)->GetArrayLength(env, elems);
2794         if (ret->datalen == 0) {
2795                 ret->data = NULL;
2796         } else {
2797                 ret->data = MALLOC(sizeof(LDKChannelDetails) * ret->datalen, "LDKCVecTempl_ChannelDetails Data");
2798                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2799                 for (size_t i = 0; i < ret->datalen; i++) {
2800                         jlong arr_elem = java_elems[i];
2801                         LDKChannelDetails arr_elem_conv;
2802                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
2803                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
2804                         if (arr_elem_conv.inner != NULL)
2805                                 arr_elem_conv = ChannelDetails_clone(&arr_elem_conv);
2806                         ret->data[i] = arr_elem_conv;
2807                 }
2808                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2809         }
2810         return (long)ret;
2811 }
2812 static jclass LDKNetAddress_IPv4_class = NULL;
2813 static jmethodID LDKNetAddress_IPv4_meth = NULL;
2814 static jclass LDKNetAddress_IPv6_class = NULL;
2815 static jmethodID LDKNetAddress_IPv6_meth = NULL;
2816 static jclass LDKNetAddress_OnionV2_class = NULL;
2817 static jmethodID LDKNetAddress_OnionV2_meth = NULL;
2818 static jclass LDKNetAddress_OnionV3_class = NULL;
2819 static jmethodID LDKNetAddress_OnionV3_meth = NULL;
2820 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_00024LDKNetAddress_init (JNIEnv * env, jclass _a) {
2821         LDKNetAddress_IPv4_class =
2822                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv4;"));
2823         CHECK(LDKNetAddress_IPv4_class != NULL);
2824         LDKNetAddress_IPv4_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv4_class, "<init>", "([BS)V");
2825         CHECK(LDKNetAddress_IPv4_meth != NULL);
2826         LDKNetAddress_IPv6_class =
2827                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$IPv6;"));
2828         CHECK(LDKNetAddress_IPv6_class != NULL);
2829         LDKNetAddress_IPv6_meth = (*env)->GetMethodID(env, LDKNetAddress_IPv6_class, "<init>", "([BS)V");
2830         CHECK(LDKNetAddress_IPv6_meth != NULL);
2831         LDKNetAddress_OnionV2_class =
2832                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV2;"));
2833         CHECK(LDKNetAddress_OnionV2_class != NULL);
2834         LDKNetAddress_OnionV2_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV2_class, "<init>", "([BS)V");
2835         CHECK(LDKNetAddress_OnionV2_meth != NULL);
2836         LDKNetAddress_OnionV3_class =
2837                 (*env)->NewGlobalRef(env, (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetAddress$OnionV3;"));
2838         CHECK(LDKNetAddress_OnionV3_class != NULL);
2839         LDKNetAddress_OnionV3_meth = (*env)->GetMethodID(env, LDKNetAddress_OnionV3_class, "<init>", "([BSBS)V");
2840         CHECK(LDKNetAddress_OnionV3_meth != NULL);
2841 }
2842 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKNetAddress_1ref_1from_1ptr (JNIEnv * _env, jclass _c, jlong ptr) {
2843         LDKNetAddress *obj = (LDKNetAddress*)ptr;
2844         switch(obj->tag) {
2845                 case LDKNetAddress_IPv4: {
2846                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 4);
2847                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 4, obj->i_pv4.addr.data);
2848                         return (*_env)->NewObject(_env, LDKNetAddress_IPv4_class, LDKNetAddress_IPv4_meth, addr_arr, obj->i_pv4.port);
2849                 }
2850                 case LDKNetAddress_IPv6: {
2851                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 16);
2852                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 16, obj->i_pv6.addr.data);
2853                         return (*_env)->NewObject(_env, LDKNetAddress_IPv6_class, LDKNetAddress_IPv6_meth, addr_arr, obj->i_pv6.port);
2854                 }
2855                 case LDKNetAddress_OnionV2: {
2856                         jbyteArray addr_arr = (*_env)->NewByteArray(_env, 10);
2857                         (*_env)->SetByteArrayRegion(_env, addr_arr, 0, 10, obj->onion_v2.addr.data);
2858                         return (*_env)->NewObject(_env, LDKNetAddress_OnionV2_class, LDKNetAddress_OnionV2_meth, addr_arr, obj->onion_v2.port);
2859                 }
2860                 case LDKNetAddress_OnionV3: {
2861                         jbyteArray ed25519_pubkey_arr = (*_env)->NewByteArray(_env, 32);
2862                         (*_env)->SetByteArrayRegion(_env, ed25519_pubkey_arr, 0, 32, obj->onion_v3.ed25519_pubkey.data);
2863                         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);
2864                 }
2865                 default: abort();
2866         }
2867 }
2868 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1NetAddress_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
2869         LDKCVecTempl_NetAddress *vec = (LDKCVecTempl_NetAddress*)ptr;
2870         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKNetAddress));
2871 }
2872 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1NetAddress_1new(JNIEnv *env, jclass _b, jlongArray elems){
2873         LDKCVecTempl_NetAddress *ret = MALLOC(sizeof(LDKCVecTempl_NetAddress), "LDKCVecTempl_NetAddress");
2874         ret->datalen = (*env)->GetArrayLength(env, elems);
2875         if (ret->datalen == 0) {
2876                 ret->data = NULL;
2877         } else {
2878                 ret->data = MALLOC(sizeof(LDKNetAddress) * ret->datalen, "LDKCVecTempl_NetAddress Data");
2879                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
2880                 for (size_t i = 0; i < ret->datalen; i++) {
2881                         jlong arr_elem = java_elems[i];
2882                         LDKNetAddress arr_elem_conv = *(LDKNetAddress*)arr_elem;
2883                         FREE((void*)arr_elem);
2884                         ret->data[i] = arr_elem_conv;
2885                 }
2886                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
2887         }
2888         return (long)ret;
2889 }
2890 typedef struct LDKChannelMessageHandler_JCalls {
2891         atomic_size_t refcnt;
2892         JavaVM *vm;
2893         jweak o;
2894         LDKMessageSendEventsProvider_JCalls* MessageSendEventsProvider;
2895         jmethodID handle_open_channel_meth;
2896         jmethodID handle_accept_channel_meth;
2897         jmethodID handle_funding_created_meth;
2898         jmethodID handle_funding_signed_meth;
2899         jmethodID handle_funding_locked_meth;
2900         jmethodID handle_shutdown_meth;
2901         jmethodID handle_closing_signed_meth;
2902         jmethodID handle_update_add_htlc_meth;
2903         jmethodID handle_update_fulfill_htlc_meth;
2904         jmethodID handle_update_fail_htlc_meth;
2905         jmethodID handle_update_fail_malformed_htlc_meth;
2906         jmethodID handle_commitment_signed_meth;
2907         jmethodID handle_revoke_and_ack_meth;
2908         jmethodID handle_update_fee_meth;
2909         jmethodID handle_announcement_signatures_meth;
2910         jmethodID peer_disconnected_meth;
2911         jmethodID peer_connected_meth;
2912         jmethodID handle_channel_reestablish_meth;
2913         jmethodID handle_error_meth;
2914 } LDKChannelMessageHandler_JCalls;
2915 void handle_open_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKOpenChannel *msg) {
2916         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
2917         JNIEnv *_env;
2918         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2919         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
2920         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
2921         LDKInitFeatures their_features_var = their_features;
2922         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2923         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2924         long their_features_ref = (long)their_features_var.inner;
2925         if (their_features_var.is_owned) {
2926                 their_features_ref |= 1;
2927         }
2928         long ret_msg = (long)msg;
2929         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2930         CHECK(obj != NULL);
2931         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_open_channel_meth, their_node_id_arr, their_features_ref, ret_msg);
2932 }
2933 void handle_accept_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, LDKInitFeatures their_features, const LDKAcceptChannel *msg) {
2934         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
2935         JNIEnv *_env;
2936         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2937         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
2938         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
2939         LDKInitFeatures their_features_var = their_features;
2940         CHECK((((long)their_features_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
2941         CHECK((((long)&their_features_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
2942         long their_features_ref = (long)their_features_var.inner;
2943         if (their_features_var.is_owned) {
2944                 their_features_ref |= 1;
2945         }
2946         long ret_msg = (long)msg;
2947         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2948         CHECK(obj != NULL);
2949         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_accept_channel_meth, their_node_id_arr, their_features_ref, ret_msg);
2950 }
2951 void handle_funding_created_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingCreated *msg) {
2952         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
2953         JNIEnv *_env;
2954         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2955         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
2956         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
2957         long ret_msg = (long)msg;
2958         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2959         CHECK(obj != NULL);
2960         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_created_meth, their_node_id_arr, ret_msg);
2961 }
2962 void handle_funding_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingSigned *msg) {
2963         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
2964         JNIEnv *_env;
2965         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2966         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
2967         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
2968         long ret_msg = (long)msg;
2969         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2970         CHECK(obj != NULL);
2971         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_signed_meth, their_node_id_arr, ret_msg);
2972 }
2973 void handle_funding_locked_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKFundingLocked *msg) {
2974         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
2975         JNIEnv *_env;
2976         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2977         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
2978         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
2979         long ret_msg = (long)msg;
2980         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2981         CHECK(obj != NULL);
2982         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_funding_locked_meth, their_node_id_arr, ret_msg);
2983 }
2984 void handle_shutdown_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKShutdown *msg) {
2985         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
2986         JNIEnv *_env;
2987         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2988         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
2989         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
2990         long ret_msg = (long)msg;
2991         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
2992         CHECK(obj != NULL);
2993         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_shutdown_meth, their_node_id_arr, ret_msg);
2994 }
2995 void handle_closing_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKClosingSigned *msg) {
2996         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
2997         JNIEnv *_env;
2998         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
2999         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3000         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3001         long ret_msg = (long)msg;
3002         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3003         CHECK(obj != NULL);
3004         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_closing_signed_meth, their_node_id_arr, ret_msg);
3005 }
3006 void handle_update_add_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateAddHTLC *msg) {
3007         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3008         JNIEnv *_env;
3009         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3010         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3011         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3012         long ret_msg = (long)msg;
3013         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3014         CHECK(obj != NULL);
3015         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_add_htlc_meth, their_node_id_arr, ret_msg);
3016 }
3017 void handle_update_fulfill_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFulfillHTLC *msg) {
3018         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3019         JNIEnv *_env;
3020         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3021         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3022         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3023         long ret_msg = (long)msg;
3024         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3025         CHECK(obj != NULL);
3026         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fulfill_htlc_meth, their_node_id_arr, ret_msg);
3027 }
3028 void handle_update_fail_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailHTLC *msg) {
3029         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3030         JNIEnv *_env;
3031         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3032         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3033         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3034         long ret_msg = (long)msg;
3035         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3036         CHECK(obj != NULL);
3037         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fail_htlc_meth, their_node_id_arr, ret_msg);
3038 }
3039 void handle_update_fail_malformed_htlc_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFailMalformedHTLC *msg) {
3040         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3041         JNIEnv *_env;
3042         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3043         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3044         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3045         long ret_msg = (long)msg;
3046         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3047         CHECK(obj != NULL);
3048         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fail_malformed_htlc_meth, their_node_id_arr, ret_msg);
3049 }
3050 void handle_commitment_signed_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKCommitmentSigned *msg) {
3051         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3052         JNIEnv *_env;
3053         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3054         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3055         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3056         long ret_msg = (long)msg;
3057         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3058         CHECK(obj != NULL);
3059         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_commitment_signed_meth, their_node_id_arr, ret_msg);
3060 }
3061 void handle_revoke_and_ack_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKRevokeAndACK *msg) {
3062         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3063         JNIEnv *_env;
3064         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3065         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3066         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3067         long ret_msg = (long)msg;
3068         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3069         CHECK(obj != NULL);
3070         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_revoke_and_ack_meth, their_node_id_arr, ret_msg);
3071 }
3072 void handle_update_fee_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKUpdateFee *msg) {
3073         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3074         JNIEnv *_env;
3075         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3076         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3077         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3078         long ret_msg = (long)msg;
3079         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3080         CHECK(obj != NULL);
3081         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_update_fee_meth, their_node_id_arr, ret_msg);
3082 }
3083 void handle_announcement_signatures_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKAnnouncementSignatures *msg) {
3084         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3085         JNIEnv *_env;
3086         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3087         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3088         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3089         long ret_msg = (long)msg;
3090         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3091         CHECK(obj != NULL);
3092         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_announcement_signatures_meth, their_node_id_arr, ret_msg);
3093 }
3094 void peer_disconnected_jcall(const void* this_arg, LDKPublicKey their_node_id, bool no_connection_possible) {
3095         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3096         JNIEnv *_env;
3097         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3098         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3099         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3100         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3101         CHECK(obj != NULL);
3102         return (*_env)->CallVoidMethod(_env, obj, j_calls->peer_disconnected_meth, their_node_id_arr, no_connection_possible);
3103 }
3104 void peer_connected_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKInit *msg) {
3105         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3106         JNIEnv *_env;
3107         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3108         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3109         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3110         long ret_msg = (long)msg;
3111         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3112         CHECK(obj != NULL);
3113         return (*_env)->CallVoidMethod(_env, obj, j_calls->peer_connected_meth, their_node_id_arr, ret_msg);
3114 }
3115 void handle_channel_reestablish_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKChannelReestablish *msg) {
3116         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3117         JNIEnv *_env;
3118         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3119         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3120         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3121         long ret_msg = (long)msg;
3122         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3123         CHECK(obj != NULL);
3124         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_channel_reestablish_meth, their_node_id_arr, ret_msg);
3125 }
3126 void handle_error_jcall(const void* this_arg, LDKPublicKey their_node_id, const LDKErrorMessage *msg) {
3127         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3128         JNIEnv *_env;
3129         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3130         jbyteArray their_node_id_arr = (*_env)->NewByteArray(_env, 33);
3131         (*_env)->SetByteArrayRegion(_env, their_node_id_arr, 0, 33, their_node_id.compressed_form);
3132         long ret_msg = (long)msg;
3133         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3134         CHECK(obj != NULL);
3135         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_error_meth, their_node_id_arr, ret_msg);
3136 }
3137 static void LDKChannelMessageHandler_JCalls_free(void* this_arg) {
3138         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3139         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3140                 JNIEnv *env;
3141                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3142                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
3143                 FREE(j_calls);
3144         }
3145 }
3146 static void* LDKChannelMessageHandler_JCalls_clone(const void* this_arg) {
3147         LDKChannelMessageHandler_JCalls *j_calls = (LDKChannelMessageHandler_JCalls*) this_arg;
3148         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3149         atomic_fetch_add_explicit(&j_calls->MessageSendEventsProvider->refcnt, 1, memory_order_release);
3150         return (void*) this_arg;
3151 }
3152 static inline LDKChannelMessageHandler LDKChannelMessageHandler_init (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
3153         jclass c = (*env)->GetObjectClass(env, o);
3154         CHECK(c != NULL);
3155         LDKChannelMessageHandler_JCalls *calls = MALLOC(sizeof(LDKChannelMessageHandler_JCalls), "LDKChannelMessageHandler_JCalls");
3156         atomic_init(&calls->refcnt, 1);
3157         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
3158         calls->o = (*env)->NewWeakGlobalRef(env, o);
3159         calls->handle_open_channel_meth = (*env)->GetMethodID(env, c, "handle_open_channel", "([BJJ)V");
3160         CHECK(calls->handle_open_channel_meth != NULL);
3161         calls->handle_accept_channel_meth = (*env)->GetMethodID(env, c, "handle_accept_channel", "([BJJ)V");
3162         CHECK(calls->handle_accept_channel_meth != NULL);
3163         calls->handle_funding_created_meth = (*env)->GetMethodID(env, c, "handle_funding_created", "([BJ)V");
3164         CHECK(calls->handle_funding_created_meth != NULL);
3165         calls->handle_funding_signed_meth = (*env)->GetMethodID(env, c, "handle_funding_signed", "([BJ)V");
3166         CHECK(calls->handle_funding_signed_meth != NULL);
3167         calls->handle_funding_locked_meth = (*env)->GetMethodID(env, c, "handle_funding_locked", "([BJ)V");
3168         CHECK(calls->handle_funding_locked_meth != NULL);
3169         calls->handle_shutdown_meth = (*env)->GetMethodID(env, c, "handle_shutdown", "([BJ)V");
3170         CHECK(calls->handle_shutdown_meth != NULL);
3171         calls->handle_closing_signed_meth = (*env)->GetMethodID(env, c, "handle_closing_signed", "([BJ)V");
3172         CHECK(calls->handle_closing_signed_meth != NULL);
3173         calls->handle_update_add_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_add_htlc", "([BJ)V");
3174         CHECK(calls->handle_update_add_htlc_meth != NULL);
3175         calls->handle_update_fulfill_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fulfill_htlc", "([BJ)V");
3176         CHECK(calls->handle_update_fulfill_htlc_meth != NULL);
3177         calls->handle_update_fail_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_htlc", "([BJ)V");
3178         CHECK(calls->handle_update_fail_htlc_meth != NULL);
3179         calls->handle_update_fail_malformed_htlc_meth = (*env)->GetMethodID(env, c, "handle_update_fail_malformed_htlc", "([BJ)V");
3180         CHECK(calls->handle_update_fail_malformed_htlc_meth != NULL);
3181         calls->handle_commitment_signed_meth = (*env)->GetMethodID(env, c, "handle_commitment_signed", "([BJ)V");
3182         CHECK(calls->handle_commitment_signed_meth != NULL);
3183         calls->handle_revoke_and_ack_meth = (*env)->GetMethodID(env, c, "handle_revoke_and_ack", "([BJ)V");
3184         CHECK(calls->handle_revoke_and_ack_meth != NULL);
3185         calls->handle_update_fee_meth = (*env)->GetMethodID(env, c, "handle_update_fee", "([BJ)V");
3186         CHECK(calls->handle_update_fee_meth != NULL);
3187         calls->handle_announcement_signatures_meth = (*env)->GetMethodID(env, c, "handle_announcement_signatures", "([BJ)V");
3188         CHECK(calls->handle_announcement_signatures_meth != NULL);
3189         calls->peer_disconnected_meth = (*env)->GetMethodID(env, c, "peer_disconnected", "([BZ)V");
3190         CHECK(calls->peer_disconnected_meth != NULL);
3191         calls->peer_connected_meth = (*env)->GetMethodID(env, c, "peer_connected", "([BJ)V");
3192         CHECK(calls->peer_connected_meth != NULL);
3193         calls->handle_channel_reestablish_meth = (*env)->GetMethodID(env, c, "handle_channel_reestablish", "([BJ)V");
3194         CHECK(calls->handle_channel_reestablish_meth != NULL);
3195         calls->handle_error_meth = (*env)->GetMethodID(env, c, "handle_error", "([BJ)V");
3196         CHECK(calls->handle_error_meth != NULL);
3197
3198         LDKChannelMessageHandler ret = {
3199                 .this_arg = (void*) calls,
3200                 .handle_open_channel = handle_open_channel_jcall,
3201                 .handle_accept_channel = handle_accept_channel_jcall,
3202                 .handle_funding_created = handle_funding_created_jcall,
3203                 .handle_funding_signed = handle_funding_signed_jcall,
3204                 .handle_funding_locked = handle_funding_locked_jcall,
3205                 .handle_shutdown = handle_shutdown_jcall,
3206                 .handle_closing_signed = handle_closing_signed_jcall,
3207                 .handle_update_add_htlc = handle_update_add_htlc_jcall,
3208                 .handle_update_fulfill_htlc = handle_update_fulfill_htlc_jcall,
3209                 .handle_update_fail_htlc = handle_update_fail_htlc_jcall,
3210                 .handle_update_fail_malformed_htlc = handle_update_fail_malformed_htlc_jcall,
3211                 .handle_commitment_signed = handle_commitment_signed_jcall,
3212                 .handle_revoke_and_ack = handle_revoke_and_ack_jcall,
3213                 .handle_update_fee = handle_update_fee_jcall,
3214                 .handle_announcement_signatures = handle_announcement_signatures_jcall,
3215                 .peer_disconnected = peer_disconnected_jcall,
3216                 .peer_connected = peer_connected_jcall,
3217                 .handle_channel_reestablish = handle_channel_reestablish_jcall,
3218                 .handle_error = handle_error_jcall,
3219                 .free = LDKChannelMessageHandler_JCalls_free,
3220                 .MessageSendEventsProvider = LDKMessageSendEventsProvider_init(env, _a, MessageSendEventsProvider),
3221         };
3222         calls->MessageSendEventsProvider = ret.MessageSendEventsProvider.this_arg;
3223         return ret;
3224 }
3225 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1new (JNIEnv * env, jclass _a, jobject o, jobject MessageSendEventsProvider) {
3226         LDKChannelMessageHandler *res_ptr = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
3227         *res_ptr = LDKChannelMessageHandler_init(env, _a, o, MessageSendEventsProvider);
3228         return (long)res_ptr;
3229 }
3230 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
3231         jobject ret = (*env)->NewLocalRef(env, ((LDKChannelMessageHandler_JCalls*)val)->o);
3232         CHECK(ret != NULL);
3233         return ret;
3234 }
3235 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) {
3236         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3237         LDKPublicKey their_node_id_ref;
3238         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3239         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3240         LDKInitFeatures their_features_conv;
3241         their_features_conv.inner = (void*)(their_features & (~1));
3242         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
3243         // Warning: we may need a move here but can't clone!
3244         LDKOpenChannel msg_conv;
3245         msg_conv.inner = (void*)(msg & (~1));
3246         msg_conv.is_owned = (msg & 1) || (msg == 0);
3247         (this_arg_conv->handle_open_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
3248 }
3249
3250 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) {
3251         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3252         LDKPublicKey their_node_id_ref;
3253         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3254         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3255         LDKInitFeatures their_features_conv;
3256         their_features_conv.inner = (void*)(their_features & (~1));
3257         their_features_conv.is_owned = (their_features & 1) || (their_features == 0);
3258         // Warning: we may need a move here but can't clone!
3259         LDKAcceptChannel msg_conv;
3260         msg_conv.inner = (void*)(msg & (~1));
3261         msg_conv.is_owned = (msg & 1) || (msg == 0);
3262         (this_arg_conv->handle_accept_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
3263 }
3264
3265 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) {
3266         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3267         LDKPublicKey their_node_id_ref;
3268         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3269         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3270         LDKFundingCreated msg_conv;
3271         msg_conv.inner = (void*)(msg & (~1));
3272         msg_conv.is_owned = (msg & 1) || (msg == 0);
3273         (this_arg_conv->handle_funding_created)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3274 }
3275
3276 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) {
3277         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3278         LDKPublicKey their_node_id_ref;
3279         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3280         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3281         LDKFundingSigned msg_conv;
3282         msg_conv.inner = (void*)(msg & (~1));
3283         msg_conv.is_owned = (msg & 1) || (msg == 0);
3284         (this_arg_conv->handle_funding_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3285 }
3286
3287 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) {
3288         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3289         LDKPublicKey their_node_id_ref;
3290         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3291         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3292         LDKFundingLocked msg_conv;
3293         msg_conv.inner = (void*)(msg & (~1));
3294         msg_conv.is_owned = (msg & 1) || (msg == 0);
3295         (this_arg_conv->handle_funding_locked)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3296 }
3297
3298 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1shutdown(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
3299         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3300         LDKPublicKey their_node_id_ref;
3301         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3302         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3303         LDKShutdown msg_conv;
3304         msg_conv.inner = (void*)(msg & (~1));
3305         msg_conv.is_owned = (msg & 1) || (msg == 0);
3306         (this_arg_conv->handle_shutdown)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3307 }
3308
3309 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) {
3310         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3311         LDKPublicKey their_node_id_ref;
3312         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3313         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3314         LDKClosingSigned msg_conv;
3315         msg_conv.inner = (void*)(msg & (~1));
3316         msg_conv.is_owned = (msg & 1) || (msg == 0);
3317         (this_arg_conv->handle_closing_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3318 }
3319
3320 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) {
3321         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3322         LDKPublicKey their_node_id_ref;
3323         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3324         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3325         LDKUpdateAddHTLC msg_conv;
3326         msg_conv.inner = (void*)(msg & (~1));
3327         msg_conv.is_owned = (msg & 1) || (msg == 0);
3328         (this_arg_conv->handle_update_add_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3329 }
3330
3331 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) {
3332         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3333         LDKPublicKey their_node_id_ref;
3334         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3335         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3336         LDKUpdateFulfillHTLC msg_conv;
3337         msg_conv.inner = (void*)(msg & (~1));
3338         msg_conv.is_owned = (msg & 1) || (msg == 0);
3339         (this_arg_conv->handle_update_fulfill_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3340 }
3341
3342 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) {
3343         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3344         LDKPublicKey their_node_id_ref;
3345         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3346         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3347         LDKUpdateFailHTLC msg_conv;
3348         msg_conv.inner = (void*)(msg & (~1));
3349         msg_conv.is_owned = (msg & 1) || (msg == 0);
3350         (this_arg_conv->handle_update_fail_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3351 }
3352
3353 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) {
3354         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3355         LDKPublicKey their_node_id_ref;
3356         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3357         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3358         LDKUpdateFailMalformedHTLC msg_conv;
3359         msg_conv.inner = (void*)(msg & (~1));
3360         msg_conv.is_owned = (msg & 1) || (msg == 0);
3361         (this_arg_conv->handle_update_fail_malformed_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3362 }
3363
3364 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) {
3365         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3366         LDKPublicKey their_node_id_ref;
3367         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3368         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3369         LDKCommitmentSigned msg_conv;
3370         msg_conv.inner = (void*)(msg & (~1));
3371         msg_conv.is_owned = (msg & 1) || (msg == 0);
3372         (this_arg_conv->handle_commitment_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3373 }
3374
3375 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) {
3376         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3377         LDKPublicKey their_node_id_ref;
3378         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3379         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3380         LDKRevokeAndACK msg_conv;
3381         msg_conv.inner = (void*)(msg & (~1));
3382         msg_conv.is_owned = (msg & 1) || (msg == 0);
3383         (this_arg_conv->handle_revoke_and_ack)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3384 }
3385
3386 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) {
3387         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3388         LDKPublicKey their_node_id_ref;
3389         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3390         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3391         LDKUpdateFee msg_conv;
3392         msg_conv.inner = (void*)(msg & (~1));
3393         msg_conv.is_owned = (msg & 1) || (msg == 0);
3394         (this_arg_conv->handle_update_fee)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3395 }
3396
3397 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) {
3398         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3399         LDKPublicKey their_node_id_ref;
3400         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3401         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3402         LDKAnnouncementSignatures msg_conv;
3403         msg_conv.inner = (void*)(msg & (~1));
3404         msg_conv.is_owned = (msg & 1) || (msg == 0);
3405         (this_arg_conv->handle_announcement_signatures)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3406 }
3407
3408 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) {
3409         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3410         LDKPublicKey their_node_id_ref;
3411         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3412         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3413         (this_arg_conv->peer_disconnected)(this_arg_conv->this_arg, their_node_id_ref, no_connection_possible);
3414 }
3415
3416 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1peer_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
3417         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3418         LDKPublicKey their_node_id_ref;
3419         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3420         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3421         LDKInit msg_conv;
3422         msg_conv.inner = (void*)(msg & (~1));
3423         msg_conv.is_owned = (msg & 1) || (msg == 0);
3424         (this_arg_conv->peer_connected)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3425 }
3426
3427 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) {
3428         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3429         LDKPublicKey their_node_id_ref;
3430         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3431         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3432         LDKChannelReestablish msg_conv;
3433         msg_conv.inner = (void*)(msg & (~1));
3434         msg_conv.is_owned = (msg & 1) || (msg == 0);
3435         (this_arg_conv->handle_channel_reestablish)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3436 }
3437
3438 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1handle_1error(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
3439         LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
3440         LDKPublicKey their_node_id_ref;
3441         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
3442         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
3443         LDKErrorMessage msg_conv;
3444         msg_conv.inner = (void*)(msg & (~1));
3445         msg_conv.is_owned = (msg & 1) || (msg == 0);
3446         (this_arg_conv->handle_error)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
3447 }
3448
3449 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1ChannelMonitor_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3450         LDKCVecTempl_ChannelMonitor *vec = (LDKCVecTempl_ChannelMonitor*)ptr;
3451         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3452         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3453         for (size_t i = 0; i < vec->datalen; i++) {
3454                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3455                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3456         }
3457         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3458         return ret;
3459 }
3460 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1ChannelMonitor_1new(JNIEnv *env, jclass _b, jlongArray elems){
3461         LDKCVecTempl_ChannelMonitor *ret = MALLOC(sizeof(LDKCVecTempl_ChannelMonitor), "LDKCVecTempl_ChannelMonitor");
3462         ret->datalen = (*env)->GetArrayLength(env, elems);
3463         if (ret->datalen == 0) {
3464                 ret->data = NULL;
3465         } else {
3466                 ret->data = MALLOC(sizeof(LDKChannelMonitor) * ret->datalen, "LDKCVecTempl_ChannelMonitor Data");
3467                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3468                 for (size_t i = 0; i < ret->datalen; i++) {
3469                         jlong arr_elem = java_elems[i];
3470                         LDKChannelMonitor arr_elem_conv;
3471                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3472                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3473                         // Warning: we may need a move here but can't clone!
3474                         ret->data[i] = arr_elem_conv;
3475                 }
3476                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3477         }
3478         return (long)ret;
3479 }
3480 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u64_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3481         LDKCVecTempl_u64 *vec = (LDKCVecTempl_u64*)ptr;
3482         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(uint64_t));
3483 }
3484 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u64_1new(JNIEnv *env, jclass _b, jlongArray elems){
3485         LDKCVecTempl_u64 *ret = MALLOC(sizeof(LDKCVecTempl_u64), "LDKCVecTempl_u64");
3486         ret->datalen = (*env)->GetArrayLength(env, elems);
3487         if (ret->datalen == 0) {
3488                 ret->data = NULL;
3489         } else {
3490                 ret->data = MALLOC(sizeof(uint64_t) * ret->datalen, "LDKCVecTempl_u64 Data");
3491                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3492                 for (size_t i = 0; i < ret->datalen; i++) {
3493                         ret->data[i] = java_elems[i];
3494                 }
3495                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3496         }
3497         return (long)ret;
3498 }
3499 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateAddHTLC_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3500         LDKCVecTempl_UpdateAddHTLC *vec = (LDKCVecTempl_UpdateAddHTLC*)ptr;
3501         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3502         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3503         for (size_t i = 0; i < vec->datalen; i++) {
3504                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3505                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3506         }
3507         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3508         return ret;
3509 }
3510 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateAddHTLC_1new(JNIEnv *env, jclass _b, jlongArray elems){
3511         LDKCVecTempl_UpdateAddHTLC *ret = MALLOC(sizeof(LDKCVecTempl_UpdateAddHTLC), "LDKCVecTempl_UpdateAddHTLC");
3512         ret->datalen = (*env)->GetArrayLength(env, elems);
3513         if (ret->datalen == 0) {
3514                 ret->data = NULL;
3515         } else {
3516                 ret->data = MALLOC(sizeof(LDKUpdateAddHTLC) * ret->datalen, "LDKCVecTempl_UpdateAddHTLC Data");
3517                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3518                 for (size_t i = 0; i < ret->datalen; i++) {
3519                         jlong arr_elem = java_elems[i];
3520                         LDKUpdateAddHTLC arr_elem_conv;
3521                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3522                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3523                         if (arr_elem_conv.inner != NULL)
3524                                 arr_elem_conv = UpdateAddHTLC_clone(&arr_elem_conv);
3525                         ret->data[i] = arr_elem_conv;
3526                 }
3527                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3528         }
3529         return (long)ret;
3530 }
3531 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFulfillHTLC_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3532         LDKCVecTempl_UpdateFulfillHTLC *vec = (LDKCVecTempl_UpdateFulfillHTLC*)ptr;
3533         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3534         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3535         for (size_t i = 0; i < vec->datalen; i++) {
3536                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3537                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3538         }
3539         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3540         return ret;
3541 }
3542 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFulfillHTLC_1new(JNIEnv *env, jclass _b, jlongArray elems){
3543         LDKCVecTempl_UpdateFulfillHTLC *ret = MALLOC(sizeof(LDKCVecTempl_UpdateFulfillHTLC), "LDKCVecTempl_UpdateFulfillHTLC");
3544         ret->datalen = (*env)->GetArrayLength(env, elems);
3545         if (ret->datalen == 0) {
3546                 ret->data = NULL;
3547         } else {
3548                 ret->data = MALLOC(sizeof(LDKUpdateFulfillHTLC) * ret->datalen, "LDKCVecTempl_UpdateFulfillHTLC Data");
3549                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3550                 for (size_t i = 0; i < ret->datalen; i++) {
3551                         jlong arr_elem = java_elems[i];
3552                         LDKUpdateFulfillHTLC arr_elem_conv;
3553                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3554                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3555                         if (arr_elem_conv.inner != NULL)
3556                                 arr_elem_conv = UpdateFulfillHTLC_clone(&arr_elem_conv);
3557                         ret->data[i] = arr_elem_conv;
3558                 }
3559                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3560         }
3561         return (long)ret;
3562 }
3563 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailHTLC_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3564         LDKCVecTempl_UpdateFailHTLC *vec = (LDKCVecTempl_UpdateFailHTLC*)ptr;
3565         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3566         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3567         for (size_t i = 0; i < vec->datalen; i++) {
3568                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3569                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3570         }
3571         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3572         return ret;
3573 }
3574 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailHTLC_1new(JNIEnv *env, jclass _b, jlongArray elems){
3575         LDKCVecTempl_UpdateFailHTLC *ret = MALLOC(sizeof(LDKCVecTempl_UpdateFailHTLC), "LDKCVecTempl_UpdateFailHTLC");
3576         ret->datalen = (*env)->GetArrayLength(env, elems);
3577         if (ret->datalen == 0) {
3578                 ret->data = NULL;
3579         } else {
3580                 ret->data = MALLOC(sizeof(LDKUpdateFailHTLC) * ret->datalen, "LDKCVecTempl_UpdateFailHTLC Data");
3581                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3582                 for (size_t i = 0; i < ret->datalen; i++) {
3583                         jlong arr_elem = java_elems[i];
3584                         LDKUpdateFailHTLC arr_elem_conv;
3585                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3586                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3587                         if (arr_elem_conv.inner != NULL)
3588                                 arr_elem_conv = UpdateFailHTLC_clone(&arr_elem_conv);
3589                         ret->data[i] = arr_elem_conv;
3590                 }
3591                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3592         }
3593         return (long)ret;
3594 }
3595 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailMalformedHTLC_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3596         LDKCVecTempl_UpdateFailMalformedHTLC *vec = (LDKCVecTempl_UpdateFailMalformedHTLC*)ptr;
3597         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3598         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3599         for (size_t i = 0; i < vec->datalen; i++) {
3600                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3601                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3602         }
3603         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3604         return ret;
3605 }
3606 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailMalformedHTLC_1new(JNIEnv *env, jclass _b, jlongArray elems){
3607         LDKCVecTempl_UpdateFailMalformedHTLC *ret = MALLOC(sizeof(LDKCVecTempl_UpdateFailMalformedHTLC), "LDKCVecTempl_UpdateFailMalformedHTLC");
3608         ret->datalen = (*env)->GetArrayLength(env, elems);
3609         if (ret->datalen == 0) {
3610                 ret->data = NULL;
3611         } else {
3612                 ret->data = MALLOC(sizeof(LDKUpdateFailMalformedHTLC) * ret->datalen, "LDKCVecTempl_UpdateFailMalformedHTLC Data");
3613                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3614                 for (size_t i = 0; i < ret->datalen; i++) {
3615                         jlong arr_elem = java_elems[i];
3616                         LDKUpdateFailMalformedHTLC arr_elem_conv;
3617                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3618                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3619                         if (arr_elem_conv.inner != NULL)
3620                                 arr_elem_conv = UpdateFailMalformedHTLC_clone(&arr_elem_conv);
3621                         ret->data[i] = arr_elem_conv;
3622                 }
3623                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3624         }
3625         return (long)ret;
3626 }
3627 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
3628         return ((LDKCResult_boolLightningErrorZ*)arg)->result_ok;
3629 }
3630 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
3631         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3632         CHECK(val->result_ok);
3633         return *val->contents.result;
3634 }
3635 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
3636         LDKCResult_boolLightningErrorZ *val = (LDKCResult_boolLightningErrorZ*)arg;
3637         CHECK(!val->result_ok);
3638         LDKLightningError err_var = (*val->contents.err);
3639         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3640         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3641         long err_ref = (long)err_var.inner & ~1;
3642         return err_ref;
3643 }
3644 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C3TupleTempl_1ChannelAnnouncement_1_1ChannelUpdate_1_1ChannelUpdate_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3645         LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate *vec = (LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate*)ptr;
3646         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate));
3647 }
3648 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C3TupleTempl_1ChannelAnnouncement_1_1ChannelUpdate_1_1ChannelUpdate_1new(JNIEnv *env, jclass _b, jlongArray elems){
3649         LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate *ret = MALLOC(sizeof(LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate), "LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate");
3650         ret->datalen = (*env)->GetArrayLength(env, elems);
3651         if (ret->datalen == 0) {
3652                 ret->data = NULL;
3653         } else {
3654                 ret->data = MALLOC(sizeof(LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate) * ret->datalen, "LDKCVecTempl_C3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate Data");
3655                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3656                 for (size_t i = 0; i < ret->datalen; i++) {
3657                         jlong arr_elem = java_elems[i];
3658                         LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate arr_elem_conv = *(LDKC3TupleTempl_ChannelAnnouncement__ChannelUpdate__ChannelUpdate*)arr_elem;
3659                         FREE((void*)arr_elem);
3660                         ret->data[i] = arr_elem_conv;
3661                 }
3662                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3663         }
3664         return (long)ret;
3665 }
3666 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1NodeAnnouncement_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
3667         LDKCVecTempl_NodeAnnouncement *vec = (LDKCVecTempl_NodeAnnouncement*)ptr;
3668         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
3669         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
3670         for (size_t i = 0; i < vec->datalen; i++) {
3671                 CHECK((((long)vec->data[i].inner) & 1) == 0);
3672                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
3673         }
3674         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
3675         return ret;
3676 }
3677 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1NodeAnnouncement_1new(JNIEnv *env, jclass _b, jlongArray elems){
3678         LDKCVecTempl_NodeAnnouncement *ret = MALLOC(sizeof(LDKCVecTempl_NodeAnnouncement), "LDKCVecTempl_NodeAnnouncement");
3679         ret->datalen = (*env)->GetArrayLength(env, elems);
3680         if (ret->datalen == 0) {
3681                 ret->data = NULL;
3682         } else {
3683                 ret->data = MALLOC(sizeof(LDKNodeAnnouncement) * ret->datalen, "LDKCVecTempl_NodeAnnouncement Data");
3684                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
3685                 for (size_t i = 0; i < ret->datalen; i++) {
3686                         jlong arr_elem = java_elems[i];
3687                         LDKNodeAnnouncement arr_elem_conv;
3688                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
3689                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
3690                         if (arr_elem_conv.inner != NULL)
3691                                 arr_elem_conv = NodeAnnouncement_clone(&arr_elem_conv);
3692                         ret->data[i] = arr_elem_conv;
3693                 }
3694                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
3695         }
3696         return (long)ret;
3697 }
3698 typedef struct LDKRoutingMessageHandler_JCalls {
3699         atomic_size_t refcnt;
3700         JavaVM *vm;
3701         jweak o;
3702         jmethodID handle_node_announcement_meth;
3703         jmethodID handle_channel_announcement_meth;
3704         jmethodID handle_channel_update_meth;
3705         jmethodID handle_htlc_fail_channel_update_meth;
3706         jmethodID get_next_channel_announcements_meth;
3707         jmethodID get_next_node_announcements_meth;
3708         jmethodID should_request_full_sync_meth;
3709 } LDKRoutingMessageHandler_JCalls;
3710 LDKCResult_boolLightningErrorZ handle_node_announcement_jcall(const void* this_arg, const LDKNodeAnnouncement *msg) {
3711         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3712         JNIEnv *_env;
3713         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3714         long ret_msg = (long)msg;
3715         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3716         CHECK(obj != NULL);
3717         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_node_announcement_meth, ret_msg);
3718         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
3719         FREE((void*)ret);
3720         return ret_conv;
3721 }
3722 LDKCResult_boolLightningErrorZ handle_channel_announcement_jcall(const void* this_arg, const LDKChannelAnnouncement *msg) {
3723         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3724         JNIEnv *_env;
3725         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3726         long ret_msg = (long)msg;
3727         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3728         CHECK(obj != NULL);
3729         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_channel_announcement_meth, ret_msg);
3730         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
3731         FREE((void*)ret);
3732         return ret_conv;
3733 }
3734 LDKCResult_boolLightningErrorZ handle_channel_update_jcall(const void* this_arg, const LDKChannelUpdate *msg) {
3735         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3736         JNIEnv *_env;
3737         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3738         long ret_msg = (long)msg;
3739         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3740         CHECK(obj != NULL);
3741         LDKCResult_boolLightningErrorZ* ret = (LDKCResult_boolLightningErrorZ*)(*_env)->CallLongMethod(_env, obj, j_calls->handle_channel_update_meth, ret_msg);
3742         LDKCResult_boolLightningErrorZ ret_conv = *(LDKCResult_boolLightningErrorZ*)ret;
3743         FREE((void*)ret);
3744         return ret_conv;
3745 }
3746 void handle_htlc_fail_channel_update_jcall(const void* this_arg, const LDKHTLCFailChannelUpdate *update) {
3747         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3748         JNIEnv *_env;
3749         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3750         long ret_update = (long)update;
3751         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3752         CHECK(obj != NULL);
3753         return (*_env)->CallVoidMethod(_env, obj, j_calls->handle_htlc_fail_channel_update_meth, ret_update);
3754 }
3755 LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ get_next_channel_announcements_jcall(const void* this_arg, uint64_t starting_point, uint8_t batch_amount) {
3756         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3757         JNIEnv *_env;
3758         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3759         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3760         CHECK(obj != NULL);
3761         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_next_channel_announcements_meth, starting_point, batch_amount);
3762         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ arg_constr;
3763         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
3764         if (arg_constr.datalen > 0)
3765                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
3766         else
3767                 arg_constr.data = NULL;
3768         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
3769         for (size_t l = 0; l < arg_constr.datalen; l++) {
3770                 long arr_conv_63 = arg_vals[l];
3771                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
3772                 FREE((void*)arr_conv_63);
3773                 arg_constr.data[l] = arr_conv_63_conv;
3774         }
3775         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
3776         return arg_constr;
3777 }
3778 LDKCVec_NodeAnnouncementZ get_next_node_announcements_jcall(const void* this_arg, LDKPublicKey starting_point, uint8_t batch_amount) {
3779         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3780         JNIEnv *_env;
3781         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3782         jbyteArray starting_point_arr = (*_env)->NewByteArray(_env, 33);
3783         (*_env)->SetByteArrayRegion(_env, starting_point_arr, 0, 33, starting_point.compressed_form);
3784         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3785         CHECK(obj != NULL);
3786         jlongArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_next_node_announcements_meth, starting_point_arr, batch_amount);
3787         LDKCVec_NodeAnnouncementZ arg_constr;
3788         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
3789         if (arg_constr.datalen > 0)
3790                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
3791         else
3792                 arg_constr.data = NULL;
3793         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
3794         for (size_t s = 0; s < arg_constr.datalen; s++) {
3795                 long arr_conv_18 = arg_vals[s];
3796                 LDKNodeAnnouncement arr_conv_18_conv;
3797                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
3798                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
3799                 if (arr_conv_18_conv.inner != NULL)
3800                         arr_conv_18_conv = NodeAnnouncement_clone(&arr_conv_18_conv);
3801                 arg_constr.data[s] = arr_conv_18_conv;
3802         }
3803         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
3804         return arg_constr;
3805 }
3806 bool should_request_full_sync_jcall(const void* this_arg, LDKPublicKey node_id) {
3807         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3808         JNIEnv *_env;
3809         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3810         jbyteArray node_id_arr = (*_env)->NewByteArray(_env, 33);
3811         (*_env)->SetByteArrayRegion(_env, node_id_arr, 0, 33, node_id.compressed_form);
3812         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3813         CHECK(obj != NULL);
3814         return (*_env)->CallBooleanMethod(_env, obj, j_calls->should_request_full_sync_meth, node_id_arr);
3815 }
3816 static void LDKRoutingMessageHandler_JCalls_free(void* this_arg) {
3817         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3818         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
3819                 JNIEnv *env;
3820                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
3821                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
3822                 FREE(j_calls);
3823         }
3824 }
3825 static void* LDKRoutingMessageHandler_JCalls_clone(const void* this_arg) {
3826         LDKRoutingMessageHandler_JCalls *j_calls = (LDKRoutingMessageHandler_JCalls*) this_arg;
3827         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
3828         return (void*) this_arg;
3829 }
3830 static inline LDKRoutingMessageHandler LDKRoutingMessageHandler_init (JNIEnv * env, jclass _a, jobject o) {
3831         jclass c = (*env)->GetObjectClass(env, o);
3832         CHECK(c != NULL);
3833         LDKRoutingMessageHandler_JCalls *calls = MALLOC(sizeof(LDKRoutingMessageHandler_JCalls), "LDKRoutingMessageHandler_JCalls");
3834         atomic_init(&calls->refcnt, 1);
3835         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
3836         calls->o = (*env)->NewWeakGlobalRef(env, o);
3837         calls->handle_node_announcement_meth = (*env)->GetMethodID(env, c, "handle_node_announcement", "(J)J");
3838         CHECK(calls->handle_node_announcement_meth != NULL);
3839         calls->handle_channel_announcement_meth = (*env)->GetMethodID(env, c, "handle_channel_announcement", "(J)J");
3840         CHECK(calls->handle_channel_announcement_meth != NULL);
3841         calls->handle_channel_update_meth = (*env)->GetMethodID(env, c, "handle_channel_update", "(J)J");
3842         CHECK(calls->handle_channel_update_meth != NULL);
3843         calls->handle_htlc_fail_channel_update_meth = (*env)->GetMethodID(env, c, "handle_htlc_fail_channel_update", "(J)V");
3844         CHECK(calls->handle_htlc_fail_channel_update_meth != NULL);
3845         calls->get_next_channel_announcements_meth = (*env)->GetMethodID(env, c, "get_next_channel_announcements", "(JB)[J");
3846         CHECK(calls->get_next_channel_announcements_meth != NULL);
3847         calls->get_next_node_announcements_meth = (*env)->GetMethodID(env, c, "get_next_node_announcements", "([BB)[J");
3848         CHECK(calls->get_next_node_announcements_meth != NULL);
3849         calls->should_request_full_sync_meth = (*env)->GetMethodID(env, c, "should_request_full_sync", "([B)Z");
3850         CHECK(calls->should_request_full_sync_meth != NULL);
3851
3852         LDKRoutingMessageHandler ret = {
3853                 .this_arg = (void*) calls,
3854                 .handle_node_announcement = handle_node_announcement_jcall,
3855                 .handle_channel_announcement = handle_channel_announcement_jcall,
3856                 .handle_channel_update = handle_channel_update_jcall,
3857                 .handle_htlc_fail_channel_update = handle_htlc_fail_channel_update_jcall,
3858                 .get_next_channel_announcements = get_next_channel_announcements_jcall,
3859                 .get_next_node_announcements = get_next_node_announcements_jcall,
3860                 .should_request_full_sync = should_request_full_sync_jcall,
3861                 .free = LDKRoutingMessageHandler_JCalls_free,
3862         };
3863         return ret;
3864 }
3865 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1new (JNIEnv * env, jclass _a, jobject o) {
3866         LDKRoutingMessageHandler *res_ptr = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
3867         *res_ptr = LDKRoutingMessageHandler_init(env, _a, o);
3868         return (long)res_ptr;
3869 }
3870 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
3871         jobject ret = (*env)->NewLocalRef(env, ((LDKRoutingMessageHandler_JCalls*)val)->o);
3872         CHECK(ret != NULL);
3873         return ret;
3874 }
3875 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1node_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
3876         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
3877         LDKNodeAnnouncement msg_conv;
3878         msg_conv.inner = (void*)(msg & (~1));
3879         msg_conv.is_owned = (msg & 1) || (msg == 0);
3880         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
3881         *ret_conv = (this_arg_conv->handle_node_announcement)(this_arg_conv->this_arg, &msg_conv);
3882         return (long)ret_conv;
3883 }
3884
3885 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
3886         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
3887         LDKChannelAnnouncement msg_conv;
3888         msg_conv.inner = (void*)(msg & (~1));
3889         msg_conv.is_owned = (msg & 1) || (msg == 0);
3890         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
3891         *ret_conv = (this_arg_conv->handle_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
3892         return (long)ret_conv;
3893 }
3894
3895 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1channel_1update(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
3896         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
3897         LDKChannelUpdate msg_conv;
3898         msg_conv.inner = (void*)(msg & (~1));
3899         msg_conv.is_owned = (msg & 1) || (msg == 0);
3900         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
3901         *ret_conv = (this_arg_conv->handle_channel_update)(this_arg_conv->this_arg, &msg_conv);
3902         return (long)ret_conv;
3903 }
3904
3905 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1handle_1htlc_1fail_1channel_1update(JNIEnv * _env, jclass _b, jlong this_arg, jlong update) {
3906         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
3907         LDKHTLCFailChannelUpdate* update_conv = (LDKHTLCFailChannelUpdate*)update;
3908         (this_arg_conv->handle_htlc_fail_channel_update)(this_arg_conv->this_arg, update_conv);
3909 }
3910
3911 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) {
3912         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
3913         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ ret_var = (this_arg_conv->get_next_channel_announcements)(this_arg_conv->this_arg, starting_point, batch_amount);
3914         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
3915         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
3916         for (size_t l = 0; l < ret_var.datalen; l++) {
3917                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* arr_conv_63_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
3918                 *arr_conv_63_ref = ret_var.data[l];
3919                 ret_arr_ptr[l] = (long)arr_conv_63_ref;
3920         }
3921         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
3922         CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(ret_var);
3923         return ret_arr;
3924 }
3925
3926 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) {
3927         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
3928         LDKPublicKey starting_point_ref;
3929         CHECK((*_env)->GetArrayLength (_env, starting_point) == 33);
3930         (*_env)->GetByteArrayRegion (_env, starting_point, 0, 33, starting_point_ref.compressed_form);
3931         LDKCVec_NodeAnnouncementZ ret_var = (this_arg_conv->get_next_node_announcements)(this_arg_conv->this_arg, starting_point_ref, batch_amount);
3932         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
3933         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
3934         for (size_t s = 0; s < ret_var.datalen; s++) {
3935                 LDKNodeAnnouncement arr_conv_18_var = ret_var.data[s];
3936                 CHECK((((long)arr_conv_18_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
3937                 CHECK((((long)&arr_conv_18_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
3938                 long arr_conv_18_ref = (long)arr_conv_18_var.inner;
3939                 if (arr_conv_18_var.is_owned) {
3940                         arr_conv_18_ref |= 1;
3941                 }
3942                 ret_arr_ptr[s] = arr_conv_18_ref;
3943         }
3944         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
3945         FREE(ret_var.data);
3946         return ret_arr;
3947 }
3948
3949 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1should_1request_1full_1sync(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray node_id) {
3950         LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
3951         LDKPublicKey node_id_ref;
3952         CHECK((*_env)->GetArrayLength (_env, node_id) == 33);
3953         (*_env)->GetByteArrayRegion (_env, node_id, 0, 33, node_id_ref.compressed_form);
3954         jboolean ret_val = (this_arg_conv->should_request_full_sync)(this_arg_conv->this_arg, node_id_ref);
3955         return ret_val;
3956 }
3957
3958 typedef struct LDKSocketDescriptor_JCalls {
3959         atomic_size_t refcnt;
3960         JavaVM *vm;
3961         jweak o;
3962         jmethodID send_data_meth;
3963         jmethodID disconnect_socket_meth;
3964         jmethodID eq_meth;
3965         jmethodID hash_meth;
3966 } LDKSocketDescriptor_JCalls;
3967 uintptr_t send_data_jcall(void* this_arg, LDKu8slice data, bool resume_read) {
3968         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
3969         JNIEnv *_env;
3970         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3971         LDKu8slice data_var = data;
3972         jbyteArray data_arr = (*_env)->NewByteArray(_env, data_var.datalen);
3973         (*_env)->SetByteArrayRegion(_env, data_arr, 0, data_var.datalen, data_var.data);
3974         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3975         CHECK(obj != NULL);
3976         return (*_env)->CallLongMethod(_env, obj, j_calls->send_data_meth, data_arr, resume_read);
3977 }
3978 void disconnect_socket_jcall(void* this_arg) {
3979         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
3980         JNIEnv *_env;
3981         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3982         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3983         CHECK(obj != NULL);
3984         return (*_env)->CallVoidMethod(_env, obj, j_calls->disconnect_socket_meth);
3985 }
3986 bool eq_jcall(const void* this_arg, const void *other_arg) {
3987         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
3988         JNIEnv *_env;
3989         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3990         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3991         CHECK(obj != NULL);
3992         return (*_env)->CallBooleanMethod(_env, obj, j_calls->eq_meth, other_arg);
3993 }
3994 uint64_t hash_jcall(const void* this_arg) {
3995         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
3996         JNIEnv *_env;
3997         DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
3998         jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
3999         CHECK(obj != NULL);
4000         return (*_env)->CallLongMethod(_env, obj, j_calls->hash_meth);
4001 }
4002 static void LDKSocketDescriptor_JCalls_free(void* this_arg) {
4003         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4004         if (atomic_fetch_sub_explicit(&j_calls->refcnt, 1, memory_order_acquire) == 1) {
4005                 JNIEnv *env;
4006                 DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
4007                 (*env)->DeleteWeakGlobalRef(env, j_calls->o);
4008                 FREE(j_calls);
4009         }
4010 }
4011 static void* LDKSocketDescriptor_JCalls_clone(const void* this_arg) {
4012         LDKSocketDescriptor_JCalls *j_calls = (LDKSocketDescriptor_JCalls*) this_arg;
4013         atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
4014         return (void*) this_arg;
4015 }
4016 static inline LDKSocketDescriptor LDKSocketDescriptor_init (JNIEnv * env, jclass _a, jobject o) {
4017         jclass c = (*env)->GetObjectClass(env, o);
4018         CHECK(c != NULL);
4019         LDKSocketDescriptor_JCalls *calls = MALLOC(sizeof(LDKSocketDescriptor_JCalls), "LDKSocketDescriptor_JCalls");
4020         atomic_init(&calls->refcnt, 1);
4021         DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
4022         calls->o = (*env)->NewWeakGlobalRef(env, o);
4023         calls->send_data_meth = (*env)->GetMethodID(env, c, "send_data", "([BZ)J");
4024         CHECK(calls->send_data_meth != NULL);
4025         calls->disconnect_socket_meth = (*env)->GetMethodID(env, c, "disconnect_socket", "()V");
4026         CHECK(calls->disconnect_socket_meth != NULL);
4027         calls->eq_meth = (*env)->GetMethodID(env, c, "eq", "(J)Z");
4028         CHECK(calls->eq_meth != NULL);
4029         calls->hash_meth = (*env)->GetMethodID(env, c, "hash", "()J");
4030         CHECK(calls->hash_meth != NULL);
4031
4032         LDKSocketDescriptor ret = {
4033                 .this_arg = (void*) calls,
4034                 .send_data = send_data_jcall,
4035                 .disconnect_socket = disconnect_socket_jcall,
4036                 .eq = eq_jcall,
4037                 .hash = hash_jcall,
4038                 .clone = LDKSocketDescriptor_JCalls_clone,
4039                 .free = LDKSocketDescriptor_JCalls_free,
4040         };
4041         return ret;
4042 }
4043 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1new (JNIEnv * env, jclass _a, jobject o) {
4044         LDKSocketDescriptor *res_ptr = MALLOC(sizeof(LDKSocketDescriptor), "LDKSocketDescriptor");
4045         *res_ptr = LDKSocketDescriptor_init(env, _a, o);
4046         return (long)res_ptr;
4047 }
4048 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
4049         jobject ret = (*env)->NewLocalRef(env, ((LDKSocketDescriptor_JCalls*)val)->o);
4050         CHECK(ret != NULL);
4051         return ret;
4052 }
4053 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1send_1data(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray data, jboolean resume_read) {
4054         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4055         LDKu8slice data_ref;
4056         data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL);
4057         data_ref.datalen = (*_env)->GetArrayLength (_env, data);
4058         jlong ret_val = (this_arg_conv->send_data)(this_arg_conv->this_arg, data_ref, resume_read);
4059         (*_env)->ReleaseByteArrayElements(_env, data, (int8_t*)data_ref.data, 0);
4060         return ret_val;
4061 }
4062
4063 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1disconnect_1socket(JNIEnv * _env, jclass _b, jlong this_arg) {
4064         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4065         (this_arg_conv->disconnect_socket)(this_arg_conv->this_arg);
4066 }
4067
4068 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1hash(JNIEnv * _env, jclass _b, jlong this_arg) {
4069         LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
4070         jlong ret_val = (this_arg_conv->hash)(this_arg_conv->this_arg);
4071         return ret_val;
4072 }
4073
4074 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1PublicKey_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4075         LDKCVecTempl_PublicKey *vec = (LDKCVecTempl_PublicKey*)ptr;
4076         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKPublicKey));
4077 }
4078 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4079         return ((LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg)->result_ok;
4080 }
4081 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4082         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
4083         CHECK(val->result_ok);
4084         LDKCVecTempl_u8 res_var = (*val->contents.result);
4085         jbyteArray res_arr = (*_env)->NewByteArray(_env, res_var.datalen);
4086         (*_env)->SetByteArrayRegion(_env, res_arr, 0, res_var.datalen, res_var.data);
4087         return res_arr;
4088 }
4089 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4090         LDKCResult_CVec_u8ZPeerHandleErrorZ *val = (LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
4091         CHECK(!val->result_ok);
4092         LDKPeerHandleError err_var = (*val->contents.err);
4093         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4094         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4095         long err_ref = (long)err_var.inner & ~1;
4096         return err_ref;
4097 }
4098 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4099         return ((LDKCResult_boolPeerHandleErrorZ*)arg)->result_ok;
4100 }
4101 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4102         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
4103         CHECK(val->result_ok);
4104         return *val->contents.result;
4105 }
4106 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4107         LDKCResult_boolPeerHandleErrorZ *val = (LDKCResult_boolPeerHandleErrorZ*)arg;
4108         CHECK(!val->result_ok);
4109         LDKPeerHandleError err_var = (*val->contents.err);
4110         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4111         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4112         long err_ref = (long)err_var.inner & ~1;
4113         return err_ref;
4114 }
4115 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4116         return ((LDKCResult_SecretKeySecpErrorZ*)arg)->result_ok;
4117 }
4118 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4119         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
4120         CHECK(val->result_ok);
4121         jbyteArray res_arr = (*_env)->NewByteArray(_env, 32);
4122         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 32, (*val->contents.result).bytes);
4123         return res_arr;
4124 }
4125 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4126         LDKCResult_SecretKeySecpErrorZ *val = (LDKCResult_SecretKeySecpErrorZ*)arg;
4127         CHECK(!val->result_ok);
4128         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
4129         return err_conv;
4130 }
4131 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4132         return ((LDKCResult_PublicKeySecpErrorZ*)arg)->result_ok;
4133 }
4134 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4135         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
4136         CHECK(val->result_ok);
4137         jbyteArray res_arr = (*_env)->NewByteArray(_env, 33);
4138         (*_env)->SetByteArrayRegion(_env, res_arr, 0, 33, (*val->contents.result).compressed_form);
4139         return res_arr;
4140 }
4141 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1PublicKeySecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4142         LDKCResult_PublicKeySecpErrorZ *val = (LDKCResult_PublicKeySecpErrorZ*)arg;
4143         CHECK(!val->result_ok);
4144         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
4145         return err_conv;
4146 }
4147 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4148         return ((LDKCResult_TxCreationKeysSecpErrorZ*)arg)->result_ok;
4149 }
4150 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4151         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
4152         CHECK(val->result_ok);
4153         LDKTxCreationKeys res_var = (*val->contents.result);
4154         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4155         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4156         long res_ref = (long)res_var.inner & ~1;
4157         return res_ref;
4158 }
4159 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4160         LDKCResult_TxCreationKeysSecpErrorZ *val = (LDKCResult_TxCreationKeysSecpErrorZ*)arg;
4161         CHECK(!val->result_ok);
4162         jclass err_conv = LDKSecp256k1Error_to_java(_env, (*val->contents.err));
4163         return err_conv;
4164 }
4165 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1HTLCOutputInCommitment_1_1Signature_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4166         LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature *vec = (LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature*)ptr;
4167         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2TupleTempl_HTLCOutputInCommitment__Signature));
4168 }
4169 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1HTLCOutputInCommitment_1_1Signature_1new(JNIEnv *env, jclass _b, jlongArray elems){
4170         LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature *ret = MALLOC(sizeof(LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature), "LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature");
4171         ret->datalen = (*env)->GetArrayLength(env, elems);
4172         if (ret->datalen == 0) {
4173                 ret->data = NULL;
4174         } else {
4175                 ret->data = MALLOC(sizeof(LDKC2TupleTempl_HTLCOutputInCommitment__Signature) * ret->datalen, "LDKCVecTempl_C2TupleTempl_HTLCOutputInCommitment__Signature Data");
4176                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
4177                 for (size_t i = 0; i < ret->datalen; i++) {
4178                         jlong arr_elem = java_elems[i];
4179                         LDKC2TupleTempl_HTLCOutputInCommitment__Signature arr_elem_conv = *(LDKC2TupleTempl_HTLCOutputInCommitment__Signature*)arr_elem;
4180                         FREE((void*)arr_elem);
4181                         ret->data[i] = arr_elem_conv;
4182                 }
4183                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
4184         }
4185         return (long)ret;
4186 }
4187 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHop_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4188         LDKCVecTempl_RouteHop *vec = (LDKCVecTempl_RouteHop*)ptr;
4189         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
4190         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
4191         for (size_t i = 0; i < vec->datalen; i++) {
4192                 CHECK((((long)vec->data[i].inner) & 1) == 0);
4193                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
4194         }
4195         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
4196         return ret;
4197 }
4198 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHop_1new(JNIEnv *env, jclass _b, jlongArray elems){
4199         LDKCVecTempl_RouteHop *ret = MALLOC(sizeof(LDKCVecTempl_RouteHop), "LDKCVecTempl_RouteHop");
4200         ret->datalen = (*env)->GetArrayLength(env, elems);
4201         if (ret->datalen == 0) {
4202                 ret->data = NULL;
4203         } else {
4204                 ret->data = MALLOC(sizeof(LDKRouteHop) * ret->datalen, "LDKCVecTempl_RouteHop Data");
4205                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
4206                 for (size_t i = 0; i < ret->datalen; i++) {
4207                         jlong arr_elem = java_elems[i];
4208                         LDKRouteHop arr_elem_conv;
4209                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
4210                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
4211                         if (arr_elem_conv.inner != NULL)
4212                                 arr_elem_conv = RouteHop_clone(&arr_elem_conv);
4213                         ret->data[i] = arr_elem_conv;
4214                 }
4215                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
4216         }
4217         return (long)ret;
4218 }
4219 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1CVecTempl_1RouteHop_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4220         LDKCVecTempl_CVecTempl_RouteHop *vec = (LDKCVecTempl_CVecTempl_RouteHop*)ptr;
4221         return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKCVecTempl_RouteHop));
4222 }
4223 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {
4224         return ((LDKCResult_RouteLightningErrorZ*)arg)->result_ok;
4225 }
4226 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1ok (JNIEnv * _env, jclass _a, jlong arg) {
4227         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
4228         CHECK(val->result_ok);
4229         LDKRoute res_var = (*val->contents.result);
4230         CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4231         CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4232         long res_ref = (long)res_var.inner & ~1;
4233         return res_ref;
4234 }
4235 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {
4236         LDKCResult_RouteLightningErrorZ *val = (LDKCResult_RouteLightningErrorZ*)arg;
4237         CHECK(!val->result_ok);
4238         LDKLightningError err_var = (*val->contents.err);
4239         CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
4240         CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
4241         long err_ref = (long)err_var.inner & ~1;
4242         return err_ref;
4243 }
4244 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHint_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
4245         LDKCVecTempl_RouteHint *vec = (LDKCVecTempl_RouteHint*)ptr;
4246         jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
4247         jlong *ret_elems = (*env)->GetPrimitiveArrayCritical(env, ret, NULL);
4248         for (size_t i = 0; i < vec->datalen; i++) {
4249                 CHECK((((long)vec->data[i].inner) & 1) == 0);
4250                 ret_elems[i] = (long)vec->data[i].inner | (vec->data[i].is_owned ? 1 : 0);
4251         }
4252         (*env)->ReleasePrimitiveArrayCritical(env, ret, ret_elems, 0);
4253         return ret;
4254 }
4255 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHint_1new(JNIEnv *env, jclass _b, jlongArray elems){
4256         LDKCVecTempl_RouteHint *ret = MALLOC(sizeof(LDKCVecTempl_RouteHint), "LDKCVecTempl_RouteHint");
4257         ret->datalen = (*env)->GetArrayLength(env, elems);
4258         if (ret->datalen == 0) {
4259                 ret->data = NULL;
4260         } else {
4261                 ret->data = MALLOC(sizeof(LDKRouteHint) * ret->datalen, "LDKCVecTempl_RouteHint Data");
4262                 jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL);
4263                 for (size_t i = 0; i < ret->datalen; i++) {
4264                         jlong arr_elem = java_elems[i];
4265                         LDKRouteHint arr_elem_conv;
4266                         arr_elem_conv.inner = (void*)(arr_elem & (~1));
4267                         arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
4268                         if (arr_elem_conv.inner != NULL)
4269                                 arr_elem_conv = RouteHint_clone(&arr_elem_conv);
4270                         ret->data[i] = arr_elem_conv;
4271                 }
4272                 (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
4273         }
4274         return (long)ret;
4275 }
4276 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1HTLCOutputInCommitmentSignatureZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4277         LDKC2Tuple_HTLCOutputInCommitmentSignatureZ arg_conv = *(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ*)arg;
4278         FREE((void*)arg);
4279         C2Tuple_HTLCOutputInCommitmentSignatureZ_free(arg_conv);
4280 }
4281
4282 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4283         LDKC2Tuple_OutPointScriptZ arg_conv = *(LDKC2Tuple_OutPointScriptZ*)arg;
4284         FREE((void*)arg);
4285         C2Tuple_OutPointScriptZ_free(arg_conv);
4286 }
4287
4288 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4289         LDKC2Tuple_SignatureCVec_SignatureZZ arg_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)arg;
4290         FREE((void*)arg);
4291         C2Tuple_SignatureCVec_SignatureZZ_free(arg_conv);
4292 }
4293
4294 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1TxOutZZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4295         LDKC2Tuple_TxidCVec_TxOutZZ arg_conv = *(LDKC2Tuple_TxidCVec_TxOutZZ*)arg;
4296         FREE((void*)arg);
4297         C2Tuple_TxidCVec_TxOutZZ_free(arg_conv);
4298 }
4299
4300 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1free(JNIEnv * _env, jclass _b, jlong arg) {
4301         LDKC2Tuple_u64u64Z arg_conv = *(LDKC2Tuple_u64u64Z*)arg;
4302         FREE((void*)arg);
4303         C2Tuple_u64u64Z_free(arg_conv);
4304 }
4305
4306 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4307         LDKC2Tuple_usizeTransactionZ arg_conv = *(LDKC2Tuple_usizeTransactionZ*)arg;
4308         FREE((void*)arg);
4309         C2Tuple_usizeTransactionZ_free(arg_conv);
4310 }
4311
4312 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4313         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arg_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arg;
4314         FREE((void*)arg);
4315         C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(arg_conv);
4316 }
4317
4318 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4319         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ arg_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)arg;
4320         FREE((void*)arg);
4321         CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(arg_conv);
4322 }
4323
4324 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1ok(JNIEnv * _env, jclass _b, jlong arg) {
4325         LDKC2Tuple_SignatureCVec_SignatureZZ arg_conv = *(LDKC2Tuple_SignatureCVec_SignatureZZ*)arg;
4326         FREE((void*)arg);
4327         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
4328         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(arg_conv);
4329         return (long)ret_conv;
4330 }
4331
4332 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4333         LDKCResult_CVec_SignatureZNoneZ arg_conv = *(LDKCResult_CVec_SignatureZNoneZ*)arg;
4334         FREE((void*)arg);
4335         CResult_CVec_SignatureZNoneZ_free(arg_conv);
4336 }
4337
4338 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1ok(JNIEnv * _env, jclass _b, jobjectArray arg) {
4339         LDKCVec_SignatureZ arg_constr;
4340         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4341         if (arg_constr.datalen > 0)
4342                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
4343         else
4344                 arg_constr.data = NULL;
4345         for (size_t i = 0; i < arg_constr.datalen; i++) {
4346                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, arg, i);
4347                 LDKSignature arr_conv_8_ref;
4348                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
4349                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
4350                 arg_constr.data[i] = arr_conv_8_ref;
4351         }
4352         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
4353         *ret_conv = CResult_CVec_SignatureZNoneZ_ok(arg_constr);
4354         return (long)ret_conv;
4355 }
4356
4357 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4358         LDKPeerHandleError arg_conv = *(LDKPeerHandleError*)arg;
4359         FREE((void*)arg);
4360         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
4361         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_err(arg_conv);
4362         return (long)ret_conv;
4363 }
4364
4365 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4366         LDKCResult_CVec_u8ZPeerHandleErrorZ arg_conv = *(LDKCResult_CVec_u8ZPeerHandleErrorZ*)arg;
4367         FREE((void*)arg);
4368         CResult_CVec_u8ZPeerHandleErrorZ_free(arg_conv);
4369 }
4370
4371 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) {
4372         LDKCVec_u8Z arg_ref;
4373         arg_ref.data = (*_env)->GetByteArrayElements (_env, arg, NULL);
4374         arg_ref.datalen = (*_env)->GetArrayLength (_env, arg);
4375         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
4376         *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_ok(arg_ref);
4377         (*_env)->ReleaseByteArrayElements(_env, arg, (int8_t*)arg_ref.data, 0);
4378         return (long)ret_conv;
4379 }
4380
4381 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4382         LDKAPIError arg_conv = *(LDKAPIError*)arg;
4383         FREE((void*)arg);
4384         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
4385         *ret_conv = CResult_NoneAPIErrorZ_err(arg_conv);
4386         return (long)ret_conv;
4387 }
4388
4389 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4390         LDKCResult_NoneAPIErrorZ arg_conv = *(LDKCResult_NoneAPIErrorZ*)arg;
4391         FREE((void*)arg);
4392         CResult_NoneAPIErrorZ_free(arg_conv);
4393 }
4394
4395 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4396         LDKChannelMonitorUpdateErr arg_conv = *(LDKChannelMonitorUpdateErr*)arg;
4397         FREE((void*)arg);
4398         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
4399         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_err(arg_conv);
4400         return (long)ret_conv;
4401 }
4402
4403 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4404         LDKCResult_NoneChannelMonitorUpdateErrZ arg_conv = *(LDKCResult_NoneChannelMonitorUpdateErrZ*)arg;
4405         FREE((void*)arg);
4406         CResult_NoneChannelMonitorUpdateErrZ_free(arg_conv);
4407 }
4408
4409 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4410         LDKMonitorUpdateError arg_conv = *(LDKMonitorUpdateError*)arg;
4411         FREE((void*)arg);
4412         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
4413         *ret_conv = CResult_NoneMonitorUpdateErrorZ_err(arg_conv);
4414         return (long)ret_conv;
4415 }
4416
4417 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4418         LDKCResult_NoneMonitorUpdateErrorZ arg_conv = *(LDKCResult_NoneMonitorUpdateErrorZ*)arg;
4419         FREE((void*)arg);
4420         CResult_NoneMonitorUpdateErrorZ_free(arg_conv);
4421 }
4422
4423 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4424         LDKPaymentSendFailure arg_conv = *(LDKPaymentSendFailure*)arg;
4425         FREE((void*)arg);
4426         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
4427         *ret_conv = CResult_NonePaymentSendFailureZ_err(arg_conv);
4428         return (long)ret_conv;
4429 }
4430
4431 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4432         LDKCResult_NonePaymentSendFailureZ arg_conv = *(LDKCResult_NonePaymentSendFailureZ*)arg;
4433         FREE((void*)arg);
4434         CResult_NonePaymentSendFailureZ_free(arg_conv);
4435 }
4436
4437 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4438         LDKPeerHandleError arg_conv = *(LDKPeerHandleError*)arg;
4439         FREE((void*)arg);
4440         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
4441         *ret_conv = CResult_NonePeerHandleErrorZ_err(arg_conv);
4442         return (long)ret_conv;
4443 }
4444
4445 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4446         LDKCResult_NonePeerHandleErrorZ arg_conv = *(LDKCResult_NonePeerHandleErrorZ*)arg;
4447         FREE((void*)arg);
4448         CResult_NonePeerHandleErrorZ_free(arg_conv);
4449 }
4450
4451 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4452         LDKSecp256k1Error arg_conv = *(LDKSecp256k1Error*)arg;
4453         FREE((void*)arg);
4454         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
4455         *ret_conv = CResult_PublicKeySecpErrorZ_err(arg_conv);
4456         return (long)ret_conv;
4457 }
4458
4459 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4460         LDKCResult_PublicKeySecpErrorZ arg_conv = *(LDKCResult_PublicKeySecpErrorZ*)arg;
4461         FREE((void*)arg);
4462         CResult_PublicKeySecpErrorZ_free(arg_conv);
4463 }
4464
4465 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) {
4466         LDKPublicKey arg_ref;
4467         CHECK((*_env)->GetArrayLength (_env, arg) == 33);
4468         (*_env)->GetByteArrayRegion (_env, arg, 0, 33, arg_ref.compressed_form);
4469         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
4470         *ret_conv = CResult_PublicKeySecpErrorZ_ok(arg_ref);
4471         return (long)ret_conv;
4472 }
4473
4474 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4475         LDKLightningError arg_conv = *(LDKLightningError*)arg;
4476         FREE((void*)arg);
4477         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
4478         *ret_conv = CResult_RouteLightningErrorZ_err(arg_conv);
4479         return (long)ret_conv;
4480 }
4481
4482 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4483         LDKCResult_RouteLightningErrorZ arg_conv = *(LDKCResult_RouteLightningErrorZ*)arg;
4484         FREE((void*)arg);
4485         CResult_RouteLightningErrorZ_free(arg_conv);
4486 }
4487
4488 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ_1ok(JNIEnv * _env, jclass _b, jlong arg) {
4489         LDKRoute arg_conv = *(LDKRoute*)arg;
4490         FREE((void*)arg);
4491         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
4492         *ret_conv = CResult_RouteLightningErrorZ_ok(arg_conv);
4493         return (long)ret_conv;
4494 }
4495
4496 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4497         LDKSecp256k1Error arg_conv = *(LDKSecp256k1Error*)arg;
4498         FREE((void*)arg);
4499         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
4500         *ret_conv = CResult_SecretKeySecpErrorZ_err(arg_conv);
4501         return (long)ret_conv;
4502 }
4503
4504 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4505         LDKCResult_SecretKeySecpErrorZ arg_conv = *(LDKCResult_SecretKeySecpErrorZ*)arg;
4506         FREE((void*)arg);
4507         CResult_SecretKeySecpErrorZ_free(arg_conv);
4508 }
4509
4510 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) {
4511         LDKSecretKey arg_ref;
4512         CHECK((*_env)->GetArrayLength (_env, arg) == 32);
4513         (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.bytes);
4514         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
4515         *ret_conv = CResult_SecretKeySecpErrorZ_ok(arg_ref);
4516         return (long)ret_conv;
4517 }
4518
4519 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4520         LDKCResult_SignatureNoneZ arg_conv = *(LDKCResult_SignatureNoneZ*)arg;
4521         FREE((void*)arg);
4522         CResult_SignatureNoneZ_free(arg_conv);
4523 }
4524
4525 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) {
4526         LDKSignature arg_ref;
4527         CHECK((*_env)->GetArrayLength (_env, arg) == 64);
4528         (*_env)->GetByteArrayRegion (_env, arg, 0, 64, arg_ref.compact_form);
4529         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
4530         *ret_conv = CResult_SignatureNoneZ_ok(arg_ref);
4531         return (long)ret_conv;
4532 }
4533
4534 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4535         LDKSecp256k1Error arg_conv = *(LDKSecp256k1Error*)arg;
4536         FREE((void*)arg);
4537         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
4538         *ret_conv = CResult_TxCreationKeysSecpErrorZ_err(arg_conv);
4539         return (long)ret_conv;
4540 }
4541
4542 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4543         LDKCResult_TxCreationKeysSecpErrorZ arg_conv = *(LDKCResult_TxCreationKeysSecpErrorZ*)arg;
4544         FREE((void*)arg);
4545         CResult_TxCreationKeysSecpErrorZ_free(arg_conv);
4546 }
4547
4548 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1ok(JNIEnv * _env, jclass _b, jlong arg) {
4549         LDKTxCreationKeys arg_conv = *(LDKTxCreationKeys*)arg;
4550         FREE((void*)arg);
4551         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
4552         *ret_conv = CResult_TxCreationKeysSecpErrorZ_ok(arg_conv);
4553         return (long)ret_conv;
4554 }
4555
4556 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1err(JNIEnv * _env, jclass _b, jclass arg) {
4557         LDKAccessError arg_conv = *(LDKAccessError*)arg;
4558         FREE((void*)arg);
4559         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
4560         *ret_conv = CResult_TxOutAccessErrorZ_err(arg_conv);
4561         return (long)ret_conv;
4562 }
4563
4564 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4565         LDKCResult_TxOutAccessErrorZ arg_conv = *(LDKCResult_TxOutAccessErrorZ*)arg;
4566         FREE((void*)arg);
4567         CResult_TxOutAccessErrorZ_free(arg_conv);
4568 }
4569
4570 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1ok(JNIEnv * _env, jclass _b, jlong arg) {
4571         LDKTxOut arg_conv = *(LDKTxOut*)arg;
4572         FREE((void*)arg);
4573         LDKCResult_TxOutAccessErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
4574         *ret_conv = CResult_TxOutAccessErrorZ_ok(arg_conv);
4575         return (long)ret_conv;
4576 }
4577
4578 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4579         LDKLightningError arg_conv = *(LDKLightningError*)arg;
4580         FREE((void*)arg);
4581         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4582         *ret_conv = CResult_boolLightningErrorZ_err(arg_conv);
4583         return (long)ret_conv;
4584 }
4585
4586 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4587         LDKCResult_boolLightningErrorZ arg_conv = *(LDKCResult_boolLightningErrorZ*)arg;
4588         FREE((void*)arg);
4589         CResult_boolLightningErrorZ_free(arg_conv);
4590 }
4591
4592 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolLightningErrorZ_1ok(JNIEnv * _env, jclass _b, jboolean arg) {
4593         LDKCResult_boolLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
4594         *ret_conv = CResult_boolLightningErrorZ_ok(arg);
4595         return (long)ret_conv;
4596 }
4597
4598 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1err(JNIEnv * _env, jclass _b, jlong arg) {
4599         LDKPeerHandleError arg_conv = *(LDKPeerHandleError*)arg;
4600         FREE((void*)arg);
4601         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
4602         *ret_conv = CResult_boolPeerHandleErrorZ_err(arg_conv);
4603         return (long)ret_conv;
4604 }
4605
4606 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1free(JNIEnv * _env, jclass _b, jlong arg) {
4607         LDKCResult_boolPeerHandleErrorZ arg_conv = *(LDKCResult_boolPeerHandleErrorZ*)arg;
4608         FREE((void*)arg);
4609         CResult_boolPeerHandleErrorZ_free(arg_conv);
4610 }
4611
4612 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1boolPeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b, jboolean arg) {
4613         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
4614         *ret_conv = CResult_boolPeerHandleErrorZ_ok(arg);
4615         return (long)ret_conv;
4616 }
4617
4618 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1HTLCOutputInCommitmentSignatureZZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4619         LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ arg_constr;
4620         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4621         if (arg_constr.datalen > 0)
4622                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ), "LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ Elements");
4623         else
4624                 arg_constr.data = NULL;
4625         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4626         for (size_t q = 0; q < arg_constr.datalen; q++) {
4627                 long arr_conv_42 = arg_vals[q];
4628                 LDKC2Tuple_HTLCOutputInCommitmentSignatureZ arr_conv_42_conv = *(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ*)arr_conv_42;
4629                 FREE((void*)arr_conv_42);
4630                 arg_constr.data[q] = arr_conv_42_conv;
4631         }
4632         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4633         CVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ_free(arg_constr);
4634 }
4635
4636 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1TxidCVec_1TxOutZZZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4637         LDKCVec_C2Tuple_TxidCVec_TxOutZZZ arg_constr;
4638         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4639         if (arg_constr.datalen > 0)
4640                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC2Tuple_TxidCVec_TxOutZZ), "LDKCVec_C2Tuple_TxidCVec_TxOutZZZ Elements");
4641         else
4642                 arg_constr.data = NULL;
4643         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4644         for (size_t b = 0; b < arg_constr.datalen; b++) {
4645                 long arr_conv_27 = arg_vals[b];
4646                 LDKC2Tuple_TxidCVec_TxOutZZ arr_conv_27_conv = *(LDKC2Tuple_TxidCVec_TxOutZZ*)arr_conv_27;
4647                 FREE((void*)arr_conv_27);
4648                 arg_constr.data[b] = arr_conv_27_conv;
4649         }
4650         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4651         CVec_C2Tuple_TxidCVec_TxOutZZZ_free(arg_constr);
4652 }
4653
4654 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1usizeTransactionZZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4655         LDKCVec_C2Tuple_usizeTransactionZZ arg_constr;
4656         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4657         if (arg_constr.datalen > 0)
4658                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
4659         else
4660                 arg_constr.data = NULL;
4661         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4662         for (size_t d = 0; d < arg_constr.datalen; d++) {
4663                 long arr_conv_29 = arg_vals[d];
4664                 LDKC2Tuple_usizeTransactionZ arr_conv_29_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_29;
4665                 FREE((void*)arr_conv_29);
4666                 arg_constr.data[d] = arr_conv_29_conv;
4667         }
4668         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4669         CVec_C2Tuple_usizeTransactionZZ_free(arg_constr);
4670 }
4671
4672 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4673         LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ arg_constr;
4674         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4675         if (arg_constr.datalen > 0)
4676                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ Elements");
4677         else
4678                 arg_constr.data = NULL;
4679         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4680         for (size_t l = 0; l < arg_constr.datalen; l++) {
4681                 long arr_conv_63 = arg_vals[l];
4682                 LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ arr_conv_63_conv = *(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ*)arr_conv_63;
4683                 FREE((void*)arr_conv_63);
4684                 arg_constr.data[l] = arr_conv_63_conv;
4685         }
4686         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4687         CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(arg_constr);
4688 }
4689
4690 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1CVec_1RouteHopZZ_1free(JNIEnv * _env, jclass _b, jobjectArray arg) {
4691         LDKCVec_CVec_RouteHopZZ arg_constr;
4692         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4693         if (arg_constr.datalen > 0)
4694                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
4695         else
4696                 arg_constr.data = NULL;
4697         for (size_t m = 0; m < arg_constr.datalen; m++) {
4698                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, arg, m);
4699                 LDKCVec_RouteHopZ arr_conv_12_constr;
4700                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
4701                 if (arr_conv_12_constr.datalen > 0)
4702                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
4703                 else
4704                         arr_conv_12_constr.data = NULL;
4705                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
4706                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
4707                         long arr_conv_10 = arr_conv_12_vals[k];
4708                         LDKRouteHop arr_conv_10_conv;
4709                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
4710                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
4711                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
4712                 }
4713                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
4714                 arg_constr.data[m] = arr_conv_12_constr;
4715         }
4716         CVec_CVec_RouteHopZZ_free(arg_constr);
4717 }
4718
4719 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelDetailsZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4720         LDKCVec_ChannelDetailsZ arg_constr;
4721         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4722         if (arg_constr.datalen > 0)
4723                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
4724         else
4725                 arg_constr.data = NULL;
4726         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4727         for (size_t q = 0; q < arg_constr.datalen; q++) {
4728                 long arr_conv_16 = arg_vals[q];
4729                 LDKChannelDetails arr_conv_16_conv;
4730                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
4731                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
4732                 arg_constr.data[q] = arr_conv_16_conv;
4733         }
4734         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4735         CVec_ChannelDetailsZ_free(arg_constr);
4736 }
4737
4738 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1ChannelMonitorZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4739         LDKCVec_ChannelMonitorZ arg_constr;
4740         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4741         if (arg_constr.datalen > 0)
4742                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
4743         else
4744                 arg_constr.data = NULL;
4745         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4746         for (size_t q = 0; q < arg_constr.datalen; q++) {
4747                 long arr_conv_16 = arg_vals[q];
4748                 LDKChannelMonitor arr_conv_16_conv;
4749                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
4750                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
4751                 arg_constr.data[q] = arr_conv_16_conv;
4752         }
4753         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4754         CVec_ChannelMonitorZ_free(arg_constr);
4755 }
4756
4757 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1EventZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4758         LDKCVec_EventZ arg_constr;
4759         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4760         if (arg_constr.datalen > 0)
4761                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKEvent), "LDKCVec_EventZ Elements");
4762         else
4763                 arg_constr.data = NULL;
4764         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4765         for (size_t h = 0; h < arg_constr.datalen; h++) {
4766                 long arr_conv_7 = arg_vals[h];
4767                 LDKEvent arr_conv_7_conv = *(LDKEvent*)arr_conv_7;
4768                 FREE((void*)arr_conv_7);
4769                 arg_constr.data[h] = arr_conv_7_conv;
4770         }
4771         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4772         CVec_EventZ_free(arg_constr);
4773 }
4774
4775 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1HTLCOutputInCommitmentZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4776         LDKCVec_HTLCOutputInCommitmentZ arg_constr;
4777         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4778         if (arg_constr.datalen > 0)
4779                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKHTLCOutputInCommitment), "LDKCVec_HTLCOutputInCommitmentZ Elements");
4780         else
4781                 arg_constr.data = NULL;
4782         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4783         for (size_t y = 0; y < arg_constr.datalen; y++) {
4784                 long arr_conv_24 = arg_vals[y];
4785                 LDKHTLCOutputInCommitment arr_conv_24_conv;
4786                 arr_conv_24_conv.inner = (void*)(arr_conv_24 & (~1));
4787                 arr_conv_24_conv.is_owned = (arr_conv_24 & 1) || (arr_conv_24 == 0);
4788                 arg_constr.data[y] = arr_conv_24_conv;
4789         }
4790         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4791         CVec_HTLCOutputInCommitmentZ_free(arg_constr);
4792 }
4793
4794 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MessageSendEventZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4795         LDKCVec_MessageSendEventZ arg_constr;
4796         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4797         if (arg_constr.datalen > 0)
4798                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMessageSendEvent), "LDKCVec_MessageSendEventZ Elements");
4799         else
4800                 arg_constr.data = NULL;
4801         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4802         for (size_t s = 0; s < arg_constr.datalen; s++) {
4803                 long arr_conv_18 = arg_vals[s];
4804                 LDKMessageSendEvent arr_conv_18_conv = *(LDKMessageSendEvent*)arr_conv_18;
4805                 FREE((void*)arr_conv_18);
4806                 arg_constr.data[s] = arr_conv_18_conv;
4807         }
4808         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4809         CVec_MessageSendEventZ_free(arg_constr);
4810 }
4811
4812 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1MonitorEventZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4813         LDKCVec_MonitorEventZ arg_constr;
4814         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4815         if (arg_constr.datalen > 0)
4816                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKMonitorEvent), "LDKCVec_MonitorEventZ Elements");
4817         else
4818                 arg_constr.data = NULL;
4819         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4820         for (size_t o = 0; o < arg_constr.datalen; o++) {
4821                 long arr_conv_14 = arg_vals[o];
4822                 LDKMonitorEvent arr_conv_14_conv;
4823                 arr_conv_14_conv.inner = (void*)(arr_conv_14 & (~1));
4824                 arr_conv_14_conv.is_owned = (arr_conv_14 & 1) || (arr_conv_14 == 0);
4825                 arg_constr.data[o] = arr_conv_14_conv;
4826         }
4827         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4828         CVec_MonitorEventZ_free(arg_constr);
4829 }
4830
4831 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NetAddressZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4832         LDKCVec_NetAddressZ arg_constr;
4833         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4834         if (arg_constr.datalen > 0)
4835                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
4836         else
4837                 arg_constr.data = NULL;
4838         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4839         for (size_t m = 0; m < arg_constr.datalen; m++) {
4840                 long arr_conv_12 = arg_vals[m];
4841                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
4842                 FREE((void*)arr_conv_12);
4843                 arg_constr.data[m] = arr_conv_12_conv;
4844         }
4845         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4846         CVec_NetAddressZ_free(arg_constr);
4847 }
4848
4849 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1NodeAnnouncementZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4850         LDKCVec_NodeAnnouncementZ arg_constr;
4851         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4852         if (arg_constr.datalen > 0)
4853                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKNodeAnnouncement), "LDKCVec_NodeAnnouncementZ Elements");
4854         else
4855                 arg_constr.data = NULL;
4856         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4857         for (size_t s = 0; s < arg_constr.datalen; s++) {
4858                 long arr_conv_18 = arg_vals[s];
4859                 LDKNodeAnnouncement arr_conv_18_conv;
4860                 arr_conv_18_conv.inner = (void*)(arr_conv_18 & (~1));
4861                 arr_conv_18_conv.is_owned = (arr_conv_18 & 1) || (arr_conv_18 == 0);
4862                 arg_constr.data[s] = arr_conv_18_conv;
4863         }
4864         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4865         CVec_NodeAnnouncementZ_free(arg_constr);
4866 }
4867
4868 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1PublicKeyZ_1free(JNIEnv * _env, jclass _b, jobjectArray arg) {
4869         LDKCVec_PublicKeyZ arg_constr;
4870         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4871         if (arg_constr.datalen > 0)
4872                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKPublicKey), "LDKCVec_PublicKeyZ Elements");
4873         else
4874                 arg_constr.data = NULL;
4875         for (size_t i = 0; i < arg_constr.datalen; i++) {
4876                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, arg, i);
4877                 LDKPublicKey arr_conv_8_ref;
4878                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 33);
4879                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 33, arr_conv_8_ref.compressed_form);
4880                 arg_constr.data[i] = arr_conv_8_ref;
4881         }
4882         CVec_PublicKeyZ_free(arg_constr);
4883 }
4884
4885 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHintZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4886         LDKCVec_RouteHintZ arg_constr;
4887         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4888         if (arg_constr.datalen > 0)
4889                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
4890         else
4891                 arg_constr.data = NULL;
4892         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4893         for (size_t l = 0; l < arg_constr.datalen; l++) {
4894                 long arr_conv_11 = arg_vals[l];
4895                 LDKRouteHint arr_conv_11_conv;
4896                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
4897                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
4898                 arg_constr.data[l] = arr_conv_11_conv;
4899         }
4900         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4901         CVec_RouteHintZ_free(arg_constr);
4902 }
4903
4904 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1RouteHopZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4905         LDKCVec_RouteHopZ arg_constr;
4906         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4907         if (arg_constr.datalen > 0)
4908                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
4909         else
4910                 arg_constr.data = NULL;
4911         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4912         for (size_t k = 0; k < arg_constr.datalen; k++) {
4913                 long arr_conv_10 = arg_vals[k];
4914                 LDKRouteHop arr_conv_10_conv;
4915                 arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
4916                 arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
4917                 arg_constr.data[k] = arr_conv_10_conv;
4918         }
4919         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4920         CVec_RouteHopZ_free(arg_constr);
4921 }
4922
4923 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SignatureZ_1free(JNIEnv * _env, jclass _b, jobjectArray arg) {
4924         LDKCVec_SignatureZ arg_constr;
4925         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4926         if (arg_constr.datalen > 0)
4927                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
4928         else
4929                 arg_constr.data = NULL;
4930         for (size_t i = 0; i < arg_constr.datalen; i++) {
4931                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, arg, i);
4932                 LDKSignature arr_conv_8_ref;
4933                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
4934                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
4935                 arg_constr.data[i] = arr_conv_8_ref;
4936         }
4937         CVec_SignatureZ_free(arg_constr);
4938 }
4939
4940 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SpendableOutputDescriptorZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4941         LDKCVec_SpendableOutputDescriptorZ arg_constr;
4942         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4943         if (arg_constr.datalen > 0)
4944                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKSpendableOutputDescriptor), "LDKCVec_SpendableOutputDescriptorZ Elements");
4945         else
4946                 arg_constr.data = NULL;
4947         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4948         for (size_t b = 0; b < arg_constr.datalen; b++) {
4949                 long arr_conv_27 = arg_vals[b];
4950                 LDKSpendableOutputDescriptor arr_conv_27_conv = *(LDKSpendableOutputDescriptor*)arr_conv_27;
4951                 FREE((void*)arr_conv_27);
4952                 arg_constr.data[b] = arr_conv_27_conv;
4953         }
4954         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4955         CVec_SpendableOutputDescriptorZ_free(arg_constr);
4956 }
4957
4958 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TransactionZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4959         LDKCVec_TransactionZ arg_constr;
4960         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4961         if (arg_constr.datalen > 0)
4962                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKTransaction), "LDKCVec_TransactionZ Elements");
4963         else
4964                 arg_constr.data = NULL;
4965         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4966         for (size_t n = 0; n < arg_constr.datalen; n++) {
4967                 long arr_conv_13 = arg_vals[n];
4968                 LDKTransaction arr_conv_13_conv = *(LDKTransaction*)arr_conv_13;
4969                 arg_constr.data[n] = arr_conv_13_conv;
4970         }
4971         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4972         CVec_TransactionZ_free(arg_constr);
4973 }
4974
4975 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TxOutZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4976         LDKCVec_TxOutZ arg_constr;
4977         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4978         if (arg_constr.datalen > 0)
4979                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKTxOut), "LDKCVec_TxOutZ Elements");
4980         else
4981                 arg_constr.data = NULL;
4982         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
4983         for (size_t h = 0; h < arg_constr.datalen; h++) {
4984                 long arr_conv_7 = arg_vals[h];
4985                 LDKTxOut arr_conv_7_conv = *(LDKTxOut*)arr_conv_7;
4986                 FREE((void*)arr_conv_7);
4987                 arg_constr.data[h] = arr_conv_7_conv;
4988         }
4989         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
4990         CVec_TxOutZ_free(arg_constr);
4991 }
4992
4993 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateAddHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
4994         LDKCVec_UpdateAddHTLCZ arg_constr;
4995         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
4996         if (arg_constr.datalen > 0)
4997                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
4998         else
4999                 arg_constr.data = NULL;
5000         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5001         for (size_t p = 0; p < arg_constr.datalen; p++) {
5002                 long arr_conv_15 = arg_vals[p];
5003                 LDKUpdateAddHTLC arr_conv_15_conv;
5004                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
5005                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
5006                 arg_constr.data[p] = arr_conv_15_conv;
5007         }
5008         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5009         CVec_UpdateAddHTLCZ_free(arg_constr);
5010 }
5011
5012 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5013         LDKCVec_UpdateFailHTLCZ arg_constr;
5014         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5015         if (arg_constr.datalen > 0)
5016                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
5017         else
5018                 arg_constr.data = NULL;
5019         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5020         for (size_t q = 0; q < arg_constr.datalen; q++) {
5021                 long arr_conv_16 = arg_vals[q];
5022                 LDKUpdateFailHTLC arr_conv_16_conv;
5023                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
5024                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
5025                 arg_constr.data[q] = arr_conv_16_conv;
5026         }
5027         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5028         CVec_UpdateFailHTLCZ_free(arg_constr);
5029 }
5030
5031 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFailMalformedHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5032         LDKCVec_UpdateFailMalformedHTLCZ arg_constr;
5033         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5034         if (arg_constr.datalen > 0)
5035                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
5036         else
5037                 arg_constr.data = NULL;
5038         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5039         for (size_t z = 0; z < arg_constr.datalen; z++) {
5040                 long arr_conv_25 = arg_vals[z];
5041                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
5042                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
5043                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
5044                 arg_constr.data[z] = arr_conv_25_conv;
5045         }
5046         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5047         CVec_UpdateFailMalformedHTLCZ_free(arg_constr);
5048 }
5049
5050 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1UpdateFulfillHTLCZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5051         LDKCVec_UpdateFulfillHTLCZ arg_constr;
5052         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5053         if (arg_constr.datalen > 0)
5054                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
5055         else
5056                 arg_constr.data = NULL;
5057         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5058         for (size_t t = 0; t < arg_constr.datalen; t++) {
5059                 long arr_conv_19 = arg_vals[t];
5060                 LDKUpdateFulfillHTLC arr_conv_19_conv;
5061                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
5062                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
5063                 arg_constr.data[t] = arr_conv_19_conv;
5064         }
5065         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5066         CVec_UpdateFulfillHTLCZ_free(arg_constr);
5067 }
5068
5069 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u64Z_1free(JNIEnv * _env, jclass _b, jlongArray arg) {
5070         LDKCVec_u64Z arg_constr;
5071         arg_constr.datalen = (*_env)->GetArrayLength (_env, arg);
5072         if (arg_constr.datalen > 0)
5073                 arg_constr.data = MALLOC(arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
5074         else
5075                 arg_constr.data = NULL;
5076         long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL);
5077         for (size_t g = 0; g < arg_constr.datalen; g++) {
5078                 long arr_conv_6 = arg_vals[g];
5079                 arg_constr.data[g] = arr_conv_6;
5080         }
5081         (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
5082         CVec_u64Z_free(arg_constr);
5083 }
5084
5085 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u8Z_1free(JNIEnv * _env, jclass _b, jbyteArray arg) {
5086         LDKCVec_u8Z arg_ref;
5087         arg_ref.data = (*_env)->GetByteArrayElements (_env, arg, NULL);
5088         arg_ref.datalen = (*_env)->GetArrayLength (_env, arg);
5089         CVec_u8Z_free(arg_ref);
5090         (*_env)->ReleaseByteArrayElements(_env, arg, (int8_t*)arg_ref.data, 0);
5091 }
5092
5093 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Transaction_1free(JNIEnv * _env, jclass _b, jlong _res) {
5094         LDKTransaction _res_conv = *(LDKTransaction*)_res;
5095         Transaction_free(_res_conv);
5096 }
5097
5098 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxOut_1free(JNIEnv * _env, jclass _b, jlong _res) {
5099         LDKTxOut _res_conv = *(LDKTxOut*)_res;
5100         FREE((void*)_res);
5101         TxOut_free(_res_conv);
5102 }
5103
5104 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1new(JNIEnv * _env, jclass _b, jlong a, jlong b) {
5105         LDKTransaction b_conv = *(LDKTransaction*)b;
5106         LDKC2Tuple_usizeTransactionZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
5107         *ret_ref = C2Tuple_usizeTransactionZ_new(a, b_conv);
5108         return (long)ret_ref;
5109 }
5110
5111 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1ok(JNIEnv * _env, jclass _b) {
5112         LDKCResult_NoneChannelMonitorUpdateErrZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
5113         *ret_conv = CResult_NoneChannelMonitorUpdateErrZ_ok();
5114         return (long)ret_conv;
5115 }
5116
5117 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneMonitorUpdateErrorZ_1ok(JNIEnv * _env, jclass _b) {
5118         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
5119         *ret_conv = CResult_NoneMonitorUpdateErrorZ_ok();
5120         return (long)ret_conv;
5121 }
5122
5123 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1new(JNIEnv * _env, jclass _b, jlong a, jbyteArray b) {
5124         LDKOutPoint a_conv;
5125         a_conv.inner = (void*)(a & (~1));
5126         a_conv.is_owned = (a & 1) || (a == 0);
5127         if (a_conv.inner != NULL)
5128                 a_conv = OutPoint_clone(&a_conv);
5129         LDKCVec_u8Z b_ref;
5130         b_ref.data = (*_env)->GetByteArrayElements (_env, b, NULL);
5131         b_ref.datalen = (*_env)->GetArrayLength (_env, b);
5132         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
5133         *ret_ref = C2Tuple_OutPointScriptZ_new(a_conv, b_ref);
5134         (*_env)->ReleaseByteArrayElements(_env, b, (int8_t*)b_ref.data, 0);
5135         return (long)ret_ref;
5136 }
5137
5138 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1TxidCVec_1TxOutZZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jlongArray b) {
5139         LDKThirtyTwoBytes a_ref;
5140         CHECK((*_env)->GetArrayLength (_env, a) == 32);
5141         (*_env)->GetByteArrayRegion (_env, a, 0, 32, a_ref.data);
5142         LDKCVec_TxOutZ b_constr;
5143         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
5144         if (b_constr.datalen > 0)
5145                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKTxOut), "LDKCVec_TxOutZ Elements");
5146         else
5147                 b_constr.data = NULL;
5148         long* b_vals = (*_env)->GetLongArrayElements (_env, b, NULL);
5149         for (size_t h = 0; h < b_constr.datalen; h++) {
5150                 long arr_conv_7 = b_vals[h];
5151                 LDKTxOut arr_conv_7_conv = *(LDKTxOut*)arr_conv_7;
5152                 FREE((void*)arr_conv_7);
5153                 b_constr.data[h] = arr_conv_7_conv;
5154         }
5155         (*_env)->ReleaseLongArrayElements (_env, b, b_vals, 0);
5156         LDKC2Tuple_TxidCVec_TxOutZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_TxOutZZ), "LDKC2Tuple_TxidCVec_TxOutZZ");
5157         *ret_ref = C2Tuple_TxidCVec_TxOutZZ_new(a_ref, b_constr);
5158         return (long)ret_ref;
5159 }
5160
5161 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1u64u64Z_1new(JNIEnv * _env, jclass _b, jlong a, jlong b) {
5162         LDKC2Tuple_u64u64Z* ret_ref = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
5163         *ret_ref = C2Tuple_u64u64Z_new(a, b);
5164         return (long)ret_ref;
5165 }
5166
5167 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1SignatureCVec_1SignatureZZ_1new(JNIEnv * _env, jclass _b, jbyteArray a, jobjectArray b) {
5168         LDKSignature a_ref;
5169         CHECK((*_env)->GetArrayLength (_env, a) == 64);
5170         (*_env)->GetByteArrayRegion (_env, a, 0, 64, a_ref.compact_form);
5171         LDKCVec_SignatureZ b_constr;
5172         b_constr.datalen = (*_env)->GetArrayLength (_env, b);
5173         if (b_constr.datalen > 0)
5174                 b_constr.data = MALLOC(b_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
5175         else
5176                 b_constr.data = NULL;
5177         for (size_t i = 0; i < b_constr.datalen; i++) {
5178                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, b, i);
5179                 LDKSignature arr_conv_8_ref;
5180                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
5181                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
5182                 b_constr.data[i] = arr_conv_8_ref;
5183         }
5184         LDKC2Tuple_SignatureCVec_SignatureZZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_SignatureCVec_SignatureZZ), "LDKC2Tuple_SignatureCVec_SignatureZZ");
5185         *ret_ref = C2Tuple_SignatureCVec_SignatureZZ_new(a_ref, b_constr);
5186         return (long)ret_ref;
5187 }
5188
5189 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1C2Tuple_1SignatureCVec_1SignatureZZNoneZ_1err(JNIEnv * _env, jclass _b) {
5190         LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
5191         *ret_conv = CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err();
5192         return (long)ret_conv;
5193 }
5194
5195 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1err(JNIEnv * _env, jclass _b) {
5196         LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
5197         *ret_conv = CResult_SignatureNoneZ_err();
5198         return (long)ret_conv;
5199 }
5200
5201 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1SignatureZNoneZ_1err(JNIEnv * _env, jclass _b) {
5202         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
5203         *ret_conv = CResult_CVec_SignatureZNoneZ_err();
5204         return (long)ret_conv;
5205 }
5206
5207 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1ok(JNIEnv * _env, jclass _b) {
5208         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
5209         *ret_conv = CResult_NoneAPIErrorZ_ok();
5210         return (long)ret_conv;
5211 }
5212
5213 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePaymentSendFailureZ_1ok(JNIEnv * _env, jclass _b) {
5214         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
5215         *ret_conv = CResult_NonePaymentSendFailureZ_ok();
5216         return (long)ret_conv;
5217 }
5218
5219 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementChannelUpdateChannelUpdateZ_1new(JNIEnv * _env, jclass _b, jlong a, jlong b, jlong c) {
5220         LDKChannelAnnouncement a_conv;
5221         a_conv.inner = (void*)(a & (~1));
5222         a_conv.is_owned = (a & 1) || (a == 0);
5223         if (a_conv.inner != NULL)
5224                 a_conv = ChannelAnnouncement_clone(&a_conv);
5225         LDKChannelUpdate b_conv;
5226         b_conv.inner = (void*)(b & (~1));
5227         b_conv.is_owned = (b & 1) || (b == 0);
5228         if (b_conv.inner != NULL)
5229                 b_conv = ChannelUpdate_clone(&b_conv);
5230         LDKChannelUpdate c_conv;
5231         c_conv.inner = (void*)(c & (~1));
5232         c_conv.is_owned = (c & 1) || (c == 0);
5233         if (c_conv.inner != NULL)
5234                 c_conv = ChannelUpdate_clone(&c_conv);
5235         LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret_ref = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
5236         *ret_ref = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(a_conv, b_conv, c_conv);
5237         return (long)ret_ref;
5238 }
5239
5240 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b) {
5241         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
5242         *ret_conv = CResult_NonePeerHandleErrorZ_ok();
5243         return (long)ret_conv;
5244 }
5245
5246 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1HTLCOutputInCommitmentSignatureZ_1new(JNIEnv * _env, jclass _b, jlong a, jbyteArray b) {
5247         LDKHTLCOutputInCommitment a_conv;
5248         a_conv.inner = (void*)(a & (~1));
5249         a_conv.is_owned = (a & 1) || (a == 0);
5250         if (a_conv.inner != NULL)
5251                 a_conv = HTLCOutputInCommitment_clone(&a_conv);
5252         LDKSignature b_ref;
5253         CHECK((*_env)->GetArrayLength (_env, b) == 64);
5254         (*_env)->GetByteArrayRegion (_env, b, 0, 64, b_ref.compact_form);
5255         LDKC2Tuple_HTLCOutputInCommitmentSignatureZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ), "LDKC2Tuple_HTLCOutputInCommitmentSignatureZ");
5256         *ret_ref = C2Tuple_HTLCOutputInCommitmentSignatureZ_new(a_conv, b_ref);
5257         return (long)ret_ref;
5258 }
5259
5260 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Event_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5261         LDKEvent this_ptr_conv = *(LDKEvent*)this_ptr;
5262         FREE((void*)this_ptr);
5263         Event_free(this_ptr_conv);
5264 }
5265
5266 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Event_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5267         LDKEvent* orig_conv = (LDKEvent*)orig;
5268         LDKEvent *ret_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
5269         *ret_copy = Event_clone(orig_conv);
5270         long ret_ref = (long)ret_copy;
5271         return ret_ref;
5272 }
5273
5274 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5275         LDKMessageSendEvent this_ptr_conv = *(LDKMessageSendEvent*)this_ptr;
5276         FREE((void*)this_ptr);
5277         MessageSendEvent_free(this_ptr_conv);
5278 }
5279
5280 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5281         LDKMessageSendEvent* orig_conv = (LDKMessageSendEvent*)orig;
5282         LDKMessageSendEvent *ret_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent");
5283         *ret_copy = MessageSendEvent_clone(orig_conv);
5284         long ret_ref = (long)ret_copy;
5285         return ret_ref;
5286 }
5287
5288 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5289         LDKMessageSendEventsProvider this_ptr_conv = *(LDKMessageSendEventsProvider*)this_ptr;
5290         FREE((void*)this_ptr);
5291         MessageSendEventsProvider_free(this_ptr_conv);
5292 }
5293
5294 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_EventsProvider_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5295         LDKEventsProvider this_ptr_conv = *(LDKEventsProvider*)this_ptr;
5296         FREE((void*)this_ptr);
5297         EventsProvider_free(this_ptr_conv);
5298 }
5299
5300 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_APIError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5301         LDKAPIError this_ptr_conv = *(LDKAPIError*)this_ptr;
5302         FREE((void*)this_ptr);
5303         APIError_free(this_ptr_conv);
5304 }
5305
5306 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_APIError_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5307         LDKAPIError* orig_conv = (LDKAPIError*)orig;
5308         LDKAPIError *ret_copy = MALLOC(sizeof(LDKAPIError), "LDKAPIError");
5309         *ret_copy = APIError_clone(orig_conv);
5310         long ret_ref = (long)ret_copy;
5311         return ret_ref;
5312 }
5313
5314 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5315         LDKLevel* orig_conv = (LDKLevel*)orig;
5316         jclass ret_conv = LDKLevel_to_java(_env, Level_clone(orig_conv));
5317         return ret_conv;
5318 }
5319
5320 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1max(JNIEnv * _env, jclass _b) {
5321         jclass ret_conv = LDKLevel_to_java(_env, Level_max());
5322         return ret_conv;
5323 }
5324
5325 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Logger_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5326         LDKLogger this_ptr_conv = *(LDKLogger*)this_ptr;
5327         FREE((void*)this_ptr);
5328         Logger_free(this_ptr_conv);
5329 }
5330
5331 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5332         LDKChannelHandshakeConfig this_ptr_conv;
5333         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5334         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5335         ChannelHandshakeConfig_free(this_ptr_conv);
5336 }
5337
5338 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5339         LDKChannelHandshakeConfig orig_conv;
5340         orig_conv.inner = (void*)(orig & (~1));
5341         orig_conv.is_owned = (orig & 1) || (orig == 0);
5342         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_clone(&orig_conv);
5343         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5344         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5345         long ret_ref = (long)ret_var.inner;
5346         if (ret_var.is_owned) {
5347                 ret_ref |= 1;
5348         }
5349         return ret_ref;
5350 }
5351
5352 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
5353         LDKChannelHandshakeConfig this_ptr_conv;
5354         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5355         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5356         jint ret_val = ChannelHandshakeConfig_get_minimum_depth(&this_ptr_conv);
5357         return ret_val;
5358 }
5359
5360 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
5361         LDKChannelHandshakeConfig this_ptr_conv;
5362         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5363         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5364         ChannelHandshakeConfig_set_minimum_depth(&this_ptr_conv, val);
5365 }
5366
5367 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
5368         LDKChannelHandshakeConfig this_ptr_conv;
5369         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5370         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5371         jshort ret_val = ChannelHandshakeConfig_get_our_to_self_delay(&this_ptr_conv);
5372         return ret_val;
5373 }
5374
5375 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1our_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
5376         LDKChannelHandshakeConfig this_ptr_conv;
5377         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5378         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5379         ChannelHandshakeConfig_set_our_to_self_delay(&this_ptr_conv, val);
5380 }
5381
5382 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1get_1our_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
5383         LDKChannelHandshakeConfig this_ptr_conv;
5384         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5385         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5386         jlong ret_val = ChannelHandshakeConfig_get_our_htlc_minimum_msat(&this_ptr_conv);
5387         return ret_val;
5388 }
5389
5390 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1set_1our_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5391         LDKChannelHandshakeConfig this_ptr_conv;
5392         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5393         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5394         ChannelHandshakeConfig_set_our_htlc_minimum_msat(&this_ptr_conv, val);
5395 }
5396
5397 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) {
5398         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_new(minimum_depth_arg, our_to_self_delay_arg, our_htlc_minimum_msat_arg);
5399         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5400         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5401         long ret_ref = (long)ret_var.inner;
5402         if (ret_var.is_owned) {
5403                 ret_ref |= 1;
5404         }
5405         return ret_ref;
5406 }
5407
5408 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeConfig_1default(JNIEnv * _env, jclass _b) {
5409         LDKChannelHandshakeConfig ret_var = ChannelHandshakeConfig_default();
5410         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5411         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5412         long ret_ref = (long)ret_var.inner;
5413         if (ret_var.is_owned) {
5414                 ret_ref |= 1;
5415         }
5416         return ret_ref;
5417 }
5418
5419 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5420         LDKChannelHandshakeLimits this_ptr_conv;
5421         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5422         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5423         ChannelHandshakeLimits_free(this_ptr_conv);
5424 }
5425
5426 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5427         LDKChannelHandshakeLimits orig_conv;
5428         orig_conv.inner = (void*)(orig & (~1));
5429         orig_conv.is_owned = (orig & 1) || (orig == 0);
5430         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_clone(&orig_conv);
5431         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5432         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5433         long ret_ref = (long)ret_var.inner;
5434         if (ret_var.is_owned) {
5435                 ret_ref |= 1;
5436         }
5437         return ret_ref;
5438 }
5439
5440 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
5441         LDKChannelHandshakeLimits this_ptr_conv;
5442         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5443         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5444         jlong ret_val = ChannelHandshakeLimits_get_min_funding_satoshis(&this_ptr_conv);
5445         return ret_val;
5446 }
5447
5448 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5449         LDKChannelHandshakeLimits this_ptr_conv;
5450         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5451         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5452         ChannelHandshakeLimits_set_min_funding_satoshis(&this_ptr_conv, val);
5453 }
5454
5455 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
5456         LDKChannelHandshakeLimits this_ptr_conv;
5457         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5458         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5459         jlong ret_val = ChannelHandshakeLimits_get_max_htlc_minimum_msat(&this_ptr_conv);
5460         return ret_val;
5461 }
5462
5463 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5464         LDKChannelHandshakeLimits this_ptr_conv;
5465         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5466         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5467         ChannelHandshakeLimits_set_max_htlc_minimum_msat(&this_ptr_conv, val);
5468 }
5469
5470 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
5471         LDKChannelHandshakeLimits this_ptr_conv;
5472         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5473         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5474         jlong ret_val = ChannelHandshakeLimits_get_min_max_htlc_value_in_flight_msat(&this_ptr_conv);
5475         return ret_val;
5476 }
5477
5478 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) {
5479         LDKChannelHandshakeLimits this_ptr_conv;
5480         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5481         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5482         ChannelHandshakeLimits_set_min_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
5483 }
5484
5485 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
5486         LDKChannelHandshakeLimits this_ptr_conv;
5487         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5488         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5489         jlong ret_val = ChannelHandshakeLimits_get_max_channel_reserve_satoshis(&this_ptr_conv);
5490         return ret_val;
5491 }
5492
5493 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5494         LDKChannelHandshakeLimits this_ptr_conv;
5495         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5496         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5497         ChannelHandshakeLimits_set_max_channel_reserve_satoshis(&this_ptr_conv, val);
5498 }
5499
5500 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
5501         LDKChannelHandshakeLimits this_ptr_conv;
5502         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5503         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5504         jshort ret_val = ChannelHandshakeLimits_get_min_max_accepted_htlcs(&this_ptr_conv);
5505         return ret_val;
5506 }
5507
5508 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
5509         LDKChannelHandshakeLimits this_ptr_conv;
5510         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5511         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5512         ChannelHandshakeLimits_set_min_max_accepted_htlcs(&this_ptr_conv, val);
5513 }
5514
5515 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1min_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
5516         LDKChannelHandshakeLimits this_ptr_conv;
5517         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5518         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5519         jlong ret_val = ChannelHandshakeLimits_get_min_dust_limit_satoshis(&this_ptr_conv);
5520         return ret_val;
5521 }
5522
5523 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1min_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5524         LDKChannelHandshakeLimits this_ptr_conv;
5525         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5526         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5527         ChannelHandshakeLimits_set_min_dust_limit_satoshis(&this_ptr_conv, val);
5528 }
5529
5530 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
5531         LDKChannelHandshakeLimits this_ptr_conv;
5532         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5533         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5534         jlong ret_val = ChannelHandshakeLimits_get_max_dust_limit_satoshis(&this_ptr_conv);
5535         return ret_val;
5536 }
5537
5538 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5539         LDKChannelHandshakeLimits this_ptr_conv;
5540         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5541         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5542         ChannelHandshakeLimits_set_max_dust_limit_satoshis(&this_ptr_conv, val);
5543 }
5544
5545 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1max_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
5546         LDKChannelHandshakeLimits this_ptr_conv;
5547         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5548         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5549         jint ret_val = ChannelHandshakeLimits_get_max_minimum_depth(&this_ptr_conv);
5550         return ret_val;
5551 }
5552
5553 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1max_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
5554         LDKChannelHandshakeLimits this_ptr_conv;
5555         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5556         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5557         ChannelHandshakeLimits_set_max_minimum_depth(&this_ptr_conv, val);
5558 }
5559
5560 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1force_1announced_1channel_1preference(JNIEnv * _env, jclass _b, jlong this_ptr) {
5561         LDKChannelHandshakeLimits this_ptr_conv;
5562         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5563         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5564         jboolean ret_val = ChannelHandshakeLimits_get_force_announced_channel_preference(&this_ptr_conv);
5565         return ret_val;
5566 }
5567
5568 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1force_1announced_1channel_1preference(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
5569         LDKChannelHandshakeLimits this_ptr_conv;
5570         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5571         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5572         ChannelHandshakeLimits_set_force_announced_channel_preference(&this_ptr_conv, val);
5573 }
5574
5575 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1get_1their_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
5576         LDKChannelHandshakeLimits this_ptr_conv;
5577         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5578         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5579         jshort ret_val = ChannelHandshakeLimits_get_their_to_self_delay(&this_ptr_conv);
5580         return ret_val;
5581 }
5582
5583 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1set_1their_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
5584         LDKChannelHandshakeLimits this_ptr_conv;
5585         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5586         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5587         ChannelHandshakeLimits_set_their_to_self_delay(&this_ptr_conv, val);
5588 }
5589
5590 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) {
5591         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);
5592         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5593         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5594         long ret_ref = (long)ret_var.inner;
5595         if (ret_var.is_owned) {
5596                 ret_ref |= 1;
5597         }
5598         return ret_ref;
5599 }
5600
5601 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelHandshakeLimits_1default(JNIEnv * _env, jclass _b) {
5602         LDKChannelHandshakeLimits ret_var = ChannelHandshakeLimits_default();
5603         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5604         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5605         long ret_ref = (long)ret_var.inner;
5606         if (ret_var.is_owned) {
5607                 ret_ref |= 1;
5608         }
5609         return ret_ref;
5610 }
5611
5612 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5613         LDKChannelConfig this_ptr_conv;
5614         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5615         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5616         ChannelConfig_free(this_ptr_conv);
5617 }
5618
5619 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5620         LDKChannelConfig orig_conv;
5621         orig_conv.inner = (void*)(orig & (~1));
5622         orig_conv.is_owned = (orig & 1) || (orig == 0);
5623         LDKChannelConfig ret_var = ChannelConfig_clone(&orig_conv);
5624         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5625         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5626         long ret_ref = (long)ret_var.inner;
5627         if (ret_var.is_owned) {
5628                 ret_ref |= 1;
5629         }
5630         return ret_ref;
5631 }
5632
5633 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
5634         LDKChannelConfig this_ptr_conv;
5635         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5636         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5637         jint ret_val = ChannelConfig_get_fee_proportional_millionths(&this_ptr_conv);
5638         return ret_val;
5639 }
5640
5641 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
5642         LDKChannelConfig this_ptr_conv;
5643         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5644         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5645         ChannelConfig_set_fee_proportional_millionths(&this_ptr_conv, val);
5646 }
5647
5648 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1announced_1channel(JNIEnv * _env, jclass _b, jlong this_ptr) {
5649         LDKChannelConfig this_ptr_conv;
5650         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5651         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5652         jboolean ret_val = ChannelConfig_get_announced_channel(&this_ptr_conv);
5653         return ret_val;
5654 }
5655
5656 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1announced_1channel(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
5657         LDKChannelConfig this_ptr_conv;
5658         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5659         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5660         ChannelConfig_set_announced_channel(&this_ptr_conv, val);
5661 }
5662
5663 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1get_1commit_1upfront_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
5664         LDKChannelConfig this_ptr_conv;
5665         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5666         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5667         jboolean ret_val = ChannelConfig_get_commit_upfront_shutdown_pubkey(&this_ptr_conv);
5668         return ret_val;
5669 }
5670
5671 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1set_1commit_1upfront_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
5672         LDKChannelConfig this_ptr_conv;
5673         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5674         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5675         ChannelConfig_set_commit_upfront_shutdown_pubkey(&this_ptr_conv, val);
5676 }
5677
5678 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) {
5679         LDKChannelConfig ret_var = ChannelConfig_new(fee_proportional_millionths_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg);
5680         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5681         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5682         long ret_ref = (long)ret_var.inner;
5683         if (ret_var.is_owned) {
5684                 ret_ref |= 1;
5685         }
5686         return ret_ref;
5687 }
5688
5689 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1default(JNIEnv * _env, jclass _b) {
5690         LDKChannelConfig ret_var = ChannelConfig_default();
5691         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5692         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5693         long ret_ref = (long)ret_var.inner;
5694         if (ret_var.is_owned) {
5695                 ret_ref |= 1;
5696         }
5697         return ret_ref;
5698 }
5699
5700 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1write(JNIEnv * _env, jclass _b, jlong obj) {
5701         LDKChannelConfig obj_conv;
5702         obj_conv.inner = (void*)(obj & (~1));
5703         obj_conv.is_owned = (obj & 1) || (obj == 0);
5704         LDKCVec_u8Z arg_var = ChannelConfig_write(&obj_conv);
5705         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
5706         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
5707         CVec_u8Z_free(arg_var);
5708         return arg_arr;
5709 }
5710
5711 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
5712         LDKu8slice ser_ref;
5713         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
5714         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
5715         LDKChannelConfig ret_var = ChannelConfig_read(ser_ref);
5716         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5717         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5718         long ret_ref = (long)ret_var.inner;
5719         if (ret_var.is_owned) {
5720                 ret_ref |= 1;
5721         }
5722         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
5723         return ret_ref;
5724 }
5725
5726 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5727         LDKUserConfig this_ptr_conv;
5728         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5729         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5730         UserConfig_free(this_ptr_conv);
5731 }
5732
5733 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5734         LDKUserConfig orig_conv;
5735         orig_conv.inner = (void*)(orig & (~1));
5736         orig_conv.is_owned = (orig & 1) || (orig == 0);
5737         LDKUserConfig ret_var = UserConfig_clone(&orig_conv);
5738         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5739         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5740         long ret_ref = (long)ret_var.inner;
5741         if (ret_var.is_owned) {
5742                 ret_ref |= 1;
5743         }
5744         return ret_ref;
5745 }
5746
5747 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1own_1channel_1config(JNIEnv * _env, jclass _b, jlong this_ptr) {
5748         LDKUserConfig this_ptr_conv;
5749         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5750         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5751         LDKChannelHandshakeConfig ret_var = UserConfig_get_own_channel_config(&this_ptr_conv);
5752         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5753         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5754         long ret_ref = (long)ret_var.inner;
5755         if (ret_var.is_owned) {
5756                 ret_ref |= 1;
5757         }
5758         return ret_ref;
5759 }
5760
5761 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1own_1channel_1config(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5762         LDKUserConfig this_ptr_conv;
5763         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5764         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5765         LDKChannelHandshakeConfig val_conv;
5766         val_conv.inner = (void*)(val & (~1));
5767         val_conv.is_owned = (val & 1) || (val == 0);
5768         if (val_conv.inner != NULL)
5769                 val_conv = ChannelHandshakeConfig_clone(&val_conv);
5770         UserConfig_set_own_channel_config(&this_ptr_conv, val_conv);
5771 }
5772
5773 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1peer_1channel_1config_1limits(JNIEnv * _env, jclass _b, jlong this_ptr) {
5774         LDKUserConfig this_ptr_conv;
5775         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5776         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5777         LDKChannelHandshakeLimits ret_var = UserConfig_get_peer_channel_config_limits(&this_ptr_conv);
5778         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5779         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5780         long ret_ref = (long)ret_var.inner;
5781         if (ret_var.is_owned) {
5782                 ret_ref |= 1;
5783         }
5784         return ret_ref;
5785 }
5786
5787 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1peer_1channel_1config_1limits(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5788         LDKUserConfig this_ptr_conv;
5789         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5790         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5791         LDKChannelHandshakeLimits val_conv;
5792         val_conv.inner = (void*)(val & (~1));
5793         val_conv.is_owned = (val & 1) || (val == 0);
5794         if (val_conv.inner != NULL)
5795                 val_conv = ChannelHandshakeLimits_clone(&val_conv);
5796         UserConfig_set_peer_channel_config_limits(&this_ptr_conv, val_conv);
5797 }
5798
5799 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1get_1channel_1options(JNIEnv * _env, jclass _b, jlong this_ptr) {
5800         LDKUserConfig this_ptr_conv;
5801         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5802         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5803         LDKChannelConfig ret_var = UserConfig_get_channel_options(&this_ptr_conv);
5804         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5805         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5806         long ret_ref = (long)ret_var.inner;
5807         if (ret_var.is_owned) {
5808                 ret_ref |= 1;
5809         }
5810         return ret_ref;
5811 }
5812
5813 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1channel_1options(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
5814         LDKUserConfig this_ptr_conv;
5815         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5816         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5817         LDKChannelConfig val_conv;
5818         val_conv.inner = (void*)(val & (~1));
5819         val_conv.is_owned = (val & 1) || (val == 0);
5820         if (val_conv.inner != NULL)
5821                 val_conv = ChannelConfig_clone(&val_conv);
5822         UserConfig_set_channel_options(&this_ptr_conv, val_conv);
5823 }
5824
5825 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) {
5826         LDKChannelHandshakeConfig own_channel_config_arg_conv;
5827         own_channel_config_arg_conv.inner = (void*)(own_channel_config_arg & (~1));
5828         own_channel_config_arg_conv.is_owned = (own_channel_config_arg & 1) || (own_channel_config_arg == 0);
5829         if (own_channel_config_arg_conv.inner != NULL)
5830                 own_channel_config_arg_conv = ChannelHandshakeConfig_clone(&own_channel_config_arg_conv);
5831         LDKChannelHandshakeLimits peer_channel_config_limits_arg_conv;
5832         peer_channel_config_limits_arg_conv.inner = (void*)(peer_channel_config_limits_arg & (~1));
5833         peer_channel_config_limits_arg_conv.is_owned = (peer_channel_config_limits_arg & 1) || (peer_channel_config_limits_arg == 0);
5834         if (peer_channel_config_limits_arg_conv.inner != NULL)
5835                 peer_channel_config_limits_arg_conv = ChannelHandshakeLimits_clone(&peer_channel_config_limits_arg_conv);
5836         LDKChannelConfig channel_options_arg_conv;
5837         channel_options_arg_conv.inner = (void*)(channel_options_arg & (~1));
5838         channel_options_arg_conv.is_owned = (channel_options_arg & 1) || (channel_options_arg == 0);
5839         if (channel_options_arg_conv.inner != NULL)
5840                 channel_options_arg_conv = ChannelConfig_clone(&channel_options_arg_conv);
5841         LDKUserConfig ret_var = UserConfig_new(own_channel_config_arg_conv, peer_channel_config_limits_arg_conv, channel_options_arg_conv);
5842         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5843         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5844         long ret_ref = (long)ret_var.inner;
5845         if (ret_var.is_owned) {
5846                 ret_ref |= 1;
5847         }
5848         return ret_ref;
5849 }
5850
5851 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1default(JNIEnv * _env, jclass _b) {
5852         LDKUserConfig ret_var = UserConfig_default();
5853         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5854         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5855         long ret_ref = (long)ret_var.inner;
5856         if (ret_var.is_owned) {
5857                 ret_ref |= 1;
5858         }
5859         return ret_ref;
5860 }
5861
5862 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_AccessError_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5863         LDKAccessError* orig_conv = (LDKAccessError*)orig;
5864         jclass ret_conv = LDKAccessError_to_java(_env, AccessError_clone(orig_conv));
5865         return ret_conv;
5866 }
5867
5868 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Access_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5869         LDKAccess this_ptr_conv = *(LDKAccess*)this_ptr;
5870         FREE((void*)this_ptr);
5871         Access_free(this_ptr_conv);
5872 }
5873
5874 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Watch_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5875         LDKWatch this_ptr_conv = *(LDKWatch*)this_ptr;
5876         FREE((void*)this_ptr);
5877         Watch_free(this_ptr_conv);
5878 }
5879
5880 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5881         LDKFilter this_ptr_conv = *(LDKFilter*)this_ptr;
5882         FREE((void*)this_ptr);
5883         Filter_free(this_ptr_conv);
5884 }
5885
5886 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5887         LDKBroadcasterInterface this_ptr_conv = *(LDKBroadcasterInterface*)this_ptr;
5888         FREE((void*)this_ptr);
5889         BroadcasterInterface_free(this_ptr_conv);
5890 }
5891
5892 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ConfirmationTarget_1clone(JNIEnv * _env, jclass _b, jlong orig) {
5893         LDKConfirmationTarget* orig_conv = (LDKConfirmationTarget*)orig;
5894         jclass ret_conv = LDKConfirmationTarget_to_java(_env, ConfirmationTarget_clone(orig_conv));
5895         return ret_conv;
5896 }
5897
5898 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FeeEstimator_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5899         LDKFeeEstimator this_ptr_conv = *(LDKFeeEstimator*)this_ptr;
5900         FREE((void*)this_ptr);
5901         FeeEstimator_free(this_ptr_conv);
5902 }
5903
5904 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5905         LDKChainMonitor this_ptr_conv;
5906         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5907         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5908         ChainMonitor_free(this_ptr_conv);
5909 }
5910
5911 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1block_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jlongArray txdata, jint height) {
5912         LDKChainMonitor this_arg_conv;
5913         this_arg_conv.inner = (void*)(this_arg & (~1));
5914         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
5915         unsigned char header_arr[80];
5916         CHECK((*_env)->GetArrayLength (_env, header) == 80);
5917         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
5918         unsigned char (*header_ref)[80] = &header_arr;
5919         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
5920         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
5921         if (txdata_constr.datalen > 0)
5922                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
5923         else
5924                 txdata_constr.data = NULL;
5925         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
5926         for (size_t d = 0; d < txdata_constr.datalen; d++) {
5927                 long arr_conv_29 = txdata_vals[d];
5928                 LDKC2Tuple_usizeTransactionZ arr_conv_29_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_29;
5929                 FREE((void*)arr_conv_29);
5930                 txdata_constr.data[d] = arr_conv_29_conv;
5931         }
5932         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
5933         ChainMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
5934 }
5935
5936 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1block_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jint disconnected_height) {
5937         LDKChainMonitor this_arg_conv;
5938         this_arg_conv.inner = (void*)(this_arg & (~1));
5939         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
5940         unsigned char header_arr[80];
5941         CHECK((*_env)->GetArrayLength (_env, header) == 80);
5942         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
5943         unsigned char (*header_ref)[80] = &header_arr;
5944         ChainMonitor_block_disconnected(&this_arg_conv, header_ref, disconnected_height);
5945 }
5946
5947 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1new(JNIEnv * _env, jclass _b, jlong chain_source, jlong broadcaster, jlong logger, jlong feeest) {
5948         LDKFilter* chain_source_conv = (LDKFilter*)chain_source;
5949         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
5950         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
5951                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
5952                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
5953         }
5954         LDKLogger logger_conv = *(LDKLogger*)logger;
5955         if (logger_conv.free == LDKLogger_JCalls_free) {
5956                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
5957                 LDKLogger_JCalls_clone(logger_conv.this_arg);
5958         }
5959         LDKFeeEstimator feeest_conv = *(LDKFeeEstimator*)feeest;
5960         if (feeest_conv.free == LDKFeeEstimator_JCalls_free) {
5961                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
5962                 LDKFeeEstimator_JCalls_clone(feeest_conv.this_arg);
5963         }
5964         LDKChainMonitor ret_var = ChainMonitor_new(chain_source_conv, broadcaster_conv, logger_conv, feeest_conv);
5965         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
5966         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
5967         long ret_ref = (long)ret_var.inner;
5968         if (ret_var.is_owned) {
5969                 ret_ref |= 1;
5970         }
5971         return ret_ref;
5972 }
5973
5974 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1Watch(JNIEnv * _env, jclass _b, jlong this_arg) {
5975         LDKChainMonitor this_arg_conv;
5976         this_arg_conv.inner = (void*)(this_arg & (~1));
5977         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
5978         LDKWatch* ret = MALLOC(sizeof(LDKWatch), "LDKWatch");
5979         *ret = ChainMonitor_as_Watch(&this_arg_conv);
5980         return (long)ret;
5981 }
5982
5983 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1as_1EventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
5984         LDKChainMonitor this_arg_conv;
5985         this_arg_conv.inner = (void*)(this_arg & (~1));
5986         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
5987         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
5988         *ret = ChainMonitor_as_EventsProvider(&this_arg_conv);
5989         return (long)ret;
5990 }
5991
5992 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
5993         LDKChannelMonitorUpdate this_ptr_conv;
5994         this_ptr_conv.inner = (void*)(this_ptr & (~1));
5995         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
5996         ChannelMonitorUpdate_free(this_ptr_conv);
5997 }
5998
5999 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6000         LDKChannelMonitorUpdate orig_conv;
6001         orig_conv.inner = (void*)(orig & (~1));
6002         orig_conv.is_owned = (orig & 1) || (orig == 0);
6003         LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_clone(&orig_conv);
6004         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6005         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6006         long ret_ref = (long)ret_var.inner;
6007         if (ret_var.is_owned) {
6008                 ret_ref |= 1;
6009         }
6010         return ret_ref;
6011 }
6012
6013 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1get_1update_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
6014         LDKChannelMonitorUpdate this_ptr_conv;
6015         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6016         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6017         jlong ret_val = ChannelMonitorUpdate_get_update_id(&this_ptr_conv);
6018         return ret_val;
6019 }
6020
6021 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1set_1update_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
6022         LDKChannelMonitorUpdate this_ptr_conv;
6023         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6024         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6025         ChannelMonitorUpdate_set_update_id(&this_ptr_conv, val);
6026 }
6027
6028 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
6029         LDKChannelMonitorUpdate obj_conv;
6030         obj_conv.inner = (void*)(obj & (~1));
6031         obj_conv.is_owned = (obj & 1) || (obj == 0);
6032         LDKCVec_u8Z arg_var = ChannelMonitorUpdate_write(&obj_conv);
6033         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
6034         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
6035         CVec_u8Z_free(arg_var);
6036         return arg_arr;
6037 }
6038
6039 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
6040         LDKu8slice ser_ref;
6041         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
6042         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
6043         LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_read(ser_ref);
6044         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6045         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6046         long ret_ref = (long)ret_var.inner;
6047         if (ret_var.is_owned) {
6048                 ret_ref |= 1;
6049         }
6050         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
6051         return ret_ref;
6052 }
6053
6054 JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdateErr_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6055         LDKChannelMonitorUpdateErr* orig_conv = (LDKChannelMonitorUpdateErr*)orig;
6056         jclass ret_conv = LDKChannelMonitorUpdateErr_to_java(_env, ChannelMonitorUpdateErr_clone(orig_conv));
6057         return ret_conv;
6058 }
6059
6060 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorUpdateError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6061         LDKMonitorUpdateError this_ptr_conv;
6062         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6063         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6064         MonitorUpdateError_free(this_ptr_conv);
6065 }
6066
6067 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6068         LDKMonitorEvent this_ptr_conv;
6069         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6070         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6071         MonitorEvent_free(this_ptr_conv);
6072 }
6073
6074 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MonitorEvent_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6075         LDKMonitorEvent orig_conv;
6076         orig_conv.inner = (void*)(orig & (~1));
6077         orig_conv.is_owned = (orig & 1) || (orig == 0);
6078         LDKMonitorEvent ret_var = MonitorEvent_clone(&orig_conv);
6079         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6080         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6081         long ret_ref = (long)ret_var.inner;
6082         if (ret_var.is_owned) {
6083                 ret_ref |= 1;
6084         }
6085         return ret_ref;
6086 }
6087
6088 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6089         LDKHTLCUpdate this_ptr_conv;
6090         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6091         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6092         HTLCUpdate_free(this_ptr_conv);
6093 }
6094
6095 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6096         LDKHTLCUpdate orig_conv;
6097         orig_conv.inner = (void*)(orig & (~1));
6098         orig_conv.is_owned = (orig & 1) || (orig == 0);
6099         LDKHTLCUpdate ret_var = HTLCUpdate_clone(&orig_conv);
6100         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6101         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6102         long ret_ref = (long)ret_var.inner;
6103         if (ret_var.is_owned) {
6104                 ret_ref |= 1;
6105         }
6106         return ret_ref;
6107 }
6108
6109 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
6110         LDKHTLCUpdate obj_conv;
6111         obj_conv.inner = (void*)(obj & (~1));
6112         obj_conv.is_owned = (obj & 1) || (obj == 0);
6113         LDKCVec_u8Z arg_var = HTLCUpdate_write(&obj_conv);
6114         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
6115         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
6116         CVec_u8Z_free(arg_var);
6117         return arg_arr;
6118 }
6119
6120 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
6121         LDKu8slice ser_ref;
6122         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
6123         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
6124         LDKHTLCUpdate ret_var = HTLCUpdate_read(ser_ref);
6125         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6126         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6127         long ret_ref = (long)ret_var.inner;
6128         if (ret_var.is_owned) {
6129                 ret_ref |= 1;
6130         }
6131         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
6132         return ret_ref;
6133 }
6134
6135 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6136         LDKChannelMonitor this_ptr_conv;
6137         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6138         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6139         ChannelMonitor_free(this_ptr_conv);
6140 }
6141
6142 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1update_1monitor(JNIEnv * _env, jclass _b, jlong this_arg, jlong updates, jlong broadcaster, jlong logger) {
6143         LDKChannelMonitor this_arg_conv;
6144         this_arg_conv.inner = (void*)(this_arg & (~1));
6145         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6146         LDKChannelMonitorUpdate updates_conv;
6147         updates_conv.inner = (void*)(updates & (~1));
6148         updates_conv.is_owned = (updates & 1) || (updates == 0);
6149         if (updates_conv.inner != NULL)
6150                 updates_conv = ChannelMonitorUpdate_clone(&updates_conv);
6151         LDKBroadcasterInterface* broadcaster_conv = (LDKBroadcasterInterface*)broadcaster;
6152         LDKLogger* logger_conv = (LDKLogger*)logger;
6153         LDKCResult_NoneMonitorUpdateErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
6154         *ret_conv = ChannelMonitor_update_monitor(&this_arg_conv, updates_conv, broadcaster_conv, logger_conv);
6155         return (long)ret_conv;
6156 }
6157
6158 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1update_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
6159         LDKChannelMonitor this_arg_conv;
6160         this_arg_conv.inner = (void*)(this_arg & (~1));
6161         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6162         jlong ret_val = ChannelMonitor_get_latest_update_id(&this_arg_conv);
6163         return ret_val;
6164 }
6165
6166 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1funding_1txo(JNIEnv * _env, jclass _b, jlong this_arg) {
6167         LDKChannelMonitor this_arg_conv;
6168         this_arg_conv.inner = (void*)(this_arg & (~1));
6169         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6170         LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
6171         *ret_ref = ChannelMonitor_get_funding_txo(&this_arg_conv);
6172         return (long)ret_ref;
6173 }
6174
6175 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1monitor_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
6176         LDKChannelMonitor this_arg_conv;
6177         this_arg_conv.inner = (void*)(this_arg & (~1));
6178         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6179         LDKCVec_MonitorEventZ ret_var = ChannelMonitor_get_and_clear_pending_monitor_events(&this_arg_conv);
6180         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
6181         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
6182         for (size_t o = 0; o < ret_var.datalen; o++) {
6183                 LDKMonitorEvent arr_conv_14_var = ret_var.data[o];
6184                 CHECK((((long)arr_conv_14_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6185                 CHECK((((long)&arr_conv_14_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6186                 long arr_conv_14_ref = (long)arr_conv_14_var.inner;
6187                 if (arr_conv_14_var.is_owned) {
6188                         arr_conv_14_ref |= 1;
6189                 }
6190                 ret_arr_ptr[o] = arr_conv_14_ref;
6191         }
6192         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
6193         FREE(ret_var.data);
6194         return ret_arr;
6195 }
6196
6197 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and_1clear_1pending_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
6198         LDKChannelMonitor this_arg_conv;
6199         this_arg_conv.inner = (void*)(this_arg & (~1));
6200         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6201         LDKCVec_EventZ ret_var = ChannelMonitor_get_and_clear_pending_events(&this_arg_conv);
6202         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
6203         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
6204         for (size_t h = 0; h < ret_var.datalen; h++) {
6205                 LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent");
6206                 *arr_conv_7_copy = Event_clone(&ret_var.data[h]);
6207                 long arr_conv_7_ref = (long)arr_conv_7_copy;
6208                 ret_arr_ptr[h] = arr_conv_7_ref;
6209         }
6210         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
6211         CVec_EventZ_free(ret_var);
6212         return ret_arr;
6213 }
6214
6215 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1holder_1commitment_1txn(JNIEnv * _env, jclass _b, jlong this_arg, jlong logger) {
6216         LDKChannelMonitor this_arg_conv;
6217         this_arg_conv.inner = (void*)(this_arg & (~1));
6218         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6219         LDKLogger* logger_conv = (LDKLogger*)logger;
6220         LDKCVec_TransactionZ ret_var = ChannelMonitor_get_latest_holder_commitment_txn(&this_arg_conv, logger_conv);
6221         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
6222         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
6223         for (size_t n = 0; n < ret_var.datalen; n++) {
6224                 LDKTransaction *arr_conv_13_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
6225                 *arr_conv_13_copy = ret_var.data[n];
6226                 long arr_conv_13_ref = (long)arr_conv_13_copy;
6227                 ret_arr_ptr[n] = arr_conv_13_ref;
6228         }
6229         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
6230         CVec_TransactionZ_free(ret_var);
6231         return ret_arr;
6232 }
6233
6234 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) {
6235         LDKChannelMonitor this_arg_conv;
6236         this_arg_conv.inner = (void*)(this_arg & (~1));
6237         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6238         unsigned char header_arr[80];
6239         CHECK((*_env)->GetArrayLength (_env, header) == 80);
6240         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
6241         unsigned char (*header_ref)[80] = &header_arr;
6242         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
6243         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
6244         if (txdata_constr.datalen > 0)
6245                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
6246         else
6247                 txdata_constr.data = NULL;
6248         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
6249         for (size_t d = 0; d < txdata_constr.datalen; d++) {
6250                 long arr_conv_29 = txdata_vals[d];
6251                 LDKC2Tuple_usizeTransactionZ arr_conv_29_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_29;
6252                 FREE((void*)arr_conv_29);
6253                 txdata_constr.data[d] = arr_conv_29_conv;
6254         }
6255         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
6256         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
6257         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
6258                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6259                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
6260         }
6261         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
6262         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
6263                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6264                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
6265         }
6266         LDKLogger logger_conv = *(LDKLogger*)logger;
6267         if (logger_conv.free == LDKLogger_JCalls_free) {
6268                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6269                 LDKLogger_JCalls_clone(logger_conv.this_arg);
6270         }
6271         LDKCVec_C2Tuple_TxidCVec_TxOutZZZ ret_var = ChannelMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height, broadcaster_conv, fee_estimator_conv, logger_conv);
6272         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
6273         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
6274         for (size_t b = 0; b < ret_var.datalen; b++) {
6275                 LDKC2Tuple_TxidCVec_TxOutZZ* arr_conv_27_ref = MALLOC(sizeof(LDKC2Tuple_TxidCVec_TxOutZZ), "LDKC2Tuple_TxidCVec_TxOutZZ");
6276                 *arr_conv_27_ref = ret_var.data[b];
6277                 ret_arr_ptr[b] = (long)arr_conv_27_ref;
6278         }
6279         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
6280         CVec_C2Tuple_TxidCVec_TxOutZZZ_free(ret_var);
6281         return ret_arr;
6282 }
6283
6284 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) {
6285         LDKChannelMonitor this_arg_conv;
6286         this_arg_conv.inner = (void*)(this_arg & (~1));
6287         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6288         unsigned char header_arr[80];
6289         CHECK((*_env)->GetArrayLength (_env, header) == 80);
6290         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
6291         unsigned char (*header_ref)[80] = &header_arr;
6292         LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster;
6293         if (broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
6294                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6295                 LDKBroadcasterInterface_JCalls_clone(broadcaster_conv.this_arg);
6296         }
6297         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
6298         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
6299                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6300                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
6301         }
6302         LDKLogger logger_conv = *(LDKLogger*)logger;
6303         if (logger_conv.free == LDKLogger_JCalls_free) {
6304                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6305                 LDKLogger_JCalls_clone(logger_conv.this_arg);
6306         }
6307         ChannelMonitor_block_disconnected(&this_arg_conv, header_ref, height, broadcaster_conv, fee_estimator_conv, logger_conv);
6308 }
6309
6310 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6311         LDKOutPoint this_ptr_conv;
6312         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6313         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6314         OutPoint_free(this_ptr_conv);
6315 }
6316
6317 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6318         LDKOutPoint orig_conv;
6319         orig_conv.inner = (void*)(orig & (~1));
6320         orig_conv.is_owned = (orig & 1) || (orig == 0);
6321         LDKOutPoint ret_var = OutPoint_clone(&orig_conv);
6322         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6323         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6324         long ret_ref = (long)ret_var.inner;
6325         if (ret_var.is_owned) {
6326                 ret_ref |= 1;
6327         }
6328         return ret_ref;
6329 }
6330
6331 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1txid(JNIEnv * _env, jclass _b, jlong this_ptr) {
6332         LDKOutPoint this_ptr_conv;
6333         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6334         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6335         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6336         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OutPoint_get_txid(&this_ptr_conv));
6337         return ret_arr;
6338 }
6339
6340 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1txid(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6341         LDKOutPoint this_ptr_conv;
6342         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6343         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6344         LDKThirtyTwoBytes val_ref;
6345         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6346         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
6347         OutPoint_set_txid(&this_ptr_conv, val_ref);
6348 }
6349
6350 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OutPoint_1get_1index(JNIEnv * _env, jclass _b, jlong this_ptr) {
6351         LDKOutPoint this_ptr_conv;
6352         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6353         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6354         jshort ret_val = OutPoint_get_index(&this_ptr_conv);
6355         return ret_val;
6356 }
6357
6358 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OutPoint_1set_1index(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
6359         LDKOutPoint this_ptr_conv;
6360         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6361         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6362         OutPoint_set_index(&this_ptr_conv, val);
6363 }
6364
6365 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1new(JNIEnv * _env, jclass _b, jbyteArray txid_arg, jshort index_arg) {
6366         LDKThirtyTwoBytes txid_arg_ref;
6367         CHECK((*_env)->GetArrayLength (_env, txid_arg) == 32);
6368         (*_env)->GetByteArrayRegion (_env, txid_arg, 0, 32, txid_arg_ref.data);
6369         LDKOutPoint ret_var = OutPoint_new(txid_arg_ref, index_arg);
6370         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6371         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6372         long ret_ref = (long)ret_var.inner;
6373         if (ret_var.is_owned) {
6374                 ret_ref |= 1;
6375         }
6376         return ret_ref;
6377 }
6378
6379 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1to_1channel_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
6380         LDKOutPoint this_arg_conv;
6381         this_arg_conv.inner = (void*)(this_arg & (~1));
6382         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6383         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
6384         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, OutPoint_to_channel_id(&this_arg_conv).data);
6385         return arg_arr;
6386 }
6387
6388 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1write(JNIEnv * _env, jclass _b, jlong obj) {
6389         LDKOutPoint obj_conv;
6390         obj_conv.inner = (void*)(obj & (~1));
6391         obj_conv.is_owned = (obj & 1) || (obj == 0);
6392         LDKCVec_u8Z arg_var = OutPoint_write(&obj_conv);
6393         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
6394         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
6395         CVec_u8Z_free(arg_var);
6396         return arg_arr;
6397 }
6398
6399 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
6400         LDKu8slice ser_ref;
6401         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
6402         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
6403         LDKOutPoint ret_var = OutPoint_read(ser_ref);
6404         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6405         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6406         long ret_ref = (long)ret_var.inner;
6407         if (ret_var.is_owned) {
6408                 ret_ref |= 1;
6409         }
6410         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
6411         return ret_ref;
6412 }
6413
6414 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6415         LDKSpendableOutputDescriptor this_ptr_conv = *(LDKSpendableOutputDescriptor*)this_ptr;
6416         FREE((void*)this_ptr);
6417         SpendableOutputDescriptor_free(this_ptr_conv);
6418 }
6419
6420 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6421         LDKSpendableOutputDescriptor* orig_conv = (LDKSpendableOutputDescriptor*)orig;
6422         LDKSpendableOutputDescriptor *ret_copy = MALLOC(sizeof(LDKSpendableOutputDescriptor), "LDKSpendableOutputDescriptor");
6423         *ret_copy = SpendableOutputDescriptor_clone(orig_conv);
6424         long ret_ref = (long)ret_copy;
6425         return ret_ref;
6426 }
6427
6428 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6429         LDKChannelKeys this_ptr_conv = *(LDKChannelKeys*)this_ptr;
6430         FREE((void*)this_ptr);
6431         ChannelKeys_free(this_ptr_conv);
6432 }
6433
6434 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysInterface_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6435         LDKKeysInterface this_ptr_conv = *(LDKKeysInterface*)this_ptr;
6436         FREE((void*)this_ptr);
6437         KeysInterface_free(this_ptr_conv);
6438 }
6439
6440 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6441         LDKInMemoryChannelKeys this_ptr_conv;
6442         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6443         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6444         InMemoryChannelKeys_free(this_ptr_conv);
6445 }
6446
6447 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6448         LDKInMemoryChannelKeys orig_conv;
6449         orig_conv.inner = (void*)(orig & (~1));
6450         orig_conv.is_owned = (orig & 1) || (orig == 0);
6451         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_clone(&orig_conv);
6452         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6453         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6454         long ret_ref = (long)ret_var.inner;
6455         if (ret_var.is_owned) {
6456                 ret_ref |= 1;
6457         }
6458         return ret_ref;
6459 }
6460
6461 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1funding_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6462         LDKInMemoryChannelKeys this_ptr_conv;
6463         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6464         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6465         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6466         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_funding_key(&this_ptr_conv));
6467         return ret_arr;
6468 }
6469
6470 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1funding_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6471         LDKInMemoryChannelKeys this_ptr_conv;
6472         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6473         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6474         LDKSecretKey val_ref;
6475         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6476         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6477         InMemoryChannelKeys_set_funding_key(&this_ptr_conv, val_ref);
6478 }
6479
6480 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1revocation_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6481         LDKInMemoryChannelKeys this_ptr_conv;
6482         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6483         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6484         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6485         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_revocation_base_key(&this_ptr_conv));
6486         return ret_arr;
6487 }
6488
6489 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1revocation_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6490         LDKInMemoryChannelKeys this_ptr_conv;
6491         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6492         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6493         LDKSecretKey val_ref;
6494         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6495         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6496         InMemoryChannelKeys_set_revocation_base_key(&this_ptr_conv, val_ref);
6497 }
6498
6499 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6500         LDKInMemoryChannelKeys this_ptr_conv;
6501         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6502         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6503         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6504         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_payment_key(&this_ptr_conv));
6505         return ret_arr;
6506 }
6507
6508 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6509         LDKInMemoryChannelKeys this_ptr_conv;
6510         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6511         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6512         LDKSecretKey val_ref;
6513         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6514         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6515         InMemoryChannelKeys_set_payment_key(&this_ptr_conv, val_ref);
6516 }
6517
6518 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1delayed_1payment_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6519         LDKInMemoryChannelKeys this_ptr_conv;
6520         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6521         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6522         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6523         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_delayed_payment_base_key(&this_ptr_conv));
6524         return ret_arr;
6525 }
6526
6527 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1delayed_1payment_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6528         LDKInMemoryChannelKeys this_ptr_conv;
6529         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6530         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6531         LDKSecretKey val_ref;
6532         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6533         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6534         InMemoryChannelKeys_set_delayed_payment_base_key(&this_ptr_conv, val_ref);
6535 }
6536
6537 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1htlc_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
6538         LDKInMemoryChannelKeys this_ptr_conv;
6539         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6540         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6541         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6542         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_htlc_base_key(&this_ptr_conv));
6543         return ret_arr;
6544 }
6545
6546 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1htlc_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6547         LDKInMemoryChannelKeys this_ptr_conv;
6548         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6549         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6550         LDKSecretKey val_ref;
6551         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6552         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
6553         InMemoryChannelKeys_set_htlc_base_key(&this_ptr_conv, val_ref);
6554 }
6555
6556 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1commitment_1seed(JNIEnv * _env, jclass _b, jlong this_ptr) {
6557         LDKInMemoryChannelKeys this_ptr_conv;
6558         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6559         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6560         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6561         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *InMemoryChannelKeys_get_commitment_seed(&this_ptr_conv));
6562         return ret_arr;
6563 }
6564
6565 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1commitment_1seed(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6566         LDKInMemoryChannelKeys this_ptr_conv;
6567         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6568         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6569         LDKThirtyTwoBytes val_ref;
6570         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6571         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
6572         InMemoryChannelKeys_set_commitment_seed(&this_ptr_conv, val_ref);
6573 }
6574
6575 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) {
6576         LDKSecretKey funding_key_ref;
6577         CHECK((*_env)->GetArrayLength (_env, funding_key) == 32);
6578         (*_env)->GetByteArrayRegion (_env, funding_key, 0, 32, funding_key_ref.bytes);
6579         LDKSecretKey revocation_base_key_ref;
6580         CHECK((*_env)->GetArrayLength (_env, revocation_base_key) == 32);
6581         (*_env)->GetByteArrayRegion (_env, revocation_base_key, 0, 32, revocation_base_key_ref.bytes);
6582         LDKSecretKey payment_key_ref;
6583         CHECK((*_env)->GetArrayLength (_env, payment_key) == 32);
6584         (*_env)->GetByteArrayRegion (_env, payment_key, 0, 32, payment_key_ref.bytes);
6585         LDKSecretKey delayed_payment_base_key_ref;
6586         CHECK((*_env)->GetArrayLength (_env, delayed_payment_base_key) == 32);
6587         (*_env)->GetByteArrayRegion (_env, delayed_payment_base_key, 0, 32, delayed_payment_base_key_ref.bytes);
6588         LDKSecretKey htlc_base_key_ref;
6589         CHECK((*_env)->GetArrayLength (_env, htlc_base_key) == 32);
6590         (*_env)->GetByteArrayRegion (_env, htlc_base_key, 0, 32, htlc_base_key_ref.bytes);
6591         LDKThirtyTwoBytes commitment_seed_ref;
6592         CHECK((*_env)->GetArrayLength (_env, commitment_seed) == 32);
6593         (*_env)->GetByteArrayRegion (_env, commitment_seed, 0, 32, commitment_seed_ref.data);
6594         LDKC2Tuple_u64u64Z key_derivation_params_conv = *(LDKC2Tuple_u64u64Z*)key_derivation_params;
6595         FREE((void*)key_derivation_params);
6596         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);
6597         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6598         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6599         long ret_ref = (long)ret_var.inner;
6600         if (ret_var.is_owned) {
6601                 ret_ref |= 1;
6602         }
6603         return ret_ref;
6604 }
6605
6606 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
6607         LDKInMemoryChannelKeys this_arg_conv;
6608         this_arg_conv.inner = (void*)(this_arg & (~1));
6609         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6610         LDKChannelPublicKeys ret_var = InMemoryChannelKeys_counterparty_pubkeys(&this_arg_conv);
6611         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6612         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6613         long ret_ref = (long)ret_var.inner;
6614         if (ret_var.is_owned) {
6615                 ret_ref |= 1;
6616         }
6617         return ret_ref;
6618 }
6619
6620 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1counterparty_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_arg) {
6621         LDKInMemoryChannelKeys this_arg_conv;
6622         this_arg_conv.inner = (void*)(this_arg & (~1));
6623         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6624         jshort ret_val = InMemoryChannelKeys_counterparty_selected_contest_delay(&this_arg_conv);
6625         return ret_val;
6626 }
6627
6628 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1holder_1selected_1contest_1delay(JNIEnv * _env, jclass _b, jlong this_arg) {
6629         LDKInMemoryChannelKeys this_arg_conv;
6630         this_arg_conv.inner = (void*)(this_arg & (~1));
6631         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6632         jshort ret_val = InMemoryChannelKeys_holder_selected_contest_delay(&this_arg_conv);
6633         return ret_val;
6634 }
6635
6636 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1as_1ChannelKeys(JNIEnv * _env, jclass _b, jlong this_arg) {
6637         LDKInMemoryChannelKeys this_arg_conv;
6638         this_arg_conv.inner = (void*)(this_arg & (~1));
6639         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6640         LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
6641         *ret = InMemoryChannelKeys_as_ChannelKeys(&this_arg_conv);
6642         return (long)ret;
6643 }
6644
6645 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
6646         LDKInMemoryChannelKeys obj_conv;
6647         obj_conv.inner = (void*)(obj & (~1));
6648         obj_conv.is_owned = (obj & 1) || (obj == 0);
6649         LDKCVec_u8Z arg_var = InMemoryChannelKeys_write(&obj_conv);
6650         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
6651         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
6652         CVec_u8Z_free(arg_var);
6653         return arg_arr;
6654 }
6655
6656 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
6657         LDKu8slice ser_ref;
6658         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
6659         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
6660         LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_read(ser_ref);
6661         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6662         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6663         long ret_ref = (long)ret_var.inner;
6664         if (ret_var.is_owned) {
6665                 ret_ref |= 1;
6666         }
6667         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
6668         return ret_ref;
6669 }
6670
6671 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6672         LDKKeysManager this_ptr_conv;
6673         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6674         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6675         KeysManager_free(this_ptr_conv);
6676 }
6677
6678 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) {
6679         unsigned char seed_arr[32];
6680         CHECK((*_env)->GetArrayLength (_env, seed) == 32);
6681         (*_env)->GetByteArrayRegion (_env, seed, 0, 32, seed_arr);
6682         unsigned char (*seed_ref)[32] = &seed_arr;
6683         LDKNetwork network_conv = LDKNetwork_from_java(_env, network);
6684         LDKKeysManager ret_var = KeysManager_new(seed_ref, network_conv, starting_time_secs, starting_time_nanos);
6685         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6686         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6687         long ret_ref = (long)ret_var.inner;
6688         if (ret_var.is_owned) {
6689                 ret_ref |= 1;
6690         }
6691         return ret_ref;
6692 }
6693
6694 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) {
6695         LDKKeysManager this_arg_conv;
6696         this_arg_conv.inner = (void*)(this_arg & (~1));
6697         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6698         LDKInMemoryChannelKeys ret_var = KeysManager_derive_channel_keys(&this_arg_conv, channel_value_satoshis, params_1, params_2);
6699         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6700         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6701         long ret_ref = (long)ret_var.inner;
6702         if (ret_var.is_owned) {
6703                 ret_ref |= 1;
6704         }
6705         return ret_ref;
6706 }
6707
6708 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_KeysManager_1as_1KeysInterface(JNIEnv * _env, jclass _b, jlong this_arg) {
6709         LDKKeysManager this_arg_conv;
6710         this_arg_conv.inner = (void*)(this_arg & (~1));
6711         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6712         LDKKeysInterface* ret = MALLOC(sizeof(LDKKeysInterface), "LDKKeysInterface");
6713         *ret = KeysManager_as_KeysInterface(&this_arg_conv);
6714         return (long)ret;
6715 }
6716
6717 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6718         LDKChannelManager this_ptr_conv;
6719         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6720         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6721         ChannelManager_free(this_ptr_conv);
6722 }
6723
6724 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6725         LDKChannelDetails this_ptr_conv;
6726         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6727         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6728         ChannelDetails_free(this_ptr_conv);
6729 }
6730
6731 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1clone(JNIEnv * _env, jclass _b, jlong orig) {
6732         LDKChannelDetails orig_conv;
6733         orig_conv.inner = (void*)(orig & (~1));
6734         orig_conv.is_owned = (orig & 1) || (orig == 0);
6735         LDKChannelDetails ret_var = ChannelDetails_clone(&orig_conv);
6736         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6737         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6738         long ret_ref = (long)ret_var.inner;
6739         if (ret_var.is_owned) {
6740                 ret_ref |= 1;
6741         }
6742         return ret_ref;
6743 }
6744
6745 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
6746         LDKChannelDetails this_ptr_conv;
6747         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6748         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6749         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
6750         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ChannelDetails_get_channel_id(&this_ptr_conv));
6751         return ret_arr;
6752 }
6753
6754 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6755         LDKChannelDetails this_ptr_conv;
6756         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6757         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6758         LDKThirtyTwoBytes val_ref;
6759         CHECK((*_env)->GetArrayLength (_env, val) == 32);
6760         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
6761         ChannelDetails_set_channel_id(&this_ptr_conv, val_ref);
6762 }
6763
6764 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1remote_1network_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
6765         LDKChannelDetails this_ptr_conv;
6766         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6767         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6768         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
6769         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelDetails_get_remote_network_id(&this_ptr_conv).compressed_form);
6770         return arg_arr;
6771 }
6772
6773 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1remote_1network_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
6774         LDKChannelDetails this_ptr_conv;
6775         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6776         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6777         LDKPublicKey val_ref;
6778         CHECK((*_env)->GetArrayLength (_env, val) == 33);
6779         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
6780         ChannelDetails_set_remote_network_id(&this_ptr_conv, val_ref);
6781 }
6782
6783 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1counterparty_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
6784         LDKChannelDetails this_ptr_conv;
6785         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6786         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6787         LDKInitFeatures ret_var = ChannelDetails_get_counterparty_features(&this_ptr_conv);
6788         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6789         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6790         long ret_ref = (long)ret_var.inner;
6791         if (ret_var.is_owned) {
6792                 ret_ref |= 1;
6793         }
6794         return ret_ref;
6795 }
6796
6797 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1counterparty_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
6798         LDKChannelDetails this_ptr_conv;
6799         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6800         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6801         LDKInitFeatures val_conv;
6802         val_conv.inner = (void*)(val & (~1));
6803         val_conv.is_owned = (val & 1) || (val == 0);
6804         // Warning: we may need a move here but can't clone!
6805         ChannelDetails_set_counterparty_features(&this_ptr_conv, val_conv);
6806 }
6807
6808 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1channel_1value_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
6809         LDKChannelDetails this_ptr_conv;
6810         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6811         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6812         jlong ret_val = ChannelDetails_get_channel_value_satoshis(&this_ptr_conv);
6813         return ret_val;
6814 }
6815
6816 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1channel_1value_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
6817         LDKChannelDetails this_ptr_conv;
6818         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6819         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6820         ChannelDetails_set_channel_value_satoshis(&this_ptr_conv, val);
6821 }
6822
6823 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1user_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
6824         LDKChannelDetails this_ptr_conv;
6825         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6826         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6827         jlong ret_val = ChannelDetails_get_user_id(&this_ptr_conv);
6828         return ret_val;
6829 }
6830
6831 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1user_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
6832         LDKChannelDetails this_ptr_conv;
6833         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6834         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6835         ChannelDetails_set_user_id(&this_ptr_conv, val);
6836 }
6837
6838 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1outbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
6839         LDKChannelDetails this_ptr_conv;
6840         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6841         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6842         jlong ret_val = ChannelDetails_get_outbound_capacity_msat(&this_ptr_conv);
6843         return ret_val;
6844 }
6845
6846 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1outbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
6847         LDKChannelDetails this_ptr_conv;
6848         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6849         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6850         ChannelDetails_set_outbound_capacity_msat(&this_ptr_conv, val);
6851 }
6852
6853 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1inbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
6854         LDKChannelDetails this_ptr_conv;
6855         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6856         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6857         jlong ret_val = ChannelDetails_get_inbound_capacity_msat(&this_ptr_conv);
6858         return ret_val;
6859 }
6860
6861 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1inbound_1capacity_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
6862         LDKChannelDetails this_ptr_conv;
6863         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6864         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6865         ChannelDetails_set_inbound_capacity_msat(&this_ptr_conv, val);
6866 }
6867
6868 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1get_1is_1live(JNIEnv * _env, jclass _b, jlong this_ptr) {
6869         LDKChannelDetails this_ptr_conv;
6870         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6871         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6872         jboolean ret_val = ChannelDetails_get_is_live(&this_ptr_conv);
6873         return ret_val;
6874 }
6875
6876 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelDetails_1set_1is_1live(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
6877         LDKChannelDetails this_ptr_conv;
6878         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6879         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6880         ChannelDetails_set_is_live(&this_ptr_conv, val);
6881 }
6882
6883 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PaymentSendFailure_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
6884         LDKPaymentSendFailure this_ptr_conv;
6885         this_ptr_conv.inner = (void*)(this_ptr & (~1));
6886         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
6887         PaymentSendFailure_free(this_ptr_conv);
6888 }
6889
6890 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) {
6891         LDKNetwork network_conv = LDKNetwork_from_java(_env, network);
6892         LDKFeeEstimator fee_est_conv = *(LDKFeeEstimator*)fee_est;
6893         if (fee_est_conv.free == LDKFeeEstimator_JCalls_free) {
6894                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6895                 LDKFeeEstimator_JCalls_clone(fee_est_conv.this_arg);
6896         }
6897         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
6898         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
6899                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6900                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
6901         }
6902         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
6903         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
6904                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6905                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
6906         }
6907         LDKLogger logger_conv = *(LDKLogger*)logger;
6908         if (logger_conv.free == LDKLogger_JCalls_free) {
6909                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6910                 LDKLogger_JCalls_clone(logger_conv.this_arg);
6911         }
6912         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
6913         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
6914                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
6915                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
6916         }
6917         LDKUserConfig config_conv;
6918         config_conv.inner = (void*)(config & (~1));
6919         config_conv.is_owned = (config & 1) || (config == 0);
6920         if (config_conv.inner != NULL)
6921                 config_conv = UserConfig_clone(&config_conv);
6922         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);
6923         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6924         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6925         long ret_ref = (long)ret_var.inner;
6926         if (ret_var.is_owned) {
6927                 ret_ref |= 1;
6928         }
6929         return ret_ref;
6930 }
6931
6932 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) {
6933         LDKChannelManager this_arg_conv;
6934         this_arg_conv.inner = (void*)(this_arg & (~1));
6935         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6936         LDKPublicKey their_network_key_ref;
6937         CHECK((*_env)->GetArrayLength (_env, their_network_key) == 33);
6938         (*_env)->GetByteArrayRegion (_env, their_network_key, 0, 33, their_network_key_ref.compressed_form);
6939         LDKUserConfig override_config_conv;
6940         override_config_conv.inner = (void*)(override_config & (~1));
6941         override_config_conv.is_owned = (override_config & 1) || (override_config == 0);
6942         if (override_config_conv.inner != NULL)
6943                 override_config_conv = UserConfig_clone(&override_config_conv);
6944         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
6945         *ret_conv = ChannelManager_create_channel(&this_arg_conv, their_network_key_ref, channel_value_satoshis, push_msat, user_id, override_config_conv);
6946         return (long)ret_conv;
6947 }
6948
6949 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
6950         LDKChannelManager this_arg_conv;
6951         this_arg_conv.inner = (void*)(this_arg & (~1));
6952         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6953         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_channels(&this_arg_conv);
6954         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
6955         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
6956         for (size_t q = 0; q < ret_var.datalen; q++) {
6957                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
6958                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6959                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6960                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
6961                 if (arr_conv_16_var.is_owned) {
6962                         arr_conv_16_ref |= 1;
6963                 }
6964                 ret_arr_ptr[q] = arr_conv_16_ref;
6965         }
6966         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
6967         FREE(ret_var.data);
6968         return ret_arr;
6969 }
6970
6971 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1usable_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
6972         LDKChannelManager this_arg_conv;
6973         this_arg_conv.inner = (void*)(this_arg & (~1));
6974         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6975         LDKCVec_ChannelDetailsZ ret_var = ChannelManager_list_usable_channels(&this_arg_conv);
6976         jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
6977         jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
6978         for (size_t q = 0; q < ret_var.datalen; q++) {
6979                 LDKChannelDetails arr_conv_16_var = ret_var.data[q];
6980                 CHECK((((long)arr_conv_16_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
6981                 CHECK((((long)&arr_conv_16_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
6982                 long arr_conv_16_ref = (long)arr_conv_16_var.inner;
6983                 if (arr_conv_16_var.is_owned) {
6984                         arr_conv_16_ref |= 1;
6985                 }
6986                 ret_arr_ptr[q] = arr_conv_16_ref;
6987         }
6988         (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
6989         FREE(ret_var.data);
6990         return ret_arr;
6991 }
6992
6993 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1close_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray channel_id) {
6994         LDKChannelManager this_arg_conv;
6995         this_arg_conv.inner = (void*)(this_arg & (~1));
6996         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
6997         unsigned char channel_id_arr[32];
6998         CHECK((*_env)->GetArrayLength (_env, channel_id) == 32);
6999         (*_env)->GetByteArrayRegion (_env, channel_id, 0, 32, channel_id_arr);
7000         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
7001         LDKCResult_NoneAPIErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
7002         *ret_conv = ChannelManager_close_channel(&this_arg_conv, channel_id_ref);
7003         return (long)ret_conv;
7004 }
7005
7006 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray channel_id) {
7007         LDKChannelManager this_arg_conv;
7008         this_arg_conv.inner = (void*)(this_arg & (~1));
7009         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7010         unsigned char channel_id_arr[32];
7011         CHECK((*_env)->GetArrayLength (_env, channel_id) == 32);
7012         (*_env)->GetByteArrayRegion (_env, channel_id, 0, 32, channel_id_arr);
7013         unsigned char (*channel_id_ref)[32] = &channel_id_arr;
7014         ChannelManager_force_close_channel(&this_arg_conv, channel_id_ref);
7015 }
7016
7017 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1force_1close_1all_1channels(JNIEnv * _env, jclass _b, jlong this_arg) {
7018         LDKChannelManager this_arg_conv;
7019         this_arg_conv.inner = (void*)(this_arg & (~1));
7020         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7021         ChannelManager_force_close_all_channels(&this_arg_conv);
7022 }
7023
7024 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) {
7025         LDKChannelManager this_arg_conv;
7026         this_arg_conv.inner = (void*)(this_arg & (~1));
7027         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7028         LDKRoute route_conv;
7029         route_conv.inner = (void*)(route & (~1));
7030         route_conv.is_owned = (route & 1) || (route == 0);
7031         LDKThirtyTwoBytes payment_hash_ref;
7032         CHECK((*_env)->GetArrayLength (_env, payment_hash) == 32);
7033         (*_env)->GetByteArrayRegion (_env, payment_hash, 0, 32, payment_hash_ref.data);
7034         LDKThirtyTwoBytes payment_secret_ref;
7035         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
7036         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
7037         LDKCResult_NonePaymentSendFailureZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePaymentSendFailureZ), "LDKCResult_NonePaymentSendFailureZ");
7038         *ret_conv = ChannelManager_send_payment(&this_arg_conv, &route_conv, payment_hash_ref, payment_secret_ref);
7039         return (long)ret_conv;
7040 }
7041
7042 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) {
7043         LDKChannelManager this_arg_conv;
7044         this_arg_conv.inner = (void*)(this_arg & (~1));
7045         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7046         unsigned char temporary_channel_id_arr[32];
7047         CHECK((*_env)->GetArrayLength (_env, temporary_channel_id) == 32);
7048         (*_env)->GetByteArrayRegion (_env, temporary_channel_id, 0, 32, temporary_channel_id_arr);
7049         unsigned char (*temporary_channel_id_ref)[32] = &temporary_channel_id_arr;
7050         LDKOutPoint funding_txo_conv;
7051         funding_txo_conv.inner = (void*)(funding_txo & (~1));
7052         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
7053         if (funding_txo_conv.inner != NULL)
7054                 funding_txo_conv = OutPoint_clone(&funding_txo_conv);
7055         ChannelManager_funding_transaction_generated(&this_arg_conv, temporary_channel_id_ref, funding_txo_conv);
7056 }
7057
7058 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) {
7059         LDKChannelManager this_arg_conv;
7060         this_arg_conv.inner = (void*)(this_arg & (~1));
7061         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7062         LDKThreeBytes rgb_ref;
7063         CHECK((*_env)->GetArrayLength (_env, rgb) == 3);
7064         (*_env)->GetByteArrayRegion (_env, rgb, 0, 3, rgb_ref.data);
7065         LDKThirtyTwoBytes alias_ref;
7066         CHECK((*_env)->GetArrayLength (_env, alias) == 32);
7067         (*_env)->GetByteArrayRegion (_env, alias, 0, 32, alias_ref.data);
7068         LDKCVec_NetAddressZ addresses_constr;
7069         addresses_constr.datalen = (*_env)->GetArrayLength (_env, addresses);
7070         if (addresses_constr.datalen > 0)
7071                 addresses_constr.data = MALLOC(addresses_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
7072         else
7073                 addresses_constr.data = NULL;
7074         long* addresses_vals = (*_env)->GetLongArrayElements (_env, addresses, NULL);
7075         for (size_t m = 0; m < addresses_constr.datalen; m++) {
7076                 long arr_conv_12 = addresses_vals[m];
7077                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
7078                 FREE((void*)arr_conv_12);
7079                 addresses_constr.data[m] = arr_conv_12_conv;
7080         }
7081         (*_env)->ReleaseLongArrayElements (_env, addresses, addresses_vals, 0);
7082         ChannelManager_broadcast_node_announcement(&this_arg_conv, rgb_ref, alias_ref, addresses_constr);
7083 }
7084
7085 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1process_1pending_1htlc_1forwards(JNIEnv * _env, jclass _b, jlong this_arg) {
7086         LDKChannelManager this_arg_conv;
7087         this_arg_conv.inner = (void*)(this_arg & (~1));
7088         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7089         ChannelManager_process_pending_htlc_forwards(&this_arg_conv);
7090 }
7091
7092 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1timer_1chan_1freshness_1every_1min(JNIEnv * _env, jclass _b, jlong this_arg) {
7093         LDKChannelManager this_arg_conv;
7094         this_arg_conv.inner = (void*)(this_arg & (~1));
7095         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7096         ChannelManager_timer_chan_freshness_every_min(&this_arg_conv);
7097 }
7098
7099 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) {
7100         LDKChannelManager this_arg_conv;
7101         this_arg_conv.inner = (void*)(this_arg & (~1));
7102         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7103         unsigned char payment_hash_arr[32];
7104         CHECK((*_env)->GetArrayLength (_env, payment_hash) == 32);
7105         (*_env)->GetByteArrayRegion (_env, payment_hash, 0, 32, payment_hash_arr);
7106         unsigned char (*payment_hash_ref)[32] = &payment_hash_arr;
7107         LDKThirtyTwoBytes payment_secret_ref;
7108         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
7109         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
7110         jboolean ret_val = ChannelManager_fail_htlc_backwards(&this_arg_conv, payment_hash_ref, payment_secret_ref);
7111         return ret_val;
7112 }
7113
7114 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) {
7115         LDKChannelManager this_arg_conv;
7116         this_arg_conv.inner = (void*)(this_arg & (~1));
7117         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7118         LDKThirtyTwoBytes payment_preimage_ref;
7119         CHECK((*_env)->GetArrayLength (_env, payment_preimage) == 32);
7120         (*_env)->GetByteArrayRegion (_env, payment_preimage, 0, 32, payment_preimage_ref.data);
7121         LDKThirtyTwoBytes payment_secret_ref;
7122         CHECK((*_env)->GetArrayLength (_env, payment_secret) == 32);
7123         (*_env)->GetByteArrayRegion (_env, payment_secret, 0, 32, payment_secret_ref.data);
7124         jboolean ret_val = ChannelManager_claim_funds(&this_arg_conv, payment_preimage_ref, payment_secret_ref, expected_amount);
7125         return ret_val;
7126 }
7127
7128 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1get_1our_1node_1id(JNIEnv * _env, jclass _b, jlong this_arg) {
7129         LDKChannelManager this_arg_conv;
7130         this_arg_conv.inner = (void*)(this_arg & (~1));
7131         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7132         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
7133         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelManager_get_our_node_id(&this_arg_conv).compressed_form);
7134         return arg_arr;
7135 }
7136
7137 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) {
7138         LDKChannelManager this_arg_conv;
7139         this_arg_conv.inner = (void*)(this_arg & (~1));
7140         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7141         LDKOutPoint funding_txo_conv;
7142         funding_txo_conv.inner = (void*)(funding_txo & (~1));
7143         funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
7144         ChannelManager_channel_monitor_updated(&this_arg_conv, &funding_txo_conv, highest_applied_update_id);
7145 }
7146
7147 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1MessageSendEventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
7148         LDKChannelManager this_arg_conv;
7149         this_arg_conv.inner = (void*)(this_arg & (~1));
7150         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7151         LDKMessageSendEventsProvider* ret = MALLOC(sizeof(LDKMessageSendEventsProvider), "LDKMessageSendEventsProvider");
7152         *ret = ChannelManager_as_MessageSendEventsProvider(&this_arg_conv);
7153         return (long)ret;
7154 }
7155
7156 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1EventsProvider(JNIEnv * _env, jclass _b, jlong this_arg) {
7157         LDKChannelManager this_arg_conv;
7158         this_arg_conv.inner = (void*)(this_arg & (~1));
7159         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7160         LDKEventsProvider* ret = MALLOC(sizeof(LDKEventsProvider), "LDKEventsProvider");
7161         *ret = ChannelManager_as_EventsProvider(&this_arg_conv);
7162         return (long)ret;
7163 }
7164
7165 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header, jlongArray txdata, jint height) {
7166         LDKChannelManager this_arg_conv;
7167         this_arg_conv.inner = (void*)(this_arg & (~1));
7168         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7169         unsigned char header_arr[80];
7170         CHECK((*_env)->GetArrayLength (_env, header) == 80);
7171         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
7172         unsigned char (*header_ref)[80] = &header_arr;
7173         LDKCVec_C2Tuple_usizeTransactionZZ txdata_constr;
7174         txdata_constr.datalen = (*_env)->GetArrayLength (_env, txdata);
7175         if (txdata_constr.datalen > 0)
7176                 txdata_constr.data = MALLOC(txdata_constr.datalen * sizeof(LDKC2Tuple_usizeTransactionZ), "LDKCVec_C2Tuple_usizeTransactionZZ Elements");
7177         else
7178                 txdata_constr.data = NULL;
7179         long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL);
7180         for (size_t d = 0; d < txdata_constr.datalen; d++) {
7181                 long arr_conv_29 = txdata_vals[d];
7182                 LDKC2Tuple_usizeTransactionZ arr_conv_29_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_29;
7183                 FREE((void*)arr_conv_29);
7184                 txdata_constr.data[d] = arr_conv_29_conv;
7185         }
7186         (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0);
7187         ChannelManager_block_connected(&this_arg_conv, header_ref, txdata_constr, height);
7188 }
7189
7190 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray header) {
7191         LDKChannelManager this_arg_conv;
7192         this_arg_conv.inner = (void*)(this_arg & (~1));
7193         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7194         unsigned char header_arr[80];
7195         CHECK((*_env)->GetArrayLength (_env, header) == 80);
7196         (*_env)->GetByteArrayRegion (_env, header, 0, 80, header_arr);
7197         unsigned char (*header_ref)[80] = &header_arr;
7198         ChannelManager_block_disconnected(&this_arg_conv, header_ref);
7199 }
7200
7201 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1as_1ChannelMessageHandler(JNIEnv * _env, jclass _b, jlong this_arg) {
7202         LDKChannelManager this_arg_conv;
7203         this_arg_conv.inner = (void*)(this_arg & (~1));
7204         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
7205         LDKChannelMessageHandler* ret = MALLOC(sizeof(LDKChannelMessageHandler), "LDKChannelMessageHandler");
7206         *ret = ChannelManager_as_ChannelMessageHandler(&this_arg_conv);
7207         return (long)ret;
7208 }
7209
7210 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7211         LDKChannelManagerReadArgs this_ptr_conv;
7212         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7213         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7214         ChannelManagerReadArgs_free(this_ptr_conv);
7215 }
7216
7217 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1keys_1manager(JNIEnv * _env, jclass _b, jlong this_ptr) {
7218         LDKChannelManagerReadArgs this_ptr_conv;
7219         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7220         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7221         long ret_ret = (long)ChannelManagerReadArgs_get_keys_manager(&this_ptr_conv);
7222         return ret_ret;
7223 }
7224
7225 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1keys_1manager(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7226         LDKChannelManagerReadArgs this_ptr_conv;
7227         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7228         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7229         LDKKeysInterface val_conv = *(LDKKeysInterface*)val;
7230         if (val_conv.free == LDKKeysInterface_JCalls_free) {
7231                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7232                 LDKKeysInterface_JCalls_clone(val_conv.this_arg);
7233         }
7234         ChannelManagerReadArgs_set_keys_manager(&this_ptr_conv, val_conv);
7235 }
7236
7237 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1fee_1estimator(JNIEnv * _env, jclass _b, jlong this_ptr) {
7238         LDKChannelManagerReadArgs this_ptr_conv;
7239         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7240         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7241         long ret_ret = (long)ChannelManagerReadArgs_get_fee_estimator(&this_ptr_conv);
7242         return ret_ret;
7243 }
7244
7245 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1fee_1estimator(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7246         LDKChannelManagerReadArgs this_ptr_conv;
7247         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7248         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7249         LDKFeeEstimator val_conv = *(LDKFeeEstimator*)val;
7250         if (val_conv.free == LDKFeeEstimator_JCalls_free) {
7251                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7252                 LDKFeeEstimator_JCalls_clone(val_conv.this_arg);
7253         }
7254         ChannelManagerReadArgs_set_fee_estimator(&this_ptr_conv, val_conv);
7255 }
7256
7257 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1chain_1monitor(JNIEnv * _env, jclass _b, jlong this_ptr) {
7258         LDKChannelManagerReadArgs this_ptr_conv;
7259         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7260         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7261         long ret_ret = (long)ChannelManagerReadArgs_get_chain_monitor(&this_ptr_conv);
7262         return ret_ret;
7263 }
7264
7265 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1chain_1monitor(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7266         LDKChannelManagerReadArgs this_ptr_conv;
7267         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7268         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7269         LDKWatch val_conv = *(LDKWatch*)val;
7270         if (val_conv.free == LDKWatch_JCalls_free) {
7271                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7272                 LDKWatch_JCalls_clone(val_conv.this_arg);
7273         }
7274         ChannelManagerReadArgs_set_chain_monitor(&this_ptr_conv, val_conv);
7275 }
7276
7277 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1tx_1broadcaster(JNIEnv * _env, jclass _b, jlong this_ptr) {
7278         LDKChannelManagerReadArgs this_ptr_conv;
7279         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7280         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7281         long ret_ret = (long)ChannelManagerReadArgs_get_tx_broadcaster(&this_ptr_conv);
7282         return ret_ret;
7283 }
7284
7285 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1tx_1broadcaster(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7286         LDKChannelManagerReadArgs this_ptr_conv;
7287         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7288         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7289         LDKBroadcasterInterface val_conv = *(LDKBroadcasterInterface*)val;
7290         if (val_conv.free == LDKBroadcasterInterface_JCalls_free) {
7291                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7292                 LDKBroadcasterInterface_JCalls_clone(val_conv.this_arg);
7293         }
7294         ChannelManagerReadArgs_set_tx_broadcaster(&this_ptr_conv, val_conv);
7295 }
7296
7297 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1logger(JNIEnv * _env, jclass _b, jlong this_ptr) {
7298         LDKChannelManagerReadArgs this_ptr_conv;
7299         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7300         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7301         long ret_ret = (long)ChannelManagerReadArgs_get_logger(&this_ptr_conv);
7302         return ret_ret;
7303 }
7304
7305 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1logger(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7306         LDKChannelManagerReadArgs this_ptr_conv;
7307         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7308         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7309         LDKLogger val_conv = *(LDKLogger*)val;
7310         if (val_conv.free == LDKLogger_JCalls_free) {
7311                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7312                 LDKLogger_JCalls_clone(val_conv.this_arg);
7313         }
7314         ChannelManagerReadArgs_set_logger(&this_ptr_conv, val_conv);
7315 }
7316
7317 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1get_1default_1config(JNIEnv * _env, jclass _b, jlong this_ptr) {
7318         LDKChannelManagerReadArgs this_ptr_conv;
7319         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7320         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7321         LDKUserConfig ret_var = ChannelManagerReadArgs_get_default_config(&this_ptr_conv);
7322         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7323         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7324         long ret_ref = (long)ret_var.inner;
7325         if (ret_var.is_owned) {
7326                 ret_ref |= 1;
7327         }
7328         return ret_ref;
7329 }
7330
7331 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1default_1config(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7332         LDKChannelManagerReadArgs this_ptr_conv;
7333         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7334         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7335         LDKUserConfig val_conv;
7336         val_conv.inner = (void*)(val & (~1));
7337         val_conv.is_owned = (val & 1) || (val == 0);
7338         if (val_conv.inner != NULL)
7339                 val_conv = UserConfig_clone(&val_conv);
7340         ChannelManagerReadArgs_set_default_config(&this_ptr_conv, val_conv);
7341 }
7342
7343 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) {
7344         LDKKeysInterface keys_manager_conv = *(LDKKeysInterface*)keys_manager;
7345         if (keys_manager_conv.free == LDKKeysInterface_JCalls_free) {
7346                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7347                 LDKKeysInterface_JCalls_clone(keys_manager_conv.this_arg);
7348         }
7349         LDKFeeEstimator fee_estimator_conv = *(LDKFeeEstimator*)fee_estimator;
7350         if (fee_estimator_conv.free == LDKFeeEstimator_JCalls_free) {
7351                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7352                 LDKFeeEstimator_JCalls_clone(fee_estimator_conv.this_arg);
7353         }
7354         LDKWatch chain_monitor_conv = *(LDKWatch*)chain_monitor;
7355         if (chain_monitor_conv.free == LDKWatch_JCalls_free) {
7356                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7357                 LDKWatch_JCalls_clone(chain_monitor_conv.this_arg);
7358         }
7359         LDKBroadcasterInterface tx_broadcaster_conv = *(LDKBroadcasterInterface*)tx_broadcaster;
7360         if (tx_broadcaster_conv.free == LDKBroadcasterInterface_JCalls_free) {
7361                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7362                 LDKBroadcasterInterface_JCalls_clone(tx_broadcaster_conv.this_arg);
7363         }
7364         LDKLogger logger_conv = *(LDKLogger*)logger;
7365         if (logger_conv.free == LDKLogger_JCalls_free) {
7366                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
7367                 LDKLogger_JCalls_clone(logger_conv.this_arg);
7368         }
7369         LDKUserConfig default_config_conv;
7370         default_config_conv.inner = (void*)(default_config & (~1));
7371         default_config_conv.is_owned = (default_config & 1) || (default_config == 0);
7372         if (default_config_conv.inner != NULL)
7373                 default_config_conv = UserConfig_clone(&default_config_conv);
7374         LDKCVec_ChannelMonitorZ channel_monitors_constr;
7375         channel_monitors_constr.datalen = (*_env)->GetArrayLength (_env, channel_monitors);
7376         if (channel_monitors_constr.datalen > 0)
7377                 channel_monitors_constr.data = MALLOC(channel_monitors_constr.datalen * sizeof(LDKChannelMonitor), "LDKCVec_ChannelMonitorZ Elements");
7378         else
7379                 channel_monitors_constr.data = NULL;
7380         long* channel_monitors_vals = (*_env)->GetLongArrayElements (_env, channel_monitors, NULL);
7381         for (size_t q = 0; q < channel_monitors_constr.datalen; q++) {
7382                 long arr_conv_16 = channel_monitors_vals[q];
7383                 LDKChannelMonitor arr_conv_16_conv;
7384                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
7385                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
7386                 channel_monitors_constr.data[q] = arr_conv_16_conv;
7387         }
7388         (*_env)->ReleaseLongArrayElements (_env, channel_monitors, channel_monitors_vals, 0);
7389         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);
7390         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7391         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7392         long ret_ref = (long)ret_var.inner;
7393         if (ret_var.is_owned) {
7394                 ret_ref |= 1;
7395         }
7396         return ret_ref;
7397 }
7398
7399 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DecodeError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7400         LDKDecodeError this_ptr_conv;
7401         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7402         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7403         DecodeError_free(this_ptr_conv);
7404 }
7405
7406 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Init_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7407         LDKInit this_ptr_conv;
7408         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7409         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7410         Init_free(this_ptr_conv);
7411 }
7412
7413 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Init_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7414         LDKInit orig_conv;
7415         orig_conv.inner = (void*)(orig & (~1));
7416         orig_conv.is_owned = (orig & 1) || (orig == 0);
7417         LDKInit ret_var = Init_clone(&orig_conv);
7418         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7419         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7420         long ret_ref = (long)ret_var.inner;
7421         if (ret_var.is_owned) {
7422                 ret_ref |= 1;
7423         }
7424         return ret_ref;
7425 }
7426
7427 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7428         LDKErrorMessage this_ptr_conv;
7429         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7430         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7431         ErrorMessage_free(this_ptr_conv);
7432 }
7433
7434 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7435         LDKErrorMessage orig_conv;
7436         orig_conv.inner = (void*)(orig & (~1));
7437         orig_conv.is_owned = (orig & 1) || (orig == 0);
7438         LDKErrorMessage ret_var = ErrorMessage_clone(&orig_conv);
7439         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7440         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7441         long ret_ref = (long)ret_var.inner;
7442         if (ret_var.is_owned) {
7443                 ret_ref |= 1;
7444         }
7445         return ret_ref;
7446 }
7447
7448 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
7449         LDKErrorMessage this_ptr_conv;
7450         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7451         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7452         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
7453         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ErrorMessage_get_channel_id(&this_ptr_conv));
7454         return ret_arr;
7455 }
7456
7457 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7458         LDKErrorMessage this_ptr_conv;
7459         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7460         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7461         LDKThirtyTwoBytes val_ref;
7462         CHECK((*_env)->GetArrayLength (_env, val) == 32);
7463         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
7464         ErrorMessage_set_channel_id(&this_ptr_conv, val_ref);
7465 }
7466
7467 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1get_1data(JNIEnv * _env, jclass _b, jlong this_ptr) {
7468         LDKErrorMessage this_ptr_conv;
7469         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7470         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7471         LDKStr _str = ErrorMessage_get_data(&this_ptr_conv);
7472         char* _buf = MALLOC(_str.len + 1, "str conv buf");
7473         memcpy(_buf, _str.chars, _str.len);
7474         _buf[_str.len] = 0;
7475         jstring _conv = (*_env)->NewStringUTF(_env, _str.chars);
7476         FREE(_buf);
7477         return _conv;
7478 }
7479
7480 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1data(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7481         LDKErrorMessage this_ptr_conv;
7482         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7483         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7484         LDKCVec_u8Z val_ref;
7485         val_ref.data = (*_env)->GetByteArrayElements (_env, val, NULL);
7486         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
7487         ErrorMessage_set_data(&this_ptr_conv, val_ref);
7488         (*_env)->ReleaseByteArrayElements(_env, val, (int8_t*)val_ref.data, 0);
7489 }
7490
7491 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray data_arg) {
7492         LDKThirtyTwoBytes channel_id_arg_ref;
7493         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
7494         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
7495         LDKCVec_u8Z data_arg_ref;
7496         data_arg_ref.data = (*_env)->GetByteArrayElements (_env, data_arg, NULL);
7497         data_arg_ref.datalen = (*_env)->GetArrayLength (_env, data_arg);
7498         LDKErrorMessage ret_var = ErrorMessage_new(channel_id_arg_ref, data_arg_ref);
7499         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7500         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7501         long ret_ref = (long)ret_var.inner;
7502         if (ret_var.is_owned) {
7503                 ret_ref |= 1;
7504         }
7505         (*_env)->ReleaseByteArrayElements(_env, data_arg, (int8_t*)data_arg_ref.data, 0);
7506         return ret_ref;
7507 }
7508
7509 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7510         LDKPing this_ptr_conv;
7511         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7512         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7513         Ping_free(this_ptr_conv);
7514 }
7515
7516 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7517         LDKPing orig_conv;
7518         orig_conv.inner = (void*)(orig & (~1));
7519         orig_conv.is_owned = (orig & 1) || (orig == 0);
7520         LDKPing ret_var = Ping_clone(&orig_conv);
7521         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7522         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7523         long ret_ref = (long)ret_var.inner;
7524         if (ret_var.is_owned) {
7525                 ret_ref |= 1;
7526         }
7527         return ret_ref;
7528 }
7529
7530 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Ping_1get_1ponglen(JNIEnv * _env, jclass _b, jlong this_ptr) {
7531         LDKPing this_ptr_conv;
7532         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7533         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7534         jshort ret_val = Ping_get_ponglen(&this_ptr_conv);
7535         return ret_val;
7536 }
7537
7538 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1ponglen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7539         LDKPing this_ptr_conv;
7540         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7541         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7542         Ping_set_ponglen(&this_ptr_conv, val);
7543 }
7544
7545 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Ping_1get_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr) {
7546         LDKPing this_ptr_conv;
7547         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7548         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7549         jshort ret_val = Ping_get_byteslen(&this_ptr_conv);
7550         return ret_val;
7551 }
7552
7553 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Ping_1set_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7554         LDKPing this_ptr_conv;
7555         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7556         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7557         Ping_set_byteslen(&this_ptr_conv, val);
7558 }
7559
7560 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1new(JNIEnv * _env, jclass _b, jshort ponglen_arg, jshort byteslen_arg) {
7561         LDKPing ret_var = Ping_new(ponglen_arg, byteslen_arg);
7562         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7563         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7564         long ret_ref = (long)ret_var.inner;
7565         if (ret_var.is_owned) {
7566                 ret_ref |= 1;
7567         }
7568         return ret_ref;
7569 }
7570
7571 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7572         LDKPong this_ptr_conv;
7573         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7574         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7575         Pong_free(this_ptr_conv);
7576 }
7577
7578 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7579         LDKPong orig_conv;
7580         orig_conv.inner = (void*)(orig & (~1));
7581         orig_conv.is_owned = (orig & 1) || (orig == 0);
7582         LDKPong ret_var = Pong_clone(&orig_conv);
7583         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7584         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7585         long ret_ref = (long)ret_var.inner;
7586         if (ret_var.is_owned) {
7587                 ret_ref |= 1;
7588         }
7589         return ret_ref;
7590 }
7591
7592 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_Pong_1get_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr) {
7593         LDKPong this_ptr_conv;
7594         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7595         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7596         jshort ret_val = Pong_get_byteslen(&this_ptr_conv);
7597         return ret_val;
7598 }
7599
7600 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Pong_1set_1byteslen(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7601         LDKPong this_ptr_conv;
7602         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7603         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7604         Pong_set_byteslen(&this_ptr_conv, val);
7605 }
7606
7607 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1new(JNIEnv * _env, jclass _b, jshort byteslen_arg) {
7608         LDKPong ret_var = Pong_new(byteslen_arg);
7609         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7610         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7611         long ret_ref = (long)ret_var.inner;
7612         if (ret_var.is_owned) {
7613                 ret_ref |= 1;
7614         }
7615         return ret_ref;
7616 }
7617
7618 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7619         LDKOpenChannel this_ptr_conv;
7620         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7621         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7622         OpenChannel_free(this_ptr_conv);
7623 }
7624
7625 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7626         LDKOpenChannel orig_conv;
7627         orig_conv.inner = (void*)(orig & (~1));
7628         orig_conv.is_owned = (orig & 1) || (orig == 0);
7629         LDKOpenChannel ret_var = OpenChannel_clone(&orig_conv);
7630         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7631         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7632         long ret_ref = (long)ret_var.inner;
7633         if (ret_var.is_owned) {
7634                 ret_ref |= 1;
7635         }
7636         return ret_ref;
7637 }
7638
7639 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
7640         LDKOpenChannel this_ptr_conv;
7641         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7642         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7643         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
7644         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OpenChannel_get_chain_hash(&this_ptr_conv));
7645         return ret_arr;
7646 }
7647
7648 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7649         LDKOpenChannel this_ptr_conv;
7650         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7651         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7652         LDKThirtyTwoBytes val_ref;
7653         CHECK((*_env)->GetArrayLength (_env, val) == 32);
7654         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
7655         OpenChannel_set_chain_hash(&this_ptr_conv, val_ref);
7656 }
7657
7658 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
7659         LDKOpenChannel this_ptr_conv;
7660         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7661         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7662         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
7663         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *OpenChannel_get_temporary_channel_id(&this_ptr_conv));
7664         return ret_arr;
7665 }
7666
7667 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7668         LDKOpenChannel this_ptr_conv;
7669         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7670         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7671         LDKThirtyTwoBytes val_ref;
7672         CHECK((*_env)->GetArrayLength (_env, val) == 32);
7673         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
7674         OpenChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
7675 }
7676
7677 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7678         LDKOpenChannel this_ptr_conv;
7679         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7680         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7681         jlong ret_val = OpenChannel_get_funding_satoshis(&this_ptr_conv);
7682         return ret_val;
7683 }
7684
7685 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7686         LDKOpenChannel this_ptr_conv;
7687         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7688         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7689         OpenChannel_set_funding_satoshis(&this_ptr_conv, val);
7690 }
7691
7692 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1push_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7693         LDKOpenChannel this_ptr_conv;
7694         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7695         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7696         jlong ret_val = OpenChannel_get_push_msat(&this_ptr_conv);
7697         return ret_val;
7698 }
7699
7700 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1push_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7701         LDKOpenChannel this_ptr_conv;
7702         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7703         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7704         OpenChannel_set_push_msat(&this_ptr_conv, val);
7705 }
7706
7707 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7708         LDKOpenChannel this_ptr_conv;
7709         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7710         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7711         jlong ret_val = OpenChannel_get_dust_limit_satoshis(&this_ptr_conv);
7712         return ret_val;
7713 }
7714
7715 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7716         LDKOpenChannel this_ptr_conv;
7717         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7718         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7719         OpenChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
7720 }
7721
7722 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7723         LDKOpenChannel this_ptr_conv;
7724         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7725         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7726         jlong ret_val = OpenChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
7727         return ret_val;
7728 }
7729
7730 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) {
7731         LDKOpenChannel this_ptr_conv;
7732         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7733         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7734         OpenChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
7735 }
7736
7737 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7738         LDKOpenChannel this_ptr_conv;
7739         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7740         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7741         jlong ret_val = OpenChannel_get_channel_reserve_satoshis(&this_ptr_conv);
7742         return ret_val;
7743 }
7744
7745 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7746         LDKOpenChannel this_ptr_conv;
7747         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7748         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7749         OpenChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
7750 }
7751
7752 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7753         LDKOpenChannel this_ptr_conv;
7754         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7755         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7756         jlong ret_val = OpenChannel_get_htlc_minimum_msat(&this_ptr_conv);
7757         return ret_val;
7758 }
7759
7760 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7761         LDKOpenChannel this_ptr_conv;
7762         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7763         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7764         OpenChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
7765 }
7766
7767 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr) {
7768         LDKOpenChannel this_ptr_conv;
7769         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7770         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7771         jint ret_val = OpenChannel_get_feerate_per_kw(&this_ptr_conv);
7772         return ret_val;
7773 }
7774
7775 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
7776         LDKOpenChannel this_ptr_conv;
7777         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7778         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7779         OpenChannel_set_feerate_per_kw(&this_ptr_conv, val);
7780 }
7781
7782 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
7783         LDKOpenChannel this_ptr_conv;
7784         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7785         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7786         jshort ret_val = OpenChannel_get_to_self_delay(&this_ptr_conv);
7787         return ret_val;
7788 }
7789
7790 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7791         LDKOpenChannel this_ptr_conv;
7792         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7793         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7794         OpenChannel_set_to_self_delay(&this_ptr_conv, val);
7795 }
7796
7797 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
7798         LDKOpenChannel this_ptr_conv;
7799         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7800         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7801         jshort ret_val = OpenChannel_get_max_accepted_htlcs(&this_ptr_conv);
7802         return ret_val;
7803 }
7804
7805 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
7806         LDKOpenChannel this_ptr_conv;
7807         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7808         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7809         OpenChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
7810 }
7811
7812 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
7813         LDKOpenChannel this_ptr_conv;
7814         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7815         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7816         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
7817         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
7818         return arg_arr;
7819 }
7820
7821 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7822         LDKOpenChannel this_ptr_conv;
7823         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7824         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7825         LDKPublicKey val_ref;
7826         CHECK((*_env)->GetArrayLength (_env, val) == 33);
7827         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
7828         OpenChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
7829 }
7830
7831 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
7832         LDKOpenChannel this_ptr_conv;
7833         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7834         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7835         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
7836         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
7837         return arg_arr;
7838 }
7839
7840 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7841         LDKOpenChannel this_ptr_conv;
7842         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7843         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7844         LDKPublicKey val_ref;
7845         CHECK((*_env)->GetArrayLength (_env, val) == 33);
7846         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
7847         OpenChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
7848 }
7849
7850 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
7851         LDKOpenChannel this_ptr_conv;
7852         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7853         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7854         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
7855         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_payment_point(&this_ptr_conv).compressed_form);
7856         return arg_arr;
7857 }
7858
7859 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7860         LDKOpenChannel this_ptr_conv;
7861         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7862         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7863         LDKPublicKey val_ref;
7864         CHECK((*_env)->GetArrayLength (_env, val) == 33);
7865         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
7866         OpenChannel_set_payment_point(&this_ptr_conv, val_ref);
7867 }
7868
7869 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
7870         LDKOpenChannel this_ptr_conv;
7871         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7872         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7873         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
7874         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
7875         return arg_arr;
7876 }
7877
7878 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7879         LDKOpenChannel this_ptr_conv;
7880         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7881         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7882         LDKPublicKey val_ref;
7883         CHECK((*_env)->GetArrayLength (_env, val) == 33);
7884         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
7885         OpenChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
7886 }
7887
7888 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
7889         LDKOpenChannel this_ptr_conv;
7890         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7891         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7892         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
7893         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
7894         return arg_arr;
7895 }
7896
7897 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7898         LDKOpenChannel this_ptr_conv;
7899         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7900         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7901         LDKPublicKey val_ref;
7902         CHECK((*_env)->GetArrayLength (_env, val) == 33);
7903         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
7904         OpenChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
7905 }
7906
7907 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
7908         LDKOpenChannel this_ptr_conv;
7909         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7910         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7911         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
7912         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, OpenChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
7913         return arg_arr;
7914 }
7915
7916 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7917         LDKOpenChannel this_ptr_conv;
7918         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7919         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7920         LDKPublicKey val_ref;
7921         CHECK((*_env)->GetArrayLength (_env, val) == 33);
7922         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
7923         OpenChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
7924 }
7925
7926 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_OpenChannel_1get_1channel_1flags(JNIEnv * _env, jclass _b, jlong this_ptr) {
7927         LDKOpenChannel this_ptr_conv;
7928         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7929         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7930         jbyte ret_val = OpenChannel_get_channel_flags(&this_ptr_conv);
7931         return ret_val;
7932 }
7933
7934 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_OpenChannel_1set_1channel_1flags(JNIEnv * _env, jclass _b, jlong this_ptr, jbyte val) {
7935         LDKOpenChannel this_ptr_conv;
7936         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7937         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7938         OpenChannel_set_channel_flags(&this_ptr_conv, val);
7939 }
7940
7941 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
7942         LDKAcceptChannel this_ptr_conv;
7943         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7944         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7945         AcceptChannel_free(this_ptr_conv);
7946 }
7947
7948 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1clone(JNIEnv * _env, jclass _b, jlong orig) {
7949         LDKAcceptChannel orig_conv;
7950         orig_conv.inner = (void*)(orig & (~1));
7951         orig_conv.is_owned = (orig & 1) || (orig == 0);
7952         LDKAcceptChannel ret_var = AcceptChannel_clone(&orig_conv);
7953         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
7954         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
7955         long ret_ref = (long)ret_var.inner;
7956         if (ret_var.is_owned) {
7957                 ret_ref |= 1;
7958         }
7959         return ret_ref;
7960 }
7961
7962 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
7963         LDKAcceptChannel this_ptr_conv;
7964         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7965         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7966         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
7967         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *AcceptChannel_get_temporary_channel_id(&this_ptr_conv));
7968         return ret_arr;
7969 }
7970
7971 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
7972         LDKAcceptChannel this_ptr_conv;
7973         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7974         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7975         LDKThirtyTwoBytes val_ref;
7976         CHECK((*_env)->GetArrayLength (_env, val) == 32);
7977         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
7978         AcceptChannel_set_temporary_channel_id(&this_ptr_conv, val_ref);
7979 }
7980
7981 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
7982         LDKAcceptChannel this_ptr_conv;
7983         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7984         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7985         jlong ret_val = AcceptChannel_get_dust_limit_satoshis(&this_ptr_conv);
7986         return ret_val;
7987 }
7988
7989 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1dust_1limit_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
7990         LDKAcceptChannel this_ptr_conv;
7991         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7992         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
7993         AcceptChannel_set_dust_limit_satoshis(&this_ptr_conv, val);
7994 }
7995
7996 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1max_1htlc_1value_1in_1flight_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
7997         LDKAcceptChannel this_ptr_conv;
7998         this_ptr_conv.inner = (void*)(this_ptr & (~1));
7999         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8000         jlong ret_val = AcceptChannel_get_max_htlc_value_in_flight_msat(&this_ptr_conv);
8001         return ret_val;
8002 }
8003
8004 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) {
8005         LDKAcceptChannel this_ptr_conv;
8006         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8007         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8008         AcceptChannel_set_max_htlc_value_in_flight_msat(&this_ptr_conv, val);
8009 }
8010
8011 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
8012         LDKAcceptChannel this_ptr_conv;
8013         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8014         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8015         jlong ret_val = AcceptChannel_get_channel_reserve_satoshis(&this_ptr_conv);
8016         return ret_val;
8017 }
8018
8019 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1channel_1reserve_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8020         LDKAcceptChannel this_ptr_conv;
8021         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8022         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8023         AcceptChannel_set_channel_reserve_satoshis(&this_ptr_conv, val);
8024 }
8025
8026 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
8027         LDKAcceptChannel this_ptr_conv;
8028         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8029         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8030         jlong ret_val = AcceptChannel_get_htlc_minimum_msat(&this_ptr_conv);
8031         return ret_val;
8032 }
8033
8034 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8035         LDKAcceptChannel this_ptr_conv;
8036         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8037         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8038         AcceptChannel_set_htlc_minimum_msat(&this_ptr_conv, val);
8039 }
8040
8041 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr) {
8042         LDKAcceptChannel this_ptr_conv;
8043         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8044         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8045         jint ret_val = AcceptChannel_get_minimum_depth(&this_ptr_conv);
8046         return ret_val;
8047 }
8048
8049 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1minimum_1depth(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
8050         LDKAcceptChannel this_ptr_conv;
8051         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8052         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8053         AcceptChannel_set_minimum_depth(&this_ptr_conv, val);
8054 }
8055
8056 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr) {
8057         LDKAcceptChannel this_ptr_conv;
8058         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8059         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8060         jshort ret_val = AcceptChannel_get_to_self_delay(&this_ptr_conv);
8061         return ret_val;
8062 }
8063
8064 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1to_1self_1delay(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8065         LDKAcceptChannel this_ptr_conv;
8066         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8067         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8068         AcceptChannel_set_to_self_delay(&this_ptr_conv, val);
8069 }
8070
8071 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr) {
8072         LDKAcceptChannel this_ptr_conv;
8073         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8074         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8075         jshort ret_val = AcceptChannel_get_max_accepted_htlcs(&this_ptr_conv);
8076         return ret_val;
8077 }
8078
8079 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1max_1accepted_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8080         LDKAcceptChannel this_ptr_conv;
8081         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8082         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8083         AcceptChannel_set_max_accepted_htlcs(&this_ptr_conv, val);
8084 }
8085
8086 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
8087         LDKAcceptChannel this_ptr_conv;
8088         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8089         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8090         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8091         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_funding_pubkey(&this_ptr_conv).compressed_form);
8092         return arg_arr;
8093 }
8094
8095 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8096         LDKAcceptChannel this_ptr_conv;
8097         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8098         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8099         LDKPublicKey val_ref;
8100         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8101         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8102         AcceptChannel_set_funding_pubkey(&this_ptr_conv, val_ref);
8103 }
8104
8105 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8106         LDKAcceptChannel this_ptr_conv;
8107         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8108         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8109         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8110         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_revocation_basepoint(&this_ptr_conv).compressed_form);
8111         return arg_arr;
8112 }
8113
8114 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8115         LDKAcceptChannel this_ptr_conv;
8116         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8117         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8118         LDKPublicKey val_ref;
8119         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8120         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8121         AcceptChannel_set_revocation_basepoint(&this_ptr_conv, val_ref);
8122 }
8123
8124 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
8125         LDKAcceptChannel this_ptr_conv;
8126         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8127         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8128         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8129         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_payment_point(&this_ptr_conv).compressed_form);
8130         return arg_arr;
8131 }
8132
8133 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8134         LDKAcceptChannel this_ptr_conv;
8135         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8136         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8137         LDKPublicKey val_ref;
8138         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8139         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8140         AcceptChannel_set_payment_point(&this_ptr_conv, val_ref);
8141 }
8142
8143 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8144         LDKAcceptChannel this_ptr_conv;
8145         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8146         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8147         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8148         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
8149         return arg_arr;
8150 }
8151
8152 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8153         LDKAcceptChannel this_ptr_conv;
8154         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8155         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8156         LDKPublicKey val_ref;
8157         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8158         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8159         AcceptChannel_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
8160 }
8161
8162 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
8163         LDKAcceptChannel this_ptr_conv;
8164         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8165         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8166         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8167         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_htlc_basepoint(&this_ptr_conv).compressed_form);
8168         return arg_arr;
8169 }
8170
8171 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8172         LDKAcceptChannel this_ptr_conv;
8173         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8174         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8175         LDKPublicKey val_ref;
8176         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8177         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8178         AcceptChannel_set_htlc_basepoint(&this_ptr_conv, val_ref);
8179 }
8180
8181 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1get_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
8182         LDKAcceptChannel this_ptr_conv;
8183         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8184         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8185         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8186         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, AcceptChannel_get_first_per_commitment_point(&this_ptr_conv).compressed_form);
8187         return arg_arr;
8188 }
8189
8190 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1set_1first_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8191         LDKAcceptChannel this_ptr_conv;
8192         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8193         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8194         LDKPublicKey val_ref;
8195         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8196         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8197         AcceptChannel_set_first_per_commitment_point(&this_ptr_conv, val_ref);
8198 }
8199
8200 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8201         LDKFundingCreated this_ptr_conv;
8202         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8203         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8204         FundingCreated_free(this_ptr_conv);
8205 }
8206
8207 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingCreated_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8208         LDKFundingCreated orig_conv;
8209         orig_conv.inner = (void*)(orig & (~1));
8210         orig_conv.is_owned = (orig & 1) || (orig == 0);
8211         LDKFundingCreated ret_var = FundingCreated_clone(&orig_conv);
8212         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8213         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8214         long ret_ref = (long)ret_var.inner;
8215         if (ret_var.is_owned) {
8216                 ret_ref |= 1;
8217         }
8218         return ret_ref;
8219 }
8220
8221 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8222         LDKFundingCreated this_ptr_conv;
8223         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8224         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8225         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8226         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingCreated_get_temporary_channel_id(&this_ptr_conv));
8227         return ret_arr;
8228 }
8229
8230 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1temporary_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8231         LDKFundingCreated this_ptr_conv;
8232         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8233         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8234         LDKThirtyTwoBytes val_ref;
8235         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8236         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8237         FundingCreated_set_temporary_channel_id(&this_ptr_conv, val_ref);
8238 }
8239
8240 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1txid(JNIEnv * _env, jclass _b, jlong this_ptr) {
8241         LDKFundingCreated this_ptr_conv;
8242         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8243         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8244         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8245         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingCreated_get_funding_txid(&this_ptr_conv));
8246         return ret_arr;
8247 }
8248
8249 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1txid(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8250         LDKFundingCreated this_ptr_conv;
8251         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8252         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8253         LDKThirtyTwoBytes val_ref;
8254         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8255         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8256         FundingCreated_set_funding_txid(&this_ptr_conv, val_ref);
8257 }
8258
8259 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1funding_1output_1index(JNIEnv * _env, jclass _b, jlong this_ptr) {
8260         LDKFundingCreated this_ptr_conv;
8261         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8262         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8263         jshort ret_val = FundingCreated_get_funding_output_index(&this_ptr_conv);
8264         return ret_val;
8265 }
8266
8267 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1funding_1output_1index(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8268         LDKFundingCreated this_ptr_conv;
8269         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8270         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8271         FundingCreated_set_funding_output_index(&this_ptr_conv, val);
8272 }
8273
8274 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
8275         LDKFundingCreated this_ptr_conv;
8276         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8277         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8278         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
8279         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, FundingCreated_get_signature(&this_ptr_conv).compact_form);
8280         return arg_arr;
8281 }
8282
8283 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingCreated_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8284         LDKFundingCreated this_ptr_conv;
8285         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8286         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8287         LDKSignature val_ref;
8288         CHECK((*_env)->GetArrayLength (_env, val) == 64);
8289         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
8290         FundingCreated_set_signature(&this_ptr_conv, val_ref);
8291 }
8292
8293 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) {
8294         LDKThirtyTwoBytes temporary_channel_id_arg_ref;
8295         CHECK((*_env)->GetArrayLength (_env, temporary_channel_id_arg) == 32);
8296         (*_env)->GetByteArrayRegion (_env, temporary_channel_id_arg, 0, 32, temporary_channel_id_arg_ref.data);
8297         LDKThirtyTwoBytes funding_txid_arg_ref;
8298         CHECK((*_env)->GetArrayLength (_env, funding_txid_arg) == 32);
8299         (*_env)->GetByteArrayRegion (_env, funding_txid_arg, 0, 32, funding_txid_arg_ref.data);
8300         LDKSignature signature_arg_ref;
8301         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
8302         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
8303         LDKFundingCreated ret_var = FundingCreated_new(temporary_channel_id_arg_ref, funding_txid_arg_ref, funding_output_index_arg, signature_arg_ref);
8304         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8305         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8306         long ret_ref = (long)ret_var.inner;
8307         if (ret_var.is_owned) {
8308                 ret_ref |= 1;
8309         }
8310         return ret_ref;
8311 }
8312
8313 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8314         LDKFundingSigned this_ptr_conv;
8315         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8316         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8317         FundingSigned_free(this_ptr_conv);
8318 }
8319
8320 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8321         LDKFundingSigned orig_conv;
8322         orig_conv.inner = (void*)(orig & (~1));
8323         orig_conv.is_owned = (orig & 1) || (orig == 0);
8324         LDKFundingSigned ret_var = FundingSigned_clone(&orig_conv);
8325         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8326         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8327         long ret_ref = (long)ret_var.inner;
8328         if (ret_var.is_owned) {
8329                 ret_ref |= 1;
8330         }
8331         return ret_ref;
8332 }
8333
8334 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8335         LDKFundingSigned this_ptr_conv;
8336         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8337         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8338         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8339         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingSigned_get_channel_id(&this_ptr_conv));
8340         return ret_arr;
8341 }
8342
8343 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8344         LDKFundingSigned this_ptr_conv;
8345         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8346         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8347         LDKThirtyTwoBytes val_ref;
8348         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8349         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8350         FundingSigned_set_channel_id(&this_ptr_conv, val_ref);
8351 }
8352
8353 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
8354         LDKFundingSigned this_ptr_conv;
8355         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8356         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8357         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
8358         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, FundingSigned_get_signature(&this_ptr_conv).compact_form);
8359         return arg_arr;
8360 }
8361
8362 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8363         LDKFundingSigned this_ptr_conv;
8364         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8365         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8366         LDKSignature val_ref;
8367         CHECK((*_env)->GetArrayLength (_env, val) == 64);
8368         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
8369         FundingSigned_set_signature(&this_ptr_conv, val_ref);
8370 }
8371
8372 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray signature_arg) {
8373         LDKThirtyTwoBytes channel_id_arg_ref;
8374         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
8375         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
8376         LDKSignature signature_arg_ref;
8377         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
8378         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
8379         LDKFundingSigned ret_var = FundingSigned_new(channel_id_arg_ref, signature_arg_ref);
8380         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8381         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8382         long ret_ref = (long)ret_var.inner;
8383         if (ret_var.is_owned) {
8384                 ret_ref |= 1;
8385         }
8386         return ret_ref;
8387 }
8388
8389 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8390         LDKFundingLocked this_ptr_conv;
8391         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8392         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8393         FundingLocked_free(this_ptr_conv);
8394 }
8395
8396 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8397         LDKFundingLocked orig_conv;
8398         orig_conv.inner = (void*)(orig & (~1));
8399         orig_conv.is_owned = (orig & 1) || (orig == 0);
8400         LDKFundingLocked ret_var = FundingLocked_clone(&orig_conv);
8401         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8402         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8403         long ret_ref = (long)ret_var.inner;
8404         if (ret_var.is_owned) {
8405                 ret_ref |= 1;
8406         }
8407         return ret_ref;
8408 }
8409
8410 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8411         LDKFundingLocked this_ptr_conv;
8412         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8413         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8414         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8415         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *FundingLocked_get_channel_id(&this_ptr_conv));
8416         return ret_arr;
8417 }
8418
8419 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8420         LDKFundingLocked this_ptr_conv;
8421         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8422         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8423         LDKThirtyTwoBytes val_ref;
8424         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8425         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8426         FundingLocked_set_channel_id(&this_ptr_conv, val_ref);
8427 }
8428
8429 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1get_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
8430         LDKFundingLocked this_ptr_conv;
8431         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8432         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8433         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
8434         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, FundingLocked_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
8435         return arg_arr;
8436 }
8437
8438 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FundingLocked_1set_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8439         LDKFundingLocked this_ptr_conv;
8440         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8441         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8442         LDKPublicKey val_ref;
8443         CHECK((*_env)->GetArrayLength (_env, val) == 33);
8444         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
8445         FundingLocked_set_next_per_commitment_point(&this_ptr_conv, val_ref);
8446 }
8447
8448 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray next_per_commitment_point_arg) {
8449         LDKThirtyTwoBytes channel_id_arg_ref;
8450         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
8451         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
8452         LDKPublicKey next_per_commitment_point_arg_ref;
8453         CHECK((*_env)->GetArrayLength (_env, next_per_commitment_point_arg) == 33);
8454         (*_env)->GetByteArrayRegion (_env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
8455         LDKFundingLocked ret_var = FundingLocked_new(channel_id_arg_ref, next_per_commitment_point_arg_ref);
8456         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8457         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8458         long ret_ref = (long)ret_var.inner;
8459         if (ret_var.is_owned) {
8460                 ret_ref |= 1;
8461         }
8462         return ret_ref;
8463 }
8464
8465 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8466         LDKShutdown this_ptr_conv;
8467         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8468         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8469         Shutdown_free(this_ptr_conv);
8470 }
8471
8472 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8473         LDKShutdown orig_conv;
8474         orig_conv.inner = (void*)(orig & (~1));
8475         orig_conv.is_owned = (orig & 1) || (orig == 0);
8476         LDKShutdown ret_var = Shutdown_clone(&orig_conv);
8477         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8478         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8479         long ret_ref = (long)ret_var.inner;
8480         if (ret_var.is_owned) {
8481                 ret_ref |= 1;
8482         }
8483         return ret_ref;
8484 }
8485
8486 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8487         LDKShutdown this_ptr_conv;
8488         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8489         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8490         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8491         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *Shutdown_get_channel_id(&this_ptr_conv));
8492         return ret_arr;
8493 }
8494
8495 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8496         LDKShutdown this_ptr_conv;
8497         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8498         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8499         LDKThirtyTwoBytes val_ref;
8500         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8501         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8502         Shutdown_set_channel_id(&this_ptr_conv, val_ref);
8503 }
8504
8505 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1get_1scriptpubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
8506         LDKShutdown this_ptr_conv;
8507         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8508         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8509         LDKu8slice arg_var = Shutdown_get_scriptpubkey(&this_ptr_conv);
8510         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
8511         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
8512         return arg_arr;
8513 }
8514
8515 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1scriptpubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8516         LDKShutdown this_ptr_conv;
8517         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8518         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8519         LDKCVec_u8Z val_ref;
8520         val_ref.data = (*_env)->GetByteArrayElements (_env, val, NULL);
8521         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
8522         Shutdown_set_scriptpubkey(&this_ptr_conv, val_ref);
8523         (*_env)->ReleaseByteArrayElements(_env, val, (int8_t*)val_ref.data, 0);
8524 }
8525
8526 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray scriptpubkey_arg) {
8527         LDKThirtyTwoBytes channel_id_arg_ref;
8528         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
8529         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
8530         LDKCVec_u8Z scriptpubkey_arg_ref;
8531         scriptpubkey_arg_ref.data = (*_env)->GetByteArrayElements (_env, scriptpubkey_arg, NULL);
8532         scriptpubkey_arg_ref.datalen = (*_env)->GetArrayLength (_env, scriptpubkey_arg);
8533         LDKShutdown ret_var = Shutdown_new(channel_id_arg_ref, scriptpubkey_arg_ref);
8534         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8535         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8536         long ret_ref = (long)ret_var.inner;
8537         if (ret_var.is_owned) {
8538                 ret_ref |= 1;
8539         }
8540         (*_env)->ReleaseByteArrayElements(_env, scriptpubkey_arg, (int8_t*)scriptpubkey_arg_ref.data, 0);
8541         return ret_ref;
8542 }
8543
8544 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8545         LDKClosingSigned this_ptr_conv;
8546         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8547         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8548         ClosingSigned_free(this_ptr_conv);
8549 }
8550
8551 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8552         LDKClosingSigned orig_conv;
8553         orig_conv.inner = (void*)(orig & (~1));
8554         orig_conv.is_owned = (orig & 1) || (orig == 0);
8555         LDKClosingSigned ret_var = ClosingSigned_clone(&orig_conv);
8556         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8557         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8558         long ret_ref = (long)ret_var.inner;
8559         if (ret_var.is_owned) {
8560                 ret_ref |= 1;
8561         }
8562         return ret_ref;
8563 }
8564
8565 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8566         LDKClosingSigned this_ptr_conv;
8567         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8568         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8569         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8570         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ClosingSigned_get_channel_id(&this_ptr_conv));
8571         return ret_arr;
8572 }
8573
8574 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8575         LDKClosingSigned this_ptr_conv;
8576         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8577         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8578         LDKThirtyTwoBytes val_ref;
8579         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8580         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8581         ClosingSigned_set_channel_id(&this_ptr_conv, val_ref);
8582 }
8583
8584 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1fee_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr) {
8585         LDKClosingSigned this_ptr_conv;
8586         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8587         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8588         jlong ret_val = ClosingSigned_get_fee_satoshis(&this_ptr_conv);
8589         return ret_val;
8590 }
8591
8592 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1fee_1satoshis(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8593         LDKClosingSigned this_ptr_conv;
8594         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8595         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8596         ClosingSigned_set_fee_satoshis(&this_ptr_conv, val);
8597 }
8598
8599 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
8600         LDKClosingSigned this_ptr_conv;
8601         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8602         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8603         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
8604         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ClosingSigned_get_signature(&this_ptr_conv).compact_form);
8605         return arg_arr;
8606 }
8607
8608 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8609         LDKClosingSigned this_ptr_conv;
8610         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8611         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8612         LDKSignature val_ref;
8613         CHECK((*_env)->GetArrayLength (_env, val) == 64);
8614         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
8615         ClosingSigned_set_signature(&this_ptr_conv, val_ref);
8616 }
8617
8618 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) {
8619         LDKThirtyTwoBytes channel_id_arg_ref;
8620         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
8621         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
8622         LDKSignature signature_arg_ref;
8623         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
8624         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
8625         LDKClosingSigned ret_var = ClosingSigned_new(channel_id_arg_ref, fee_satoshis_arg, signature_arg_ref);
8626         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8627         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8628         long ret_ref = (long)ret_var.inner;
8629         if (ret_var.is_owned) {
8630                 ret_ref |= 1;
8631         }
8632         return ret_ref;
8633 }
8634
8635 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8636         LDKUpdateAddHTLC this_ptr_conv;
8637         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8638         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8639         UpdateAddHTLC_free(this_ptr_conv);
8640 }
8641
8642 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8643         LDKUpdateAddHTLC orig_conv;
8644         orig_conv.inner = (void*)(orig & (~1));
8645         orig_conv.is_owned = (orig & 1) || (orig == 0);
8646         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_clone(&orig_conv);
8647         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8648         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8649         long ret_ref = (long)ret_var.inner;
8650         if (ret_var.is_owned) {
8651                 ret_ref |= 1;
8652         }
8653         return ret_ref;
8654 }
8655
8656 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8657         LDKUpdateAddHTLC this_ptr_conv;
8658         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8659         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8660         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8661         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateAddHTLC_get_channel_id(&this_ptr_conv));
8662         return ret_arr;
8663 }
8664
8665 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8666         LDKUpdateAddHTLC this_ptr_conv;
8667         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8668         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8669         LDKThirtyTwoBytes val_ref;
8670         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8671         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8672         UpdateAddHTLC_set_channel_id(&this_ptr_conv, val_ref);
8673 }
8674
8675 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8676         LDKUpdateAddHTLC this_ptr_conv;
8677         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8678         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8679         jlong ret_val = UpdateAddHTLC_get_htlc_id(&this_ptr_conv);
8680         return ret_val;
8681 }
8682
8683 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8684         LDKUpdateAddHTLC this_ptr_conv;
8685         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8686         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8687         UpdateAddHTLC_set_htlc_id(&this_ptr_conv, val);
8688 }
8689
8690 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
8691         LDKUpdateAddHTLC this_ptr_conv;
8692         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8693         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8694         jlong ret_val = UpdateAddHTLC_get_amount_msat(&this_ptr_conv);
8695         return ret_val;
8696 }
8697
8698 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8699         LDKUpdateAddHTLC this_ptr_conv;
8700         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8701         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8702         UpdateAddHTLC_set_amount_msat(&this_ptr_conv, val);
8703 }
8704
8705 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
8706         LDKUpdateAddHTLC this_ptr_conv;
8707         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8708         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8709         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8710         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateAddHTLC_get_payment_hash(&this_ptr_conv));
8711         return ret_arr;
8712 }
8713
8714 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8715         LDKUpdateAddHTLC this_ptr_conv;
8716         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8717         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8718         LDKThirtyTwoBytes val_ref;
8719         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8720         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8721         UpdateAddHTLC_set_payment_hash(&this_ptr_conv, val_ref);
8722 }
8723
8724 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1get_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr) {
8725         LDKUpdateAddHTLC this_ptr_conv;
8726         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8727         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8728         jint ret_val = UpdateAddHTLC_get_cltv_expiry(&this_ptr_conv);
8729         return ret_val;
8730 }
8731
8732 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1set_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
8733         LDKUpdateAddHTLC this_ptr_conv;
8734         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8735         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8736         UpdateAddHTLC_set_cltv_expiry(&this_ptr_conv, val);
8737 }
8738
8739 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8740         LDKUpdateFulfillHTLC this_ptr_conv;
8741         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8742         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8743         UpdateFulfillHTLC_free(this_ptr_conv);
8744 }
8745
8746 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8747         LDKUpdateFulfillHTLC orig_conv;
8748         orig_conv.inner = (void*)(orig & (~1));
8749         orig_conv.is_owned = (orig & 1) || (orig == 0);
8750         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_clone(&orig_conv);
8751         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8752         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8753         long ret_ref = (long)ret_var.inner;
8754         if (ret_var.is_owned) {
8755                 ret_ref |= 1;
8756         }
8757         return ret_ref;
8758 }
8759
8760 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8761         LDKUpdateFulfillHTLC this_ptr_conv;
8762         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8763         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8764         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8765         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_channel_id(&this_ptr_conv));
8766         return ret_arr;
8767 }
8768
8769 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8770         LDKUpdateFulfillHTLC this_ptr_conv;
8771         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8772         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8773         LDKThirtyTwoBytes val_ref;
8774         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8775         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8776         UpdateFulfillHTLC_set_channel_id(&this_ptr_conv, val_ref);
8777 }
8778
8779 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8780         LDKUpdateFulfillHTLC this_ptr_conv;
8781         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8782         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8783         jlong ret_val = UpdateFulfillHTLC_get_htlc_id(&this_ptr_conv);
8784         return ret_val;
8785 }
8786
8787 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8788         LDKUpdateFulfillHTLC this_ptr_conv;
8789         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8790         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8791         UpdateFulfillHTLC_set_htlc_id(&this_ptr_conv, val);
8792 }
8793
8794 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1get_1payment_1preimage(JNIEnv * _env, jclass _b, jlong this_ptr) {
8795         LDKUpdateFulfillHTLC this_ptr_conv;
8796         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8797         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8798         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8799         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFulfillHTLC_get_payment_preimage(&this_ptr_conv));
8800         return ret_arr;
8801 }
8802
8803 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1set_1payment_1preimage(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8804         LDKUpdateFulfillHTLC this_ptr_conv;
8805         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8806         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8807         LDKThirtyTwoBytes val_ref;
8808         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8809         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8810         UpdateFulfillHTLC_set_payment_preimage(&this_ptr_conv, val_ref);
8811 }
8812
8813 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) {
8814         LDKThirtyTwoBytes channel_id_arg_ref;
8815         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
8816         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
8817         LDKThirtyTwoBytes payment_preimage_arg_ref;
8818         CHECK((*_env)->GetArrayLength (_env, payment_preimage_arg) == 32);
8819         (*_env)->GetByteArrayRegion (_env, payment_preimage_arg, 0, 32, payment_preimage_arg_ref.data);
8820         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_new(channel_id_arg_ref, htlc_id_arg, payment_preimage_arg_ref);
8821         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8822         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8823         long ret_ref = (long)ret_var.inner;
8824         if (ret_var.is_owned) {
8825                 ret_ref |= 1;
8826         }
8827         return ret_ref;
8828 }
8829
8830 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8831         LDKUpdateFailHTLC this_ptr_conv;
8832         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8833         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8834         UpdateFailHTLC_free(this_ptr_conv);
8835 }
8836
8837 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8838         LDKUpdateFailHTLC orig_conv;
8839         orig_conv.inner = (void*)(orig & (~1));
8840         orig_conv.is_owned = (orig & 1) || (orig == 0);
8841         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_clone(&orig_conv);
8842         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8843         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8844         long ret_ref = (long)ret_var.inner;
8845         if (ret_var.is_owned) {
8846                 ret_ref |= 1;
8847         }
8848         return ret_ref;
8849 }
8850
8851 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8852         LDKUpdateFailHTLC this_ptr_conv;
8853         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8854         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8855         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8856         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFailHTLC_get_channel_id(&this_ptr_conv));
8857         return ret_arr;
8858 }
8859
8860 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8861         LDKUpdateFailHTLC this_ptr_conv;
8862         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8863         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8864         LDKThirtyTwoBytes val_ref;
8865         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8866         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8867         UpdateFailHTLC_set_channel_id(&this_ptr_conv, val_ref);
8868 }
8869
8870 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8871         LDKUpdateFailHTLC this_ptr_conv;
8872         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8873         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8874         jlong ret_val = UpdateFailHTLC_get_htlc_id(&this_ptr_conv);
8875         return ret_val;
8876 }
8877
8878 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8879         LDKUpdateFailHTLC this_ptr_conv;
8880         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8881         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8882         UpdateFailHTLC_set_htlc_id(&this_ptr_conv, val);
8883 }
8884
8885 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8886         LDKUpdateFailMalformedHTLC this_ptr_conv;
8887         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8888         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8889         UpdateFailMalformedHTLC_free(this_ptr_conv);
8890 }
8891
8892 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8893         LDKUpdateFailMalformedHTLC orig_conv;
8894         orig_conv.inner = (void*)(orig & (~1));
8895         orig_conv.is_owned = (orig & 1) || (orig == 0);
8896         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_clone(&orig_conv);
8897         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8898         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8899         long ret_ref = (long)ret_var.inner;
8900         if (ret_var.is_owned) {
8901                 ret_ref |= 1;
8902         }
8903         return ret_ref;
8904 }
8905
8906 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8907         LDKUpdateFailMalformedHTLC this_ptr_conv;
8908         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8909         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8910         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8911         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFailMalformedHTLC_get_channel_id(&this_ptr_conv));
8912         return ret_arr;
8913 }
8914
8915 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8916         LDKUpdateFailMalformedHTLC this_ptr_conv;
8917         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8918         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8919         LDKThirtyTwoBytes val_ref;
8920         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8921         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8922         UpdateFailMalformedHTLC_set_channel_id(&this_ptr_conv, val_ref);
8923 }
8924
8925 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8926         LDKUpdateFailMalformedHTLC this_ptr_conv;
8927         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8928         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8929         jlong ret_val = UpdateFailMalformedHTLC_get_htlc_id(&this_ptr_conv);
8930         return ret_val;
8931 }
8932
8933 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1htlc_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
8934         LDKUpdateFailMalformedHTLC this_ptr_conv;
8935         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8936         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8937         UpdateFailMalformedHTLC_set_htlc_id(&this_ptr_conv, val);
8938 }
8939
8940 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1get_1failure_1code(JNIEnv * _env, jclass _b, jlong this_ptr) {
8941         LDKUpdateFailMalformedHTLC this_ptr_conv;
8942         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8943         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8944         jshort ret_val = UpdateFailMalformedHTLC_get_failure_code(&this_ptr_conv);
8945         return ret_val;
8946 }
8947
8948 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1set_1failure_1code(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
8949         LDKUpdateFailMalformedHTLC this_ptr_conv;
8950         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8951         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8952         UpdateFailMalformedHTLC_set_failure_code(&this_ptr_conv, val);
8953 }
8954
8955 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
8956         LDKCommitmentSigned this_ptr_conv;
8957         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8958         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8959         CommitmentSigned_free(this_ptr_conv);
8960 }
8961
8962 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1clone(JNIEnv * _env, jclass _b, jlong orig) {
8963         LDKCommitmentSigned orig_conv;
8964         orig_conv.inner = (void*)(orig & (~1));
8965         orig_conv.is_owned = (orig & 1) || (orig == 0);
8966         LDKCommitmentSigned ret_var = CommitmentSigned_clone(&orig_conv);
8967         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
8968         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
8969         long ret_ref = (long)ret_var.inner;
8970         if (ret_var.is_owned) {
8971                 ret_ref |= 1;
8972         }
8973         return ret_ref;
8974 }
8975
8976 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
8977         LDKCommitmentSigned this_ptr_conv;
8978         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8979         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8980         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
8981         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *CommitmentSigned_get_channel_id(&this_ptr_conv));
8982         return ret_arr;
8983 }
8984
8985 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
8986         LDKCommitmentSigned this_ptr_conv;
8987         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8988         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8989         LDKThirtyTwoBytes val_ref;
8990         CHECK((*_env)->GetArrayLength (_env, val) == 32);
8991         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
8992         CommitmentSigned_set_channel_id(&this_ptr_conv, val_ref);
8993 }
8994
8995 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
8996         LDKCommitmentSigned this_ptr_conv;
8997         this_ptr_conv.inner = (void*)(this_ptr & (~1));
8998         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
8999         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9000         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, CommitmentSigned_get_signature(&this_ptr_conv).compact_form);
9001         return arg_arr;
9002 }
9003
9004 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9005         LDKCommitmentSigned this_ptr_conv;
9006         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9007         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9008         LDKSignature val_ref;
9009         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9010         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9011         CommitmentSigned_set_signature(&this_ptr_conv, val_ref);
9012 }
9013
9014 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1set_1htlc_1signatures(JNIEnv * _env, jclass _b, jlong this_ptr, jobjectArray val) {
9015         LDKCommitmentSigned this_ptr_conv;
9016         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9017         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9018         LDKCVec_SignatureZ val_constr;
9019         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
9020         if (val_constr.datalen > 0)
9021                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
9022         else
9023                 val_constr.data = NULL;
9024         for (size_t i = 0; i < val_constr.datalen; i++) {
9025                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, val, i);
9026                 LDKSignature arr_conv_8_ref;
9027                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
9028                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
9029                 val_constr.data[i] = arr_conv_8_ref;
9030         }
9031         CommitmentSigned_set_htlc_signatures(&this_ptr_conv, val_constr);
9032 }
9033
9034 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) {
9035         LDKThirtyTwoBytes channel_id_arg_ref;
9036         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9037         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9038         LDKSignature signature_arg_ref;
9039         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
9040         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
9041         LDKCVec_SignatureZ htlc_signatures_arg_constr;
9042         htlc_signatures_arg_constr.datalen = (*_env)->GetArrayLength (_env, htlc_signatures_arg);
9043         if (htlc_signatures_arg_constr.datalen > 0)
9044                 htlc_signatures_arg_constr.data = MALLOC(htlc_signatures_arg_constr.datalen * sizeof(LDKSignature), "LDKCVec_SignatureZ Elements");
9045         else
9046                 htlc_signatures_arg_constr.data = NULL;
9047         for (size_t i = 0; i < htlc_signatures_arg_constr.datalen; i++) {
9048                 jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, htlc_signatures_arg, i);
9049                 LDKSignature arr_conv_8_ref;
9050                 CHECK((*_env)->GetArrayLength (_env, arr_conv_8) == 64);
9051                 (*_env)->GetByteArrayRegion (_env, arr_conv_8, 0, 64, arr_conv_8_ref.compact_form);
9052                 htlc_signatures_arg_constr.data[i] = arr_conv_8_ref;
9053         }
9054         LDKCommitmentSigned ret_var = CommitmentSigned_new(channel_id_arg_ref, signature_arg_ref, htlc_signatures_arg_constr);
9055         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9056         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9057         long ret_ref = (long)ret_var.inner;
9058         if (ret_var.is_owned) {
9059                 ret_ref |= 1;
9060         }
9061         return ret_ref;
9062 }
9063
9064 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9065         LDKRevokeAndACK this_ptr_conv;
9066         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9067         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9068         RevokeAndACK_free(this_ptr_conv);
9069 }
9070
9071 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9072         LDKRevokeAndACK orig_conv;
9073         orig_conv.inner = (void*)(orig & (~1));
9074         orig_conv.is_owned = (orig & 1) || (orig == 0);
9075         LDKRevokeAndACK ret_var = RevokeAndACK_clone(&orig_conv);
9076         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9077         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9078         long ret_ref = (long)ret_var.inner;
9079         if (ret_var.is_owned) {
9080                 ret_ref |= 1;
9081         }
9082         return ret_ref;
9083 }
9084
9085 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9086         LDKRevokeAndACK this_ptr_conv;
9087         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9088         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9089         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9090         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *RevokeAndACK_get_channel_id(&this_ptr_conv));
9091         return ret_arr;
9092 }
9093
9094 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9095         LDKRevokeAndACK this_ptr_conv;
9096         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9097         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9098         LDKThirtyTwoBytes val_ref;
9099         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9100         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9101         RevokeAndACK_set_channel_id(&this_ptr_conv, val_ref);
9102 }
9103
9104 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr) {
9105         LDKRevokeAndACK this_ptr_conv;
9106         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9107         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9108         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9109         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *RevokeAndACK_get_per_commitment_secret(&this_ptr_conv));
9110         return ret_arr;
9111 }
9112
9113 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9114         LDKRevokeAndACK this_ptr_conv;
9115         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9116         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9117         LDKThirtyTwoBytes val_ref;
9118         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9119         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9120         RevokeAndACK_set_per_commitment_secret(&this_ptr_conv, val_ref);
9121 }
9122
9123 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1get_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
9124         LDKRevokeAndACK this_ptr_conv;
9125         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9126         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9127         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9128         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RevokeAndACK_get_next_per_commitment_point(&this_ptr_conv).compressed_form);
9129         return arg_arr;
9130 }
9131
9132 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1set_1next_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9133         LDKRevokeAndACK this_ptr_conv;
9134         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9135         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9136         LDKPublicKey val_ref;
9137         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9138         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9139         RevokeAndACK_set_next_per_commitment_point(&this_ptr_conv, val_ref);
9140 }
9141
9142 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) {
9143         LDKThirtyTwoBytes channel_id_arg_ref;
9144         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9145         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9146         LDKThirtyTwoBytes per_commitment_secret_arg_ref;
9147         CHECK((*_env)->GetArrayLength (_env, per_commitment_secret_arg) == 32);
9148         (*_env)->GetByteArrayRegion (_env, per_commitment_secret_arg, 0, 32, per_commitment_secret_arg_ref.data);
9149         LDKPublicKey next_per_commitment_point_arg_ref;
9150         CHECK((*_env)->GetArrayLength (_env, next_per_commitment_point_arg) == 33);
9151         (*_env)->GetByteArrayRegion (_env, next_per_commitment_point_arg, 0, 33, next_per_commitment_point_arg_ref.compressed_form);
9152         LDKRevokeAndACK ret_var = RevokeAndACK_new(channel_id_arg_ref, per_commitment_secret_arg_ref, next_per_commitment_point_arg_ref);
9153         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9154         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9155         long ret_ref = (long)ret_var.inner;
9156         if (ret_var.is_owned) {
9157                 ret_ref |= 1;
9158         }
9159         return ret_ref;
9160 }
9161
9162 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9163         LDKUpdateFee this_ptr_conv;
9164         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9165         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9166         UpdateFee_free(this_ptr_conv);
9167 }
9168
9169 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9170         LDKUpdateFee orig_conv;
9171         orig_conv.inner = (void*)(orig & (~1));
9172         orig_conv.is_owned = (orig & 1) || (orig == 0);
9173         LDKUpdateFee ret_var = UpdateFee_clone(&orig_conv);
9174         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9175         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9176         long ret_ref = (long)ret_var.inner;
9177         if (ret_var.is_owned) {
9178                 ret_ref |= 1;
9179         }
9180         return ret_ref;
9181 }
9182
9183 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9184         LDKUpdateFee this_ptr_conv;
9185         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9186         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9187         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9188         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UpdateFee_get_channel_id(&this_ptr_conv));
9189         return ret_arr;
9190 }
9191
9192 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9193         LDKUpdateFee this_ptr_conv;
9194         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9195         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9196         LDKThirtyTwoBytes val_ref;
9197         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9198         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9199         UpdateFee_set_channel_id(&this_ptr_conv, val_ref);
9200 }
9201
9202 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UpdateFee_1get_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr) {
9203         LDKUpdateFee this_ptr_conv;
9204         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9205         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9206         jint ret_val = UpdateFee_get_feerate_per_kw(&this_ptr_conv);
9207         return ret_val;
9208 }
9209
9210 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UpdateFee_1set_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
9211         LDKUpdateFee this_ptr_conv;
9212         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9213         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9214         UpdateFee_set_feerate_per_kw(&this_ptr_conv, val);
9215 }
9216
9217 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jint feerate_per_kw_arg) {
9218         LDKThirtyTwoBytes channel_id_arg_ref;
9219         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9220         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9221         LDKUpdateFee ret_var = UpdateFee_new(channel_id_arg_ref, feerate_per_kw_arg);
9222         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9223         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9224         long ret_ref = (long)ret_var.inner;
9225         if (ret_var.is_owned) {
9226                 ret_ref |= 1;
9227         }
9228         return ret_ref;
9229 }
9230
9231 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9232         LDKDataLossProtect this_ptr_conv;
9233         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9234         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9235         DataLossProtect_free(this_ptr_conv);
9236 }
9237
9238 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9239         LDKDataLossProtect orig_conv;
9240         orig_conv.inner = (void*)(orig & (~1));
9241         orig_conv.is_owned = (orig & 1) || (orig == 0);
9242         LDKDataLossProtect ret_var = DataLossProtect_clone(&orig_conv);
9243         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9244         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9245         long ret_ref = (long)ret_var.inner;
9246         if (ret_var.is_owned) {
9247                 ret_ref |= 1;
9248         }
9249         return ret_ref;
9250 }
9251
9252 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1your_1last_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr) {
9253         LDKDataLossProtect this_ptr_conv;
9254         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9255         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9256         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9257         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *DataLossProtect_get_your_last_per_commitment_secret(&this_ptr_conv));
9258         return ret_arr;
9259 }
9260
9261 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1set_1your_1last_1per_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9262         LDKDataLossProtect this_ptr_conv;
9263         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9264         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9265         LDKThirtyTwoBytes val_ref;
9266         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9267         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9268         DataLossProtect_set_your_last_per_commitment_secret(&this_ptr_conv, val_ref);
9269 }
9270
9271 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1get_1my_1current_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
9272         LDKDataLossProtect this_ptr_conv;
9273         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9274         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9275         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9276         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, DataLossProtect_get_my_current_per_commitment_point(&this_ptr_conv).compressed_form);
9277         return arg_arr;
9278 }
9279
9280 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DataLossProtect_1set_1my_1current_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9281         LDKDataLossProtect this_ptr_conv;
9282         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9283         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9284         LDKPublicKey val_ref;
9285         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9286         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9287         DataLossProtect_set_my_current_per_commitment_point(&this_ptr_conv, val_ref);
9288 }
9289
9290 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) {
9291         LDKThirtyTwoBytes your_last_per_commitment_secret_arg_ref;
9292         CHECK((*_env)->GetArrayLength (_env, your_last_per_commitment_secret_arg) == 32);
9293         (*_env)->GetByteArrayRegion (_env, your_last_per_commitment_secret_arg, 0, 32, your_last_per_commitment_secret_arg_ref.data);
9294         LDKPublicKey my_current_per_commitment_point_arg_ref;
9295         CHECK((*_env)->GetArrayLength (_env, my_current_per_commitment_point_arg) == 33);
9296         (*_env)->GetByteArrayRegion (_env, my_current_per_commitment_point_arg, 0, 33, my_current_per_commitment_point_arg_ref.compressed_form);
9297         LDKDataLossProtect ret_var = DataLossProtect_new(your_last_per_commitment_secret_arg_ref, my_current_per_commitment_point_arg_ref);
9298         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9299         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9300         long ret_ref = (long)ret_var.inner;
9301         if (ret_var.is_owned) {
9302                 ret_ref |= 1;
9303         }
9304         return ret_ref;
9305 }
9306
9307 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9308         LDKChannelReestablish this_ptr_conv;
9309         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9310         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9311         ChannelReestablish_free(this_ptr_conv);
9312 }
9313
9314 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9315         LDKChannelReestablish orig_conv;
9316         orig_conv.inner = (void*)(orig & (~1));
9317         orig_conv.is_owned = (orig & 1) || (orig == 0);
9318         LDKChannelReestablish ret_var = ChannelReestablish_clone(&orig_conv);
9319         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9320         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9321         long ret_ref = (long)ret_var.inner;
9322         if (ret_var.is_owned) {
9323                 ret_ref |= 1;
9324         }
9325         return ret_ref;
9326 }
9327
9328 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9329         LDKChannelReestablish this_ptr_conv;
9330         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9331         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9332         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9333         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ChannelReestablish_get_channel_id(&this_ptr_conv));
9334         return ret_arr;
9335 }
9336
9337 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9338         LDKChannelReestablish this_ptr_conv;
9339         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9340         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9341         LDKThirtyTwoBytes val_ref;
9342         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9343         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9344         ChannelReestablish_set_channel_id(&this_ptr_conv, val_ref);
9345 }
9346
9347 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1local_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr) {
9348         LDKChannelReestablish this_ptr_conv;
9349         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9350         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9351         jlong ret_val = ChannelReestablish_get_next_local_commitment_number(&this_ptr_conv);
9352         return ret_val;
9353 }
9354
9355 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1next_1local_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9356         LDKChannelReestablish this_ptr_conv;
9357         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9358         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9359         ChannelReestablish_set_next_local_commitment_number(&this_ptr_conv, val);
9360 }
9361
9362 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1get_1next_1remote_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr) {
9363         LDKChannelReestablish this_ptr_conv;
9364         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9365         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9366         jlong ret_val = ChannelReestablish_get_next_remote_commitment_number(&this_ptr_conv);
9367         return ret_val;
9368 }
9369
9370 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1set_1next_1remote_1commitment_1number(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9371         LDKChannelReestablish this_ptr_conv;
9372         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9373         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9374         ChannelReestablish_set_next_remote_commitment_number(&this_ptr_conv, val);
9375 }
9376
9377 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9378         LDKAnnouncementSignatures this_ptr_conv;
9379         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9380         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9381         AnnouncementSignatures_free(this_ptr_conv);
9382 }
9383
9384 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9385         LDKAnnouncementSignatures orig_conv;
9386         orig_conv.inner = (void*)(orig & (~1));
9387         orig_conv.is_owned = (orig & 1) || (orig == 0);
9388         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_clone(&orig_conv);
9389         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9390         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9391         long ret_ref = (long)ret_var.inner;
9392         if (ret_var.is_owned) {
9393                 ret_ref |= 1;
9394         }
9395         return ret_ref;
9396 }
9397
9398 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9399         LDKAnnouncementSignatures this_ptr_conv;
9400         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9401         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9402         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9403         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *AnnouncementSignatures_get_channel_id(&this_ptr_conv));
9404         return ret_arr;
9405 }
9406
9407 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9408         LDKAnnouncementSignatures this_ptr_conv;
9409         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9410         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9411         LDKThirtyTwoBytes val_ref;
9412         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9413         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9414         AnnouncementSignatures_set_channel_id(&this_ptr_conv, val_ref);
9415 }
9416
9417 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9418         LDKAnnouncementSignatures this_ptr_conv;
9419         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9420         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9421         jlong ret_val = AnnouncementSignatures_get_short_channel_id(&this_ptr_conv);
9422         return ret_val;
9423 }
9424
9425 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9426         LDKAnnouncementSignatures this_ptr_conv;
9427         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9428         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9429         AnnouncementSignatures_set_short_channel_id(&this_ptr_conv, val);
9430 }
9431
9432 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1node_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
9433         LDKAnnouncementSignatures this_ptr_conv;
9434         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9435         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9436         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9437         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, AnnouncementSignatures_get_node_signature(&this_ptr_conv).compact_form);
9438         return arg_arr;
9439 }
9440
9441 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1node_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9442         LDKAnnouncementSignatures this_ptr_conv;
9443         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9444         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9445         LDKSignature val_ref;
9446         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9447         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9448         AnnouncementSignatures_set_node_signature(&this_ptr_conv, val_ref);
9449 }
9450
9451 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1get_1bitcoin_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
9452         LDKAnnouncementSignatures this_ptr_conv;
9453         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9454         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9455         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9456         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, AnnouncementSignatures_get_bitcoin_signature(&this_ptr_conv).compact_form);
9457         return arg_arr;
9458 }
9459
9460 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1set_1bitcoin_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9461         LDKAnnouncementSignatures this_ptr_conv;
9462         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9463         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9464         LDKSignature val_ref;
9465         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9466         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9467         AnnouncementSignatures_set_bitcoin_signature(&this_ptr_conv, val_ref);
9468 }
9469
9470 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) {
9471         LDKThirtyTwoBytes channel_id_arg_ref;
9472         CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32);
9473         (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data);
9474         LDKSignature node_signature_arg_ref;
9475         CHECK((*_env)->GetArrayLength (_env, node_signature_arg) == 64);
9476         (*_env)->GetByteArrayRegion (_env, node_signature_arg, 0, 64, node_signature_arg_ref.compact_form);
9477         LDKSignature bitcoin_signature_arg_ref;
9478         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_arg) == 64);
9479         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_arg, 0, 64, bitcoin_signature_arg_ref.compact_form);
9480         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_new(channel_id_arg_ref, short_channel_id_arg, node_signature_arg_ref, bitcoin_signature_arg_ref);
9481         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9482         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9483         long ret_ref = (long)ret_var.inner;
9484         if (ret_var.is_owned) {
9485                 ret_ref |= 1;
9486         }
9487         return ret_ref;
9488 }
9489
9490 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetAddress_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9491         LDKNetAddress this_ptr_conv = *(LDKNetAddress*)this_ptr;
9492         FREE((void*)this_ptr);
9493         NetAddress_free(this_ptr_conv);
9494 }
9495
9496 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetAddress_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9497         LDKNetAddress* orig_conv = (LDKNetAddress*)orig;
9498         LDKNetAddress *ret_copy = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress");
9499         *ret_copy = NetAddress_clone(orig_conv);
9500         long ret_ref = (long)ret_copy;
9501         return ret_ref;
9502 }
9503
9504 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9505         LDKUnsignedNodeAnnouncement this_ptr_conv;
9506         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9507         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9508         UnsignedNodeAnnouncement_free(this_ptr_conv);
9509 }
9510
9511 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9512         LDKUnsignedNodeAnnouncement orig_conv;
9513         orig_conv.inner = (void*)(orig & (~1));
9514         orig_conv.is_owned = (orig & 1) || (orig == 0);
9515         LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_clone(&orig_conv);
9516         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9517         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9518         long ret_ref = (long)ret_var.inner;
9519         if (ret_var.is_owned) {
9520                 ret_ref |= 1;
9521         }
9522         return ret_ref;
9523 }
9524
9525 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
9526         LDKUnsignedNodeAnnouncement this_ptr_conv;
9527         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9528         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9529         LDKNodeFeatures ret_var = UnsignedNodeAnnouncement_get_features(&this_ptr_conv);
9530         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9531         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9532         long ret_ref = (long)ret_var.inner;
9533         if (ret_var.is_owned) {
9534                 ret_ref |= 1;
9535         }
9536         return ret_ref;
9537 }
9538
9539 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9540         LDKUnsignedNodeAnnouncement this_ptr_conv;
9541         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9542         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9543         LDKNodeFeatures val_conv;
9544         val_conv.inner = (void*)(val & (~1));
9545         val_conv.is_owned = (val & 1) || (val == 0);
9546         // Warning: we may need a move here but can't clone!
9547         UnsignedNodeAnnouncement_set_features(&this_ptr_conv, val_conv);
9548 }
9549
9550 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
9551         LDKUnsignedNodeAnnouncement this_ptr_conv;
9552         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9553         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9554         jint ret_val = UnsignedNodeAnnouncement_get_timestamp(&this_ptr_conv);
9555         return ret_val;
9556 }
9557
9558 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
9559         LDKUnsignedNodeAnnouncement this_ptr_conv;
9560         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9561         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9562         UnsignedNodeAnnouncement_set_timestamp(&this_ptr_conv, val);
9563 }
9564
9565 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9566         LDKUnsignedNodeAnnouncement this_ptr_conv;
9567         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9568         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9569         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9570         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedNodeAnnouncement_get_node_id(&this_ptr_conv).compressed_form);
9571         return arg_arr;
9572 }
9573
9574 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9575         LDKUnsignedNodeAnnouncement this_ptr_conv;
9576         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9577         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9578         LDKPublicKey val_ref;
9579         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9580         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9581         UnsignedNodeAnnouncement_set_node_id(&this_ptr_conv, val_ref);
9582 }
9583
9584 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr) {
9585         LDKUnsignedNodeAnnouncement this_ptr_conv;
9586         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9587         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9588         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 3);
9589         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 3, *UnsignedNodeAnnouncement_get_rgb(&this_ptr_conv));
9590         return ret_arr;
9591 }
9592
9593 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9594         LDKUnsignedNodeAnnouncement this_ptr_conv;
9595         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9596         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9597         LDKThreeBytes val_ref;
9598         CHECK((*_env)->GetArrayLength (_env, val) == 3);
9599         (*_env)->GetByteArrayRegion (_env, val, 0, 3, val_ref.data);
9600         UnsignedNodeAnnouncement_set_rgb(&this_ptr_conv, val_ref);
9601 }
9602
9603 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1get_1alias(JNIEnv * _env, jclass _b, jlong this_ptr) {
9604         LDKUnsignedNodeAnnouncement this_ptr_conv;
9605         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9606         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9607         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9608         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedNodeAnnouncement_get_alias(&this_ptr_conv));
9609         return ret_arr;
9610 }
9611
9612 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1alias(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9613         LDKUnsignedNodeAnnouncement this_ptr_conv;
9614         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9615         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9616         LDKThirtyTwoBytes val_ref;
9617         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9618         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9619         UnsignedNodeAnnouncement_set_alias(&this_ptr_conv, val_ref);
9620 }
9621
9622 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1set_1addresses(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
9623         LDKUnsignedNodeAnnouncement this_ptr_conv;
9624         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9625         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9626         LDKCVec_NetAddressZ val_constr;
9627         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
9628         if (val_constr.datalen > 0)
9629                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
9630         else
9631                 val_constr.data = NULL;
9632         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
9633         for (size_t m = 0; m < val_constr.datalen; m++) {
9634                 long arr_conv_12 = val_vals[m];
9635                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
9636                 FREE((void*)arr_conv_12);
9637                 val_constr.data[m] = arr_conv_12_conv;
9638         }
9639         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
9640         UnsignedNodeAnnouncement_set_addresses(&this_ptr_conv, val_constr);
9641 }
9642
9643 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9644         LDKNodeAnnouncement this_ptr_conv;
9645         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9646         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9647         NodeAnnouncement_free(this_ptr_conv);
9648 }
9649
9650 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9651         LDKNodeAnnouncement orig_conv;
9652         orig_conv.inner = (void*)(orig & (~1));
9653         orig_conv.is_owned = (orig & 1) || (orig == 0);
9654         LDKNodeAnnouncement ret_var = NodeAnnouncement_clone(&orig_conv);
9655         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9656         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9657         long ret_ref = (long)ret_var.inner;
9658         if (ret_var.is_owned) {
9659                 ret_ref |= 1;
9660         }
9661         return ret_ref;
9662 }
9663
9664 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
9665         LDKNodeAnnouncement this_ptr_conv;
9666         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9667         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9668         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9669         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, NodeAnnouncement_get_signature(&this_ptr_conv).compact_form);
9670         return arg_arr;
9671 }
9672
9673 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9674         LDKNodeAnnouncement this_ptr_conv;
9675         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9676         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9677         LDKSignature val_ref;
9678         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9679         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9680         NodeAnnouncement_set_signature(&this_ptr_conv, val_ref);
9681 }
9682
9683 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
9684         LDKNodeAnnouncement this_ptr_conv;
9685         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9686         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9687         LDKUnsignedNodeAnnouncement ret_var = NodeAnnouncement_get_contents(&this_ptr_conv);
9688         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9689         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9690         long ret_ref = (long)ret_var.inner;
9691         if (ret_var.is_owned) {
9692                 ret_ref |= 1;
9693         }
9694         return ret_ref;
9695 }
9696
9697 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9698         LDKNodeAnnouncement this_ptr_conv;
9699         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9700         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9701         LDKUnsignedNodeAnnouncement val_conv;
9702         val_conv.inner = (void*)(val & (~1));
9703         val_conv.is_owned = (val & 1) || (val == 0);
9704         if (val_conv.inner != NULL)
9705                 val_conv = UnsignedNodeAnnouncement_clone(&val_conv);
9706         NodeAnnouncement_set_contents(&this_ptr_conv, val_conv);
9707 }
9708
9709 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1new(JNIEnv * _env, jclass _b, jbyteArray signature_arg, jlong contents_arg) {
9710         LDKSignature signature_arg_ref;
9711         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
9712         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
9713         LDKUnsignedNodeAnnouncement contents_arg_conv;
9714         contents_arg_conv.inner = (void*)(contents_arg & (~1));
9715         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
9716         if (contents_arg_conv.inner != NULL)
9717                 contents_arg_conv = UnsignedNodeAnnouncement_clone(&contents_arg_conv);
9718         LDKNodeAnnouncement ret_var = NodeAnnouncement_new(signature_arg_ref, contents_arg_conv);
9719         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9720         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9721         long ret_ref = (long)ret_var.inner;
9722         if (ret_var.is_owned) {
9723                 ret_ref |= 1;
9724         }
9725         return ret_ref;
9726 }
9727
9728 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9729         LDKUnsignedChannelAnnouncement this_ptr_conv;
9730         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9731         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9732         UnsignedChannelAnnouncement_free(this_ptr_conv);
9733 }
9734
9735 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9736         LDKUnsignedChannelAnnouncement orig_conv;
9737         orig_conv.inner = (void*)(orig & (~1));
9738         orig_conv.is_owned = (orig & 1) || (orig == 0);
9739         LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_clone(&orig_conv);
9740         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9741         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9742         long ret_ref = (long)ret_var.inner;
9743         if (ret_var.is_owned) {
9744                 ret_ref |= 1;
9745         }
9746         return ret_ref;
9747 }
9748
9749 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
9750         LDKUnsignedChannelAnnouncement this_ptr_conv;
9751         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9752         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9753         LDKChannelFeatures ret_var = UnsignedChannelAnnouncement_get_features(&this_ptr_conv);
9754         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9755         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9756         long ret_ref = (long)ret_var.inner;
9757         if (ret_var.is_owned) {
9758                 ret_ref |= 1;
9759         }
9760         return ret_ref;
9761 }
9762
9763 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9764         LDKUnsignedChannelAnnouncement this_ptr_conv;
9765         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9766         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9767         LDKChannelFeatures val_conv;
9768         val_conv.inner = (void*)(val & (~1));
9769         val_conv.is_owned = (val & 1) || (val == 0);
9770         // Warning: we may need a move here but can't clone!
9771         UnsignedChannelAnnouncement_set_features(&this_ptr_conv, val_conv);
9772 }
9773
9774 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
9775         LDKUnsignedChannelAnnouncement this_ptr_conv;
9776         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9777         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9778         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
9779         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedChannelAnnouncement_get_chain_hash(&this_ptr_conv));
9780         return ret_arr;
9781 }
9782
9783 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9784         LDKUnsignedChannelAnnouncement this_ptr_conv;
9785         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9786         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9787         LDKThirtyTwoBytes val_ref;
9788         CHECK((*_env)->GetArrayLength (_env, val) == 32);
9789         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
9790         UnsignedChannelAnnouncement_set_chain_hash(&this_ptr_conv, val_ref);
9791 }
9792
9793 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
9794         LDKUnsignedChannelAnnouncement this_ptr_conv;
9795         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9796         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9797         jlong ret_val = UnsignedChannelAnnouncement_get_short_channel_id(&this_ptr_conv);
9798         return ret_val;
9799 }
9800
9801 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9802         LDKUnsignedChannelAnnouncement this_ptr_conv;
9803         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9804         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9805         UnsignedChannelAnnouncement_set_short_channel_id(&this_ptr_conv, val);
9806 }
9807
9808 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
9809         LDKUnsignedChannelAnnouncement this_ptr_conv;
9810         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9811         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9812         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9813         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_1(&this_ptr_conv).compressed_form);
9814         return arg_arr;
9815 }
9816
9817 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9818         LDKUnsignedChannelAnnouncement this_ptr_conv;
9819         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9820         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9821         LDKPublicKey val_ref;
9822         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9823         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9824         UnsignedChannelAnnouncement_set_node_id_1(&this_ptr_conv, val_ref);
9825 }
9826
9827 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1node_1id_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
9828         LDKUnsignedChannelAnnouncement this_ptr_conv;
9829         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9830         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9831         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9832         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_node_id_2(&this_ptr_conv).compressed_form);
9833         return arg_arr;
9834 }
9835
9836 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1node_1id_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9837         LDKUnsignedChannelAnnouncement this_ptr_conv;
9838         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9839         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9840         LDKPublicKey val_ref;
9841         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9842         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9843         UnsignedChannelAnnouncement_set_node_id_2(&this_ptr_conv, val_ref);
9844 }
9845
9846 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
9847         LDKUnsignedChannelAnnouncement this_ptr_conv;
9848         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9849         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9850         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9851         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_1(&this_ptr_conv).compressed_form);
9852         return arg_arr;
9853 }
9854
9855 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9856         LDKUnsignedChannelAnnouncement this_ptr_conv;
9857         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9858         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9859         LDKPublicKey val_ref;
9860         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9861         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9862         UnsignedChannelAnnouncement_set_bitcoin_key_1(&this_ptr_conv, val_ref);
9863 }
9864
9865 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1get_1bitcoin_1key_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
9866         LDKUnsignedChannelAnnouncement this_ptr_conv;
9867         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9868         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9869         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
9870         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, UnsignedChannelAnnouncement_get_bitcoin_key_2(&this_ptr_conv).compressed_form);
9871         return arg_arr;
9872 }
9873
9874 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1set_1bitcoin_1key_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9875         LDKUnsignedChannelAnnouncement this_ptr_conv;
9876         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9877         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9878         LDKPublicKey val_ref;
9879         CHECK((*_env)->GetArrayLength (_env, val) == 33);
9880         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
9881         UnsignedChannelAnnouncement_set_bitcoin_key_2(&this_ptr_conv, val_ref);
9882 }
9883
9884 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
9885         LDKChannelAnnouncement this_ptr_conv;
9886         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9887         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9888         ChannelAnnouncement_free(this_ptr_conv);
9889 }
9890
9891 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1clone(JNIEnv * _env, jclass _b, jlong orig) {
9892         LDKChannelAnnouncement orig_conv;
9893         orig_conv.inner = (void*)(orig & (~1));
9894         orig_conv.is_owned = (orig & 1) || (orig == 0);
9895         LDKChannelAnnouncement ret_var = ChannelAnnouncement_clone(&orig_conv);
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 jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
9906         LDKChannelAnnouncement 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         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9910         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_1(&this_ptr_conv).compact_form);
9911         return arg_arr;
9912 }
9913
9914 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9915         LDKChannelAnnouncement this_ptr_conv;
9916         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9917         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9918         LDKSignature val_ref;
9919         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9920         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9921         ChannelAnnouncement_set_node_signature_1(&this_ptr_conv, val_ref);
9922 }
9923
9924 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1node_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
9925         LDKChannelAnnouncement this_ptr_conv;
9926         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9927         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9928         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9929         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_node_signature_2(&this_ptr_conv).compact_form);
9930         return arg_arr;
9931 }
9932
9933 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1node_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9934         LDKChannelAnnouncement this_ptr_conv;
9935         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9936         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9937         LDKSignature val_ref;
9938         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9939         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9940         ChannelAnnouncement_set_node_signature_2(&this_ptr_conv, val_ref);
9941 }
9942
9943 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr) {
9944         LDKChannelAnnouncement this_ptr_conv;
9945         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9946         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9947         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9948         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_1(&this_ptr_conv).compact_form);
9949         return arg_arr;
9950 }
9951
9952 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_11(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9953         LDKChannelAnnouncement 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         LDKSignature val_ref;
9957         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9958         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9959         ChannelAnnouncement_set_bitcoin_signature_1(&this_ptr_conv, val_ref);
9960 }
9961
9962 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1bitcoin_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr) {
9963         LDKChannelAnnouncement this_ptr_conv;
9964         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9965         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9966         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
9967         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelAnnouncement_get_bitcoin_signature_2(&this_ptr_conv).compact_form);
9968         return arg_arr;
9969 }
9970
9971 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1bitcoin_1signature_12(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
9972         LDKChannelAnnouncement this_ptr_conv;
9973         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9974         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9975         LDKSignature val_ref;
9976         CHECK((*_env)->GetArrayLength (_env, val) == 64);
9977         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
9978         ChannelAnnouncement_set_bitcoin_signature_2(&this_ptr_conv, val_ref);
9979 }
9980
9981 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
9982         LDKChannelAnnouncement this_ptr_conv;
9983         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9984         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9985         LDKUnsignedChannelAnnouncement ret_var = ChannelAnnouncement_get_contents(&this_ptr_conv);
9986         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
9987         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
9988         long ret_ref = (long)ret_var.inner;
9989         if (ret_var.is_owned) {
9990                 ret_ref |= 1;
9991         }
9992         return ret_ref;
9993 }
9994
9995 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
9996         LDKChannelAnnouncement this_ptr_conv;
9997         this_ptr_conv.inner = (void*)(this_ptr & (~1));
9998         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
9999         LDKUnsignedChannelAnnouncement val_conv;
10000         val_conv.inner = (void*)(val & (~1));
10001         val_conv.is_owned = (val & 1) || (val == 0);
10002         if (val_conv.inner != NULL)
10003                 val_conv = UnsignedChannelAnnouncement_clone(&val_conv);
10004         ChannelAnnouncement_set_contents(&this_ptr_conv, val_conv);
10005 }
10006
10007 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) {
10008         LDKSignature node_signature_1_arg_ref;
10009         CHECK((*_env)->GetArrayLength (_env, node_signature_1_arg) == 64);
10010         (*_env)->GetByteArrayRegion (_env, node_signature_1_arg, 0, 64, node_signature_1_arg_ref.compact_form);
10011         LDKSignature node_signature_2_arg_ref;
10012         CHECK((*_env)->GetArrayLength (_env, node_signature_2_arg) == 64);
10013         (*_env)->GetByteArrayRegion (_env, node_signature_2_arg, 0, 64, node_signature_2_arg_ref.compact_form);
10014         LDKSignature bitcoin_signature_1_arg_ref;
10015         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_1_arg) == 64);
10016         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_1_arg, 0, 64, bitcoin_signature_1_arg_ref.compact_form);
10017         LDKSignature bitcoin_signature_2_arg_ref;
10018         CHECK((*_env)->GetArrayLength (_env, bitcoin_signature_2_arg) == 64);
10019         (*_env)->GetByteArrayRegion (_env, bitcoin_signature_2_arg, 0, 64, bitcoin_signature_2_arg_ref.compact_form);
10020         LDKUnsignedChannelAnnouncement contents_arg_conv;
10021         contents_arg_conv.inner = (void*)(contents_arg & (~1));
10022         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
10023         if (contents_arg_conv.inner != NULL)
10024                 contents_arg_conv = UnsignedChannelAnnouncement_clone(&contents_arg_conv);
10025         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);
10026         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10027         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10028         long ret_ref = (long)ret_var.inner;
10029         if (ret_var.is_owned) {
10030                 ret_ref |= 1;
10031         }
10032         return ret_ref;
10033 }
10034
10035 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10036         LDKUnsignedChannelUpdate this_ptr_conv;
10037         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10038         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10039         UnsignedChannelUpdate_free(this_ptr_conv);
10040 }
10041
10042 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10043         LDKUnsignedChannelUpdate orig_conv;
10044         orig_conv.inner = (void*)(orig & (~1));
10045         orig_conv.is_owned = (orig & 1) || (orig == 0);
10046         LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_clone(&orig_conv);
10047         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10048         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10049         long ret_ref = (long)ret_var.inner;
10050         if (ret_var.is_owned) {
10051                 ret_ref |= 1;
10052         }
10053         return ret_ref;
10054 }
10055
10056 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10057         LDKUnsignedChannelUpdate this_ptr_conv;
10058         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10059         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10060         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10061         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *UnsignedChannelUpdate_get_chain_hash(&this_ptr_conv));
10062         return ret_arr;
10063 }
10064
10065 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10066         LDKUnsignedChannelUpdate this_ptr_conv;
10067         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10068         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10069         LDKThirtyTwoBytes val_ref;
10070         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10071         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10072         UnsignedChannelUpdate_set_chain_hash(&this_ptr_conv, val_ref);
10073 }
10074
10075 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
10076         LDKUnsignedChannelUpdate this_ptr_conv;
10077         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10078         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10079         jlong ret_val = UnsignedChannelUpdate_get_short_channel_id(&this_ptr_conv);
10080         return ret_val;
10081 }
10082
10083 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10084         LDKUnsignedChannelUpdate this_ptr_conv;
10085         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10086         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10087         UnsignedChannelUpdate_set_short_channel_id(&this_ptr_conv, val);
10088 }
10089
10090 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
10091         LDKUnsignedChannelUpdate this_ptr_conv;
10092         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10093         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10094         jint ret_val = UnsignedChannelUpdate_get_timestamp(&this_ptr_conv);
10095         return ret_val;
10096 }
10097
10098 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10099         LDKUnsignedChannelUpdate this_ptr_conv;
10100         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10101         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10102         UnsignedChannelUpdate_set_timestamp(&this_ptr_conv, val);
10103 }
10104
10105 JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1flags(JNIEnv * _env, jclass _b, jlong this_ptr) {
10106         LDKUnsignedChannelUpdate this_ptr_conv;
10107         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10108         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10109         jbyte ret_val = UnsignedChannelUpdate_get_flags(&this_ptr_conv);
10110         return ret_val;
10111 }
10112
10113 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1flags(JNIEnv * _env, jclass _b, jlong this_ptr, jbyte val) {
10114         LDKUnsignedChannelUpdate this_ptr_conv;
10115         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10116         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10117         UnsignedChannelUpdate_set_flags(&this_ptr_conv, val);
10118 }
10119
10120 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
10121         LDKUnsignedChannelUpdate this_ptr_conv;
10122         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10123         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10124         jshort ret_val = UnsignedChannelUpdate_get_cltv_expiry_delta(&this_ptr_conv);
10125         return ret_val;
10126 }
10127
10128 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
10129         LDKUnsignedChannelUpdate this_ptr_conv;
10130         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10131         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10132         UnsignedChannelUpdate_set_cltv_expiry_delta(&this_ptr_conv, val);
10133 }
10134
10135 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10136         LDKUnsignedChannelUpdate this_ptr_conv;
10137         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10138         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10139         jlong ret_val = UnsignedChannelUpdate_get_htlc_minimum_msat(&this_ptr_conv);
10140         return ret_val;
10141 }
10142
10143 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10144         LDKUnsignedChannelUpdate this_ptr_conv;
10145         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10146         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10147         UnsignedChannelUpdate_set_htlc_minimum_msat(&this_ptr_conv, val);
10148 }
10149
10150 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
10151         LDKUnsignedChannelUpdate this_ptr_conv;
10152         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10153         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10154         jint ret_val = UnsignedChannelUpdate_get_fee_base_msat(&this_ptr_conv);
10155         return ret_val;
10156 }
10157
10158 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10159         LDKUnsignedChannelUpdate this_ptr_conv;
10160         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10161         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10162         UnsignedChannelUpdate_set_fee_base_msat(&this_ptr_conv, val);
10163 }
10164
10165 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1get_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
10166         LDKUnsignedChannelUpdate this_ptr_conv;
10167         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10168         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10169         jint ret_val = UnsignedChannelUpdate_get_fee_proportional_millionths(&this_ptr_conv);
10170         return ret_val;
10171 }
10172
10173 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1set_1fee_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10174         LDKUnsignedChannelUpdate this_ptr_conv;
10175         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10176         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10177         UnsignedChannelUpdate_set_fee_proportional_millionths(&this_ptr_conv, val);
10178 }
10179
10180 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10181         LDKChannelUpdate this_ptr_conv;
10182         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10183         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10184         ChannelUpdate_free(this_ptr_conv);
10185 }
10186
10187 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10188         LDKChannelUpdate orig_conv;
10189         orig_conv.inner = (void*)(orig & (~1));
10190         orig_conv.is_owned = (orig & 1) || (orig == 0);
10191         LDKChannelUpdate ret_var = ChannelUpdate_clone(&orig_conv);
10192         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10193         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10194         long ret_ref = (long)ret_var.inner;
10195         if (ret_var.is_owned) {
10196                 ret_ref |= 1;
10197         }
10198         return ret_ref;
10199 }
10200
10201 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1signature(JNIEnv * _env, jclass _b, jlong this_ptr) {
10202         LDKChannelUpdate this_ptr_conv;
10203         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10204         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10205         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
10206         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, ChannelUpdate_get_signature(&this_ptr_conv).compact_form);
10207         return arg_arr;
10208 }
10209
10210 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1signature(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10211         LDKChannelUpdate this_ptr_conv;
10212         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10213         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10214         LDKSignature val_ref;
10215         CHECK((*_env)->GetArrayLength (_env, val) == 64);
10216         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
10217         ChannelUpdate_set_signature(&this_ptr_conv, val_ref);
10218 }
10219
10220 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1get_1contents(JNIEnv * _env, jclass _b, jlong this_ptr) {
10221         LDKChannelUpdate this_ptr_conv;
10222         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10223         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10224         LDKUnsignedChannelUpdate ret_var = ChannelUpdate_get_contents(&this_ptr_conv);
10225         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10226         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10227         long ret_ref = (long)ret_var.inner;
10228         if (ret_var.is_owned) {
10229                 ret_ref |= 1;
10230         }
10231         return ret_ref;
10232 }
10233
10234 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1contents(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10235         LDKChannelUpdate this_ptr_conv;
10236         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10237         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10238         LDKUnsignedChannelUpdate val_conv;
10239         val_conv.inner = (void*)(val & (~1));
10240         val_conv.is_owned = (val & 1) || (val == 0);
10241         if (val_conv.inner != NULL)
10242                 val_conv = UnsignedChannelUpdate_clone(&val_conv);
10243         ChannelUpdate_set_contents(&this_ptr_conv, val_conv);
10244 }
10245
10246 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1new(JNIEnv * _env, jclass _b, jbyteArray signature_arg, jlong contents_arg) {
10247         LDKSignature signature_arg_ref;
10248         CHECK((*_env)->GetArrayLength (_env, signature_arg) == 64);
10249         (*_env)->GetByteArrayRegion (_env, signature_arg, 0, 64, signature_arg_ref.compact_form);
10250         LDKUnsignedChannelUpdate contents_arg_conv;
10251         contents_arg_conv.inner = (void*)(contents_arg & (~1));
10252         contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
10253         if (contents_arg_conv.inner != NULL)
10254                 contents_arg_conv = UnsignedChannelUpdate_clone(&contents_arg_conv);
10255         LDKChannelUpdate ret_var = ChannelUpdate_new(signature_arg_ref, contents_arg_conv);
10256         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10257         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10258         long ret_ref = (long)ret_var.inner;
10259         if (ret_var.is_owned) {
10260                 ret_ref |= 1;
10261         }
10262         return ret_ref;
10263 }
10264
10265 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10266         LDKQueryChannelRange this_ptr_conv;
10267         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10268         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10269         QueryChannelRange_free(this_ptr_conv);
10270 }
10271
10272 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10273         LDKQueryChannelRange orig_conv;
10274         orig_conv.inner = (void*)(orig & (~1));
10275         orig_conv.is_owned = (orig & 1) || (orig == 0);
10276         LDKQueryChannelRange ret_var = QueryChannelRange_clone(&orig_conv);
10277         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10278         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10279         long ret_ref = (long)ret_var.inner;
10280         if (ret_var.is_owned) {
10281                 ret_ref |= 1;
10282         }
10283         return ret_ref;
10284 }
10285
10286 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10287         LDKQueryChannelRange this_ptr_conv;
10288         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10289         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10290         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10291         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *QueryChannelRange_get_chain_hash(&this_ptr_conv));
10292         return ret_arr;
10293 }
10294
10295 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10296         LDKQueryChannelRange this_ptr_conv;
10297         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10298         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10299         LDKThirtyTwoBytes val_ref;
10300         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10301         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10302         QueryChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
10303 }
10304
10305 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr) {
10306         LDKQueryChannelRange this_ptr_conv;
10307         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10308         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10309         jint ret_val = QueryChannelRange_get_first_blocknum(&this_ptr_conv);
10310         return ret_val;
10311 }
10312
10313 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10314         LDKQueryChannelRange this_ptr_conv;
10315         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10316         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10317         QueryChannelRange_set_first_blocknum(&this_ptr_conv, val);
10318 }
10319
10320 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1get_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr) {
10321         LDKQueryChannelRange this_ptr_conv;
10322         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10323         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10324         jint ret_val = QueryChannelRange_get_number_of_blocks(&this_ptr_conv);
10325         return ret_val;
10326 }
10327
10328 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1set_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10329         LDKQueryChannelRange this_ptr_conv;
10330         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10331         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10332         QueryChannelRange_set_number_of_blocks(&this_ptr_conv, val);
10333 }
10334
10335 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) {
10336         LDKThirtyTwoBytes chain_hash_arg_ref;
10337         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10338         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10339         LDKQueryChannelRange ret_var = QueryChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg);
10340         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10341         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10342         long ret_ref = (long)ret_var.inner;
10343         if (ret_var.is_owned) {
10344                 ret_ref |= 1;
10345         }
10346         return ret_ref;
10347 }
10348
10349 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10350         LDKReplyChannelRange this_ptr_conv;
10351         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10352         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10353         ReplyChannelRange_free(this_ptr_conv);
10354 }
10355
10356 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10357         LDKReplyChannelRange orig_conv;
10358         orig_conv.inner = (void*)(orig & (~1));
10359         orig_conv.is_owned = (orig & 1) || (orig == 0);
10360         LDKReplyChannelRange ret_var = ReplyChannelRange_clone(&orig_conv);
10361         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10362         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10363         long ret_ref = (long)ret_var.inner;
10364         if (ret_var.is_owned) {
10365                 ret_ref |= 1;
10366         }
10367         return ret_ref;
10368 }
10369
10370 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10371         LDKReplyChannelRange this_ptr_conv;
10372         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10373         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10374         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10375         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ReplyChannelRange_get_chain_hash(&this_ptr_conv));
10376         return ret_arr;
10377 }
10378
10379 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10380         LDKReplyChannelRange this_ptr_conv;
10381         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10382         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10383         LDKThirtyTwoBytes val_ref;
10384         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10385         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10386         ReplyChannelRange_set_chain_hash(&this_ptr_conv, val_ref);
10387 }
10388
10389 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr) {
10390         LDKReplyChannelRange this_ptr_conv;
10391         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10392         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10393         jint ret_val = ReplyChannelRange_get_first_blocknum(&this_ptr_conv);
10394         return ret_val;
10395 }
10396
10397 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1first_1blocknum(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10398         LDKReplyChannelRange this_ptr_conv;
10399         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10400         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10401         ReplyChannelRange_set_first_blocknum(&this_ptr_conv, val);
10402 }
10403
10404 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr) {
10405         LDKReplyChannelRange this_ptr_conv;
10406         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10407         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10408         jint ret_val = ReplyChannelRange_get_number_of_blocks(&this_ptr_conv);
10409         return ret_val;
10410 }
10411
10412 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1number_1of_1blocks(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10413         LDKReplyChannelRange this_ptr_conv;
10414         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10415         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10416         ReplyChannelRange_set_number_of_blocks(&this_ptr_conv, val);
10417 }
10418
10419 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1get_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr) {
10420         LDKReplyChannelRange this_ptr_conv;
10421         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10422         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10423         jboolean ret_val = ReplyChannelRange_get_full_information(&this_ptr_conv);
10424         return ret_val;
10425 }
10426
10427 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
10428         LDKReplyChannelRange this_ptr_conv;
10429         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10430         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10431         ReplyChannelRange_set_full_information(&this_ptr_conv, val);
10432 }
10433
10434 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1set_1short_1channel_1ids(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
10435         LDKReplyChannelRange this_ptr_conv;
10436         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10437         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10438         LDKCVec_u64Z val_constr;
10439         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
10440         if (val_constr.datalen > 0)
10441                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
10442         else
10443                 val_constr.data = NULL;
10444         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
10445         for (size_t g = 0; g < val_constr.datalen; g++) {
10446                 long arr_conv_6 = val_vals[g];
10447                 val_constr.data[g] = arr_conv_6;
10448         }
10449         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
10450         ReplyChannelRange_set_short_channel_ids(&this_ptr_conv, val_constr);
10451 }
10452
10453 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) {
10454         LDKThirtyTwoBytes chain_hash_arg_ref;
10455         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10456         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10457         LDKCVec_u64Z short_channel_ids_arg_constr;
10458         short_channel_ids_arg_constr.datalen = (*_env)->GetArrayLength (_env, short_channel_ids_arg);
10459         if (short_channel_ids_arg_constr.datalen > 0)
10460                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
10461         else
10462                 short_channel_ids_arg_constr.data = NULL;
10463         long* short_channel_ids_arg_vals = (*_env)->GetLongArrayElements (_env, short_channel_ids_arg, NULL);
10464         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
10465                 long arr_conv_6 = short_channel_ids_arg_vals[g];
10466                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
10467         }
10468         (*_env)->ReleaseLongArrayElements (_env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
10469         LDKReplyChannelRange ret_var = ReplyChannelRange_new(chain_hash_arg_ref, first_blocknum_arg, number_of_blocks_arg, full_information_arg, short_channel_ids_arg_constr);
10470         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10471         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10472         long ret_ref = (long)ret_var.inner;
10473         if (ret_var.is_owned) {
10474                 ret_ref |= 1;
10475         }
10476         return ret_ref;
10477 }
10478
10479 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10480         LDKQueryShortChannelIds this_ptr_conv;
10481         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10482         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10483         QueryShortChannelIds_free(this_ptr_conv);
10484 }
10485
10486 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10487         LDKQueryShortChannelIds orig_conv;
10488         orig_conv.inner = (void*)(orig & (~1));
10489         orig_conv.is_owned = (orig & 1) || (orig == 0);
10490         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_clone(&orig_conv);
10491         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10492         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10493         long ret_ref = (long)ret_var.inner;
10494         if (ret_var.is_owned) {
10495                 ret_ref |= 1;
10496         }
10497         return ret_ref;
10498 }
10499
10500 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10501         LDKQueryShortChannelIds this_ptr_conv;
10502         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10503         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10504         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10505         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *QueryShortChannelIds_get_chain_hash(&this_ptr_conv));
10506         return ret_arr;
10507 }
10508
10509 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10510         LDKQueryShortChannelIds this_ptr_conv;
10511         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10512         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10513         LDKThirtyTwoBytes val_ref;
10514         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10515         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10516         QueryShortChannelIds_set_chain_hash(&this_ptr_conv, val_ref);
10517 }
10518
10519 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1set_1short_1channel_1ids(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
10520         LDKQueryShortChannelIds this_ptr_conv;
10521         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10522         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10523         LDKCVec_u64Z val_constr;
10524         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
10525         if (val_constr.datalen > 0)
10526                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
10527         else
10528                 val_constr.data = NULL;
10529         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
10530         for (size_t g = 0; g < val_constr.datalen; g++) {
10531                 long arr_conv_6 = val_vals[g];
10532                 val_constr.data[g] = arr_conv_6;
10533         }
10534         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
10535         QueryShortChannelIds_set_short_channel_ids(&this_ptr_conv, val_constr);
10536 }
10537
10538 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1new(JNIEnv * _env, jclass _b, jbyteArray chain_hash_arg, jlongArray short_channel_ids_arg) {
10539         LDKThirtyTwoBytes chain_hash_arg_ref;
10540         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10541         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10542         LDKCVec_u64Z short_channel_ids_arg_constr;
10543         short_channel_ids_arg_constr.datalen = (*_env)->GetArrayLength (_env, short_channel_ids_arg);
10544         if (short_channel_ids_arg_constr.datalen > 0)
10545                 short_channel_ids_arg_constr.data = MALLOC(short_channel_ids_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
10546         else
10547                 short_channel_ids_arg_constr.data = NULL;
10548         long* short_channel_ids_arg_vals = (*_env)->GetLongArrayElements (_env, short_channel_ids_arg, NULL);
10549         for (size_t g = 0; g < short_channel_ids_arg_constr.datalen; g++) {
10550                 long arr_conv_6 = short_channel_ids_arg_vals[g];
10551                 short_channel_ids_arg_constr.data[g] = arr_conv_6;
10552         }
10553         (*_env)->ReleaseLongArrayElements (_env, short_channel_ids_arg, short_channel_ids_arg_vals, 0);
10554         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_new(chain_hash_arg_ref, short_channel_ids_arg_constr);
10555         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10556         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10557         long ret_ref = (long)ret_var.inner;
10558         if (ret_var.is_owned) {
10559                 ret_ref |= 1;
10560         }
10561         return ret_ref;
10562 }
10563
10564 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10565         LDKReplyShortChannelIdsEnd this_ptr_conv;
10566         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10567         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10568         ReplyShortChannelIdsEnd_free(this_ptr_conv);
10569 }
10570
10571 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10572         LDKReplyShortChannelIdsEnd orig_conv;
10573         orig_conv.inner = (void*)(orig & (~1));
10574         orig_conv.is_owned = (orig & 1) || (orig == 0);
10575         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_clone(&orig_conv);
10576         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10577         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10578         long ret_ref = (long)ret_var.inner;
10579         if (ret_var.is_owned) {
10580                 ret_ref |= 1;
10581         }
10582         return ret_ref;
10583 }
10584
10585 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10586         LDKReplyShortChannelIdsEnd this_ptr_conv;
10587         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10588         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10589         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10590         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *ReplyShortChannelIdsEnd_get_chain_hash(&this_ptr_conv));
10591         return ret_arr;
10592 }
10593
10594 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10595         LDKReplyShortChannelIdsEnd this_ptr_conv;
10596         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10597         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10598         LDKThirtyTwoBytes val_ref;
10599         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10600         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10601         ReplyShortChannelIdsEnd_set_chain_hash(&this_ptr_conv, val_ref);
10602 }
10603
10604 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1get_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr) {
10605         LDKReplyShortChannelIdsEnd this_ptr_conv;
10606         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10607         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10608         jboolean ret_val = ReplyShortChannelIdsEnd_get_full_information(&this_ptr_conv);
10609         return ret_val;
10610 }
10611
10612 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1set_1full_1information(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
10613         LDKReplyShortChannelIdsEnd this_ptr_conv;
10614         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10615         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10616         ReplyShortChannelIdsEnd_set_full_information(&this_ptr_conv, val);
10617 }
10618
10619 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1new(JNIEnv * _env, jclass _b, jbyteArray chain_hash_arg, jboolean full_information_arg) {
10620         LDKThirtyTwoBytes chain_hash_arg_ref;
10621         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10622         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10623         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_new(chain_hash_arg_ref, full_information_arg);
10624         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10625         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10626         long ret_ref = (long)ret_var.inner;
10627         if (ret_var.is_owned) {
10628                 ret_ref |= 1;
10629         }
10630         return ret_ref;
10631 }
10632
10633 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10634         LDKGossipTimestampFilter this_ptr_conv;
10635         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10636         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10637         GossipTimestampFilter_free(this_ptr_conv);
10638 }
10639
10640 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10641         LDKGossipTimestampFilter orig_conv;
10642         orig_conv.inner = (void*)(orig & (~1));
10643         orig_conv.is_owned = (orig & 1) || (orig == 0);
10644         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_clone(&orig_conv);
10645         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10646         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10647         long ret_ref = (long)ret_var.inner;
10648         if (ret_var.is_owned) {
10649                 ret_ref |= 1;
10650         }
10651         return ret_ref;
10652 }
10653
10654 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
10655         LDKGossipTimestampFilter this_ptr_conv;
10656         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10657         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10658         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
10659         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *GossipTimestampFilter_get_chain_hash(&this_ptr_conv));
10660         return ret_arr;
10661 }
10662
10663 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1chain_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10664         LDKGossipTimestampFilter this_ptr_conv;
10665         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10666         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10667         LDKThirtyTwoBytes val_ref;
10668         CHECK((*_env)->GetArrayLength (_env, val) == 32);
10669         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
10670         GossipTimestampFilter_set_chain_hash(&this_ptr_conv, val_ref);
10671 }
10672
10673 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1first_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr) {
10674         LDKGossipTimestampFilter this_ptr_conv;
10675         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10676         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10677         jint ret_val = GossipTimestampFilter_get_first_timestamp(&this_ptr_conv);
10678         return ret_val;
10679 }
10680
10681 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1first_1timestamp(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10682         LDKGossipTimestampFilter this_ptr_conv;
10683         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10684         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10685         GossipTimestampFilter_set_first_timestamp(&this_ptr_conv, val);
10686 }
10687
10688 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1get_1timestamp_1range(JNIEnv * _env, jclass _b, jlong this_ptr) {
10689         LDKGossipTimestampFilter this_ptr_conv;
10690         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10691         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10692         jint ret_val = GossipTimestampFilter_get_timestamp_range(&this_ptr_conv);
10693         return ret_val;
10694 }
10695
10696 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1set_1timestamp_1range(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
10697         LDKGossipTimestampFilter this_ptr_conv;
10698         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10699         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10700         GossipTimestampFilter_set_timestamp_range(&this_ptr_conv, val);
10701 }
10702
10703 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) {
10704         LDKThirtyTwoBytes chain_hash_arg_ref;
10705         CHECK((*_env)->GetArrayLength (_env, chain_hash_arg) == 32);
10706         (*_env)->GetByteArrayRegion (_env, chain_hash_arg, 0, 32, chain_hash_arg_ref.data);
10707         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_new(chain_hash_arg_ref, first_timestamp_arg, timestamp_range_arg);
10708         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10709         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10710         long ret_ref = (long)ret_var.inner;
10711         if (ret_var.is_owned) {
10712                 ret_ref |= 1;
10713         }
10714         return ret_ref;
10715 }
10716
10717 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorAction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10718         LDKErrorAction this_ptr_conv = *(LDKErrorAction*)this_ptr;
10719         FREE((void*)this_ptr);
10720         ErrorAction_free(this_ptr_conv);
10721 }
10722
10723 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorAction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10724         LDKErrorAction* orig_conv = (LDKErrorAction*)orig;
10725         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
10726         *ret_copy = ErrorAction_clone(orig_conv);
10727         long ret_ref = (long)ret_copy;
10728         return ret_ref;
10729 }
10730
10731 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10732         LDKLightningError this_ptr_conv;
10733         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10734         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10735         LightningError_free(this_ptr_conv);
10736 }
10737
10738 JNIEXPORT jstring JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1err(JNIEnv * _env, jclass _b, jlong this_ptr) {
10739         LDKLightningError this_ptr_conv;
10740         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10741         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10742         LDKStr _str = LightningError_get_err(&this_ptr_conv);
10743         char* _buf = MALLOC(_str.len + 1, "str conv buf");
10744         memcpy(_buf, _str.chars, _str.len);
10745         _buf[_str.len] = 0;
10746         jstring _conv = (*_env)->NewStringUTF(_env, _str.chars);
10747         FREE(_buf);
10748         return _conv;
10749 }
10750
10751 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1err(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
10752         LDKLightningError this_ptr_conv;
10753         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10754         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10755         LDKCVec_u8Z val_ref;
10756         val_ref.data = (*_env)->GetByteArrayElements (_env, val, NULL);
10757         val_ref.datalen = (*_env)->GetArrayLength (_env, val);
10758         LightningError_set_err(&this_ptr_conv, val_ref);
10759         (*_env)->ReleaseByteArrayElements(_env, val, (int8_t*)val_ref.data, 0);
10760 }
10761
10762 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1action(JNIEnv * _env, jclass _b, jlong this_ptr) {
10763         LDKLightningError this_ptr_conv;
10764         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10765         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10766         LDKErrorAction *ret_copy = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction");
10767         *ret_copy = LightningError_get_action(&this_ptr_conv);
10768         long ret_ref = (long)ret_copy;
10769         return ret_ref;
10770 }
10771
10772 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1action(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10773         LDKLightningError this_ptr_conv;
10774         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10775         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10776         LDKErrorAction val_conv = *(LDKErrorAction*)val;
10777         FREE((void*)val);
10778         LightningError_set_action(&this_ptr_conv, val_conv);
10779 }
10780
10781 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LightningError_1new(JNIEnv * _env, jclass _b, jbyteArray err_arg, jlong action_arg) {
10782         LDKCVec_u8Z err_arg_ref;
10783         err_arg_ref.data = (*_env)->GetByteArrayElements (_env, err_arg, NULL);
10784         err_arg_ref.datalen = (*_env)->GetArrayLength (_env, err_arg);
10785         LDKErrorAction action_arg_conv = *(LDKErrorAction*)action_arg;
10786         FREE((void*)action_arg);
10787         LDKLightningError ret_var = LightningError_new(err_arg_ref, action_arg_conv);
10788         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10789         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10790         long ret_ref = (long)ret_var.inner;
10791         if (ret_var.is_owned) {
10792                 ret_ref |= 1;
10793         }
10794         (*_env)->ReleaseByteArrayElements(_env, err_arg, (int8_t*)err_arg_ref.data, 0);
10795         return ret_ref;
10796 }
10797
10798 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
10799         LDKCommitmentUpdate this_ptr_conv;
10800         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10801         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10802         CommitmentUpdate_free(this_ptr_conv);
10803 }
10804
10805 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
10806         LDKCommitmentUpdate orig_conv;
10807         orig_conv.inner = (void*)(orig & (~1));
10808         orig_conv.is_owned = (orig & 1) || (orig == 0);
10809         LDKCommitmentUpdate ret_var = CommitmentUpdate_clone(&orig_conv);
10810         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10811         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10812         long ret_ref = (long)ret_var.inner;
10813         if (ret_var.is_owned) {
10814                 ret_ref |= 1;
10815         }
10816         return ret_ref;
10817 }
10818
10819 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1add_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
10820         LDKCommitmentUpdate this_ptr_conv;
10821         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10822         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10823         LDKCVec_UpdateAddHTLCZ val_constr;
10824         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
10825         if (val_constr.datalen > 0)
10826                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
10827         else
10828                 val_constr.data = NULL;
10829         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
10830         for (size_t p = 0; p < val_constr.datalen; p++) {
10831                 long arr_conv_15 = val_vals[p];
10832                 LDKUpdateAddHTLC arr_conv_15_conv;
10833                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
10834                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
10835                 if (arr_conv_15_conv.inner != NULL)
10836                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
10837                 val_constr.data[p] = arr_conv_15_conv;
10838         }
10839         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
10840         CommitmentUpdate_set_update_add_htlcs(&this_ptr_conv, val_constr);
10841 }
10842
10843 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fulfill_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
10844         LDKCommitmentUpdate this_ptr_conv;
10845         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10846         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10847         LDKCVec_UpdateFulfillHTLCZ val_constr;
10848         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
10849         if (val_constr.datalen > 0)
10850                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
10851         else
10852                 val_constr.data = NULL;
10853         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
10854         for (size_t t = 0; t < val_constr.datalen; t++) {
10855                 long arr_conv_19 = val_vals[t];
10856                 LDKUpdateFulfillHTLC arr_conv_19_conv;
10857                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
10858                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
10859                 if (arr_conv_19_conv.inner != NULL)
10860                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
10861                 val_constr.data[t] = arr_conv_19_conv;
10862         }
10863         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
10864         CommitmentUpdate_set_update_fulfill_htlcs(&this_ptr_conv, val_constr);
10865 }
10866
10867 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fail_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
10868         LDKCommitmentUpdate this_ptr_conv;
10869         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10870         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10871         LDKCVec_UpdateFailHTLCZ val_constr;
10872         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
10873         if (val_constr.datalen > 0)
10874                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
10875         else
10876                 val_constr.data = NULL;
10877         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
10878         for (size_t q = 0; q < val_constr.datalen; q++) {
10879                 long arr_conv_16 = val_vals[q];
10880                 LDKUpdateFailHTLC arr_conv_16_conv;
10881                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
10882                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
10883                 if (arr_conv_16_conv.inner != NULL)
10884                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
10885                 val_constr.data[q] = arr_conv_16_conv;
10886         }
10887         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
10888         CommitmentUpdate_set_update_fail_htlcs(&this_ptr_conv, val_constr);
10889 }
10890
10891 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fail_1malformed_1htlcs(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
10892         LDKCommitmentUpdate this_ptr_conv;
10893         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10894         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10895         LDKCVec_UpdateFailMalformedHTLCZ val_constr;
10896         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
10897         if (val_constr.datalen > 0)
10898                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
10899         else
10900                 val_constr.data = NULL;
10901         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
10902         for (size_t z = 0; z < val_constr.datalen; z++) {
10903                 long arr_conv_25 = val_vals[z];
10904                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
10905                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
10906                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
10907                 if (arr_conv_25_conv.inner != NULL)
10908                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
10909                 val_constr.data[z] = arr_conv_25_conv;
10910         }
10911         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
10912         CommitmentUpdate_set_update_fail_malformed_htlcs(&this_ptr_conv, val_constr);
10913 }
10914
10915 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1update_1fee(JNIEnv * _env, jclass _b, jlong this_ptr) {
10916         LDKCommitmentUpdate this_ptr_conv;
10917         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10918         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10919         LDKUpdateFee ret_var = CommitmentUpdate_get_update_fee(&this_ptr_conv);
10920         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10921         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10922         long ret_ref = (long)ret_var.inner;
10923         if (ret_var.is_owned) {
10924                 ret_ref |= 1;
10925         }
10926         return ret_ref;
10927 }
10928
10929 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_1fee(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10930         LDKCommitmentUpdate this_ptr_conv;
10931         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10932         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10933         LDKUpdateFee val_conv;
10934         val_conv.inner = (void*)(val & (~1));
10935         val_conv.is_owned = (val & 1) || (val == 0);
10936         if (val_conv.inner != NULL)
10937                 val_conv = UpdateFee_clone(&val_conv);
10938         CommitmentUpdate_set_update_fee(&this_ptr_conv, val_conv);
10939 }
10940
10941 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1get_1commitment_1signed(JNIEnv * _env, jclass _b, jlong this_ptr) {
10942         LDKCommitmentUpdate this_ptr_conv;
10943         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10944         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10945         LDKCommitmentSigned ret_var = CommitmentUpdate_get_commitment_signed(&this_ptr_conv);
10946         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
10947         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
10948         long ret_ref = (long)ret_var.inner;
10949         if (ret_var.is_owned) {
10950                 ret_ref |= 1;
10951         }
10952         return ret_ref;
10953 }
10954
10955 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1commitment_1signed(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
10956         LDKCommitmentUpdate this_ptr_conv;
10957         this_ptr_conv.inner = (void*)(this_ptr & (~1));
10958         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
10959         LDKCommitmentSigned val_conv;
10960         val_conv.inner = (void*)(val & (~1));
10961         val_conv.is_owned = (val & 1) || (val == 0);
10962         if (val_conv.inner != NULL)
10963                 val_conv = CommitmentSigned_clone(&val_conv);
10964         CommitmentUpdate_set_commitment_signed(&this_ptr_conv, val_conv);
10965 }
10966
10967 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) {
10968         LDKCVec_UpdateAddHTLCZ update_add_htlcs_arg_constr;
10969         update_add_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_add_htlcs_arg);
10970         if (update_add_htlcs_arg_constr.datalen > 0)
10971                 update_add_htlcs_arg_constr.data = MALLOC(update_add_htlcs_arg_constr.datalen * sizeof(LDKUpdateAddHTLC), "LDKCVec_UpdateAddHTLCZ Elements");
10972         else
10973                 update_add_htlcs_arg_constr.data = NULL;
10974         long* update_add_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_add_htlcs_arg, NULL);
10975         for (size_t p = 0; p < update_add_htlcs_arg_constr.datalen; p++) {
10976                 long arr_conv_15 = update_add_htlcs_arg_vals[p];
10977                 LDKUpdateAddHTLC arr_conv_15_conv;
10978                 arr_conv_15_conv.inner = (void*)(arr_conv_15 & (~1));
10979                 arr_conv_15_conv.is_owned = (arr_conv_15 & 1) || (arr_conv_15 == 0);
10980                 if (arr_conv_15_conv.inner != NULL)
10981                         arr_conv_15_conv = UpdateAddHTLC_clone(&arr_conv_15_conv);
10982                 update_add_htlcs_arg_constr.data[p] = arr_conv_15_conv;
10983         }
10984         (*_env)->ReleaseLongArrayElements (_env, update_add_htlcs_arg, update_add_htlcs_arg_vals, 0);
10985         LDKCVec_UpdateFulfillHTLCZ update_fulfill_htlcs_arg_constr;
10986         update_fulfill_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fulfill_htlcs_arg);
10987         if (update_fulfill_htlcs_arg_constr.datalen > 0)
10988                 update_fulfill_htlcs_arg_constr.data = MALLOC(update_fulfill_htlcs_arg_constr.datalen * sizeof(LDKUpdateFulfillHTLC), "LDKCVec_UpdateFulfillHTLCZ Elements");
10989         else
10990                 update_fulfill_htlcs_arg_constr.data = NULL;
10991         long* update_fulfill_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fulfill_htlcs_arg, NULL);
10992         for (size_t t = 0; t < update_fulfill_htlcs_arg_constr.datalen; t++) {
10993                 long arr_conv_19 = update_fulfill_htlcs_arg_vals[t];
10994                 LDKUpdateFulfillHTLC arr_conv_19_conv;
10995                 arr_conv_19_conv.inner = (void*)(arr_conv_19 & (~1));
10996                 arr_conv_19_conv.is_owned = (arr_conv_19 & 1) || (arr_conv_19 == 0);
10997                 if (arr_conv_19_conv.inner != NULL)
10998                         arr_conv_19_conv = UpdateFulfillHTLC_clone(&arr_conv_19_conv);
10999                 update_fulfill_htlcs_arg_constr.data[t] = arr_conv_19_conv;
11000         }
11001         (*_env)->ReleaseLongArrayElements (_env, update_fulfill_htlcs_arg, update_fulfill_htlcs_arg_vals, 0);
11002         LDKCVec_UpdateFailHTLCZ update_fail_htlcs_arg_constr;
11003         update_fail_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fail_htlcs_arg);
11004         if (update_fail_htlcs_arg_constr.datalen > 0)
11005                 update_fail_htlcs_arg_constr.data = MALLOC(update_fail_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailHTLC), "LDKCVec_UpdateFailHTLCZ Elements");
11006         else
11007                 update_fail_htlcs_arg_constr.data = NULL;
11008         long* update_fail_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fail_htlcs_arg, NULL);
11009         for (size_t q = 0; q < update_fail_htlcs_arg_constr.datalen; q++) {
11010                 long arr_conv_16 = update_fail_htlcs_arg_vals[q];
11011                 LDKUpdateFailHTLC arr_conv_16_conv;
11012                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
11013                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
11014                 if (arr_conv_16_conv.inner != NULL)
11015                         arr_conv_16_conv = UpdateFailHTLC_clone(&arr_conv_16_conv);
11016                 update_fail_htlcs_arg_constr.data[q] = arr_conv_16_conv;
11017         }
11018         (*_env)->ReleaseLongArrayElements (_env, update_fail_htlcs_arg, update_fail_htlcs_arg_vals, 0);
11019         LDKCVec_UpdateFailMalformedHTLCZ update_fail_malformed_htlcs_arg_constr;
11020         update_fail_malformed_htlcs_arg_constr.datalen = (*_env)->GetArrayLength (_env, update_fail_malformed_htlcs_arg);
11021         if (update_fail_malformed_htlcs_arg_constr.datalen > 0)
11022                 update_fail_malformed_htlcs_arg_constr.data = MALLOC(update_fail_malformed_htlcs_arg_constr.datalen * sizeof(LDKUpdateFailMalformedHTLC), "LDKCVec_UpdateFailMalformedHTLCZ Elements");
11023         else
11024                 update_fail_malformed_htlcs_arg_constr.data = NULL;
11025         long* update_fail_malformed_htlcs_arg_vals = (*_env)->GetLongArrayElements (_env, update_fail_malformed_htlcs_arg, NULL);
11026         for (size_t z = 0; z < update_fail_malformed_htlcs_arg_constr.datalen; z++) {
11027                 long arr_conv_25 = update_fail_malformed_htlcs_arg_vals[z];
11028                 LDKUpdateFailMalformedHTLC arr_conv_25_conv;
11029                 arr_conv_25_conv.inner = (void*)(arr_conv_25 & (~1));
11030                 arr_conv_25_conv.is_owned = (arr_conv_25 & 1) || (arr_conv_25 == 0);
11031                 if (arr_conv_25_conv.inner != NULL)
11032                         arr_conv_25_conv = UpdateFailMalformedHTLC_clone(&arr_conv_25_conv);
11033                 update_fail_malformed_htlcs_arg_constr.data[z] = arr_conv_25_conv;
11034         }
11035         (*_env)->ReleaseLongArrayElements (_env, update_fail_malformed_htlcs_arg, update_fail_malformed_htlcs_arg_vals, 0);
11036         LDKUpdateFee update_fee_arg_conv;
11037         update_fee_arg_conv.inner = (void*)(update_fee_arg & (~1));
11038         update_fee_arg_conv.is_owned = (update_fee_arg & 1) || (update_fee_arg == 0);
11039         if (update_fee_arg_conv.inner != NULL)
11040                 update_fee_arg_conv = UpdateFee_clone(&update_fee_arg_conv);
11041         LDKCommitmentSigned commitment_signed_arg_conv;
11042         commitment_signed_arg_conv.inner = (void*)(commitment_signed_arg & (~1));
11043         commitment_signed_arg_conv.is_owned = (commitment_signed_arg & 1) || (commitment_signed_arg == 0);
11044         if (commitment_signed_arg_conv.inner != NULL)
11045                 commitment_signed_arg_conv = CommitmentSigned_clone(&commitment_signed_arg_conv);
11046         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);
11047         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11048         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11049         long ret_ref = (long)ret_var.inner;
11050         if (ret_var.is_owned) {
11051                 ret_ref |= 1;
11052         }
11053         return ret_ref;
11054 }
11055
11056 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11057         LDKHTLCFailChannelUpdate this_ptr_conv = *(LDKHTLCFailChannelUpdate*)this_ptr;
11058         FREE((void*)this_ptr);
11059         HTLCFailChannelUpdate_free(this_ptr_conv);
11060 }
11061
11062 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) {
11063         LDKHTLCFailChannelUpdate* orig_conv = (LDKHTLCFailChannelUpdate*)orig;
11064         LDKHTLCFailChannelUpdate *ret_copy = MALLOC(sizeof(LDKHTLCFailChannelUpdate), "LDKHTLCFailChannelUpdate");
11065         *ret_copy = HTLCFailChannelUpdate_clone(orig_conv);
11066         long ret_ref = (long)ret_copy;
11067         return ret_ref;
11068 }
11069
11070 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11071         LDKChannelMessageHandler this_ptr_conv = *(LDKChannelMessageHandler*)this_ptr;
11072         FREE((void*)this_ptr);
11073         ChannelMessageHandler_free(this_ptr_conv);
11074 }
11075
11076 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11077         LDKRoutingMessageHandler this_ptr_conv = *(LDKRoutingMessageHandler*)this_ptr;
11078         FREE((void*)this_ptr);
11079         RoutingMessageHandler_free(this_ptr_conv);
11080 }
11081
11082 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1write(JNIEnv * _env, jclass _b, jlong obj) {
11083         LDKAcceptChannel obj_conv;
11084         obj_conv.inner = (void*)(obj & (~1));
11085         obj_conv.is_owned = (obj & 1) || (obj == 0);
11086         LDKCVec_u8Z arg_var = AcceptChannel_write(&obj_conv);
11087         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11088         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11089         CVec_u8Z_free(arg_var);
11090         return arg_arr;
11091 }
11092
11093 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11094         LDKu8slice ser_ref;
11095         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11096         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11097         LDKAcceptChannel ret_var = AcceptChannel_read(ser_ref);
11098         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11099         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11100         long ret_ref = (long)ret_var.inner;
11101         if (ret_var.is_owned) {
11102                 ret_ref |= 1;
11103         }
11104         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11105         return ret_ref;
11106 }
11107
11108 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1write(JNIEnv * _env, jclass _b, jlong obj) {
11109         LDKAnnouncementSignatures obj_conv;
11110         obj_conv.inner = (void*)(obj & (~1));
11111         obj_conv.is_owned = (obj & 1) || (obj == 0);
11112         LDKCVec_u8Z arg_var = AnnouncementSignatures_write(&obj_conv);
11113         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11114         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11115         CVec_u8Z_free(arg_var);
11116         return arg_arr;
11117 }
11118
11119 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11120         LDKu8slice ser_ref;
11121         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11122         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11123         LDKAnnouncementSignatures ret_var = AnnouncementSignatures_read(ser_ref);
11124         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11125         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11126         long ret_ref = (long)ret_var.inner;
11127         if (ret_var.is_owned) {
11128                 ret_ref |= 1;
11129         }
11130         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11131         return ret_ref;
11132 }
11133
11134 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1write(JNIEnv * _env, jclass _b, jlong obj) {
11135         LDKChannelReestablish obj_conv;
11136         obj_conv.inner = (void*)(obj & (~1));
11137         obj_conv.is_owned = (obj & 1) || (obj == 0);
11138         LDKCVec_u8Z arg_var = ChannelReestablish_write(&obj_conv);
11139         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11140         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11141         CVec_u8Z_free(arg_var);
11142         return arg_arr;
11143 }
11144
11145 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11146         LDKu8slice ser_ref;
11147         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11148         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11149         LDKChannelReestablish ret_var = ChannelReestablish_read(ser_ref);
11150         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11151         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11152         long ret_ref = (long)ret_var.inner;
11153         if (ret_var.is_owned) {
11154                 ret_ref |= 1;
11155         }
11156         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11157         return ret_ref;
11158 }
11159
11160 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
11161         LDKClosingSigned obj_conv;
11162         obj_conv.inner = (void*)(obj & (~1));
11163         obj_conv.is_owned = (obj & 1) || (obj == 0);
11164         LDKCVec_u8Z arg_var = ClosingSigned_write(&obj_conv);
11165         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11166         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11167         CVec_u8Z_free(arg_var);
11168         return arg_arr;
11169 }
11170
11171 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11172         LDKu8slice ser_ref;
11173         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11174         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11175         LDKClosingSigned ret_var = ClosingSigned_read(ser_ref);
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         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11183         return ret_ref;
11184 }
11185
11186 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
11187         LDKCommitmentSigned obj_conv;
11188         obj_conv.inner = (void*)(obj & (~1));
11189         obj_conv.is_owned = (obj & 1) || (obj == 0);
11190         LDKCVec_u8Z arg_var = CommitmentSigned_write(&obj_conv);
11191         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11192         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11193         CVec_u8Z_free(arg_var);
11194         return arg_arr;
11195 }
11196
11197 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11198         LDKu8slice ser_ref;
11199         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11200         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11201         LDKCommitmentSigned ret_var = CommitmentSigned_read(ser_ref);
11202         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11203         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11204         long ret_ref = (long)ret_var.inner;
11205         if (ret_var.is_owned) {
11206                 ret_ref |= 1;
11207         }
11208         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11209         return ret_ref;
11210 }
11211
11212 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1write(JNIEnv * _env, jclass _b, jlong obj) {
11213         LDKFundingCreated obj_conv;
11214         obj_conv.inner = (void*)(obj & (~1));
11215         obj_conv.is_owned = (obj & 1) || (obj == 0);
11216         LDKCVec_u8Z arg_var = FundingCreated_write(&obj_conv);
11217         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11218         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11219         CVec_u8Z_free(arg_var);
11220         return arg_arr;
11221 }
11222
11223 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingCreated_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11224         LDKu8slice ser_ref;
11225         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11226         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11227         LDKFundingCreated ret_var = FundingCreated_read(ser_ref);
11228         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11229         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11230         long ret_ref = (long)ret_var.inner;
11231         if (ret_var.is_owned) {
11232                 ret_ref |= 1;
11233         }
11234         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11235         return ret_ref;
11236 }
11237
11238 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1write(JNIEnv * _env, jclass _b, jlong obj) {
11239         LDKFundingSigned obj_conv;
11240         obj_conv.inner = (void*)(obj & (~1));
11241         obj_conv.is_owned = (obj & 1) || (obj == 0);
11242         LDKCVec_u8Z arg_var = FundingSigned_write(&obj_conv);
11243         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11244         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11245         CVec_u8Z_free(arg_var);
11246         return arg_arr;
11247 }
11248
11249 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11250         LDKu8slice ser_ref;
11251         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11252         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11253         LDKFundingSigned ret_var = FundingSigned_read(ser_ref);
11254         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11255         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11256         long ret_ref = (long)ret_var.inner;
11257         if (ret_var.is_owned) {
11258                 ret_ref |= 1;
11259         }
11260         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11261         return ret_ref;
11262 }
11263
11264 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1write(JNIEnv * _env, jclass _b, jlong obj) {
11265         LDKFundingLocked obj_conv;
11266         obj_conv.inner = (void*)(obj & (~1));
11267         obj_conv.is_owned = (obj & 1) || (obj == 0);
11268         LDKCVec_u8Z arg_var = FundingLocked_write(&obj_conv);
11269         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11270         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11271         CVec_u8Z_free(arg_var);
11272         return arg_arr;
11273 }
11274
11275 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11276         LDKu8slice ser_ref;
11277         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11278         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11279         LDKFundingLocked ret_var = FundingLocked_read(ser_ref);
11280         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11281         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11282         long ret_ref = (long)ret_var.inner;
11283         if (ret_var.is_owned) {
11284                 ret_ref |= 1;
11285         }
11286         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11287         return ret_ref;
11288 }
11289
11290 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Init_1write(JNIEnv * _env, jclass _b, jlong obj) {
11291         LDKInit obj_conv;
11292         obj_conv.inner = (void*)(obj & (~1));
11293         obj_conv.is_owned = (obj & 1) || (obj == 0);
11294         LDKCVec_u8Z arg_var = Init_write(&obj_conv);
11295         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11296         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11297         CVec_u8Z_free(arg_var);
11298         return arg_arr;
11299 }
11300
11301 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Init_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11302         LDKu8slice ser_ref;
11303         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11304         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11305         LDKInit ret_var = Init_read(ser_ref);
11306         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11307         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11308         long ret_ref = (long)ret_var.inner;
11309         if (ret_var.is_owned) {
11310                 ret_ref |= 1;
11311         }
11312         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11313         return ret_ref;
11314 }
11315
11316 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1write(JNIEnv * _env, jclass _b, jlong obj) {
11317         LDKOpenChannel obj_conv;
11318         obj_conv.inner = (void*)(obj & (~1));
11319         obj_conv.is_owned = (obj & 1) || (obj == 0);
11320         LDKCVec_u8Z arg_var = OpenChannel_write(&obj_conv);
11321         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11322         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11323         CVec_u8Z_free(arg_var);
11324         return arg_arr;
11325 }
11326
11327 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11328         LDKu8slice ser_ref;
11329         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11330         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11331         LDKOpenChannel ret_var = OpenChannel_read(ser_ref);
11332         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11333         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11334         long ret_ref = (long)ret_var.inner;
11335         if (ret_var.is_owned) {
11336                 ret_ref |= 1;
11337         }
11338         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11339         return ret_ref;
11340 }
11341
11342 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1write(JNIEnv * _env, jclass _b, jlong obj) {
11343         LDKRevokeAndACK obj_conv;
11344         obj_conv.inner = (void*)(obj & (~1));
11345         obj_conv.is_owned = (obj & 1) || (obj == 0);
11346         LDKCVec_u8Z arg_var = RevokeAndACK_write(&obj_conv);
11347         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11348         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11349         CVec_u8Z_free(arg_var);
11350         return arg_arr;
11351 }
11352
11353 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11354         LDKu8slice ser_ref;
11355         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11356         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11357         LDKRevokeAndACK ret_var = RevokeAndACK_read(ser_ref);
11358         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11359         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11360         long ret_ref = (long)ret_var.inner;
11361         if (ret_var.is_owned) {
11362                 ret_ref |= 1;
11363         }
11364         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11365         return ret_ref;
11366 }
11367
11368 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1write(JNIEnv * _env, jclass _b, jlong obj) {
11369         LDKShutdown obj_conv;
11370         obj_conv.inner = (void*)(obj & (~1));
11371         obj_conv.is_owned = (obj & 1) || (obj == 0);
11372         LDKCVec_u8Z arg_var = Shutdown_write(&obj_conv);
11373         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11374         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11375         CVec_u8Z_free(arg_var);
11376         return arg_arr;
11377 }
11378
11379 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11380         LDKu8slice ser_ref;
11381         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11382         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11383         LDKShutdown ret_var = Shutdown_read(ser_ref);
11384         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11385         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11386         long ret_ref = (long)ret_var.inner;
11387         if (ret_var.is_owned) {
11388                 ret_ref |= 1;
11389         }
11390         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11391         return ret_ref;
11392 }
11393
11394 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
11395         LDKUpdateFailHTLC obj_conv;
11396         obj_conv.inner = (void*)(obj & (~1));
11397         obj_conv.is_owned = (obj & 1) || (obj == 0);
11398         LDKCVec_u8Z arg_var = UpdateFailHTLC_write(&obj_conv);
11399         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11400         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11401         CVec_u8Z_free(arg_var);
11402         return arg_arr;
11403 }
11404
11405 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11406         LDKu8slice ser_ref;
11407         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11408         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11409         LDKUpdateFailHTLC ret_var = UpdateFailHTLC_read(ser_ref);
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         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11417         return ret_ref;
11418 }
11419
11420 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
11421         LDKUpdateFailMalformedHTLC obj_conv;
11422         obj_conv.inner = (void*)(obj & (~1));
11423         obj_conv.is_owned = (obj & 1) || (obj == 0);
11424         LDKCVec_u8Z arg_var = UpdateFailMalformedHTLC_write(&obj_conv);
11425         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11426         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11427         CVec_u8Z_free(arg_var);
11428         return arg_arr;
11429 }
11430
11431 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11432         LDKu8slice ser_ref;
11433         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11434         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11435         LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_read(ser_ref);
11436         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11437         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11438         long ret_ref = (long)ret_var.inner;
11439         if (ret_var.is_owned) {
11440                 ret_ref |= 1;
11441         }
11442         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11443         return ret_ref;
11444 }
11445
11446 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1write(JNIEnv * _env, jclass _b, jlong obj) {
11447         LDKUpdateFee obj_conv;
11448         obj_conv.inner = (void*)(obj & (~1));
11449         obj_conv.is_owned = (obj & 1) || (obj == 0);
11450         LDKCVec_u8Z arg_var = UpdateFee_write(&obj_conv);
11451         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11452         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11453         CVec_u8Z_free(arg_var);
11454         return arg_arr;
11455 }
11456
11457 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11458         LDKu8slice ser_ref;
11459         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11460         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11461         LDKUpdateFee ret_var = UpdateFee_read(ser_ref);
11462         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11463         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11464         long ret_ref = (long)ret_var.inner;
11465         if (ret_var.is_owned) {
11466                 ret_ref |= 1;
11467         }
11468         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11469         return ret_ref;
11470 }
11471
11472 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
11473         LDKUpdateFulfillHTLC obj_conv;
11474         obj_conv.inner = (void*)(obj & (~1));
11475         obj_conv.is_owned = (obj & 1) || (obj == 0);
11476         LDKCVec_u8Z arg_var = UpdateFulfillHTLC_write(&obj_conv);
11477         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11478         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11479         CVec_u8Z_free(arg_var);
11480         return arg_arr;
11481 }
11482
11483 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11484         LDKu8slice ser_ref;
11485         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11486         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11487         LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_read(ser_ref);
11488         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11489         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11490         long ret_ref = (long)ret_var.inner;
11491         if (ret_var.is_owned) {
11492                 ret_ref |= 1;
11493         }
11494         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11495         return ret_ref;
11496 }
11497
11498 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1write(JNIEnv * _env, jclass _b, jlong obj) {
11499         LDKUpdateAddHTLC obj_conv;
11500         obj_conv.inner = (void*)(obj & (~1));
11501         obj_conv.is_owned = (obj & 1) || (obj == 0);
11502         LDKCVec_u8Z arg_var = UpdateAddHTLC_write(&obj_conv);
11503         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11504         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11505         CVec_u8Z_free(arg_var);
11506         return arg_arr;
11507 }
11508
11509 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11510         LDKu8slice ser_ref;
11511         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11512         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11513         LDKUpdateAddHTLC ret_var = UpdateAddHTLC_read(ser_ref);
11514         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11515         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11516         long ret_ref = (long)ret_var.inner;
11517         if (ret_var.is_owned) {
11518                 ret_ref |= 1;
11519         }
11520         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11521         return ret_ref;
11522 }
11523
11524 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Ping_1write(JNIEnv * _env, jclass _b, jlong obj) {
11525         LDKPing obj_conv;
11526         obj_conv.inner = (void*)(obj & (~1));
11527         obj_conv.is_owned = (obj & 1) || (obj == 0);
11528         LDKCVec_u8Z arg_var = Ping_write(&obj_conv);
11529         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11530         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11531         CVec_u8Z_free(arg_var);
11532         return arg_arr;
11533 }
11534
11535 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11536         LDKu8slice ser_ref;
11537         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11538         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11539         LDKPing ret_var = Ping_read(ser_ref);
11540         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11541         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11542         long ret_ref = (long)ret_var.inner;
11543         if (ret_var.is_owned) {
11544                 ret_ref |= 1;
11545         }
11546         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11547         return ret_ref;
11548 }
11549
11550 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Pong_1write(JNIEnv * _env, jclass _b, jlong obj) {
11551         LDKPong obj_conv;
11552         obj_conv.inner = (void*)(obj & (~1));
11553         obj_conv.is_owned = (obj & 1) || (obj == 0);
11554         LDKCVec_u8Z arg_var = Pong_write(&obj_conv);
11555         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11556         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11557         CVec_u8Z_free(arg_var);
11558         return arg_arr;
11559 }
11560
11561 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11562         LDKu8slice ser_ref;
11563         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11564         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11565         LDKPong ret_var = Pong_read(ser_ref);
11566         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11567         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11568         long ret_ref = (long)ret_var.inner;
11569         if (ret_var.is_owned) {
11570                 ret_ref |= 1;
11571         }
11572         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11573         return ret_ref;
11574 }
11575
11576 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
11577         LDKUnsignedChannelAnnouncement obj_conv;
11578         obj_conv.inner = (void*)(obj & (~1));
11579         obj_conv.is_owned = (obj & 1) || (obj == 0);
11580         LDKCVec_u8Z arg_var = UnsignedChannelAnnouncement_write(&obj_conv);
11581         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11582         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11583         CVec_u8Z_free(arg_var);
11584         return arg_arr;
11585 }
11586
11587 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11588         LDKu8slice ser_ref;
11589         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11590         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11591         LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_read(ser_ref);
11592         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11593         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11594         long ret_ref = (long)ret_var.inner;
11595         if (ret_var.is_owned) {
11596                 ret_ref |= 1;
11597         }
11598         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11599         return ret_ref;
11600 }
11601
11602 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
11603         LDKChannelAnnouncement obj_conv;
11604         obj_conv.inner = (void*)(obj & (~1));
11605         obj_conv.is_owned = (obj & 1) || (obj == 0);
11606         LDKCVec_u8Z arg_var = ChannelAnnouncement_write(&obj_conv);
11607         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11608         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11609         CVec_u8Z_free(arg_var);
11610         return arg_arr;
11611 }
11612
11613 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11614         LDKu8slice ser_ref;
11615         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11616         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11617         LDKChannelAnnouncement ret_var = ChannelAnnouncement_read(ser_ref);
11618         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11619         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11620         long ret_ref = (long)ret_var.inner;
11621         if (ret_var.is_owned) {
11622                 ret_ref |= 1;
11623         }
11624         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11625         return ret_ref;
11626 }
11627
11628 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
11629         LDKUnsignedChannelUpdate obj_conv;
11630         obj_conv.inner = (void*)(obj & (~1));
11631         obj_conv.is_owned = (obj & 1) || (obj == 0);
11632         LDKCVec_u8Z arg_var = UnsignedChannelUpdate_write(&obj_conv);
11633         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11634         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11635         CVec_u8Z_free(arg_var);
11636         return arg_arr;
11637 }
11638
11639 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11640         LDKu8slice ser_ref;
11641         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11642         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11643         LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_read(ser_ref);
11644         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11645         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11646         long ret_ref = (long)ret_var.inner;
11647         if (ret_var.is_owned) {
11648                 ret_ref |= 1;
11649         }
11650         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11651         return ret_ref;
11652 }
11653
11654 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1write(JNIEnv * _env, jclass _b, jlong obj) {
11655         LDKChannelUpdate obj_conv;
11656         obj_conv.inner = (void*)(obj & (~1));
11657         obj_conv.is_owned = (obj & 1) || (obj == 0);
11658         LDKCVec_u8Z arg_var = ChannelUpdate_write(&obj_conv);
11659         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11660         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11661         CVec_u8Z_free(arg_var);
11662         return arg_arr;
11663 }
11664
11665 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11666         LDKu8slice ser_ref;
11667         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11668         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11669         LDKChannelUpdate ret_var = ChannelUpdate_read(ser_ref);
11670         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11671         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11672         long ret_ref = (long)ret_var.inner;
11673         if (ret_var.is_owned) {
11674                 ret_ref |= 1;
11675         }
11676         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11677         return ret_ref;
11678 }
11679
11680 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1write(JNIEnv * _env, jclass _b, jlong obj) {
11681         LDKErrorMessage obj_conv;
11682         obj_conv.inner = (void*)(obj & (~1));
11683         obj_conv.is_owned = (obj & 1) || (obj == 0);
11684         LDKCVec_u8Z arg_var = ErrorMessage_write(&obj_conv);
11685         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11686         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11687         CVec_u8Z_free(arg_var);
11688         return arg_arr;
11689 }
11690
11691 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11692         LDKu8slice ser_ref;
11693         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11694         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11695         LDKErrorMessage ret_var = ErrorMessage_read(ser_ref);
11696         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11697         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11698         long ret_ref = (long)ret_var.inner;
11699         if (ret_var.is_owned) {
11700                 ret_ref |= 1;
11701         }
11702         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11703         return ret_ref;
11704 }
11705
11706 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
11707         LDKUnsignedNodeAnnouncement obj_conv;
11708         obj_conv.inner = (void*)(obj & (~1));
11709         obj_conv.is_owned = (obj & 1) || (obj == 0);
11710         LDKCVec_u8Z arg_var = UnsignedNodeAnnouncement_write(&obj_conv);
11711         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11712         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11713         CVec_u8Z_free(arg_var);
11714         return arg_arr;
11715 }
11716
11717 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11718         LDKu8slice ser_ref;
11719         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11720         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11721         LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_read(ser_ref);
11722         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11723         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11724         long ret_ref = (long)ret_var.inner;
11725         if (ret_var.is_owned) {
11726                 ret_ref |= 1;
11727         }
11728         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11729         return ret_ref;
11730 }
11731
11732 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1write(JNIEnv * _env, jclass _b, jlong obj) {
11733         LDKNodeAnnouncement obj_conv;
11734         obj_conv.inner = (void*)(obj & (~1));
11735         obj_conv.is_owned = (obj & 1) || (obj == 0);
11736         LDKCVec_u8Z arg_var = NodeAnnouncement_write(&obj_conv);
11737         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11738         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11739         CVec_u8Z_free(arg_var);
11740         return arg_arr;
11741 }
11742
11743 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11744         LDKu8slice ser_ref;
11745         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11746         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11747         LDKNodeAnnouncement ret_var = NodeAnnouncement_read(ser_ref);
11748         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11749         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11750         long ret_ref = (long)ret_var.inner;
11751         if (ret_var.is_owned) {
11752                 ret_ref |= 1;
11753         }
11754         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11755         return ret_ref;
11756 }
11757
11758 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11759         LDKu8slice ser_ref;
11760         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11761         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11762         LDKQueryShortChannelIds ret_var = QueryShortChannelIds_read(ser_ref);
11763         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11764         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11765         long ret_ref = (long)ret_var.inner;
11766         if (ret_var.is_owned) {
11767                 ret_ref |= 1;
11768         }
11769         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11770         return ret_ref;
11771 }
11772
11773 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1write(JNIEnv * _env, jclass _b, jlong obj) {
11774         LDKQueryShortChannelIds obj_conv;
11775         obj_conv.inner = (void*)(obj & (~1));
11776         obj_conv.is_owned = (obj & 1) || (obj == 0);
11777         LDKCVec_u8Z arg_var = QueryShortChannelIds_write(&obj_conv);
11778         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11779         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11780         CVec_u8Z_free(arg_var);
11781         return arg_arr;
11782 }
11783
11784 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11785         LDKu8slice ser_ref;
11786         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11787         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11788         LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_read(ser_ref);
11789         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11790         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11791         long ret_ref = (long)ret_var.inner;
11792         if (ret_var.is_owned) {
11793                 ret_ref |= 1;
11794         }
11795         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11796         return ret_ref;
11797 }
11798
11799 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1write(JNIEnv * _env, jclass _b, jlong obj) {
11800         LDKReplyShortChannelIdsEnd obj_conv;
11801         obj_conv.inner = (void*)(obj & (~1));
11802         obj_conv.is_owned = (obj & 1) || (obj == 0);
11803         LDKCVec_u8Z arg_var = ReplyShortChannelIdsEnd_write(&obj_conv);
11804         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11805         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11806         CVec_u8Z_free(arg_var);
11807         return arg_arr;
11808 }
11809
11810 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11811         LDKu8slice ser_ref;
11812         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11813         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11814         LDKQueryChannelRange ret_var = QueryChannelRange_read(ser_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         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11822         return ret_ref;
11823 }
11824
11825 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1write(JNIEnv * _env, jclass _b, jlong obj) {
11826         LDKQueryChannelRange obj_conv;
11827         obj_conv.inner = (void*)(obj & (~1));
11828         obj_conv.is_owned = (obj & 1) || (obj == 0);
11829         LDKCVec_u8Z arg_var = QueryChannelRange_write(&obj_conv);
11830         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11831         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11832         CVec_u8Z_free(arg_var);
11833         return arg_arr;
11834 }
11835
11836 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11837         LDKu8slice ser_ref;
11838         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11839         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11840         LDKReplyChannelRange ret_var = ReplyChannelRange_read(ser_ref);
11841         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11842         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11843         long ret_ref = (long)ret_var.inner;
11844         if (ret_var.is_owned) {
11845                 ret_ref |= 1;
11846         }
11847         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11848         return ret_ref;
11849 }
11850
11851 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1write(JNIEnv * _env, jclass _b, jlong obj) {
11852         LDKReplyChannelRange obj_conv;
11853         obj_conv.inner = (void*)(obj & (~1));
11854         obj_conv.is_owned = (obj & 1) || (obj == 0);
11855         LDKCVec_u8Z arg_var = ReplyChannelRange_write(&obj_conv);
11856         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11857         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11858         CVec_u8Z_free(arg_var);
11859         return arg_arr;
11860 }
11861
11862 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
11863         LDKu8slice ser_ref;
11864         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
11865         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
11866         LDKGossipTimestampFilter ret_var = GossipTimestampFilter_read(ser_ref);
11867         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11868         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11869         long ret_ref = (long)ret_var.inner;
11870         if (ret_var.is_owned) {
11871                 ret_ref |= 1;
11872         }
11873         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
11874         return ret_ref;
11875 }
11876
11877 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1write(JNIEnv * _env, jclass _b, jlong obj) {
11878         LDKGossipTimestampFilter obj_conv;
11879         obj_conv.inner = (void*)(obj & (~1));
11880         obj_conv.is_owned = (obj & 1) || (obj == 0);
11881         LDKCVec_u8Z arg_var = GossipTimestampFilter_write(&obj_conv);
11882         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
11883         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
11884         CVec_u8Z_free(arg_var);
11885         return arg_arr;
11886 }
11887
11888 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11889         LDKMessageHandler this_ptr_conv;
11890         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11891         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11892         MessageHandler_free(this_ptr_conv);
11893 }
11894
11895 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1chan_1handler(JNIEnv * _env, jclass _b, jlong this_ptr) {
11896         LDKMessageHandler this_ptr_conv;
11897         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11898         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11899         long ret_ret = (long)MessageHandler_get_chan_handler(&this_ptr_conv);
11900         return ret_ret;
11901 }
11902
11903 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1chan_1handler(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11904         LDKMessageHandler this_ptr_conv;
11905         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11906         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11907         LDKChannelMessageHandler val_conv = *(LDKChannelMessageHandler*)val;
11908         if (val_conv.free == LDKChannelMessageHandler_JCalls_free) {
11909                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
11910                 LDKChannelMessageHandler_JCalls_clone(val_conv.this_arg);
11911         }
11912         MessageHandler_set_chan_handler(&this_ptr_conv, val_conv);
11913 }
11914
11915 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1get_1route_1handler(JNIEnv * _env, jclass _b, jlong this_ptr) {
11916         LDKMessageHandler this_ptr_conv;
11917         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11918         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11919         long ret_ret = (long)MessageHandler_get_route_handler(&this_ptr_conv);
11920         return ret_ret;
11921 }
11922
11923 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageHandler_1set_1route_1handler(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
11924         LDKMessageHandler this_ptr_conv;
11925         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11926         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11927         LDKRoutingMessageHandler val_conv = *(LDKRoutingMessageHandler*)val;
11928         if (val_conv.free == LDKRoutingMessageHandler_JCalls_free) {
11929                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
11930                 LDKRoutingMessageHandler_JCalls_clone(val_conv.this_arg);
11931         }
11932         MessageHandler_set_route_handler(&this_ptr_conv, val_conv);
11933 }
11934
11935 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageHandler_1new(JNIEnv * _env, jclass _b, jlong chan_handler_arg, jlong route_handler_arg) {
11936         LDKChannelMessageHandler chan_handler_arg_conv = *(LDKChannelMessageHandler*)chan_handler_arg;
11937         if (chan_handler_arg_conv.free == LDKChannelMessageHandler_JCalls_free) {
11938                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
11939                 LDKChannelMessageHandler_JCalls_clone(chan_handler_arg_conv.this_arg);
11940         }
11941         LDKRoutingMessageHandler route_handler_arg_conv = *(LDKRoutingMessageHandler*)route_handler_arg;
11942         if (route_handler_arg_conv.free == LDKRoutingMessageHandler_JCalls_free) {
11943                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
11944                 LDKRoutingMessageHandler_JCalls_clone(route_handler_arg_conv.this_arg);
11945         }
11946         LDKMessageHandler ret_var = MessageHandler_new(chan_handler_arg_conv, route_handler_arg_conv);
11947         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11948         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11949         long ret_ref = (long)ret_var.inner;
11950         if (ret_var.is_owned) {
11951                 ret_ref |= 1;
11952         }
11953         return ret_ref;
11954 }
11955
11956 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11957         LDKSocketDescriptor this_ptr_conv = *(LDKSocketDescriptor*)this_ptr;
11958         FREE((void*)this_ptr);
11959         SocketDescriptor_free(this_ptr_conv);
11960 }
11961
11962 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11963         LDKPeerHandleError this_ptr_conv;
11964         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11965         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11966         PeerHandleError_free(this_ptr_conv);
11967 }
11968
11969 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1get_1no_1connection_1possible(JNIEnv * _env, jclass _b, jlong this_ptr) {
11970         LDKPeerHandleError this_ptr_conv;
11971         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11972         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11973         jboolean ret_val = PeerHandleError_get_no_connection_possible(&this_ptr_conv);
11974         return ret_val;
11975 }
11976
11977 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1set_1no_1connection_1possible(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
11978         LDKPeerHandleError this_ptr_conv;
11979         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11980         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11981         PeerHandleError_set_no_connection_possible(&this_ptr_conv, val);
11982 }
11983
11984 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerHandleError_1new(JNIEnv * _env, jclass _b, jboolean no_connection_possible_arg) {
11985         LDKPeerHandleError ret_var = PeerHandleError_new(no_connection_possible_arg);
11986         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
11987         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
11988         long ret_ref = (long)ret_var.inner;
11989         if (ret_var.is_owned) {
11990                 ret_ref |= 1;
11991         }
11992         return ret_ref;
11993 }
11994
11995 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
11996         LDKPeerManager this_ptr_conv;
11997         this_ptr_conv.inner = (void*)(this_ptr & (~1));
11998         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
11999         PeerManager_free(this_ptr_conv);
12000 }
12001
12002 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) {
12003         LDKMessageHandler message_handler_conv;
12004         message_handler_conv.inner = (void*)(message_handler & (~1));
12005         message_handler_conv.is_owned = (message_handler & 1) || (message_handler == 0);
12006         // Warning: we may need a move here but can't clone!
12007         LDKSecretKey our_node_secret_ref;
12008         CHECK((*_env)->GetArrayLength (_env, our_node_secret) == 32);
12009         (*_env)->GetByteArrayRegion (_env, our_node_secret, 0, 32, our_node_secret_ref.bytes);
12010         unsigned char ephemeral_random_data_arr[32];
12011         CHECK((*_env)->GetArrayLength (_env, ephemeral_random_data) == 32);
12012         (*_env)->GetByteArrayRegion (_env, ephemeral_random_data, 0, 32, ephemeral_random_data_arr);
12013         unsigned char (*ephemeral_random_data_ref)[32] = &ephemeral_random_data_arr;
12014         LDKLogger logger_conv = *(LDKLogger*)logger;
12015         if (logger_conv.free == LDKLogger_JCalls_free) {
12016                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12017                 LDKLogger_JCalls_clone(logger_conv.this_arg);
12018         }
12019         LDKPeerManager ret_var = PeerManager_new(message_handler_conv, our_node_secret_ref, ephemeral_random_data_ref, logger_conv);
12020         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12021         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12022         long ret_ref = (long)ret_var.inner;
12023         if (ret_var.is_owned) {
12024                 ret_ref |= 1;
12025         }
12026         return ret_ref;
12027 }
12028
12029 JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_PeerManager_1get_1peer_1node_1ids(JNIEnv * _env, jclass _b, jlong this_arg) {
12030         LDKPeerManager this_arg_conv;
12031         this_arg_conv.inner = (void*)(this_arg & (~1));
12032         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12033         LDKCVec_PublicKeyZ ret_var = PeerManager_get_peer_node_ids(&this_arg_conv);
12034         jobjectArray ret_arr = (*_env)->NewObjectArray(_env, ret_var.datalen, NULL, NULL);
12035         for (size_t i = 0; i < ret_var.datalen; i++) {
12036                 jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 33);
12037                 (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 33, ret_var.data[i].compressed_form);
12038                 (*_env)->SetObjectArrayElement(_env, ret_arr, i, arr_conv_8_arr);
12039         }
12040         CVec_PublicKeyZ_free(ret_var);
12041         return ret_arr;
12042 }
12043
12044 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) {
12045         LDKPeerManager this_arg_conv;
12046         this_arg_conv.inner = (void*)(this_arg & (~1));
12047         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12048         LDKPublicKey their_node_id_ref;
12049         CHECK((*_env)->GetArrayLength (_env, their_node_id) == 33);
12050         (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
12051         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
12052         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
12053                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12054                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
12055         }
12056         LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ");
12057         *ret_conv = PeerManager_new_outbound_connection(&this_arg_conv, their_node_id_ref, descriptor_conv);
12058         return (long)ret_conv;
12059 }
12060
12061 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1new_1inbound_1connection(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
12062         LDKPeerManager this_arg_conv;
12063         this_arg_conv.inner = (void*)(this_arg & (~1));
12064         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12065         LDKSocketDescriptor descriptor_conv = *(LDKSocketDescriptor*)descriptor;
12066         if (descriptor_conv.free == LDKSocketDescriptor_JCalls_free) {
12067                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
12068                 LDKSocketDescriptor_JCalls_clone(descriptor_conv.this_arg);
12069         }
12070         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
12071         *ret_conv = PeerManager_new_inbound_connection(&this_arg_conv, descriptor_conv);
12072         return (long)ret_conv;
12073 }
12074
12075 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1write_1buffer_1space_1avail(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
12076         LDKPeerManager this_arg_conv;
12077         this_arg_conv.inner = (void*)(this_arg & (~1));
12078         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12079         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
12080         LDKCResult_NonePeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_NonePeerHandleErrorZ), "LDKCResult_NonePeerHandleErrorZ");
12081         *ret_conv = PeerManager_write_buffer_space_avail(&this_arg_conv, descriptor_conv);
12082         return (long)ret_conv;
12083 }
12084
12085 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1read_1event(JNIEnv * _env, jclass _b, jlong this_arg, jlong peer_descriptor, jbyteArray data) {
12086         LDKPeerManager this_arg_conv;
12087         this_arg_conv.inner = (void*)(this_arg & (~1));
12088         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12089         LDKSocketDescriptor* peer_descriptor_conv = (LDKSocketDescriptor*)peer_descriptor;
12090         LDKu8slice data_ref;
12091         data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL);
12092         data_ref.datalen = (*_env)->GetArrayLength (_env, data);
12093         LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ");
12094         *ret_conv = PeerManager_read_event(&this_arg_conv, peer_descriptor_conv, data_ref);
12095         (*_env)->ReleaseByteArrayElements(_env, data, (int8_t*)data_ref.data, 0);
12096         return (long)ret_conv;
12097 }
12098
12099 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1process_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
12100         LDKPeerManager this_arg_conv;
12101         this_arg_conv.inner = (void*)(this_arg & (~1));
12102         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12103         PeerManager_process_events(&this_arg_conv);
12104 }
12105
12106 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1socket_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jlong descriptor) {
12107         LDKPeerManager this_arg_conv;
12108         this_arg_conv.inner = (void*)(this_arg & (~1));
12109         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12110         LDKSocketDescriptor* descriptor_conv = (LDKSocketDescriptor*)descriptor;
12111         PeerManager_socket_disconnected(&this_arg_conv, descriptor_conv);
12112 }
12113
12114 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1timer_1tick_1occured(JNIEnv * _env, jclass _b, jlong this_arg) {
12115         LDKPeerManager this_arg_conv;
12116         this_arg_conv.inner = (void*)(this_arg & (~1));
12117         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12118         PeerManager_timer_tick_occured(&this_arg_conv);
12119 }
12120
12121 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_build_1commitment_1secret(JNIEnv * _env, jclass _b, jbyteArray commitment_seed, jlong idx) {
12122         unsigned char commitment_seed_arr[32];
12123         CHECK((*_env)->GetArrayLength (_env, commitment_seed) == 32);
12124         (*_env)->GetByteArrayRegion (_env, commitment_seed, 0, 32, commitment_seed_arr);
12125         unsigned char (*commitment_seed_ref)[32] = &commitment_seed_arr;
12126         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
12127         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, build_commitment_secret(commitment_seed_ref, idx).data);
12128         return arg_arr;
12129 }
12130
12131 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_derive_1private_1key(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jbyteArray base_secret) {
12132         LDKPublicKey per_commitment_point_ref;
12133         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
12134         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
12135         unsigned char base_secret_arr[32];
12136         CHECK((*_env)->GetArrayLength (_env, base_secret) == 32);
12137         (*_env)->GetByteArrayRegion (_env, base_secret, 0, 32, base_secret_arr);
12138         unsigned char (*base_secret_ref)[32] = &base_secret_arr;
12139         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
12140         *ret_conv = derive_private_key(per_commitment_point_ref, base_secret_ref);
12141         return (long)ret_conv;
12142 }
12143
12144 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_derive_1public_1key(JNIEnv * _env, jclass _b, jbyteArray per_commitment_point, jbyteArray base_point) {
12145         LDKPublicKey per_commitment_point_ref;
12146         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
12147         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
12148         LDKPublicKey base_point_ref;
12149         CHECK((*_env)->GetArrayLength (_env, base_point) == 33);
12150         (*_env)->GetByteArrayRegion (_env, base_point, 0, 33, base_point_ref.compressed_form);
12151         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
12152         *ret_conv = derive_public_key(per_commitment_point_ref, base_point_ref);
12153         return (long)ret_conv;
12154 }
12155
12156 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) {
12157         unsigned char per_commitment_secret_arr[32];
12158         CHECK((*_env)->GetArrayLength (_env, per_commitment_secret) == 32);
12159         (*_env)->GetByteArrayRegion (_env, per_commitment_secret, 0, 32, per_commitment_secret_arr);
12160         unsigned char (*per_commitment_secret_ref)[32] = &per_commitment_secret_arr;
12161         unsigned char countersignatory_revocation_base_secret_arr[32];
12162         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base_secret) == 32);
12163         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base_secret, 0, 32, countersignatory_revocation_base_secret_arr);
12164         unsigned char (*countersignatory_revocation_base_secret_ref)[32] = &countersignatory_revocation_base_secret_arr;
12165         LDKCResult_SecretKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
12166         *ret_conv = derive_private_revocation_key(per_commitment_secret_ref, countersignatory_revocation_base_secret_ref);
12167         return (long)ret_conv;
12168 }
12169
12170 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) {
12171         LDKPublicKey per_commitment_point_ref;
12172         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
12173         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
12174         LDKPublicKey countersignatory_revocation_base_point_ref;
12175         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base_point) == 33);
12176         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base_point, 0, 33, countersignatory_revocation_base_point_ref.compressed_form);
12177         LDKCResult_PublicKeySecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_PublicKeySecpErrorZ), "LDKCResult_PublicKeySecpErrorZ");
12178         *ret_conv = derive_public_revocation_key(per_commitment_point_ref, countersignatory_revocation_base_point_ref);
12179         return (long)ret_conv;
12180 }
12181
12182 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12183         LDKTxCreationKeys this_ptr_conv;
12184         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12185         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12186         TxCreationKeys_free(this_ptr_conv);
12187 }
12188
12189 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12190         LDKTxCreationKeys orig_conv;
12191         orig_conv.inner = (void*)(orig & (~1));
12192         orig_conv.is_owned = (orig & 1) || (orig == 0);
12193         LDKTxCreationKeys ret_var = TxCreationKeys_clone(&orig_conv);
12194         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12195         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12196         long ret_ref = (long)ret_var.inner;
12197         if (ret_var.is_owned) {
12198                 ret_ref |= 1;
12199         }
12200         return ret_ref;
12201 }
12202
12203 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
12204         LDKTxCreationKeys this_ptr_conv;
12205         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12206         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12207         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12208         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_per_commitment_point(&this_ptr_conv).compressed_form);
12209         return arg_arr;
12210 }
12211
12212 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12213         LDKTxCreationKeys this_ptr_conv;
12214         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12215         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12216         LDKPublicKey val_ref;
12217         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12218         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12219         TxCreationKeys_set_per_commitment_point(&this_ptr_conv, val_ref);
12220 }
12221
12222 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1revocation_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
12223         LDKTxCreationKeys this_ptr_conv;
12224         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12225         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12226         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12227         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_revocation_key(&this_ptr_conv).compressed_form);
12228         return arg_arr;
12229 }
12230
12231 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1revocation_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12232         LDKTxCreationKeys this_ptr_conv;
12233         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12234         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12235         LDKPublicKey val_ref;
12236         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12237         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12238         TxCreationKeys_set_revocation_key(&this_ptr_conv, val_ref);
12239 }
12240
12241 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
12242         LDKTxCreationKeys this_ptr_conv;
12243         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12244         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12245         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12246         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_htlc_key(&this_ptr_conv).compressed_form);
12247         return arg_arr;
12248 }
12249
12250 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1broadcaster_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12251         LDKTxCreationKeys this_ptr_conv;
12252         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12253         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12254         LDKPublicKey val_ref;
12255         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12256         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12257         TxCreationKeys_set_broadcaster_htlc_key(&this_ptr_conv, val_ref);
12258 }
12259
12260 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1countersignatory_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
12261         LDKTxCreationKeys this_ptr_conv;
12262         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12263         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12264         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12265         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_countersignatory_htlc_key(&this_ptr_conv).compressed_form);
12266         return arg_arr;
12267 }
12268
12269 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1countersignatory_1htlc_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12270         LDKTxCreationKeys this_ptr_conv;
12271         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12272         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12273         LDKPublicKey val_ref;
12274         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12275         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12276         TxCreationKeys_set_countersignatory_htlc_key(&this_ptr_conv, val_ref);
12277 }
12278
12279 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1get_1broadcaster_1delayed_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
12280         LDKTxCreationKeys this_ptr_conv;
12281         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12282         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12283         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12284         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, TxCreationKeys_get_broadcaster_delayed_payment_key(&this_ptr_conv).compressed_form);
12285         return arg_arr;
12286 }
12287
12288 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1set_1broadcaster_1delayed_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12289         LDKTxCreationKeys this_ptr_conv;
12290         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12291         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12292         LDKPublicKey val_ref;
12293         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12294         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12295         TxCreationKeys_set_broadcaster_delayed_payment_key(&this_ptr_conv, val_ref);
12296 }
12297
12298 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) {
12299         LDKPublicKey per_commitment_point_arg_ref;
12300         CHECK((*_env)->GetArrayLength (_env, per_commitment_point_arg) == 33);
12301         (*_env)->GetByteArrayRegion (_env, per_commitment_point_arg, 0, 33, per_commitment_point_arg_ref.compressed_form);
12302         LDKPublicKey revocation_key_arg_ref;
12303         CHECK((*_env)->GetArrayLength (_env, revocation_key_arg) == 33);
12304         (*_env)->GetByteArrayRegion (_env, revocation_key_arg, 0, 33, revocation_key_arg_ref.compressed_form);
12305         LDKPublicKey broadcaster_htlc_key_arg_ref;
12306         CHECK((*_env)->GetArrayLength (_env, broadcaster_htlc_key_arg) == 33);
12307         (*_env)->GetByteArrayRegion (_env, broadcaster_htlc_key_arg, 0, 33, broadcaster_htlc_key_arg_ref.compressed_form);
12308         LDKPublicKey countersignatory_htlc_key_arg_ref;
12309         CHECK((*_env)->GetArrayLength (_env, countersignatory_htlc_key_arg) == 33);
12310         (*_env)->GetByteArrayRegion (_env, countersignatory_htlc_key_arg, 0, 33, countersignatory_htlc_key_arg_ref.compressed_form);
12311         LDKPublicKey broadcaster_delayed_payment_key_arg_ref;
12312         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key_arg) == 33);
12313         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key_arg, 0, 33, broadcaster_delayed_payment_key_arg_ref.compressed_form);
12314         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);
12315         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12316         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12317         long ret_ref = (long)ret_var.inner;
12318         if (ret_var.is_owned) {
12319                 ret_ref |= 1;
12320         }
12321         return ret_ref;
12322 }
12323
12324 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
12325         LDKTxCreationKeys obj_conv;
12326         obj_conv.inner = (void*)(obj & (~1));
12327         obj_conv.is_owned = (obj & 1) || (obj == 0);
12328         LDKCVec_u8Z arg_var = TxCreationKeys_write(&obj_conv);
12329         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12330         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12331         CVec_u8Z_free(arg_var);
12332         return arg_arr;
12333 }
12334
12335 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12336         LDKu8slice ser_ref;
12337         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12338         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12339         LDKTxCreationKeys ret_var = TxCreationKeys_read(ser_ref);
12340         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12341         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12342         long ret_ref = (long)ret_var.inner;
12343         if (ret_var.is_owned) {
12344                 ret_ref |= 1;
12345         }
12346         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12347         return ret_ref;
12348 }
12349
12350 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12351         LDKPreCalculatedTxCreationKeys this_ptr_conv;
12352         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12353         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12354         PreCalculatedTxCreationKeys_free(this_ptr_conv);
12355 }
12356
12357 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1new(JNIEnv * _env, jclass _b, jlong keys) {
12358         LDKTxCreationKeys keys_conv;
12359         keys_conv.inner = (void*)(keys & (~1));
12360         keys_conv.is_owned = (keys & 1) || (keys == 0);
12361         if (keys_conv.inner != NULL)
12362                 keys_conv = TxCreationKeys_clone(&keys_conv);
12363         LDKPreCalculatedTxCreationKeys ret_var = PreCalculatedTxCreationKeys_new(keys_conv);
12364         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12365         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12366         long ret_ref = (long)ret_var.inner;
12367         if (ret_var.is_owned) {
12368                 ret_ref |= 1;
12369         }
12370         return ret_ref;
12371 }
12372
12373 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1trust_1key_1derivation(JNIEnv * _env, jclass _b, jlong this_arg) {
12374         LDKPreCalculatedTxCreationKeys this_arg_conv;
12375         this_arg_conv.inner = (void*)(this_arg & (~1));
12376         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12377         LDKTxCreationKeys ret_var = PreCalculatedTxCreationKeys_trust_key_derivation(&this_arg_conv);
12378         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12379         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12380         long ret_ref = (long)ret_var.inner;
12381         if (ret_var.is_owned) {
12382                 ret_ref |= 1;
12383         }
12384         return ret_ref;
12385 }
12386
12387 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_arg) {
12388         LDKPreCalculatedTxCreationKeys this_arg_conv;
12389         this_arg_conv.inner = (void*)(this_arg & (~1));
12390         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12391         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12392         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, PreCalculatedTxCreationKeys_per_commitment_point(&this_arg_conv).compressed_form);
12393         return arg_arr;
12394 }
12395
12396 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12397         LDKChannelPublicKeys this_ptr_conv;
12398         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12399         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12400         ChannelPublicKeys_free(this_ptr_conv);
12401 }
12402
12403 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12404         LDKChannelPublicKeys orig_conv;
12405         orig_conv.inner = (void*)(orig & (~1));
12406         orig_conv.is_owned = (orig & 1) || (orig == 0);
12407         LDKChannelPublicKeys ret_var = ChannelPublicKeys_clone(&orig_conv);
12408         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12409         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12410         long ret_ref = (long)ret_var.inner;
12411         if (ret_var.is_owned) {
12412                 ret_ref |= 1;
12413         }
12414         return ret_ref;
12415 }
12416
12417 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
12418         LDKChannelPublicKeys this_ptr_conv;
12419         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12420         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12421         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12422         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_funding_pubkey(&this_ptr_conv).compressed_form);
12423         return arg_arr;
12424 }
12425
12426 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1funding_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12427         LDKChannelPublicKeys this_ptr_conv;
12428         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12429         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12430         LDKPublicKey val_ref;
12431         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12432         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12433         ChannelPublicKeys_set_funding_pubkey(&this_ptr_conv, val_ref);
12434 }
12435
12436 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
12437         LDKChannelPublicKeys this_ptr_conv;
12438         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12439         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12440         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12441         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_revocation_basepoint(&this_ptr_conv).compressed_form);
12442         return arg_arr;
12443 }
12444
12445 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1revocation_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12446         LDKChannelPublicKeys this_ptr_conv;
12447         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12448         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12449         LDKPublicKey val_ref;
12450         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12451         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12452         ChannelPublicKeys_set_revocation_basepoint(&this_ptr_conv, val_ref);
12453 }
12454
12455 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr) {
12456         LDKChannelPublicKeys this_ptr_conv;
12457         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12458         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12459         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12460         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_payment_point(&this_ptr_conv).compressed_form);
12461         return arg_arr;
12462 }
12463
12464 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1payment_1point(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12465         LDKChannelPublicKeys this_ptr_conv;
12466         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12467         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12468         LDKPublicKey val_ref;
12469         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12470         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12471         ChannelPublicKeys_set_payment_point(&this_ptr_conv, val_ref);
12472 }
12473
12474 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
12475         LDKChannelPublicKeys this_ptr_conv;
12476         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12477         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12478         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12479         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_delayed_payment_basepoint(&this_ptr_conv).compressed_form);
12480         return arg_arr;
12481 }
12482
12483 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1delayed_1payment_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12484         LDKChannelPublicKeys this_ptr_conv;
12485         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12486         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12487         LDKPublicKey val_ref;
12488         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12489         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12490         ChannelPublicKeys_set_delayed_payment_basepoint(&this_ptr_conv, val_ref);
12491 }
12492
12493 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1get_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr) {
12494         LDKChannelPublicKeys this_ptr_conv;
12495         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12496         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12497         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
12498         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelPublicKeys_get_htlc_basepoint(&this_ptr_conv).compressed_form);
12499         return arg_arr;
12500 }
12501
12502 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1set_1htlc_1basepoint(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12503         LDKChannelPublicKeys this_ptr_conv;
12504         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12505         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12506         LDKPublicKey val_ref;
12507         CHECK((*_env)->GetArrayLength (_env, val) == 33);
12508         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
12509         ChannelPublicKeys_set_htlc_basepoint(&this_ptr_conv, val_ref);
12510 }
12511
12512 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) {
12513         LDKPublicKey funding_pubkey_arg_ref;
12514         CHECK((*_env)->GetArrayLength (_env, funding_pubkey_arg) == 33);
12515         (*_env)->GetByteArrayRegion (_env, funding_pubkey_arg, 0, 33, funding_pubkey_arg_ref.compressed_form);
12516         LDKPublicKey revocation_basepoint_arg_ref;
12517         CHECK((*_env)->GetArrayLength (_env, revocation_basepoint_arg) == 33);
12518         (*_env)->GetByteArrayRegion (_env, revocation_basepoint_arg, 0, 33, revocation_basepoint_arg_ref.compressed_form);
12519         LDKPublicKey payment_point_arg_ref;
12520         CHECK((*_env)->GetArrayLength (_env, payment_point_arg) == 33);
12521         (*_env)->GetByteArrayRegion (_env, payment_point_arg, 0, 33, payment_point_arg_ref.compressed_form);
12522         LDKPublicKey delayed_payment_basepoint_arg_ref;
12523         CHECK((*_env)->GetArrayLength (_env, delayed_payment_basepoint_arg) == 33);
12524         (*_env)->GetByteArrayRegion (_env, delayed_payment_basepoint_arg, 0, 33, delayed_payment_basepoint_arg_ref.compressed_form);
12525         LDKPublicKey htlc_basepoint_arg_ref;
12526         CHECK((*_env)->GetArrayLength (_env, htlc_basepoint_arg) == 33);
12527         (*_env)->GetByteArrayRegion (_env, htlc_basepoint_arg, 0, 33, htlc_basepoint_arg_ref.compressed_form);
12528         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);
12529         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12530         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12531         long ret_ref = (long)ret_var.inner;
12532         if (ret_var.is_owned) {
12533                 ret_ref |= 1;
12534         }
12535         return ret_ref;
12536 }
12537
12538 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1write(JNIEnv * _env, jclass _b, jlong obj) {
12539         LDKChannelPublicKeys obj_conv;
12540         obj_conv.inner = (void*)(obj & (~1));
12541         obj_conv.is_owned = (obj & 1) || (obj == 0);
12542         LDKCVec_u8Z arg_var = ChannelPublicKeys_write(&obj_conv);
12543         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12544         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12545         CVec_u8Z_free(arg_var);
12546         return arg_arr;
12547 }
12548
12549 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12550         LDKu8slice ser_ref;
12551         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12552         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12553         LDKChannelPublicKeys ret_var = ChannelPublicKeys_read(ser_ref);
12554         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12555         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12556         long ret_ref = (long)ret_var.inner;
12557         if (ret_var.is_owned) {
12558                 ret_ref |= 1;
12559         }
12560         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12561         return ret_ref;
12562 }
12563
12564 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) {
12565         LDKPublicKey per_commitment_point_ref;
12566         CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
12567         (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
12568         LDKPublicKey broadcaster_delayed_payment_base_ref;
12569         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_base) == 33);
12570         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_base, 0, 33, broadcaster_delayed_payment_base_ref.compressed_form);
12571         LDKPublicKey broadcaster_htlc_base_ref;
12572         CHECK((*_env)->GetArrayLength (_env, broadcaster_htlc_base) == 33);
12573         (*_env)->GetByteArrayRegion (_env, broadcaster_htlc_base, 0, 33, broadcaster_htlc_base_ref.compressed_form);
12574         LDKPublicKey countersignatory_revocation_base_ref;
12575         CHECK((*_env)->GetArrayLength (_env, countersignatory_revocation_base) == 33);
12576         (*_env)->GetByteArrayRegion (_env, countersignatory_revocation_base, 0, 33, countersignatory_revocation_base_ref.compressed_form);
12577         LDKPublicKey countersignatory_htlc_base_ref;
12578         CHECK((*_env)->GetArrayLength (_env, countersignatory_htlc_base) == 33);
12579         (*_env)->GetByteArrayRegion (_env, countersignatory_htlc_base, 0, 33, countersignatory_htlc_base_ref.compressed_form);
12580         LDKCResult_TxCreationKeysSecpErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_TxCreationKeysSecpErrorZ), "LDKCResult_TxCreationKeysSecpErrorZ");
12581         *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);
12582         return (long)ret_conv;
12583 }
12584
12585 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) {
12586         LDKPublicKey revocation_key_ref;
12587         CHECK((*_env)->GetArrayLength (_env, revocation_key) == 33);
12588         (*_env)->GetByteArrayRegion (_env, revocation_key, 0, 33, revocation_key_ref.compressed_form);
12589         LDKPublicKey broadcaster_delayed_payment_key_ref;
12590         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key) == 33);
12591         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
12592         LDKCVec_u8Z arg_var = get_revokeable_redeemscript(revocation_key_ref, contest_delay, broadcaster_delayed_payment_key_ref);
12593         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12594         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12595         CVec_u8Z_free(arg_var);
12596         return arg_arr;
12597 }
12598
12599 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12600         LDKHTLCOutputInCommitment this_ptr_conv;
12601         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12602         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12603         HTLCOutputInCommitment_free(this_ptr_conv);
12604 }
12605
12606 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12607         LDKHTLCOutputInCommitment orig_conv;
12608         orig_conv.inner = (void*)(orig & (~1));
12609         orig_conv.is_owned = (orig & 1) || (orig == 0);
12610         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_clone(&orig_conv);
12611         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12612         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12613         long ret_ref = (long)ret_var.inner;
12614         if (ret_var.is_owned) {
12615                 ret_ref |= 1;
12616         }
12617         return ret_ref;
12618 }
12619
12620 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1offered(JNIEnv * _env, jclass _b, jlong this_ptr) {
12621         LDKHTLCOutputInCommitment this_ptr_conv;
12622         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12623         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12624         jboolean ret_val = HTLCOutputInCommitment_get_offered(&this_ptr_conv);
12625         return ret_val;
12626 }
12627
12628 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1offered(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
12629         LDKHTLCOutputInCommitment this_ptr_conv;
12630         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12631         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12632         HTLCOutputInCommitment_set_offered(&this_ptr_conv, val);
12633 }
12634
12635 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
12636         LDKHTLCOutputInCommitment this_ptr_conv;
12637         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12638         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12639         jlong ret_val = HTLCOutputInCommitment_get_amount_msat(&this_ptr_conv);
12640         return ret_val;
12641 }
12642
12643 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1amount_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12644         LDKHTLCOutputInCommitment this_ptr_conv;
12645         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12646         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12647         HTLCOutputInCommitment_set_amount_msat(&this_ptr_conv, val);
12648 }
12649
12650 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr) {
12651         LDKHTLCOutputInCommitment this_ptr_conv;
12652         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12653         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12654         jint ret_val = HTLCOutputInCommitment_get_cltv_expiry(&this_ptr_conv);
12655         return ret_val;
12656 }
12657
12658 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1cltv_1expiry(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12659         LDKHTLCOutputInCommitment this_ptr_conv;
12660         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12661         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12662         HTLCOutputInCommitment_set_cltv_expiry(&this_ptr_conv, val);
12663 }
12664
12665 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1get_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr) {
12666         LDKHTLCOutputInCommitment this_ptr_conv;
12667         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12668         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12669         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
12670         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *HTLCOutputInCommitment_get_payment_hash(&this_ptr_conv));
12671         return ret_arr;
12672 }
12673
12674 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1set_1payment_1hash(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12675         LDKHTLCOutputInCommitment this_ptr_conv;
12676         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12677         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12678         LDKThirtyTwoBytes val_ref;
12679         CHECK((*_env)->GetArrayLength (_env, val) == 32);
12680         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
12681         HTLCOutputInCommitment_set_payment_hash(&this_ptr_conv, val_ref);
12682 }
12683
12684 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1write(JNIEnv * _env, jclass _b, jlong obj) {
12685         LDKHTLCOutputInCommitment obj_conv;
12686         obj_conv.inner = (void*)(obj & (~1));
12687         obj_conv.is_owned = (obj & 1) || (obj == 0);
12688         LDKCVec_u8Z arg_var = HTLCOutputInCommitment_write(&obj_conv);
12689         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12690         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12691         CVec_u8Z_free(arg_var);
12692         return arg_arr;
12693 }
12694
12695 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12696         LDKu8slice ser_ref;
12697         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12698         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12699         LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_read(ser_ref);
12700         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12701         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12702         long ret_ref = (long)ret_var.inner;
12703         if (ret_var.is_owned) {
12704                 ret_ref |= 1;
12705         }
12706         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12707         return ret_ref;
12708 }
12709
12710 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_get_1htlc_1redeemscript(JNIEnv * _env, jclass _b, jlong htlc, jlong keys) {
12711         LDKHTLCOutputInCommitment htlc_conv;
12712         htlc_conv.inner = (void*)(htlc & (~1));
12713         htlc_conv.is_owned = (htlc & 1) || (htlc == 0);
12714         LDKTxCreationKeys keys_conv;
12715         keys_conv.inner = (void*)(keys & (~1));
12716         keys_conv.is_owned = (keys & 1) || (keys == 0);
12717         LDKCVec_u8Z arg_var = get_htlc_redeemscript(&htlc_conv, &keys_conv);
12718         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12719         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12720         CVec_u8Z_free(arg_var);
12721         return arg_arr;
12722 }
12723
12724 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_make_1funding_1redeemscript(JNIEnv * _env, jclass _b, jbyteArray broadcaster, jbyteArray countersignatory) {
12725         LDKPublicKey broadcaster_ref;
12726         CHECK((*_env)->GetArrayLength (_env, broadcaster) == 33);
12727         (*_env)->GetByteArrayRegion (_env, broadcaster, 0, 33, broadcaster_ref.compressed_form);
12728         LDKPublicKey countersignatory_ref;
12729         CHECK((*_env)->GetArrayLength (_env, countersignatory) == 33);
12730         (*_env)->GetByteArrayRegion (_env, countersignatory, 0, 33, countersignatory_ref.compressed_form);
12731         LDKCVec_u8Z arg_var = make_funding_redeemscript(broadcaster_ref, countersignatory_ref);
12732         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12733         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12734         CVec_u8Z_free(arg_var);
12735         return arg_arr;
12736 }
12737
12738 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_build_1htlc_1transaction(JNIEnv * _env, jclass _b, jbyteArray prev_hash, jint feerate_per_kw, jshort contest_delay, jlong htlc, jbyteArray broadcaster_delayed_payment_key, jbyteArray revocation_key) {
12739         unsigned char prev_hash_arr[32];
12740         CHECK((*_env)->GetArrayLength (_env, prev_hash) == 32);
12741         (*_env)->GetByteArrayRegion (_env, prev_hash, 0, 32, prev_hash_arr);
12742         unsigned char (*prev_hash_ref)[32] = &prev_hash_arr;
12743         LDKHTLCOutputInCommitment htlc_conv;
12744         htlc_conv.inner = (void*)(htlc & (~1));
12745         htlc_conv.is_owned = (htlc & 1) || (htlc == 0);
12746         LDKPublicKey broadcaster_delayed_payment_key_ref;
12747         CHECK((*_env)->GetArrayLength (_env, broadcaster_delayed_payment_key) == 33);
12748         (*_env)->GetByteArrayRegion (_env, broadcaster_delayed_payment_key, 0, 33, broadcaster_delayed_payment_key_ref.compressed_form);
12749         LDKPublicKey revocation_key_ref;
12750         CHECK((*_env)->GetArrayLength (_env, revocation_key) == 33);
12751         (*_env)->GetByteArrayRegion (_env, revocation_key, 0, 33, revocation_key_ref.compressed_form);
12752         LDKTransaction *ret_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
12753         *ret_copy = build_htlc_transaction(prev_hash_ref, feerate_per_kw, contest_delay, &htlc_conv, broadcaster_delayed_payment_key_ref, revocation_key_ref);
12754         long ret_ref = (long)ret_copy;
12755         return ret_ref;
12756 }
12757
12758 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12759         LDKHolderCommitmentTransaction this_ptr_conv;
12760         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12761         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12762         HolderCommitmentTransaction_free(this_ptr_conv);
12763 }
12764
12765 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1clone(JNIEnv * _env, jclass _b, jlong orig) {
12766         LDKHolderCommitmentTransaction orig_conv;
12767         orig_conv.inner = (void*)(orig & (~1));
12768         orig_conv.is_owned = (orig & 1) || (orig == 0);
12769         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_clone(&orig_conv);
12770         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12771         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12772         long ret_ref = (long)ret_var.inner;
12773         if (ret_var.is_owned) {
12774                 ret_ref |= 1;
12775         }
12776         return ret_ref;
12777 }
12778
12779 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1unsigned_1tx(JNIEnv * _env, jclass _b, jlong this_ptr) {
12780         LDKHolderCommitmentTransaction this_ptr_conv;
12781         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12782         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12783         LDKTransaction *ret_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
12784         *ret_copy = HolderCommitmentTransaction_get_unsigned_tx(&this_ptr_conv);
12785         long ret_ref = (long)ret_copy;
12786         return ret_ref;
12787 }
12788
12789 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1unsigned_1tx(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
12790         LDKHolderCommitmentTransaction this_ptr_conv;
12791         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12792         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12793         LDKTransaction val_conv = *(LDKTransaction*)val;
12794         HolderCommitmentTransaction_set_unsigned_tx(&this_ptr_conv, val_conv);
12795 }
12796
12797 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1counterparty_1sig(JNIEnv * _env, jclass _b, jlong this_ptr) {
12798         LDKHolderCommitmentTransaction this_ptr_conv;
12799         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12800         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12801         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12802         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, HolderCommitmentTransaction_get_counterparty_sig(&this_ptr_conv).compact_form);
12803         return arg_arr;
12804 }
12805
12806 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1counterparty_1sig(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
12807         LDKHolderCommitmentTransaction this_ptr_conv;
12808         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12809         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12810         LDKSignature val_ref;
12811         CHECK((*_env)->GetArrayLength (_env, val) == 64);
12812         (*_env)->GetByteArrayRegion (_env, val, 0, 64, val_ref.compact_form);
12813         HolderCommitmentTransaction_set_counterparty_sig(&this_ptr_conv, val_ref);
12814 }
12815
12816 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr) {
12817         LDKHolderCommitmentTransaction this_ptr_conv;
12818         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12819         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12820         jint ret_val = HolderCommitmentTransaction_get_feerate_per_kw(&this_ptr_conv);
12821         return ret_val;
12822 }
12823
12824 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1feerate_1per_1kw(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
12825         LDKHolderCommitmentTransaction this_ptr_conv;
12826         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12827         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12828         HolderCommitmentTransaction_set_feerate_per_kw(&this_ptr_conv, val);
12829 }
12830
12831 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1per_1htlc(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
12832         LDKHolderCommitmentTransaction this_ptr_conv;
12833         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12834         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12835         LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ val_constr;
12836         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
12837         if (val_constr.datalen > 0)
12838                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ), "LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ Elements");
12839         else
12840                 val_constr.data = NULL;
12841         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
12842         for (size_t q = 0; q < val_constr.datalen; q++) {
12843                 long arr_conv_42 = val_vals[q];
12844                 LDKC2Tuple_HTLCOutputInCommitmentSignatureZ arr_conv_42_conv = *(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ*)arr_conv_42;
12845                 FREE((void*)arr_conv_42);
12846                 val_constr.data[q] = arr_conv_42_conv;
12847         }
12848         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
12849         HolderCommitmentTransaction_set_per_htlc(&this_ptr_conv, val_constr);
12850 }
12851
12852 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1new_1missing_1holder_1sig(JNIEnv * _env, jclass _b, jlong unsigned_tx, jbyteArray counterparty_sig, jbyteArray holder_funding_key, jbyteArray counterparty_funding_key, jlong keys, jint feerate_per_kw, jlongArray htlc_data) {
12853         LDKTransaction unsigned_tx_conv = *(LDKTransaction*)unsigned_tx;
12854         LDKSignature counterparty_sig_ref;
12855         CHECK((*_env)->GetArrayLength (_env, counterparty_sig) == 64);
12856         (*_env)->GetByteArrayRegion (_env, counterparty_sig, 0, 64, counterparty_sig_ref.compact_form);
12857         LDKPublicKey holder_funding_key_ref;
12858         CHECK((*_env)->GetArrayLength (_env, holder_funding_key) == 33);
12859         (*_env)->GetByteArrayRegion (_env, holder_funding_key, 0, 33, holder_funding_key_ref.compressed_form);
12860         LDKPublicKey counterparty_funding_key_ref;
12861         CHECK((*_env)->GetArrayLength (_env, counterparty_funding_key) == 33);
12862         (*_env)->GetByteArrayRegion (_env, counterparty_funding_key, 0, 33, counterparty_funding_key_ref.compressed_form);
12863         LDKTxCreationKeys keys_conv;
12864         keys_conv.inner = (void*)(keys & (~1));
12865         keys_conv.is_owned = (keys & 1) || (keys == 0);
12866         if (keys_conv.inner != NULL)
12867                 keys_conv = TxCreationKeys_clone(&keys_conv);
12868         LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ htlc_data_constr;
12869         htlc_data_constr.datalen = (*_env)->GetArrayLength (_env, htlc_data);
12870         if (htlc_data_constr.datalen > 0)
12871                 htlc_data_constr.data = MALLOC(htlc_data_constr.datalen * sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ), "LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ Elements");
12872         else
12873                 htlc_data_constr.data = NULL;
12874         long* htlc_data_vals = (*_env)->GetLongArrayElements (_env, htlc_data, NULL);
12875         for (size_t q = 0; q < htlc_data_constr.datalen; q++) {
12876                 long arr_conv_42 = htlc_data_vals[q];
12877                 LDKC2Tuple_HTLCOutputInCommitmentSignatureZ arr_conv_42_conv = *(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ*)arr_conv_42;
12878                 FREE((void*)arr_conv_42);
12879                 htlc_data_constr.data[q] = arr_conv_42_conv;
12880         }
12881         (*_env)->ReleaseLongArrayElements (_env, htlc_data, htlc_data_vals, 0);
12882         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_new_missing_holder_sig(unsigned_tx_conv, counterparty_sig_ref, holder_funding_key_ref, counterparty_funding_key_ref, keys_conv, feerate_per_kw, htlc_data_constr);
12883         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12884         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12885         long ret_ref = (long)ret_var.inner;
12886         if (ret_var.is_owned) {
12887                 ret_ref |= 1;
12888         }
12889         return ret_ref;
12890 }
12891
12892 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1trust_1key_1derivation(JNIEnv * _env, jclass _b, jlong this_arg) {
12893         LDKHolderCommitmentTransaction this_arg_conv;
12894         this_arg_conv.inner = (void*)(this_arg & (~1));
12895         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12896         LDKTxCreationKeys ret_var = HolderCommitmentTransaction_trust_key_derivation(&this_arg_conv);
12897         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12898         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12899         long ret_ref = (long)ret_var.inner;
12900         if (ret_var.is_owned) {
12901                 ret_ref |= 1;
12902         }
12903         return ret_ref;
12904 }
12905
12906 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1txid(JNIEnv * _env, jclass _b, jlong this_arg) {
12907         LDKHolderCommitmentTransaction this_arg_conv;
12908         this_arg_conv.inner = (void*)(this_arg & (~1));
12909         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12910         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
12911         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, HolderCommitmentTransaction_txid(&this_arg_conv).data);
12912         return arg_arr;
12913 }
12914
12915 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1holder_1sig(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray funding_key, jbyteArray funding_redeemscript, jlong channel_value_satoshis) {
12916         LDKHolderCommitmentTransaction this_arg_conv;
12917         this_arg_conv.inner = (void*)(this_arg & (~1));
12918         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12919         unsigned char funding_key_arr[32];
12920         CHECK((*_env)->GetArrayLength (_env, funding_key) == 32);
12921         (*_env)->GetByteArrayRegion (_env, funding_key, 0, 32, funding_key_arr);
12922         unsigned char (*funding_key_ref)[32] = &funding_key_arr;
12923         LDKu8slice funding_redeemscript_ref;
12924         funding_redeemscript_ref.data = (*_env)->GetByteArrayElements (_env, funding_redeemscript, NULL);
12925         funding_redeemscript_ref.datalen = (*_env)->GetArrayLength (_env, funding_redeemscript);
12926         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64);
12927         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, HolderCommitmentTransaction_get_holder_sig(&this_arg_conv, funding_key_ref, funding_redeemscript_ref, channel_value_satoshis).compact_form);
12928         (*_env)->ReleaseByteArrayElements(_env, funding_redeemscript, (int8_t*)funding_redeemscript_ref.data, 0);
12929         return arg_arr;
12930 }
12931
12932 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1htlc_1sigs(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray htlc_base_key, jshort counterparty_selected_contest_delay) {
12933         LDKHolderCommitmentTransaction this_arg_conv;
12934         this_arg_conv.inner = (void*)(this_arg & (~1));
12935         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
12936         unsigned char htlc_base_key_arr[32];
12937         CHECK((*_env)->GetArrayLength (_env, htlc_base_key) == 32);
12938         (*_env)->GetByteArrayRegion (_env, htlc_base_key, 0, 32, htlc_base_key_arr);
12939         unsigned char (*htlc_base_key_ref)[32] = &htlc_base_key_arr;
12940         LDKCResult_CVec_SignatureZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
12941         *ret_conv = HolderCommitmentTransaction_get_htlc_sigs(&this_arg_conv, htlc_base_key_ref, counterparty_selected_contest_delay);
12942         return (long)ret_conv;
12943 }
12944
12945 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1write(JNIEnv * _env, jclass _b, jlong obj) {
12946         LDKHolderCommitmentTransaction obj_conv;
12947         obj_conv.inner = (void*)(obj & (~1));
12948         obj_conv.is_owned = (obj & 1) || (obj == 0);
12949         LDKCVec_u8Z arg_var = HolderCommitmentTransaction_write(&obj_conv);
12950         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
12951         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
12952         CVec_u8Z_free(arg_var);
12953         return arg_arr;
12954 }
12955
12956 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
12957         LDKu8slice ser_ref;
12958         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
12959         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
12960         LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_read(ser_ref);
12961         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
12962         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
12963         long ret_ref = (long)ret_var.inner;
12964         if (ret_var.is_owned) {
12965                 ret_ref |= 1;
12966         }
12967         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
12968         return ret_ref;
12969 }
12970
12971 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InitFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12972         LDKInitFeatures this_ptr_conv;
12973         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12974         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12975         InitFeatures_free(this_ptr_conv);
12976 }
12977
12978 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12979         LDKNodeFeatures this_ptr_conv;
12980         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12981         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12982         NodeFeatures_free(this_ptr_conv);
12983 }
12984
12985 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelFeatures_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12986         LDKChannelFeatures this_ptr_conv;
12987         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12988         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12989         ChannelFeatures_free(this_ptr_conv);
12990 }
12991
12992 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
12993         LDKRouteHop this_ptr_conv;
12994         this_ptr_conv.inner = (void*)(this_ptr & (~1));
12995         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
12996         RouteHop_free(this_ptr_conv);
12997 }
12998
12999 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13000         LDKRouteHop orig_conv;
13001         orig_conv.inner = (void*)(orig & (~1));
13002         orig_conv.is_owned = (orig & 1) || (orig == 0);
13003         LDKRouteHop ret_var = RouteHop_clone(&orig_conv);
13004         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13005         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13006         long ret_ref = (long)ret_var.inner;
13007         if (ret_var.is_owned) {
13008                 ret_ref |= 1;
13009         }
13010         return ret_ref;
13011 }
13012
13013 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr) {
13014         LDKRouteHop this_ptr_conv;
13015         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13016         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13017         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
13018         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RouteHop_get_pubkey(&this_ptr_conv).compressed_form);
13019         return arg_arr;
13020 }
13021
13022 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1pubkey(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13023         LDKRouteHop this_ptr_conv;
13024         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13025         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13026         LDKPublicKey val_ref;
13027         CHECK((*_env)->GetArrayLength (_env, val) == 33);
13028         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
13029         RouteHop_set_pubkey(&this_ptr_conv, val_ref);
13030 }
13031
13032 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1node_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
13033         LDKRouteHop this_ptr_conv;
13034         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13035         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13036         LDKNodeFeatures ret_var = RouteHop_get_node_features(&this_ptr_conv);
13037         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13038         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13039         long ret_ref = (long)ret_var.inner;
13040         if (ret_var.is_owned) {
13041                 ret_ref |= 1;
13042         }
13043         return ret_ref;
13044 }
13045
13046 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1node_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13047         LDKRouteHop this_ptr_conv;
13048         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13049         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13050         LDKNodeFeatures val_conv;
13051         val_conv.inner = (void*)(val & (~1));
13052         val_conv.is_owned = (val & 1) || (val == 0);
13053         // Warning: we may need a move here but can't clone!
13054         RouteHop_set_node_features(&this_ptr_conv, val_conv);
13055 }
13056
13057 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
13058         LDKRouteHop this_ptr_conv;
13059         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13060         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13061         jlong ret_val = RouteHop_get_short_channel_id(&this_ptr_conv);
13062         return ret_val;
13063 }
13064
13065 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13066         LDKRouteHop this_ptr_conv;
13067         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13068         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13069         RouteHop_set_short_channel_id(&this_ptr_conv, val);
13070 }
13071
13072 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1channel_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
13073         LDKRouteHop this_ptr_conv;
13074         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13075         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13076         LDKChannelFeatures ret_var = RouteHop_get_channel_features(&this_ptr_conv);
13077         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13078         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13079         long ret_ref = (long)ret_var.inner;
13080         if (ret_var.is_owned) {
13081                 ret_ref |= 1;
13082         }
13083         return ret_ref;
13084 }
13085
13086 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1channel_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13087         LDKRouteHop this_ptr_conv;
13088         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13089         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13090         LDKChannelFeatures val_conv;
13091         val_conv.inner = (void*)(val & (~1));
13092         val_conv.is_owned = (val & 1) || (val == 0);
13093         // Warning: we may need a move here but can't clone!
13094         RouteHop_set_channel_features(&this_ptr_conv, val_conv);
13095 }
13096
13097 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1fee_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
13098         LDKRouteHop this_ptr_conv;
13099         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13100         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13101         jlong ret_val = RouteHop_get_fee_msat(&this_ptr_conv);
13102         return ret_val;
13103 }
13104
13105 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1fee_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13106         LDKRouteHop this_ptr_conv;
13107         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13108         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13109         RouteHop_set_fee_msat(&this_ptr_conv, val);
13110 }
13111
13112 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RouteHop_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
13113         LDKRouteHop this_ptr_conv;
13114         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13115         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13116         jint ret_val = RouteHop_get_cltv_expiry_delta(&this_ptr_conv);
13117         return ret_val;
13118 }
13119
13120 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHop_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13121         LDKRouteHop this_ptr_conv;
13122         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13123         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13124         RouteHop_set_cltv_expiry_delta(&this_ptr_conv, val);
13125 }
13126
13127 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) {
13128         LDKPublicKey pubkey_arg_ref;
13129         CHECK((*_env)->GetArrayLength (_env, pubkey_arg) == 33);
13130         (*_env)->GetByteArrayRegion (_env, pubkey_arg, 0, 33, pubkey_arg_ref.compressed_form);
13131         LDKNodeFeatures node_features_arg_conv;
13132         node_features_arg_conv.inner = (void*)(node_features_arg & (~1));
13133         node_features_arg_conv.is_owned = (node_features_arg & 1) || (node_features_arg == 0);
13134         // Warning: we may need a move here but can't clone!
13135         LDKChannelFeatures channel_features_arg_conv;
13136         channel_features_arg_conv.inner = (void*)(channel_features_arg & (~1));
13137         channel_features_arg_conv.is_owned = (channel_features_arg & 1) || (channel_features_arg == 0);
13138         // Warning: we may need a move here but can't clone!
13139         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);
13140         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13141         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13142         long ret_ref = (long)ret_var.inner;
13143         if (ret_var.is_owned) {
13144                 ret_ref |= 1;
13145         }
13146         return ret_ref;
13147 }
13148
13149 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13150         LDKRoute this_ptr_conv;
13151         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13152         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13153         Route_free(this_ptr_conv);
13154 }
13155
13156 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13157         LDKRoute orig_conv;
13158         orig_conv.inner = (void*)(orig & (~1));
13159         orig_conv.is_owned = (orig & 1) || (orig == 0);
13160         LDKRoute ret_var = Route_clone(&orig_conv);
13161         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13162         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13163         long ret_ref = (long)ret_var.inner;
13164         if (ret_var.is_owned) {
13165                 ret_ref |= 1;
13166         }
13167         return ret_ref;
13168 }
13169
13170 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Route_1set_1paths(JNIEnv * _env, jclass _b, jlong this_ptr, jobjectArray val) {
13171         LDKRoute this_ptr_conv;
13172         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13173         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13174         LDKCVec_CVec_RouteHopZZ val_constr;
13175         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
13176         if (val_constr.datalen > 0)
13177                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
13178         else
13179                 val_constr.data = NULL;
13180         for (size_t m = 0; m < val_constr.datalen; m++) {
13181                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, val, m);
13182                 LDKCVec_RouteHopZ arr_conv_12_constr;
13183                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
13184                 if (arr_conv_12_constr.datalen > 0)
13185                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
13186                 else
13187                         arr_conv_12_constr.data = NULL;
13188                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
13189                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
13190                         long arr_conv_10 = arr_conv_12_vals[k];
13191                         LDKRouteHop arr_conv_10_conv;
13192                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
13193                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
13194                         if (arr_conv_10_conv.inner != NULL)
13195                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
13196                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
13197                 }
13198                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
13199                 val_constr.data[m] = arr_conv_12_constr;
13200         }
13201         Route_set_paths(&this_ptr_conv, val_constr);
13202 }
13203
13204 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1new(JNIEnv * _env, jclass _b, jobjectArray paths_arg) {
13205         LDKCVec_CVec_RouteHopZZ paths_arg_constr;
13206         paths_arg_constr.datalen = (*_env)->GetArrayLength (_env, paths_arg);
13207         if (paths_arg_constr.datalen > 0)
13208                 paths_arg_constr.data = MALLOC(paths_arg_constr.datalen * sizeof(LDKCVec_RouteHopZ), "LDKCVec_CVec_RouteHopZZ Elements");
13209         else
13210                 paths_arg_constr.data = NULL;
13211         for (size_t m = 0; m < paths_arg_constr.datalen; m++) {
13212                 jobject arr_conv_12 = (*_env)->GetObjectArrayElement(_env, paths_arg, m);
13213                 LDKCVec_RouteHopZ arr_conv_12_constr;
13214                 arr_conv_12_constr.datalen = (*_env)->GetArrayLength (_env, arr_conv_12);
13215                 if (arr_conv_12_constr.datalen > 0)
13216                         arr_conv_12_constr.data = MALLOC(arr_conv_12_constr.datalen * sizeof(LDKRouteHop), "LDKCVec_RouteHopZ Elements");
13217                 else
13218                         arr_conv_12_constr.data = NULL;
13219                 long* arr_conv_12_vals = (*_env)->GetLongArrayElements (_env, arr_conv_12, NULL);
13220                 for (size_t k = 0; k < arr_conv_12_constr.datalen; k++) {
13221                         long arr_conv_10 = arr_conv_12_vals[k];
13222                         LDKRouteHop arr_conv_10_conv;
13223                         arr_conv_10_conv.inner = (void*)(arr_conv_10 & (~1));
13224                         arr_conv_10_conv.is_owned = (arr_conv_10 & 1) || (arr_conv_10 == 0);
13225                         if (arr_conv_10_conv.inner != NULL)
13226                                 arr_conv_10_conv = RouteHop_clone(&arr_conv_10_conv);
13227                         arr_conv_12_constr.data[k] = arr_conv_10_conv;
13228                 }
13229                 (*_env)->ReleaseLongArrayElements (_env, arr_conv_12, arr_conv_12_vals, 0);
13230                 paths_arg_constr.data[m] = arr_conv_12_constr;
13231         }
13232         LDKRoute ret_var = Route_new(paths_arg_constr);
13233         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13234         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13235         long ret_ref = (long)ret_var.inner;
13236         if (ret_var.is_owned) {
13237                 ret_ref |= 1;
13238         }
13239         return ret_ref;
13240 }
13241
13242 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Route_1write(JNIEnv * _env, jclass _b, jlong obj) {
13243         LDKRoute obj_conv;
13244         obj_conv.inner = (void*)(obj & (~1));
13245         obj_conv.is_owned = (obj & 1) || (obj == 0);
13246         LDKCVec_u8Z arg_var = Route_write(&obj_conv);
13247         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13248         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13249         CVec_u8Z_free(arg_var);
13250         return arg_arr;
13251 }
13252
13253 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13254         LDKu8slice ser_ref;
13255         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13256         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13257         LDKRoute ret_var = Route_read(ser_ref);
13258         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13259         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13260         long ret_ref = (long)ret_var.inner;
13261         if (ret_var.is_owned) {
13262                 ret_ref |= 1;
13263         }
13264         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13265         return ret_ref;
13266 }
13267
13268 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13269         LDKRouteHint this_ptr_conv;
13270         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13271         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13272         RouteHint_free(this_ptr_conv);
13273 }
13274
13275 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13276         LDKRouteHint orig_conv;
13277         orig_conv.inner = (void*)(orig & (~1));
13278         orig_conv.is_owned = (orig & 1) || (orig == 0);
13279         LDKRouteHint ret_var = RouteHint_clone(&orig_conv);
13280         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13281         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13282         long ret_ref = (long)ret_var.inner;
13283         if (ret_var.is_owned) {
13284                 ret_ref |= 1;
13285         }
13286         return ret_ref;
13287 }
13288
13289 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1src_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
13290         LDKRouteHint this_ptr_conv;
13291         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13292         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13293         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
13294         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, RouteHint_get_src_node_id(&this_ptr_conv).compressed_form);
13295         return arg_arr;
13296 }
13297
13298 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1src_1node_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13299         LDKRouteHint this_ptr_conv;
13300         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13301         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13302         LDKPublicKey val_ref;
13303         CHECK((*_env)->GetArrayLength (_env, val) == 33);
13304         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
13305         RouteHint_set_src_node_id(&this_ptr_conv, val_ref);
13306 }
13307
13308 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr) {
13309         LDKRouteHint this_ptr_conv;
13310         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13311         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13312         jlong ret_val = RouteHint_get_short_channel_id(&this_ptr_conv);
13313         return ret_val;
13314 }
13315
13316 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1short_1channel_1id(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13317         LDKRouteHint this_ptr_conv;
13318         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13319         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13320         RouteHint_set_short_channel_id(&this_ptr_conv, val);
13321 }
13322
13323 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1fees(JNIEnv * _env, jclass _b, jlong this_ptr) {
13324         LDKRouteHint this_ptr_conv;
13325         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13326         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13327         LDKRoutingFees ret_var = RouteHint_get_fees(&this_ptr_conv);
13328         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13329         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13330         long ret_ref = (long)ret_var.inner;
13331         if (ret_var.is_owned) {
13332                 ret_ref |= 1;
13333         }
13334         return ret_ref;
13335 }
13336
13337 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1fees(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13338         LDKRouteHint this_ptr_conv;
13339         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13340         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13341         LDKRoutingFees val_conv;
13342         val_conv.inner = (void*)(val & (~1));
13343         val_conv.is_owned = (val & 1) || (val == 0);
13344         if (val_conv.inner != NULL)
13345                 val_conv = RoutingFees_clone(&val_conv);
13346         RouteHint_set_fees(&this_ptr_conv, val_conv);
13347 }
13348
13349 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
13350         LDKRouteHint this_ptr_conv;
13351         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13352         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13353         jshort ret_val = RouteHint_get_cltv_expiry_delta(&this_ptr_conv);
13354         return ret_val;
13355 }
13356
13357 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
13358         LDKRouteHint this_ptr_conv;
13359         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13360         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13361         RouteHint_set_cltv_expiry_delta(&this_ptr_conv, val);
13362 }
13363
13364 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
13365         LDKRouteHint this_ptr_conv;
13366         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13367         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13368         jlong ret_val = RouteHint_get_htlc_minimum_msat(&this_ptr_conv);
13369         return ret_val;
13370 }
13371
13372 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13373         LDKRouteHint this_ptr_conv;
13374         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13375         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13376         RouteHint_set_htlc_minimum_msat(&this_ptr_conv, val);
13377 }
13378
13379 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) {
13380         LDKPublicKey src_node_id_arg_ref;
13381         CHECK((*_env)->GetArrayLength (_env, src_node_id_arg) == 33);
13382         (*_env)->GetByteArrayRegion (_env, src_node_id_arg, 0, 33, src_node_id_arg_ref.compressed_form);
13383         LDKRoutingFees fees_arg_conv;
13384         fees_arg_conv.inner = (void*)(fees_arg & (~1));
13385         fees_arg_conv.is_owned = (fees_arg & 1) || (fees_arg == 0);
13386         if (fees_arg_conv.inner != NULL)
13387                 fees_arg_conv = RoutingFees_clone(&fees_arg_conv);
13388         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);
13389         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13390         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13391         long ret_ref = (long)ret_var.inner;
13392         if (ret_var.is_owned) {
13393                 ret_ref |= 1;
13394         }
13395         return ret_ref;
13396 }
13397
13398 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) {
13399         LDKPublicKey our_node_id_ref;
13400         CHECK((*_env)->GetArrayLength (_env, our_node_id) == 33);
13401         (*_env)->GetByteArrayRegion (_env, our_node_id, 0, 33, our_node_id_ref.compressed_form);
13402         LDKNetworkGraph network_conv;
13403         network_conv.inner = (void*)(network & (~1));
13404         network_conv.is_owned = (network & 1) || (network == 0);
13405         LDKPublicKey target_ref;
13406         CHECK((*_env)->GetArrayLength (_env, target) == 33);
13407         (*_env)->GetByteArrayRegion (_env, target, 0, 33, target_ref.compressed_form);
13408         LDKCVec_ChannelDetailsZ first_hops_constr;
13409         first_hops_constr.datalen = (*_env)->GetArrayLength (_env, first_hops);
13410         if (first_hops_constr.datalen > 0)
13411                 first_hops_constr.data = MALLOC(first_hops_constr.datalen * sizeof(LDKChannelDetails), "LDKCVec_ChannelDetailsZ Elements");
13412         else
13413                 first_hops_constr.data = NULL;
13414         long* first_hops_vals = (*_env)->GetLongArrayElements (_env, first_hops, NULL);
13415         for (size_t q = 0; q < first_hops_constr.datalen; q++) {
13416                 long arr_conv_16 = first_hops_vals[q];
13417                 LDKChannelDetails arr_conv_16_conv;
13418                 arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
13419                 arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
13420                 first_hops_constr.data[q] = arr_conv_16_conv;
13421         }
13422         (*_env)->ReleaseLongArrayElements (_env, first_hops, first_hops_vals, 0);
13423         LDKCVec_RouteHintZ last_hops_constr;
13424         last_hops_constr.datalen = (*_env)->GetArrayLength (_env, last_hops);
13425         if (last_hops_constr.datalen > 0)
13426                 last_hops_constr.data = MALLOC(last_hops_constr.datalen * sizeof(LDKRouteHint), "LDKCVec_RouteHintZ Elements");
13427         else
13428                 last_hops_constr.data = NULL;
13429         long* last_hops_vals = (*_env)->GetLongArrayElements (_env, last_hops, NULL);
13430         for (size_t l = 0; l < last_hops_constr.datalen; l++) {
13431                 long arr_conv_11 = last_hops_vals[l];
13432                 LDKRouteHint arr_conv_11_conv;
13433                 arr_conv_11_conv.inner = (void*)(arr_conv_11 & (~1));
13434                 arr_conv_11_conv.is_owned = (arr_conv_11 & 1) || (arr_conv_11 == 0);
13435                 if (arr_conv_11_conv.inner != NULL)
13436                         arr_conv_11_conv = RouteHint_clone(&arr_conv_11_conv);
13437                 last_hops_constr.data[l] = arr_conv_11_conv;
13438         }
13439         (*_env)->ReleaseLongArrayElements (_env, last_hops, last_hops_vals, 0);
13440         LDKLogger logger_conv = *(LDKLogger*)logger;
13441         if (logger_conv.free == LDKLogger_JCalls_free) {
13442                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
13443                 LDKLogger_JCalls_clone(logger_conv.this_arg);
13444         }
13445         LDKCResult_RouteLightningErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_RouteLightningErrorZ), "LDKCResult_RouteLightningErrorZ");
13446         *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);
13447         FREE(first_hops_constr.data);
13448         return (long)ret_conv;
13449 }
13450
13451 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13452         LDKNetworkGraph this_ptr_conv;
13453         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13454         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13455         NetworkGraph_free(this_ptr_conv);
13456 }
13457
13458 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13459         LDKLockedNetworkGraph this_ptr_conv;
13460         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13461         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13462         LockedNetworkGraph_free(this_ptr_conv);
13463 }
13464
13465 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13466         LDKNetGraphMsgHandler this_ptr_conv;
13467         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13468         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13469         NetGraphMsgHandler_free(this_ptr_conv);
13470 }
13471
13472 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1new(JNIEnv * _env, jclass _b, jlong chain_access, jlong logger) {
13473         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
13474         LDKLogger logger_conv = *(LDKLogger*)logger;
13475         if (logger_conv.free == LDKLogger_JCalls_free) {
13476                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
13477                 LDKLogger_JCalls_clone(logger_conv.this_arg);
13478         }
13479         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_new(chain_access_conv, logger_conv);
13480         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13481         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13482         long ret_ref = (long)ret_var.inner;
13483         if (ret_var.is_owned) {
13484                 ret_ref |= 1;
13485         }
13486         return ret_ref;
13487 }
13488
13489 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1from_1net_1graph(JNIEnv * _env, jclass _b, jlong chain_access, jlong logger, jlong network_graph) {
13490         LDKAccess* chain_access_conv = (LDKAccess*)chain_access;
13491         LDKLogger logger_conv = *(LDKLogger*)logger;
13492         if (logger_conv.free == LDKLogger_JCalls_free) {
13493                 // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
13494                 LDKLogger_JCalls_clone(logger_conv.this_arg);
13495         }
13496         LDKNetworkGraph network_graph_conv;
13497         network_graph_conv.inner = (void*)(network_graph & (~1));
13498         network_graph_conv.is_owned = (network_graph & 1) || (network_graph == 0);
13499         // Warning: we may need a move here but can't clone!
13500         LDKNetGraphMsgHandler ret_var = NetGraphMsgHandler_from_net_graph(chain_access_conv, logger_conv, network_graph_conv);
13501         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13502         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13503         long ret_ref = (long)ret_var.inner;
13504         if (ret_var.is_owned) {
13505                 ret_ref |= 1;
13506         }
13507         return ret_ref;
13508 }
13509
13510 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1read_1locked_1graph(JNIEnv * _env, jclass _b, jlong this_arg) {
13511         LDKNetGraphMsgHandler this_arg_conv;
13512         this_arg_conv.inner = (void*)(this_arg & (~1));
13513         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
13514         LDKLockedNetworkGraph ret_var = NetGraphMsgHandler_read_locked_graph(&this_arg_conv);
13515         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13516         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13517         long ret_ref = (long)ret_var.inner;
13518         if (ret_var.is_owned) {
13519                 ret_ref |= 1;
13520         }
13521         return ret_ref;
13522 }
13523
13524 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LockedNetworkGraph_1graph(JNIEnv * _env, jclass _b, jlong this_arg) {
13525         LDKLockedNetworkGraph this_arg_conv;
13526         this_arg_conv.inner = (void*)(this_arg & (~1));
13527         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
13528         LDKNetworkGraph ret_var = LockedNetworkGraph_graph(&this_arg_conv);
13529         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13530         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13531         long ret_ref = (long)ret_var.inner;
13532         if (ret_var.is_owned) {
13533                 ret_ref |= 1;
13534         }
13535         return ret_ref;
13536 }
13537
13538 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetGraphMsgHandler_1as_1RoutingMessageHandler(JNIEnv * _env, jclass _b, jlong this_arg) {
13539         LDKNetGraphMsgHandler this_arg_conv;
13540         this_arg_conv.inner = (void*)(this_arg & (~1));
13541         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
13542         LDKRoutingMessageHandler* ret = MALLOC(sizeof(LDKRoutingMessageHandler), "LDKRoutingMessageHandler");
13543         *ret = NetGraphMsgHandler_as_RoutingMessageHandler(&this_arg_conv);
13544         return (long)ret;
13545 }
13546
13547 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13548         LDKDirectionalChannelInfo this_ptr_conv;
13549         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13550         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13551         DirectionalChannelInfo_free(this_ptr_conv);
13552 }
13553
13554 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr) {
13555         LDKDirectionalChannelInfo this_ptr_conv;
13556         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13557         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13558         jint ret_val = DirectionalChannelInfo_get_last_update(&this_ptr_conv);
13559         return ret_val;
13560 }
13561
13562 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13563         LDKDirectionalChannelInfo this_ptr_conv;
13564         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13565         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13566         DirectionalChannelInfo_set_last_update(&this_ptr_conv, val);
13567 }
13568
13569 JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1enabled(JNIEnv * _env, jclass _b, jlong this_ptr) {
13570         LDKDirectionalChannelInfo this_ptr_conv;
13571         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13572         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13573         jboolean ret_val = DirectionalChannelInfo_get_enabled(&this_ptr_conv);
13574         return ret_val;
13575 }
13576
13577 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1enabled(JNIEnv * _env, jclass _b, jlong this_ptr, jboolean val) {
13578         LDKDirectionalChannelInfo this_ptr_conv;
13579         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13580         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13581         DirectionalChannelInfo_set_enabled(&this_ptr_conv, val);
13582 }
13583
13584 JNIEXPORT jshort JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr) {
13585         LDKDirectionalChannelInfo this_ptr_conv;
13586         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13587         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13588         jshort ret_val = DirectionalChannelInfo_get_cltv_expiry_delta(&this_ptr_conv);
13589         return ret_val;
13590 }
13591
13592 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1cltv_1expiry_1delta(JNIEnv * _env, jclass _b, jlong this_ptr, jshort val) {
13593         LDKDirectionalChannelInfo this_ptr_conv;
13594         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13595         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13596         DirectionalChannelInfo_set_cltv_expiry_delta(&this_ptr_conv, val);
13597 }
13598
13599 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
13600         LDKDirectionalChannelInfo this_ptr_conv;
13601         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13602         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13603         jlong ret_val = DirectionalChannelInfo_get_htlc_minimum_msat(&this_ptr_conv);
13604         return ret_val;
13605 }
13606
13607 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1htlc_1minimum_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13608         LDKDirectionalChannelInfo this_ptr_conv;
13609         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13610         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13611         DirectionalChannelInfo_set_htlc_minimum_msat(&this_ptr_conv, val);
13612 }
13613
13614 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1get_1last_1update_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
13615         LDKDirectionalChannelInfo this_ptr_conv;
13616         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13617         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13618         LDKChannelUpdate ret_var = DirectionalChannelInfo_get_last_update_message(&this_ptr_conv);
13619         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13620         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13621         long ret_ref = (long)ret_var.inner;
13622         if (ret_var.is_owned) {
13623                 ret_ref |= 1;
13624         }
13625         return ret_ref;
13626 }
13627
13628 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1last_1update_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13629         LDKDirectionalChannelInfo this_ptr_conv;
13630         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13631         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13632         LDKChannelUpdate val_conv;
13633         val_conv.inner = (void*)(val & (~1));
13634         val_conv.is_owned = (val & 1) || (val == 0);
13635         if (val_conv.inner != NULL)
13636                 val_conv = ChannelUpdate_clone(&val_conv);
13637         DirectionalChannelInfo_set_last_update_message(&this_ptr_conv, val_conv);
13638 }
13639
13640 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
13641         LDKDirectionalChannelInfo obj_conv;
13642         obj_conv.inner = (void*)(obj & (~1));
13643         obj_conv.is_owned = (obj & 1) || (obj == 0);
13644         LDKCVec_u8Z arg_var = DirectionalChannelInfo_write(&obj_conv);
13645         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13646         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13647         CVec_u8Z_free(arg_var);
13648         return arg_arr;
13649 }
13650
13651 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13652         LDKu8slice ser_ref;
13653         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13654         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13655         LDKDirectionalChannelInfo ret_var = DirectionalChannelInfo_read(ser_ref);
13656         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13657         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13658         long ret_ref = (long)ret_var.inner;
13659         if (ret_var.is_owned) {
13660                 ret_ref |= 1;
13661         }
13662         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13663         return ret_ref;
13664 }
13665
13666 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13667         LDKChannelInfo this_ptr_conv;
13668         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13669         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13670         ChannelInfo_free(this_ptr_conv);
13671 }
13672
13673 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
13674         LDKChannelInfo this_ptr_conv;
13675         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13676         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13677         LDKChannelFeatures ret_var = ChannelInfo_get_features(&this_ptr_conv);
13678         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13679         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13680         long ret_ref = (long)ret_var.inner;
13681         if (ret_var.is_owned) {
13682                 ret_ref |= 1;
13683         }
13684         return ret_ref;
13685 }
13686
13687 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13688         LDKChannelInfo this_ptr_conv;
13689         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13690         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13691         LDKChannelFeatures val_conv;
13692         val_conv.inner = (void*)(val & (~1));
13693         val_conv.is_owned = (val & 1) || (val == 0);
13694         // Warning: we may need a move here but can't clone!
13695         ChannelInfo_set_features(&this_ptr_conv, val_conv);
13696 }
13697
13698 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1one(JNIEnv * _env, jclass _b, jlong this_ptr) {
13699         LDKChannelInfo this_ptr_conv;
13700         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13701         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13702         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
13703         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelInfo_get_node_one(&this_ptr_conv).compressed_form);
13704         return arg_arr;
13705 }
13706
13707 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1one(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13708         LDKChannelInfo this_ptr_conv;
13709         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13710         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13711         LDKPublicKey val_ref;
13712         CHECK((*_env)->GetArrayLength (_env, val) == 33);
13713         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
13714         ChannelInfo_set_node_one(&this_ptr_conv, val_ref);
13715 }
13716
13717 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1one_1to_1two(JNIEnv * _env, jclass _b, jlong this_ptr) {
13718         LDKChannelInfo this_ptr_conv;
13719         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13720         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13721         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_one_to_two(&this_ptr_conv);
13722         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13723         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13724         long ret_ref = (long)ret_var.inner;
13725         if (ret_var.is_owned) {
13726                 ret_ref |= 1;
13727         }
13728         return ret_ref;
13729 }
13730
13731 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1one_1to_1two(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13732         LDKChannelInfo this_ptr_conv;
13733         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13734         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13735         LDKDirectionalChannelInfo val_conv;
13736         val_conv.inner = (void*)(val & (~1));
13737         val_conv.is_owned = (val & 1) || (val == 0);
13738         // Warning: we may need a move here but can't clone!
13739         ChannelInfo_set_one_to_two(&this_ptr_conv, val_conv);
13740 }
13741
13742 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1node_1two(JNIEnv * _env, jclass _b, jlong this_ptr) {
13743         LDKChannelInfo this_ptr_conv;
13744         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13745         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13746         jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
13747         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, ChannelInfo_get_node_two(&this_ptr_conv).compressed_form);
13748         return arg_arr;
13749 }
13750
13751 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1node_1two(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13752         LDKChannelInfo this_ptr_conv;
13753         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13754         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13755         LDKPublicKey val_ref;
13756         CHECK((*_env)->GetArrayLength (_env, val) == 33);
13757         (*_env)->GetByteArrayRegion (_env, val, 0, 33, val_ref.compressed_form);
13758         ChannelInfo_set_node_two(&this_ptr_conv, val_ref);
13759 }
13760
13761 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1two_1to_1one(JNIEnv * _env, jclass _b, jlong this_ptr) {
13762         LDKChannelInfo this_ptr_conv;
13763         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13764         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13765         LDKDirectionalChannelInfo ret_var = ChannelInfo_get_two_to_one(&this_ptr_conv);
13766         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13767         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13768         long ret_ref = (long)ret_var.inner;
13769         if (ret_var.is_owned) {
13770                 ret_ref |= 1;
13771         }
13772         return ret_ref;
13773 }
13774
13775 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1two_1to_1one(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13776         LDKChannelInfo this_ptr_conv;
13777         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13778         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13779         LDKDirectionalChannelInfo val_conv;
13780         val_conv.inner = (void*)(val & (~1));
13781         val_conv.is_owned = (val & 1) || (val == 0);
13782         // Warning: we may need a move here but can't clone!
13783         ChannelInfo_set_two_to_one(&this_ptr_conv, val_conv);
13784 }
13785
13786 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1get_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
13787         LDKChannelInfo this_ptr_conv;
13788         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13789         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13790         LDKChannelAnnouncement ret_var = ChannelInfo_get_announcement_message(&this_ptr_conv);
13791         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13792         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13793         long ret_ref = (long)ret_var.inner;
13794         if (ret_var.is_owned) {
13795                 ret_ref |= 1;
13796         }
13797         return ret_ref;
13798 }
13799
13800 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13801         LDKChannelInfo this_ptr_conv;
13802         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13803         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13804         LDKChannelAnnouncement val_conv;
13805         val_conv.inner = (void*)(val & (~1));
13806         val_conv.is_owned = (val & 1) || (val == 0);
13807         if (val_conv.inner != NULL)
13808                 val_conv = ChannelAnnouncement_clone(&val_conv);
13809         ChannelInfo_set_announcement_message(&this_ptr_conv, val_conv);
13810 }
13811
13812 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
13813         LDKChannelInfo obj_conv;
13814         obj_conv.inner = (void*)(obj & (~1));
13815         obj_conv.is_owned = (obj & 1) || (obj == 0);
13816         LDKCVec_u8Z arg_var = ChannelInfo_write(&obj_conv);
13817         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13818         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13819         CVec_u8Z_free(arg_var);
13820         return arg_arr;
13821 }
13822
13823 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13824         LDKu8slice ser_ref;
13825         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13826         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13827         LDKChannelInfo ret_var = ChannelInfo_read(ser_ref);
13828         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13829         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13830         long ret_ref = (long)ret_var.inner;
13831         if (ret_var.is_owned) {
13832                 ret_ref |= 1;
13833         }
13834         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13835         return ret_ref;
13836 }
13837
13838 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13839         LDKRoutingFees this_ptr_conv;
13840         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13841         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13842         RoutingFees_free(this_ptr_conv);
13843 }
13844
13845 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1clone(JNIEnv * _env, jclass _b, jlong orig) {
13846         LDKRoutingFees orig_conv;
13847         orig_conv.inner = (void*)(orig & (~1));
13848         orig_conv.is_owned = (orig & 1) || (orig == 0);
13849         LDKRoutingFees ret_var = RoutingFees_clone(&orig_conv);
13850         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13851         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13852         long ret_ref = (long)ret_var.inner;
13853         if (ret_var.is_owned) {
13854                 ret_ref |= 1;
13855         }
13856         return ret_ref;
13857 }
13858
13859 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr) {
13860         LDKRoutingFees this_ptr_conv;
13861         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13862         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13863         jint ret_val = RoutingFees_get_base_msat(&this_ptr_conv);
13864         return ret_val;
13865 }
13866
13867 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1base_1msat(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13868         LDKRoutingFees this_ptr_conv;
13869         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13870         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13871         RoutingFees_set_base_msat(&this_ptr_conv, val);
13872 }
13873
13874 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_RoutingFees_1get_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr) {
13875         LDKRoutingFees this_ptr_conv;
13876         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13877         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13878         jint ret_val = RoutingFees_get_proportional_millionths(&this_ptr_conv);
13879         return ret_val;
13880 }
13881
13882 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingFees_1set_1proportional_1millionths(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13883         LDKRoutingFees this_ptr_conv;
13884         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13885         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13886         RoutingFees_set_proportional_millionths(&this_ptr_conv, val);
13887 }
13888
13889 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1new(JNIEnv * _env, jclass _b, jint base_msat_arg, jint proportional_millionths_arg) {
13890         LDKRoutingFees ret_var = RoutingFees_new(base_msat_arg, proportional_millionths_arg);
13891         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13892         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13893         long ret_ref = (long)ret_var.inner;
13894         if (ret_var.is_owned) {
13895                 ret_ref |= 1;
13896         }
13897         return ret_ref;
13898 }
13899
13900 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
13901         LDKu8slice ser_ref;
13902         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
13903         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
13904         LDKRoutingFees ret_var = RoutingFees_read(ser_ref);
13905         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13906         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13907         long ret_ref = (long)ret_var.inner;
13908         if (ret_var.is_owned) {
13909                 ret_ref |= 1;
13910         }
13911         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
13912         return ret_ref;
13913 }
13914
13915 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RoutingFees_1write(JNIEnv * _env, jclass _b, jlong obj) {
13916         LDKRoutingFees obj_conv;
13917         obj_conv.inner = (void*)(obj & (~1));
13918         obj_conv.is_owned = (obj & 1) || (obj == 0);
13919         LDKCVec_u8Z arg_var = RoutingFees_write(&obj_conv);
13920         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
13921         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
13922         CVec_u8Z_free(arg_var);
13923         return arg_arr;
13924 }
13925
13926 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
13927         LDKNodeAnnouncementInfo this_ptr_conv;
13928         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13929         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13930         NodeAnnouncementInfo_free(this_ptr_conv);
13931 }
13932
13933 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1features(JNIEnv * _env, jclass _b, jlong this_ptr) {
13934         LDKNodeAnnouncementInfo this_ptr_conv;
13935         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13936         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13937         LDKNodeFeatures ret_var = NodeAnnouncementInfo_get_features(&this_ptr_conv);
13938         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
13939         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
13940         long ret_ref = (long)ret_var.inner;
13941         if (ret_var.is_owned) {
13942                 ret_ref |= 1;
13943         }
13944         return ret_ref;
13945 }
13946
13947 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1features(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
13948         LDKNodeAnnouncementInfo this_ptr_conv;
13949         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13950         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13951         LDKNodeFeatures val_conv;
13952         val_conv.inner = (void*)(val & (~1));
13953         val_conv.is_owned = (val & 1) || (val == 0);
13954         // Warning: we may need a move here but can't clone!
13955         NodeAnnouncementInfo_set_features(&this_ptr_conv, val_conv);
13956 }
13957
13958 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr) {
13959         LDKNodeAnnouncementInfo this_ptr_conv;
13960         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13961         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13962         jint ret_val = NodeAnnouncementInfo_get_last_update(&this_ptr_conv);
13963         return ret_val;
13964 }
13965
13966 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1last_1update(JNIEnv * _env, jclass _b, jlong this_ptr, jint val) {
13967         LDKNodeAnnouncementInfo this_ptr_conv;
13968         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13969         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13970         NodeAnnouncementInfo_set_last_update(&this_ptr_conv, val);
13971 }
13972
13973 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr) {
13974         LDKNodeAnnouncementInfo this_ptr_conv;
13975         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13976         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13977         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 3);
13978         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 3, *NodeAnnouncementInfo_get_rgb(&this_ptr_conv));
13979         return ret_arr;
13980 }
13981
13982 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1rgb(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
13983         LDKNodeAnnouncementInfo this_ptr_conv;
13984         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13985         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13986         LDKThreeBytes val_ref;
13987         CHECK((*_env)->GetArrayLength (_env, val) == 3);
13988         (*_env)->GetByteArrayRegion (_env, val, 0, 3, val_ref.data);
13989         NodeAnnouncementInfo_set_rgb(&this_ptr_conv, val_ref);
13990 }
13991
13992 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1alias(JNIEnv * _env, jclass _b, jlong this_ptr) {
13993         LDKNodeAnnouncementInfo this_ptr_conv;
13994         this_ptr_conv.inner = (void*)(this_ptr & (~1));
13995         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
13996         jbyteArray ret_arr = (*_env)->NewByteArray(_env, 32);
13997         (*_env)->SetByteArrayRegion(_env, ret_arr, 0, 32, *NodeAnnouncementInfo_get_alias(&this_ptr_conv));
13998         return ret_arr;
13999 }
14000
14001 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1alias(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
14002         LDKNodeAnnouncementInfo this_ptr_conv;
14003         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14004         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14005         LDKThirtyTwoBytes val_ref;
14006         CHECK((*_env)->GetArrayLength (_env, val) == 32);
14007         (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.data);
14008         NodeAnnouncementInfo_set_alias(&this_ptr_conv, val_ref);
14009 }
14010
14011 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1addresses(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
14012         LDKNodeAnnouncementInfo this_ptr_conv;
14013         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14014         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14015         LDKCVec_NetAddressZ val_constr;
14016         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
14017         if (val_constr.datalen > 0)
14018                 val_constr.data = MALLOC(val_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
14019         else
14020                 val_constr.data = NULL;
14021         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
14022         for (size_t m = 0; m < val_constr.datalen; m++) {
14023                 long arr_conv_12 = val_vals[m];
14024                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
14025                 FREE((void*)arr_conv_12);
14026                 val_constr.data[m] = arr_conv_12_conv;
14027         }
14028         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
14029         NodeAnnouncementInfo_set_addresses(&this_ptr_conv, val_constr);
14030 }
14031
14032 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1get_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr) {
14033         LDKNodeAnnouncementInfo this_ptr_conv;
14034         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14035         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14036         LDKNodeAnnouncement ret_var = NodeAnnouncementInfo_get_announcement_message(&this_ptr_conv);
14037         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14038         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14039         long ret_ref = (long)ret_var.inner;
14040         if (ret_var.is_owned) {
14041                 ret_ref |= 1;
14042         }
14043         return ret_ref;
14044 }
14045
14046 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1announcement_1message(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14047         LDKNodeAnnouncementInfo this_ptr_conv;
14048         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14049         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14050         LDKNodeAnnouncement val_conv;
14051         val_conv.inner = (void*)(val & (~1));
14052         val_conv.is_owned = (val & 1) || (val == 0);
14053         if (val_conv.inner != NULL)
14054                 val_conv = NodeAnnouncement_clone(&val_conv);
14055         NodeAnnouncementInfo_set_announcement_message(&this_ptr_conv, val_conv);
14056 }
14057
14058 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) {
14059         LDKNodeFeatures features_arg_conv;
14060         features_arg_conv.inner = (void*)(features_arg & (~1));
14061         features_arg_conv.is_owned = (features_arg & 1) || (features_arg == 0);
14062         // Warning: we may need a move here but can't clone!
14063         LDKThreeBytes rgb_arg_ref;
14064         CHECK((*_env)->GetArrayLength (_env, rgb_arg) == 3);
14065         (*_env)->GetByteArrayRegion (_env, rgb_arg, 0, 3, rgb_arg_ref.data);
14066         LDKThirtyTwoBytes alias_arg_ref;
14067         CHECK((*_env)->GetArrayLength (_env, alias_arg) == 32);
14068         (*_env)->GetByteArrayRegion (_env, alias_arg, 0, 32, alias_arg_ref.data);
14069         LDKCVec_NetAddressZ addresses_arg_constr;
14070         addresses_arg_constr.datalen = (*_env)->GetArrayLength (_env, addresses_arg);
14071         if (addresses_arg_constr.datalen > 0)
14072                 addresses_arg_constr.data = MALLOC(addresses_arg_constr.datalen * sizeof(LDKNetAddress), "LDKCVec_NetAddressZ Elements");
14073         else
14074                 addresses_arg_constr.data = NULL;
14075         long* addresses_arg_vals = (*_env)->GetLongArrayElements (_env, addresses_arg, NULL);
14076         for (size_t m = 0; m < addresses_arg_constr.datalen; m++) {
14077                 long arr_conv_12 = addresses_arg_vals[m];
14078                 LDKNetAddress arr_conv_12_conv = *(LDKNetAddress*)arr_conv_12;
14079                 FREE((void*)arr_conv_12);
14080                 addresses_arg_constr.data[m] = arr_conv_12_conv;
14081         }
14082         (*_env)->ReleaseLongArrayElements (_env, addresses_arg, addresses_arg_vals, 0);
14083         LDKNodeAnnouncement announcement_message_arg_conv;
14084         announcement_message_arg_conv.inner = (void*)(announcement_message_arg & (~1));
14085         announcement_message_arg_conv.is_owned = (announcement_message_arg & 1) || (announcement_message_arg == 0);
14086         if (announcement_message_arg_conv.inner != NULL)
14087                 announcement_message_arg_conv = NodeAnnouncement_clone(&announcement_message_arg_conv);
14088         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_new(features_arg_conv, last_update_arg, rgb_arg_ref, alias_arg_ref, addresses_arg_constr, announcement_message_arg_conv);
14089         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14090         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14091         long ret_ref = (long)ret_var.inner;
14092         if (ret_var.is_owned) {
14093                 ret_ref |= 1;
14094         }
14095         return ret_ref;
14096 }
14097
14098 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
14099         LDKNodeAnnouncementInfo obj_conv;
14100         obj_conv.inner = (void*)(obj & (~1));
14101         obj_conv.is_owned = (obj & 1) || (obj == 0);
14102         LDKCVec_u8Z arg_var = NodeAnnouncementInfo_write(&obj_conv);
14103         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14104         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14105         CVec_u8Z_free(arg_var);
14106         return arg_arr;
14107 }
14108
14109 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14110         LDKu8slice ser_ref;
14111         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14112         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14113         LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_read(ser_ref);
14114         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14115         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14116         long ret_ref = (long)ret_var.inner;
14117         if (ret_var.is_owned) {
14118                 ret_ref |= 1;
14119         }
14120         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14121         return ret_ref;
14122 }
14123
14124 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1free(JNIEnv * _env, jclass _b, jlong this_ptr) {
14125         LDKNodeInfo this_ptr_conv;
14126         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14127         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14128         NodeInfo_free(this_ptr_conv);
14129 }
14130
14131 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1channels(JNIEnv * _env, jclass _b, jlong this_ptr, jlongArray val) {
14132         LDKNodeInfo this_ptr_conv;
14133         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14134         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14135         LDKCVec_u64Z val_constr;
14136         val_constr.datalen = (*_env)->GetArrayLength (_env, val);
14137         if (val_constr.datalen > 0)
14138                 val_constr.data = MALLOC(val_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
14139         else
14140                 val_constr.data = NULL;
14141         long* val_vals = (*_env)->GetLongArrayElements (_env, val, NULL);
14142         for (size_t g = 0; g < val_constr.datalen; g++) {
14143                 long arr_conv_6 = val_vals[g];
14144                 val_constr.data[g] = arr_conv_6;
14145         }
14146         (*_env)->ReleaseLongArrayElements (_env, val, val_vals, 0);
14147         NodeInfo_set_channels(&this_ptr_conv, val_constr);
14148 }
14149
14150 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1lowest_1inbound_1channel_1fees(JNIEnv * _env, jclass _b, jlong this_ptr) {
14151         LDKNodeInfo this_ptr_conv;
14152         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14153         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14154         LDKRoutingFees ret_var = NodeInfo_get_lowest_inbound_channel_fees(&this_ptr_conv);
14155         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14156         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14157         long ret_ref = (long)ret_var.inner;
14158         if (ret_var.is_owned) {
14159                 ret_ref |= 1;
14160         }
14161         return ret_ref;
14162 }
14163
14164 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1lowest_1inbound_1channel_1fees(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14165         LDKNodeInfo this_ptr_conv;
14166         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14167         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14168         LDKRoutingFees val_conv;
14169         val_conv.inner = (void*)(val & (~1));
14170         val_conv.is_owned = (val & 1) || (val == 0);
14171         if (val_conv.inner != NULL)
14172                 val_conv = RoutingFees_clone(&val_conv);
14173         NodeInfo_set_lowest_inbound_channel_fees(&this_ptr_conv, val_conv);
14174 }
14175
14176 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1get_1announcement_1info(JNIEnv * _env, jclass _b, jlong this_ptr) {
14177         LDKNodeInfo 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         LDKNodeAnnouncementInfo ret_var = NodeInfo_get_announcement_info(&this_ptr_conv);
14181         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14182         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14183         long ret_ref = (long)ret_var.inner;
14184         if (ret_var.is_owned) {
14185                 ret_ref |= 1;
14186         }
14187         return ret_ref;
14188 }
14189
14190 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1announcement_1info(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
14191         LDKNodeInfo this_ptr_conv;
14192         this_ptr_conv.inner = (void*)(this_ptr & (~1));
14193         this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
14194         LDKNodeAnnouncementInfo val_conv;
14195         val_conv.inner = (void*)(val & (~1));
14196         val_conv.is_owned = (val & 1) || (val == 0);
14197         // Warning: we may need a move here but can't clone!
14198         NodeInfo_set_announcement_info(&this_ptr_conv, val_conv);
14199 }
14200
14201 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) {
14202         LDKCVec_u64Z channels_arg_constr;
14203         channels_arg_constr.datalen = (*_env)->GetArrayLength (_env, channels_arg);
14204         if (channels_arg_constr.datalen > 0)
14205                 channels_arg_constr.data = MALLOC(channels_arg_constr.datalen * sizeof(jlong), "LDKCVec_u64Z Elements");
14206         else
14207                 channels_arg_constr.data = NULL;
14208         long* channels_arg_vals = (*_env)->GetLongArrayElements (_env, channels_arg, NULL);
14209         for (size_t g = 0; g < channels_arg_constr.datalen; g++) {
14210                 long arr_conv_6 = channels_arg_vals[g];
14211                 channels_arg_constr.data[g] = arr_conv_6;
14212         }
14213         (*_env)->ReleaseLongArrayElements (_env, channels_arg, channels_arg_vals, 0);
14214         LDKRoutingFees lowest_inbound_channel_fees_arg_conv;
14215         lowest_inbound_channel_fees_arg_conv.inner = (void*)(lowest_inbound_channel_fees_arg & (~1));
14216         lowest_inbound_channel_fees_arg_conv.is_owned = (lowest_inbound_channel_fees_arg & 1) || (lowest_inbound_channel_fees_arg == 0);
14217         if (lowest_inbound_channel_fees_arg_conv.inner != NULL)
14218                 lowest_inbound_channel_fees_arg_conv = RoutingFees_clone(&lowest_inbound_channel_fees_arg_conv);
14219         LDKNodeAnnouncementInfo announcement_info_arg_conv;
14220         announcement_info_arg_conv.inner = (void*)(announcement_info_arg & (~1));
14221         announcement_info_arg_conv.is_owned = (announcement_info_arg & 1) || (announcement_info_arg == 0);
14222         // Warning: we may need a move here but can't clone!
14223         LDKNodeInfo ret_var = NodeInfo_new(channels_arg_constr, lowest_inbound_channel_fees_arg_conv, announcement_info_arg_conv);
14224         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14225         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14226         long ret_ref = (long)ret_var.inner;
14227         if (ret_var.is_owned) {
14228                 ret_ref |= 1;
14229         }
14230         return ret_ref;
14231 }
14232
14233 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeInfo_1write(JNIEnv * _env, jclass _b, jlong obj) {
14234         LDKNodeInfo obj_conv;
14235         obj_conv.inner = (void*)(obj & (~1));
14236         obj_conv.is_owned = (obj & 1) || (obj == 0);
14237         LDKCVec_u8Z arg_var = NodeInfo_write(&obj_conv);
14238         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14239         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14240         CVec_u8Z_free(arg_var);
14241         return arg_arr;
14242 }
14243
14244 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14245         LDKu8slice ser_ref;
14246         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14247         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14248         LDKNodeInfo ret_var = NodeInfo_read(ser_ref);
14249         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14250         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14251         long ret_ref = (long)ret_var.inner;
14252         if (ret_var.is_owned) {
14253                 ret_ref |= 1;
14254         }
14255         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14256         return ret_ref;
14257 }
14258
14259 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1write(JNIEnv * _env, jclass _b, jlong obj) {
14260         LDKNetworkGraph obj_conv;
14261         obj_conv.inner = (void*)(obj & (~1));
14262         obj_conv.is_owned = (obj & 1) || (obj == 0);
14263         LDKCVec_u8Z arg_var = NetworkGraph_write(&obj_conv);
14264         jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen);
14265         (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data);
14266         CVec_u8Z_free(arg_var);
14267         return arg_arr;
14268 }
14269
14270 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1read(JNIEnv * _env, jclass _b, jbyteArray ser) {
14271         LDKu8slice ser_ref;
14272         ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL);
14273         ser_ref.datalen = (*_env)->GetArrayLength (_env, ser);
14274         LDKNetworkGraph ret_var = NetworkGraph_read(ser_ref);
14275         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14276         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14277         long ret_ref = (long)ret_var.inner;
14278         if (ret_var.is_owned) {
14279                 ret_ref |= 1;
14280         }
14281         (*_env)->ReleaseByteArrayElements(_env, ser, (int8_t*)ser_ref.data, 0);
14282         return ret_ref;
14283 }
14284
14285 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1new(JNIEnv * _env, jclass _b) {
14286         LDKNetworkGraph ret_var = NetworkGraph_new();
14287         CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.
14288         CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.
14289         long ret_ref = (long)ret_var.inner;
14290         if (ret_var.is_owned) {
14291                 ret_ref |= 1;
14292         }
14293         return ret_ref;
14294 }
14295
14296 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) {
14297         LDKNetworkGraph this_arg_conv;
14298         this_arg_conv.inner = (void*)(this_arg & (~1));
14299         this_arg_conv.is_owned = (this_arg & 1) || (this_arg == 0);
14300         NetworkGraph_close_channel_from_update(&this_arg_conv, short_channel_id, is_permanent);
14301 }
14302