X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=typescript_strings.py;h=092a9e152631388dbd97c99f8d3ea064db7f989e;hb=4f95adad9cbb821f489d89f73d3e493933ba60fe;hp=102d2256798cc7d3d80ccc46459c7ff7867b682e;hpb=d941cc4e66ea53ce81912a04d35b164344f3a7ee;p=ldk-java diff --git a/typescript_strings.py b/typescript_strings.py index 102d2256..092a9e15 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -36,7 +36,7 @@ class Consts: 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 = {}; @@ -149,6 +149,17 @@ export function uint5ArrToBytes(inputArray: Array): Uint8Array { return arr; } +/* @internal */ +export function WitnessVersionArrToBytes(inputArray: Array): 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); @@ -326,6 +337,19 @@ export class UInt5 { return this.val; } } + +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.txout_defn = """export class TxOut extends CommonBase { @@ -592,7 +616,7 @@ jstring __attribute__((export_name("TS_get_ldk_version"))) get_ldk_version() { }""" self.hu_struct_file_prefix = """ -import { CommonBase, UInt5 } from './CommonBase.mjs'; +import { CommonBase, UInt5, WitnessVersion, UnqualifiedError } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' """ @@ -722,6 +746,9 @@ import * as bindings from '../bindings.mjs' with open(self.outdir + "/imports.mts.part", 'a') as imports: imports.write(f"import {{ {', '.join(struct_names)} }} from '../{folder}/{struct_names[0]}.mjs';\n") + def fully_qualified_hu_ty_path(self, ty): + return ty.java_hu_ty + def native_c_unitary_enum_map(self, struct_name, variants, enum_doc_comment): out_c = "static inline LDK" + struct_name + " LDK" + struct_name + "_from_js(int32_t ord) {\n" out_c = out_c + "\tswitch (ord) {\n" @@ -1082,7 +1109,10 @@ export class {struct_name.replace("LDK","")} extends CommonBase {{ return (out_typescript_bindings, out_typescript_human, out_c) def trait_struct_inc_refcnt(self, ty_info): - return "" + base_conv = "\nif (" + ty_info.var_name + "_conv.free == " + ty_info.rust_obj + "_JCalls_free) {\n" + base_conv = base_conv + "\t// If this_arg is a JCalls struct, then we need to increment the refcnt in it.\n" + base_conv = base_conv + "\t" + ty_info.rust_obj + "_JCalls_cloned(&" + ty_info.var_name + "_conv);\n}" + return base_conv def map_complex_enum(self, struct_name, variant_list, camel_to_snake, enum_doc_comment): bindings_type = struct_name.replace("LDK", "")