X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=typescript_strings.py;h=3dd8d53b3b56d6741ba3545b7e1f9bd2503fafd0;hb=eb8cafbbe3799877aaca271a271debc839ab07d2;hp=5d5eb814c79ac28e95381e42f3608a8571af60a5;hpb=94769d9a2cfac383d62769f096674b9f7a7f25df;p=ldk-java diff --git a/typescript_strings.py b/typescript_strings.py index 5d5eb814..3dd8d53b 100644 --- a/typescript_strings.py +++ b/typescript_strings.py @@ -21,7 +21,9 @@ class Consts: uint8_t = ['number', 'number', 'Uint8Array'], uint16_t = ['number', 'number', 'Uint16Array'], uint32_t = ['number', 'number', 'Uint32Array'], + int64_t = ['bigint', 'bigint', 'BigInt64Array'], uint64_t = ['bigint', 'bigint', 'BigUint64Array'], + double = ['number', 'number', 'Float64Array'], ) self.java_type_map = dict( String = "number" @@ -126,7 +128,7 @@ async function finishInitializeWasm(wasmInstance: WebAssembly.Instance) { isWasmInitialized = true; } -const fn_list = ["uuuuuu", "buuuuu", "bbuuuu", "bbbuuu", "bbbbuu", +const fn_list = ["uuuuuu", "buuuuu", "bbuuuu", "bbbuuu", "bbbbuu", "bbbbbu", "bbbbbb", "ubuubu", "ubuuuu", "ubbuuu", "uubuuu", "uububu", "ububuu"]; /* @internal */ @@ -445,6 +447,33 @@ export class UnqualifiedError { }""" self.obj_defined(["TxOut"], "structs") + self.txin_defn = """export class TxIn extends CommonBase { + /** The witness in this input, in serialized form */ + public witness: Uint8Array; + /** The script_sig in this input */ + public script_sig: Uint8Array; + /** The transaction output's sequence number */ + public sequence: number; + /** The txid this input is spending */ + public previous_txid: Uint8Array; + /** The output index within the spent transaction of the output this input is spending */ + public previous_vout: number; + + /* @internal */ + public constructor(_dummy: null, ptr: bigint) { + super(ptr, bindings.TxIn_free); + this.witness = bindings.decodeUint8Array(bindings.TxIn_get_witness(ptr)); + this.script_sig = bindings.decodeUint8Array(bindings.TxIn_get_script_sig(ptr)); + this.sequence = bindings.TxIn_get_sequence(ptr); + this.previous_txid = bindings.decodeUint8Array(bindings.TxIn_get_previous_txid(ptr)); + this.previous_vout = bindings.TxIn_get_previous_vout(ptr); + } + public static constructor_new(witness: Uint8Array, script_sig: Uint8Array, sequence: number, previous_txid: Uint8Array, previous_vout: number): TxIn { + return new TxIn(null, bindings.TxIn_new(bindings.encodeUint8Array(witness), bindings.encodeUint8Array(script_sig), sequence, bindings.encodeUint8Array(previous_txid), previous_vout)); + } +}""" + self.obj_defined(["TxIn"], "structs") + self.scalar_defn = """export class BigEndianScalar extends CommonBase { /** The bytes of the scalar value, in big endian */ public scalar_bytes: Uint8Array; @@ -735,7 +764,7 @@ import * as bindings from '../bindings.mjs' return None def create_native_arr_call(self, arr_len, ty_info): if ty_info.c_ty == "ptrArray": - assert ty_info.rust_obj == "LDKCVec_U5Z" or (ty_info.subty is not None and ty_info.subty.c_ty.endswith("Array")) + assert ty_info.rust_obj == "LDKCVec_U5Z" or (ty_info.subty is not None and (ty_info.subty.c_ty.endswith("Array") or ty_info.subty.rust_obj == "LDKStr")) return "init_" + ty_info.c_ty + "(" + arr_len + ", __LINE__)" def set_native_arr_contents(self, arr_name, arr_len, ty_info): if ty_info.c_ty == "int8_tArray": @@ -770,11 +799,14 @@ import * as bindings from '../bindings.mjs' else: return "FREE(" + arr_name + ")" - def map_hu_array_elems(self, arr_name, conv_name, arr_ty, elem_ty): + def map_hu_array_elems(self, arr_name, conv_name, arr_ty, elem_ty, is_nullable): if elem_ty.rust_obj == "LDKU5": return arr_name + " != null ? bindings.uint5ArrToBytes(" + arr_name + ") : null" - assert elem_ty.c_ty == "uint64_t" or elem_ty.c_ty.endswith("Array") - return arr_name + " != null ? " + arr_name + ".map(" + conv_name + " => " + elem_ty.from_hu_conv[0] + ") : null" + assert elem_ty.c_ty == "uint64_t" or elem_ty.c_ty.endswith("Array") or elem_ty.rust_obj == "LDKStr" + if is_nullable: + return arr_name + " != null ? " + arr_name + ".map(" + conv_name + " => " + elem_ty.from_hu_conv[0] + ") : null" + else: + return arr_name + ".map(" + conv_name + " => " + elem_ty.from_hu_conv[0] + ")" def str_ref_to_native_call(self, var_name, str_len): return "str_ref_to_ts(" + var_name + ", " + str_len + ")" @@ -800,6 +832,8 @@ import * as bindings from '../bindings.mjs' return "bindings.getU64ArrayElem(" + arr_name + ", " + idx + ")" elif elem_ty.rust_obj == "LDKU5": return "bindings.getU8ArrayElem(" + arr_name + ", " + idx + ")" + elif elem_ty.rust_obj == "LDKStr": + return "bindings.getU32ArrayElem(" + arr_name + ", " + idx + ")" else: assert False def constr_hu_array(self, ty_info, arr_len): @@ -823,7 +857,7 @@ import * as bindings from '../bindings.mjs' return ("bindings.encodeUint8Array(" + inner + ")", "") elif mapped_ty.c_ty == "uint16_t" or mapped_ty.c_ty == "int16_t": return ("bindings.encodeUint16Array(" + inner + ")", "") - elif mapped_ty.c_ty == "uint32_t": + elif mapped_ty.c_ty == "uint32_t" or mapped_ty.rust_obj == "LDKStr": return ("bindings.encodeUint32Array(" + inner + ")", "") elif mapped_ty.c_ty == "int64_t" or mapped_ty.c_ty == "uint64_t": return ("bindings.encodeUint64Array(" + inner + ")", "") @@ -1638,7 +1672,14 @@ js_invoke = function(obj_ptr: number, fn_id: number, arg1: bigint|number, arg2: console.error("Got function call with id " + fn_id + " on incorrect JS object: " + obj); throw new Error("Got function call with id " + fn_id + " on incorrect JS object: " + obj); } - const ret = fn.value.bind(obj)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + var ret; + try { + ret = fn.value.bind(obj)(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10); + } catch (e) { + console.error("Got an exception calling function with id " + fn_id + "! This is fatal."); + console.error(e); + throw e; + } if (ret === undefined || ret === null) return BigInt(0); return BigInt(ret); }""")