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 = ("0", ""))
- if ty_info.rust_obj == "LDKu5":
+ if ty_info.rust_obj == "LDKu5" or ty_info.rust_obj == "LDKWitnessVersion":
assert from_hu_conv is None
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,
+ arg_conv = "", arg_conv_name = "(" + ty_info.rust_obj + "){ ._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 = 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()", ""))
arr_ty = "uint8_t"
fn_arg = fn_arg[7:].strip()
is_primitive = True
- elif fn_arg.startswith("LDKu5"):
+ elif fn_arg.startswith("LDKu5") or fn_arg.startswith("LDKWitnessVersion"):
java_ty = consts.c_type_map['uint8_t'][0]
- java_hu_ty = "UInt5"
- rust_obj = "LDKu5"
+ if fn_arg.startswith("LDKu5"):
+ java_hu_ty = "UInt5"
+ rust_obj = "LDKu5"
+ fn_arg = fn_arg[6:].strip()
+ else:
+ java_hu_ty = "WitnessVersion"
+ rust_obj = "LDKWitnessVersion"
+ fn_arg = fn_arg[18:].strip()
c_ty = "int8_t"
arr_ty = "uint8_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]
return arr_name + " != null ? Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + elem_ty.from_hu_conv[0] + ").toArray() : null"
elif elem_ty.java_hu_ty == "UInt5":
return arr_name + " != null ? InternalUtils.convUInt5Array(" + arr_name + ") : null"
+ elif elem_ty.java_hu_ty == "WitnessVersion":
+ return arr_name + " != null ? InternalUtils.convWitnessVersionArray(" + arr_name + ") : null"
else:
return arr_name + " != null ? Arrays.stream(" + arr_name + ").map(" + conv_name + " -> " + elem_ty.from_hu_conv[0] + ").toArray(" + arr_ty.java_ty + "::new) : null"
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":
+ if ty.java_hu_ty == "UnqualifiedError" or ty.java_hu_ty == "UInt5" or ty.java_hu_ty == "WitnessVersion":
return "org.ldk.util." + ty.java_hu_ty
if ty.rust_obj is not None and not "[]" in ty.java_hu_ty:
return "org.ldk.structs." + ty.java_hu_ty
--- /dev/null
+package org.ldk.util;
+
+/**
+ * A 4-bit unsigned integer representing a Bitcoin SegWit version
+ */
+public class WitnessVersion {
+ byte val;
+ public WitnessVersion(byte val) {
+ if (val > 16 || val < 0) {
+ throw new IllegalArgumentException();
+ }
+ this.val = val;
+ }
+
+ /**
+ * @return the value represented
+ */
+ public byte getVal() {
+ return val;
+ }
+}
self.bindings_header = """
import * as version from './version.mjs';
-import { UInt5 } from './structs/CommonBase.mjs';
+import { UInt5, WitnessVersion } from './structs/CommonBase.mjs';
const imports: any = {};
imports.env = {};
return arr;
}
+/* @internal */
+export function WitnessVersionArrToBytes(inputArray: Array<WitnessVersion>): Uint8Array {
+ const arr = new Uint8Array(inputArray.length);
+ for (var i = 0; i < inputArray.length; i++) {
+ arr[i] = inputArray[i].getVal();
+ }
+ return arr;
+}
+
+
+
/* @internal */
export function encodeUint8Array (inputArray: Uint8Array): number {
const cArrayPointer = wasm.TS_malloc(inputArray.length + 4);
}
}
+export class WitnessVersion {
+ public constructor(private val: number) {
+ if (val > 16 || val < 0) throw new Error("WitnessVersion value is out of range");
+ }
+ public getVal(): number {
+ return this.val;
+ }
+}
+
export class UnqualifiedError {
public constructor(val: number) {}
}
}"""
self.hu_struct_file_prefix = """
-import { CommonBase, UInt5, UnqualifiedError } from './CommonBase.mjs';
+import { CommonBase, UInt5, WitnessVersion, UnqualifiedError } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs'
"""