From 153c5653d39ca5dc40e4cd9bfbab41936b850768 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 7 Jan 2022 23:02:42 +0000 Subject: [PATCH] Make TxOut language-specific, fix typescript UtilMethods compilation --- genbindings.py | 25 +------------------------ java_strings.py | 24 ++++++++++++++++++++++++ typescript_strings.py | 23 ++++++++++++++++++++--- 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/genbindings.py b/genbindings.py index a5fb3c25..06827cf0 100755 --- a/genbindings.py +++ b/genbindings.py @@ -911,30 +911,7 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}", elif struct_name == "LDKTxOut": with open(f"{sys.argv[3]}/structs/TxOut{consts.file_ext}", "w") as out_java_struct: out_java_struct.write(consts.hu_struct_file_prefix) - out_java_struct.write("public class TxOut extends CommonBase{\n") - out_java_struct.write("\t/** The script_pubkey in this output */\n") - out_java_struct.write("\tpublic final byte[] script_pubkey;\n") - out_java_struct.write("\t/** The value, in satoshis, of this output */\n") - out_java_struct.write("\tpublic final long value;\n") - out_java_struct.write("\n") - out_java_struct.write("\tTxOut(java.lang.Object _dummy, long ptr) {\n") - out_java_struct.write("\t\tsuper(ptr);\n") - out_java_struct.write("\t\tthis.script_pubkey = bindings.TxOut_get_script_pubkey(ptr);\n") - out_java_struct.write("\t\tthis.value = bindings.TxOut_get_value(ptr);\n") - out_java_struct.write("\t}\n") - out_java_struct.write("\tpublic TxOut(long value, byte[] script_pubkey) {\n") - out_java_struct.write("\t\tsuper(bindings.TxOut_new(script_pubkey, value));\n") - out_java_struct.write("\t\tthis.script_pubkey = bindings.TxOut_get_script_pubkey(ptr);\n") - out_java_struct.write("\t\tthis.value = bindings.TxOut_get_value(ptr);\n") - out_java_struct.write("\t}\n") - out_java_struct.write("\n") - out_java_struct.write("\t@Override @SuppressWarnings(\"deprecation\")\n") - out_java_struct.write("\tprotected void finalize() throws Throwable {\n") - out_java_struct.write("\t\tsuper.finalize();\n") - out_java_struct.write("\t\tif (ptr != 0) { bindings.TxOut_free(ptr); }\n") - out_java_struct.write("\t}\n") - out_java_struct.write("\n") - out_java_struct.write("}") + out_java_struct.write(consts.txout_defn) fn_line = "struct LDKCVec_u8Z TxOut_get_script_pubkey (struct LDKTxOut* thing)" write_c(fn_line + " {") write_c("\treturn CVec_u8Z_clone(&thing->script_pubkey);") diff --git a/java_strings.py b/java_strings.py index 535646b9..8338bc17 100644 --- a/java_strings.py +++ b/java_strings.py @@ -121,6 +121,30 @@ class CommonBase { } """ + self.txout_defn = """public class TxOut extends CommonBase { + /** The script_pubkey in this output */ + public final byte[] script_pubkey; + /** The value, in satoshis, of this output */ + public final long value; + + TxOut(java.lang.Object _dummy, long ptr) { + super(ptr); + this.script_pubkey = bindings.TxOut_get_script_pubkey(ptr); + this.value = bindings.TxOut_get_value(ptr); + } + public TxOut(long value, byte[] script_pubkey) { + super(bindings.TxOut_new(script_pubkey, value)); + this.script_pubkey = bindings.TxOut_get_script_pubkey(ptr); + this.value = bindings.TxOut_get_value(ptr); + } + + @Override @SuppressWarnings(\"deprecation\") + protected void finalize() throws Throwable { + super.finalize(); + if (ptr != 0) { bindings.TxOut_free(ptr); } + } +}""" + self.c_file_pfx = """#include // On OSX jlong (ie long long) is not equivalent to int64_t, so we override here #define int64_t jlong diff --git a/typescript_strings.py b/typescript_strings.py index f889519b..d595e4d2 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -76,9 +76,6 @@ public static native long new_empty_slice_vec(); self.bindings_footer = "" - self.util_fn_pfx = "" - self.util_fn_sfx = "" - self.common_base = """ function freer(f: () => void) { f() } const finalizer = new FinalizationRegistry(freer); @@ -113,6 +110,24 @@ export default class CommonBase { } """ + self.txout_defn = """export class TxOut extends CommonBase { + /** The script_pubkey in this output */ + public script_pubkey: Uint8Array; + /** The value, in satoshis, of this output */ + public value: number; + + /* @internal */ + public constructor(_dummy: object, ptr: number) { + super(ptr, bindings.TxOut_free); + this.script_pubkey = bindings.TxOut_get_script_pubkey(ptr); + this.value = bindings.TxOut_get_value(ptr); + } + public constructor_new(value: number, script_pubkey: Uint8Array): TxOut { + return new TxOut(null, bindings.TxOut_new(script_pubkey, value)); + } +}""" + self.obj_defined(["TxOut"], "structs") + self.c_file_pfx = """#include "js-wasm.h" #include #include @@ -309,6 +324,8 @@ import * as bindings from '../bindings.mjs' import * as InternalUtils from '../InternalUtils.mjs' """ + self.util_fn_pfx = self.hu_struct_file_prefix + "\nexport class UtilMethods extends CommonBase {\n" + self.util_fn_sfx = "}" self.c_fn_ty_pfx = "" self.file_ext = ".mts" self.ptr_c_ty = "uint32_t" -- 2.39.5