X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=java_strings.py;h=b0c100e7fa6fc82e89eb1823593e7dbdab4305a2;hb=6ea339247734db7b67f07ee4c839d6c02d2747fa;hp=33326cd4332c7273753b292591320436ecff8e23;hpb=981f68200795eef6fffe8171ec55c7be0fc5486e;p=ldk-java diff --git a/java_strings.py b/java_strings.py index 33326cd4..b0c100e7 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"