]> git.bitcoin.ninja Git - ldk-java/commitdiff
Handle u5, LDKTwentyBytes, and LDKRecoverableSignature
authorMatt Corallo <git@bluematt.me>
Thu, 29 Apr 2021 16:39:03 +0000 (16:39 +0000)
committerMatt Corallo <git@bluematt.me>
Sat, 1 May 2021 00:11:31 +0000 (00:11 +0000)
gen_type_mapping.py
genbindings.py
src/main/java/org/ldk/util/UInt5.java [new file with mode: 0644]

index 3e0d9aeef86b7a5578d5d9a3009925a5e78193bd..475e132bc447a1b71133b763181dd277c7af19e8 100644 (file)
@@ -398,7 +398,14 @@ class TypeMappingGenerator:
                         ret_conv = ("long " + ty_info.var_name + "_ref = (long)(&", ") | 1;"), ret_conv_name = ty_info.var_name + "_ref",
                         to_hu_conv = to_hu_conv, to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = (from_hu_conv + ")", from_hu_conv_sfx))
 
-                # The manually-defined types - TxOut and Transaction
+                # The manually-defined types - TxOut and u5
+                if ty_info.rust_obj == "LDKu5":
+                    return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
+                        arg_conv = "", arg_conv_name = "(LDKu5){ ._0 = " + ty_info.var_name + " }", arg_conv_cleanup = None,
+                        ret_conv = ("uint8_t " + ty_info.var_name + "_val = ", "._0;"), ret_conv_name = ty_info.var_name + "_val",
+                        to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_conv = new " + ty_info.java_hu_ty + "(" + ty_info.var_name + ");",
+                        to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = (ty_info.var_name + ".ptr", ""))
+
                 assert ty_info.rust_obj == "LDKTxOut"
                 if not ty_info.is_ptr and not holds_ref:
                     ret_conv = ("LDKTxOut* " + ty_info.var_name + "_ref = MALLOC(sizeof(LDKTxOut), \"LDKTxOut\");\n*" + ty_info.var_name + "_ref = ", ";")
index bac54945477f0182e3d378511e6b32962c786243..32980aa3c4e7cf8071ebcff248bac9d1ca9993d2 100755 (executable)
@@ -121,6 +121,11 @@ def java_c_types(fn_arg, ret_arr_len):
         assert var_is_arr_regex.match(fn_arg[8:])
         rust_obj = "LDKSignature"
         arr_access = "compact_form"
+    elif fn_arg.startswith("LDKRecoverableSignature"):
+        fn_arg = "uint8_t (*" + fn_arg[25:] + ")[68]"
+        assert var_is_arr_regex.match(fn_arg[8:])
+        rust_obj = "LDKRecoverableSignature"
+        arr_access = "serialized_form"
     elif fn_arg.startswith("LDKThreeBytes"):
         fn_arg = "uint8_t (*" + fn_arg[14:] + ")[3]"
         assert var_is_arr_regex.match(fn_arg[8:])
@@ -136,6 +141,11 @@ def java_c_types(fn_arg, ret_arr_len):
         assert var_is_arr_regex.match(fn_arg[8:])
         rust_obj = "LDKSixteenBytes"
         arr_access = "data"
+    elif fn_arg.startswith("LDKTwentyBytes"):
+        fn_arg = "uint8_t (*" + fn_arg[15:] + ")[20]"
+        assert var_is_arr_regex.match(fn_arg[8:])
+        rust_obj = "LDKTwentyBytes"
+        arr_access = "data"
     elif fn_arg.startswith("LDKTenBytes"):
         fn_arg = "uint8_t (*" + fn_arg[12:] + ")[10]"
         assert var_is_arr_regex.match(fn_arg[8:])
@@ -210,6 +220,13 @@ def java_c_types(fn_arg, ret_arr_len):
         fn_ty_arg = "B"
         fn_arg = fn_arg[7:].strip()
         is_primitive = True
+    elif fn_arg.startswith("LDKu5"):
+        java_ty = consts.c_type_map['uint8_t'][0]
+        java_hu_ty = "UInt5"
+        rust_obj = "LDKu5"
+        c_ty = "int8_t"
+        fn_ty_arg = "B"
+        fn_arg = fn_arg[6:].strip()
     elif fn_arg.startswith("uint16_t"):
         mapped_type = consts.c_type_map['uint16_t']
         java_ty = mapped_type[0]
diff --git a/src/main/java/org/ldk/util/UInt5.java b/src/main/java/org/ldk/util/UInt5.java
new file mode 100644 (file)
index 0000000..1bd627b
--- /dev/null
@@ -0,0 +1,14 @@
+package org.ldk.util;
+
+/**
+ * A 5-bit unsigned integer
+ */
+public class UInt5 {
+    byte val;
+    public UInt5(byte val) {
+        if (val > 32 || val < 0) {
+            throw new IllegalArgumentException();
+        }
+        this.val = val;
+    }
+}