}
}"""
+ self.witness_program_defn = """public class WitnessProgram : CommonBase {
+ /** The witness program bytes themselves */
+ public readonly byte[] program;
+ /** The witness version */
+ public readonly WitnessVersion version;
+
+ internal WitnessProgram(object _dummy, long ptr) : base(ptr) {
+ this.program = InternalUtils.decodeUint8Array(bindings.WitnessProgram_get_program(ptr));
+ this.version = new WitnessVersion(bindings.WitnessProgram_get_version(ptr));
+ }
+ static private long check_args(byte[] program, WitnessVersion version) {
+ if (program.Length < 2 || program.Length > 40) throw new ArgumentException();
+ if (version.getVal() == 0 && program.Length != 20 && program.Length != 32) throw new ArgumentException();
+ return InternalUtils.encodeUint8Array(program);
+ }
+ public WitnessProgram(byte[] program, WitnessVersion version) :
+ this(null, bindings.WitnessProgram_new(version.getVal(), check_args(program, version))) {}
+
+ ~WitnessProgram() {
+ if (ptr != 0) { bindings.WitnessProgram_free(ptr); }
+ }
+}"""
self.c_file_pfx = """
// On OSX jlong (ie long long) is not equivalent to int64_t, so we override here
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" or ty_info.rust_obj == "LDKTxIn" or ty_info.rust_obj == "LDKBigEndianScalar"
+ assert ty_info.rust_obj == "LDKWitnessProgram" or ty_info.rust_obj == "LDKTxOut" or ty_info.rust_obj == "LDKTxIn" or ty_info.rust_obj == "LDKBigEndianScalar"
if not ty_info.is_ptr and not holds_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)"
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("TxIn") and
- not method_name.startswith("BigEndianScalar") and not method_name.startswith("_") and
+ not method_name.startswith("BigEndianScalar") and not method_name.startswith("WitnessProgram") and
+ not method_name.startswith("_") and
method_name != "check_platform" and method_name != "Result_read" and
not expected_struct in unitary_enums and
((not method_name.startswith("C2Tuple_") and not method_name.startswith("C3Tuple_"))
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)
+ elif struct_name == "LDKWitnessProgram":
+ with open(f"{sys.argv[3]}/structs/WitnessProgram{consts.file_ext}", "w") as out_java_struct:
+ out_java_struct.write(consts.hu_struct_file_prefix)
+ out_java_struct.write(consts.witness_program_defn)
+ out_java_struct.write(consts.hu_struct_file_suffix)
else:
pass # Everything remaining is a byte[] of some form
cur_block_obj = None
}
}"""
+ self.witness_program_defn = """public class WitnessProgram extends CommonBase {
+ /** The witness program bytes themselves */
+ public final byte[] program;
+ /** The witness version */
+ public final WitnessVersion version;
+
+ WitnessProgram(java.lang.Object _dummy, long ptr) {
+ super(ptr);
+ this.program = bindings.WitnessProgram_get_program(ptr);
+ this.version = new WitnessVersion(bindings.WitnessProgram_get_version(ptr));
+ }
+ static byte check_args(byte[] program, WitnessVersion version) {
+ if (program.length < 2 || program.length > 40) throw new IllegalArgumentException();
+ if (version.getVal() == 0 && program.length != 20 && program.length != 32) throw new IllegalArgumentException();
+ return version.getVal();
+ }
+ public WitnessProgram(byte[] program, WitnessVersion version) {
+ super(bindings.WitnessProgram_new(check_args(program, version), program));
+ this.program = bindings.WitnessProgram_get_program(ptr);
+ this.version = new WitnessVersion(bindings.WitnessProgram_get_version(ptr));
+ }
+
+ @Override @SuppressWarnings(\"deprecation\")
+ protected void finalize() throws Throwable {
+ super.finalize();
+ if (ptr != 0) { bindings.WitnessProgram_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
}"""
self.obj_defined(["BigEndianScalar"], "structs")
+ self.witness_program_defn = """export class WitnessProgram extends CommonBase {
+ /** The witness program bytes themselves */
+ public program: Uint8Array;
+ /** The witness program version */
+ public version: WitnessVersion;
+
+ /* @internal */
+ public constructor(_dummy: null, ptr: bigint) {
+ super(ptr, bindings.WitnessProgram_free);
+ this.program = bindings.decodeUint8Array(bindings.WitnessProgram_get_program(ptr));
+ this.version = new WitnessVersion(bindings.WitnessProgram_get_version(ptr));
+ }
+ public static constructor_new(program: Uint8Array, version: WitnessVersion): WitnessProgram {
+ if (program.length < 2 || program.length > 40)
+ throw new Error("WitnessProgram must be between 2 and 40 bytes long");
+ if (version.getVal() == 0 && program.length != 20 && program.length != 32)
+ throw new Error("WitnessProgram for version 0 must be between either 20 or 30 bytes");
+ return new WitnessProgram(null, bindings.WitnessProgram_new(version.getVal(), bindings.encodeUint8Array(program)));
+ }
+}"""
+ self.obj_defined(["WitnessProgram"], "structs")
+
self.c_file_pfx = """#include "js-wasm.h"
#include <stdatomic.h>
#include <lightning.h>