Add support for U128, passed as [u8; 16] but with human wrappers
[ldk-java] / java_strings.py
index 487df5d612d66475eca01cc196b342147052262c..151edba5ef5641e39092ba922751b8cd1235f645 100644 (file)
@@ -74,8 +74,7 @@ public class bindings {
                if (!get_lib_version_string().equals(version.get_ldk_java_bindings_version()))
                        throw new IllegalArgumentException("Compiled LDK library and LDK class failes do not match");
                // Fetching the LDK versions from C also checks that the header and binaries match
-               get_ldk_c_bindings_version();
-               get_ldk_version();
+               System.err.println("Loaded LDK-Java Bindings " + version.get_ldk_java_bindings_version() + " with LDK " + get_ldk_version() + " and LDK-C-Bindings " + get_ldk_c_bindings_version());
        }
        static native void init(java.lang.Class c, java.lang.Class slicedef);
        static native void init_class_cache();
@@ -237,7 +236,6 @@ void __attribute__((constructor)) debug_log_version() {
                DEBUG_PRINT("LDK version did not match the header we built against\\n");
        if (check_get_ldk_bindings_version() == NULL)
                DEBUG_PRINT("LDK C Bindings version did not match the header we built against\\n");
-       DEBUG_PRINT("Loaded LDK-Java Bindings with LDK %s and LDK-C-Bindings %s\\n", check_get_ldk_version(), check_get_ldk_bindings_version());
 }
 """
 
@@ -576,6 +574,7 @@ import javax.annotation.Nullable;
         self.file_ext = ".java"
         self.ptr_c_ty = "int64_t"
         self.ptr_native_ty = "long"
+        self.u128_native_ty = "UInt128"
         self.usize_c_ty = "int64_t"
         self.usize_native_ty = "long"
         self.native_zero_ptr = "0"
@@ -704,11 +703,16 @@ import javax.annotation.Nullable;
     def cleanup_converted_native_array(self, ty_info, arr_name):
         return None
 
-    def primitive_arr_from_hu(self, mapped_ty, fixed_len, arr_name):
+    def primitive_arr_from_hu(self, arr_ty, fixed_len, arr_name):
+        mapped_ty = arr_ty.subty
+        if arr_ty.rust_obj == "LDKU128":
+            return ("" + arr_name + ".getLEBytes()", "")
         if fixed_len is not None:
             return ("InternalUtils.check_arr_len(" + arr_name + ", " + fixed_len + ")", "")
         return None
-    def primitive_arr_to_hu(self, primitive_ty, fixed_len, arr_name, conv_name):
+    def primitive_arr_to_hu(self, arr_ty, fixed_len, arr_name, conv_name):
+        if arr_ty.rust_obj == "LDKU128":
+            return "org.ldk.util.UInt128 " + conv_name + " = new org.ldk.util.UInt128(" + arr_name + ");"
         return None
 
     def java_arr_ty_str(self, elem_ty_str):
@@ -730,7 +734,7 @@ import javax.annotation.Nullable;
     def fully_qualified_hu_ty_path(self, ty):
         if ty.java_fn_ty_arg.startswith("L") and ty.java_fn_ty_arg.endswith(";"):
             return ty.java_fn_ty_arg.strip("L;").replace("/", ".")
-        if ty.java_hu_ty == "UnqualifiedError" or ty.java_hu_ty == "UInt5" or ty.java_hu_ty == "WitnessVersion":
+        if ty.java_hu_ty == "UnqualifiedError" or ty.java_hu_ty == "UInt128" or ty.java_hu_ty == "UInt5" or ty.java_hu_ty == "WitnessVersion":
             return "org.ldk.util." + ty.java_hu_ty
         if not ty.is_native_primitive and ty.rust_obj is not None and not "[]" in ty.java_hu_ty:
             return "org.ldk.structs." + ty.java_hu_ty
@@ -1013,8 +1017,8 @@ import javax.annotation.Nullable;
                 if fn_line.ret_ty_info.c_ty.endswith("Array"):
                     out_c = out_c + "\t" + fn_line.ret_ty_info.c_ty + " ret = (*env)->CallObjectMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
                 elif fn_line.ret_ty_info.c_ty == "void":
-                    out_c += "\t(*env)->Call" + fn_line.ret_ty_info.java_ty.title() + "Method(env, obj, j_calls->" + fn_line.fn_name + "_meth"
-                elif fn_line.ret_ty_info.java_hu_ty == "String":
+                    out_c += "\t(*env)->CallVoidMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
+                elif fn_line.ret_ty_info.java_hu_ty == "String" or "org/ldk/enums" in fn_line.ret_ty_info.java_fn_ty_arg:
                     # Manually write out String methods as they're just an Object
                     out_c += "\t" + fn_line.ret_ty_info.c_ty + " ret = (*env)->CallObjectMethod(env, obj, j_calls->" + fn_line.fn_name + "_meth"
                 elif not fn_line.ret_ty_info.passed_as_ptr: