Merge pull request #103 from TheBlueMatt/main
[ldk-java] / typescript_strings.py
index 670eb2ae73124346a41e919247f43d601e12a63f..9e4cf192a1aa76abf604c1b3123d7265b9840e0c 100644 (file)
@@ -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<UInt5>): Uint8Array {
        return arr;
 }
 
+/* @internal */
+export function WitnessVersionArrToBytes(inputArray: Array<WitnessVersion>): 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);
@@ -327,6 +338,15 @@ export class UInt5 {
        }
 }
 
+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) {}
 }
@@ -596,7 +616,7 @@ jstring __attribute__((export_name("TS_get_ldk_version"))) get_ldk_version() {
 }"""
 
         self.hu_struct_file_prefix = """
-import { CommonBase, UInt5, UnqualifiedError } from './CommonBase.mjs';
+import { CommonBase, UInt5, WitnessVersion, UnqualifiedError } from './CommonBase.mjs';
 import * as bindings from '../bindings.mjs'
 
 """
@@ -1089,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", "")
@@ -1176,7 +1199,7 @@ export class {struct_name.replace("LDK","")} extends CommonBase {{
 
         hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDK", "")
         out_opaque_struct_human = f"{self.hu_struct_file_prefix}"
-        if struct_name.startswith("LDKLocked"):
+        if struct_name.startswith("LDKLocked") or struct_name.startswith("LDKReadOnly"):
             out_opaque_struct_human += "/** XXX: DO NOT USE THIS - it remains locked until the GC runs (if that ever happens */"
         formatted_doc_comment = struct_doc_comment.replace("\n", "\n * ")
         out_opaque_struct_human += f"""