to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_hu_conv", "new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ")") + ";" + to_hu_conv_sfx,
to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = from_hu_conv)
- # The manually-defined types - TxOut, u5, and Error
+ # The manually-defined types - TxOut, BigEndianScalar, u5, and Error
if ty_info.rust_obj == "LDKError":
assert from_hu_conv is None
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
to_hu_conv = self.consts.var_decl_statement(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 + ".getVal()", ""))
- assert ty_info.rust_obj == "LDKTxOut"
+ assert ty_info.rust_obj == "LDKTxOut" or ty_info.rust_obj == "LDKBigEndianScalar"
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 = ", ";")
+ ret_conv = (ty_info.rust_obj + "* " + ty_info.var_name + "_ref = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n*" + ty_info.var_name + "_ref = ", ";")
ret_conv_name = "tag_ptr(" + ty_info.var_name + "_ref, true)"
else:
- ret_conv = ("LDKTxOut* " + ty_info.var_name + "_ref = &", ";")
+ ret_conv = (ty_info.rust_obj + "* " + ty_info.var_name + "_ref = &", ";")
ret_conv_name = "tag_ptr(" + ty_info.var_name + "_ref, false)"
return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
expected_struct in complex_enums or expected_struct in complex_enums or
expected_struct in result_types or expected_struct in tuple_types) and not is_free
impl_on_utils = not impl_on_struct and (not is_free and not method_name.endswith("_clone") and
- not method_name.startswith("TxOut") and
+ not method_name.startswith("TxOut") and not method_name.startswith("BigEndianScalar") and
not method_name.startswith("_") and
method_name != "check_platform" and method_name != "Result_read" and
not expected_struct in unitary_enums and
write_c("\treturn thing->value;")
write_c("}")
map_fn(fn_line + "\n", re.compile("(.*) (TxOut_get_value) \((.*)\)").match(fn_line), None, None, None)
+ elif struct_name == "LDKBigEndianScalar":
+ with open(f"{sys.argv[3]}/structs/BigEndianScalar{consts.file_ext}", "w") as out_java_struct:
+ out_java_struct.write(consts.hu_struct_file_prefix)
+ out_java_struct.write(consts.scalar_defn)
+ fn_line = "struct LDKThirtyTwoBytes BigEndianScalar_get_bytes (struct LDKBigEndianScalar* thing)"
+ write_c(fn_line + " {\n")
+ write_c("\tLDKThirtyTwoBytes ret = { .data = *thing->big_endian_bytes };\n")
+ write_c("\treturn ret;\n")
+ write_c("}\n")
+ map_fn(fn_line + "\n", re.compile("(.*) (BigEndianScalar_get_bytes) \((.*)\)").match(fn_line), None, None, None)
+
+ # We need to be able to FREE a heap-allocated BigEndianScalar, but because
+ # there's nothing heap-allocated inside it the C bindings don't bother
+ # exposing a `_free` method. Instead, we have to manually write one here,
+ # though it doesn't need to do anything, the autogenerated wrapper will do
+ # the required FREE.
+ fn_line = "static void BigEndianScalar_free (struct LDKBigEndianScalar thing)"
+ write_c(fn_line + " {}\n")
+ map_fn(fn_line + "\n", re.compile("static (.*) (BigEndianScalar_free) \((.*)\)").match(fn_line), None, None, None)
else:
- pass # Everything remaining is a byte[] or some form
+ pass # Everything remaining is a byte[] of some form
cur_block_obj = None
else:
fn_ptr = fn_ptr_regex.match(line)
}
}"""
+ self.scalar_defn = """public class BigEndianScalar extends CommonBase {
+ /** The bytes of the scalar value, in big endian */
+ public final byte[] scalar_bytes;
+
+ BigEndianScalar(java.lang.Object _dummy, long ptr) {
+ super(ptr);
+ this.scalar_bytes = bindings.BigEndianScalar_get_bytes(ptr);
+ }
+ public BigEndianScalar(byte[] scalar_bytes) {
+ super(bindings.BigEndianScalar_new(scalar_bytes));
+ this.scalar_bytes = bindings.BigEndianScalar_get_bytes(ptr);
+ }
+
+ @Override @SuppressWarnings(\"deprecation\")
+ protected void finalize() throws Throwable {
+ super.finalize();
+ if (ptr != 0) { bindings.BigEndianScalar_free(ptr); }
+ }
+}"""
+
+
self.c_file_pfx = """#include <jni.h>
// On OSX jlong (ie long long) is not equivalent to int64_t, so we override here
#define int64_t jlong
}"""
self.obj_defined(["TxOut"], "structs")
+ self.scalar_defn = """export class BigEndianScalar extends CommonBase {
+ /** The bytes of the scalar value, in big endian */
+ public scalar_bytes: Uint8Array;
+
+ /* @internal */
+ public constructor(_dummy: object, ptr: bigint) {
+ super(ptr, bindings.BigEndianScalar_free);
+ this.scalar_bytes = bindings.decodeUint8Array(bindings.BigEndianScalar_get_bytes(ptr));
+ }
+ public static constructor_new(scalar_bytes: Uint8Array): BigEndianScalar {
+ return new BigEndianScalar(null, bindings.BigEndianScalar_new(bindings.encodeUint8Array(scalar_bytes)));
+ }
+}"""
+ self.obj_defined(["BigEndianScalar"], "structs")
+
self.c_file_pfx = """#include "js-wasm.h"
#include <stdatomic.h>
#include <lightning.h>