From 061af94fdcd85acba1cbaed29cba0e9a3a1fd6b4 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 29 Apr 2021 16:39:03 +0000 Subject: [PATCH] Handle u5, LDKTwentyBytes, and LDKRecoverableSignature --- gen_type_mapping.py | 9 ++++++++- genbindings.py | 17 +++++++++++++++++ src/main/java/org/ldk/util/UInt5.java | 14 ++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/ldk/util/UInt5.java diff --git a/gen_type_mapping.py b/gen_type_mapping.py index 3e0d9aee..475e132b 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -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 = ", ";") diff --git a/genbindings.py b/genbindings.py index bac54945..32980aa3 100755 --- a/genbindings.py +++ b/genbindings.py @@ -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 index 00000000..1bd627b8 --- /dev/null +++ b/src/main/java/org/ldk/util/UInt5.java @@ -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; + } +} -- 2.30.2