X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=blobdiff_plain;f=java_strings.py;h=f6bf763d9695bef6b0ae028da82f0f0b8c77a01c;hp=33326cd4332c7273753b292591320436ecff8e23;hb=HEAD;hpb=981f68200795eef6fffe8171ec55c7be0fc5486e diff --git a/java_strings.py b/java_strings.py index 33326cd4..7e35d175 100644 --- a/java_strings.py +++ b/java_strings.py @@ -72,6 +72,7 @@ public class bindings { // Fetching the LDK versions from C also checks that the header and binaries match System.err.println("Loaded LDK-Java Bindings " + version.get_ldk_java_bindings_version() + " with LDK " + get_ldk_version() + " and LDK-C-Bindings " + get_ldk_c_bindings_version()); } + public static void run_statics() { /* Useful to force the statics to run */ } static native void init(java.lang.Class c); static native void init_class_cache(); static native String get_lib_version_string(); @@ -184,6 +185,34 @@ class CommonBase { } }""" + 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 // On OSX jlong (ie long long) is not equivalent to int64_t, so we override here @@ -833,7 +862,7 @@ import javax.annotation.Nullable; out_c = out_c + "\t\tcase %d: return %s;\n" % (ord_v, var) ord_v = ord_v + 1 out_java_enum = out_java_enum + "\t; static native void init();\n" - out_java_enum = out_java_enum + "\tstatic { init(); }\n" + out_java_enum = out_java_enum + "\tstatic { org.ldk.impl.bindings.run_statics(); init(); }\n" out_java_enum = out_java_enum + "}" out_java = out_java + "\tstatic { " + struct_name + ".values(); /* Force enum statics to run */ }\n" out_c += "\t}\n" @@ -1361,7 +1390,7 @@ import javax.annotation.Nullable; out_opaque_struct_human += self.hu_struct_file_prefix out_opaque_struct_human += "\n/**\n * " + struct_doc_comment.replace("\n", "\n * ") + "\n */\n" out_opaque_struct_human += "@SuppressWarnings(\"unchecked\") // We correctly assign various generic arrays\n" - hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDK", "") + hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC4Tuple", "FourTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDK", "") out_opaque_struct_human += ("public class " + hu_name + " extends CommonBase") if struct_name.startswith("LDKLocked") or struct_name.startswith("LDKReadOnly"): out_opaque_struct_human += (" implements AutoCloseable") @@ -1389,6 +1418,9 @@ import javax.annotation.Nullable; java_hu_struct += "\tprotected void finalize() throws Throwable {\n" java_hu_struct += "\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); } super.finalize();\n" java_hu_struct += "\t}\n\n" + java_hu_struct += "\tprotected void force_free() {\n" # Used by NioPeerHandler + java_hu_struct += "\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); ptr = 0; }\n" + java_hu_struct += "\t}\n\n" java_hu_struct += "\tstatic " + human_ty + " constr_from_ptr(long ptr) {\n" java_hu_struct += "\t\tif (bindings." + struct_name.replace("LDK", "") + "_is_ok(ptr)) {\n" java_hu_struct += "\t\t\treturn new " + human_ty + "_OK(null, ptr);\n"