]> git.bitcoin.ninja Git - ldk-java/blobdiff - genbindings.py
Go all the way through to channel creation in PeerTest
[ldk-java] / genbindings.py
index a5e9ec41e38c62742b561606341f301aa0bd3b0c..b4f9323db3b6b6eb44d77395aa81f7d97213e41c 100755 (executable)
@@ -544,7 +544,8 @@ void __attribute__((destructor)) check_leaks() {
        public static native void free_heap_ptr(long ptr);
        public static native byte[] get_u8_slice_bytes(long slice_ptr);
        public static native long bytes_to_u8_vec(byte[] bytes);
-       public static native long u8_vec_len(long vec);
+       public static native long vec_slice_len(long vec);
+       public static native long new_empty_slice_vec();
 
 """)
     out_c.write("""
@@ -576,10 +577,26 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec (JNIEnv * _
        (*_env)->GetByteArrayRegion (_env, bytes, 0, vec->datalen, vec->data);
        return (long)vec;
 }
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_u8_1vec_1len (JNIEnv * env, jclass _a, jlong ptr) {
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) {
+        // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically");
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically");
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically");
+       _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_C2Tuple_usizeTransactionZZ, datalen), "Vec<*> needs to be mapped identically");
        LDKCVec_u8Z *vec = (LDKCVec_u8Z*)ptr;
        return (long)vec->datalen;
 }
+JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec (JNIEnv * _env, jclass _b) {
+        // Check sizes of a few Vec types are all consistent as we're meant to be generic across types
+       _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_SignatureZ), "Vec<*> needs to be mapped identically");
+       _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_MessageSendEventZ), "Vec<*> needs to be mapped identically");
+       _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_EventZ), "Vec<*> needs to be mapped identically");
+       _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_C2Tuple_usizeTransactionZZ), "Vec<*> needs to be mapped identically");
+       LDKCVec_u8Z *vec = (LDKCVec_u8Z*)MALLOC(sizeof(LDKCVec_u8Z), "Empty LDKCVec");
+       vec->data = NULL;
+       vec->datalen = 0;
+       return (long)vec;
+}
 
 // We assume that CVec_u8Z and u8slice are the same size and layout (and thus pointers to the two can be mixed)
 _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKu8slice), "Vec<u8> and [u8] need to have been mapped identically");
@@ -674,6 +691,12 @@ _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen),
                 assert(not is_union or not (len(trait_fn_lines) != 0 or is_unitary_enum or is_union_enum or is_opaque))
                 if is_opaque:
                     opaque_structs.add(struct_name)
+                    out_java.write("\tpublic static native long " + struct_name + "_optional_none();\n")
+                    out_c.write("JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_" + struct_name.replace("_", "_1") + "_1optional_1none (JNIEnv * env, jclass _a) {\n")
+                    out_c.write("\t" + struct_name + " *ret = MALLOC(sizeof(" + struct_name + "), \"" + struct_name + "\");\n")
+                    out_c.write("\tret->inner = NULL;\n")
+                    out_c.write("\treturn (long)ret;\n")
+                    out_c.write("}\n")
                 elif is_result:
                     result_templ_structs.add(struct_name)
                 elif is_unitary_enum: