[C#] Update test to LDK 0.0.123 and pay a BOLT12 offer
[ldk-java] / genbindings.py
index 9f5c9545a6305157ffaac04e9af71edd56bc3bdc..9ae48c4e234dae675047412f5508fd4ccd39e5d5 100755 (executable)
@@ -28,10 +28,17 @@ elif sys.argv[6] == "typescript":
     target = typescript_strings.Target.NODEJS
     if len(sys.argv) == 8 and sys.argv[7] == 'browser':
         target = typescript_strings.Target.BROWSER
     target = typescript_strings.Target.NODEJS
     if len(sys.argv) == 8 and sys.argv[7] == 'browser':
         target = typescript_strings.Target.BROWSER
-elif sys.argv[6] == "c_sharp":
+elif sys.argv[6].startswith("c_sharp"):
     import csharp_strings
     from csharp_strings import Consts
     import csharp_strings
     from csharp_strings import Consts
-    target = csharp_strings.Target.CSHARP
+    if sys.argv[6] == "c_sharp-win":
+        target = csharp_strings.Target.WINDOWS
+    elif sys.argv[6] == "c_sharp-darwin":
+        target = csharp_strings.Target.PTHREAD
+    elif sys.argv[6] == "c_sharp-linux":
+        target = csharp_strings.Target.LINUX
+    else:
+        assert False
 elif sys.argv[6] == "python":
     import python_strings
     from python_strings import Consts
 elif sys.argv[6] == "python":
     import python_strings
     from python_strings import Consts
@@ -158,6 +165,11 @@ def java_c_types(fn_arg, ret_arr_len):
         assert var_is_arr_regex.match(fn_arg[8:])
         rust_obj = "LDKPublicKey"
         arr_access = "compressed_form"
         assert var_is_arr_regex.match(fn_arg[8:])
         rust_obj = "LDKPublicKey"
         arr_access = "compressed_form"
+    elif fn_arg.startswith("LDKTweakedPublicKey"):
+        fn_arg = "uint8_t (*" + fn_arg[21:] + ")[32]"
+        assert var_is_arr_regex.match(fn_arg[8:])
+        rust_obj = "LDKTweakedPublicKey"
+        arr_access = "x_coordinate"
     elif fn_arg.startswith("LDKSecretKey"):
         fn_arg = "uint8_t (*" + fn_arg[13:] + ")[32]"
         assert var_is_arr_regex.match(fn_arg[8:])
     elif fn_arg.startswith("LDKSecretKey"):
         fn_arg = "uint8_t (*" + fn_arg[13:] + ")[32]"
         assert var_is_arr_regex.match(fn_arg[8:])
@@ -384,7 +396,7 @@ def java_c_types(fn_arg, ret_arr_len):
             assert ma.group(1).strip().startswith("LDK")
             java_ty = ma.group(1).strip()[3:]
             java_hu_ty = java_ty
             assert ma.group(1).strip().startswith("LDK")
             java_ty = ma.group(1).strip()[3:]
             java_hu_ty = java_ty
-            c_ty = consts.result_c_ty
+            c_ty = consts.unitary_enum_c_ty
             fn_ty_arg = "Lorg/ldk/enums/" + java_ty + ";"
             fn_arg = ma.group(2).strip()
             rust_obj = ma.group(1).strip()
             fn_ty_arg = "Lorg/ldk/enums/" + java_ty + ";"
             fn_arg = ma.group(2).strip()
             rust_obj = ma.group(1).strip()
@@ -396,6 +408,7 @@ def java_c_types(fn_arg, ret_arr_len):
             java_hu_ty = java_hu_ty.replace("LDKCResult", "Result")
             java_hu_ty = java_hu_ty.replace("LDKC2Tuple", "TwoTuple")
             java_hu_ty = java_hu_ty.replace("LDKC3Tuple", "ThreeTuple")
             java_hu_ty = java_hu_ty.replace("LDKCResult", "Result")
             java_hu_ty = java_hu_ty.replace("LDKC2Tuple", "TwoTuple")
             java_hu_ty = java_hu_ty.replace("LDKC3Tuple", "ThreeTuple")
+            java_hu_ty = java_hu_ty.replace("LDKC4Tuple", "FourTuple")
             java_hu_ty = java_hu_ty.replace("LDK", "")
             fn_ty_arg = "J"
             fn_arg = ma.group(2).strip()
             java_hu_ty = java_hu_ty.replace("LDK", "")
             fn_ty_arg = "J"
             fn_arg = ma.group(2).strip()
@@ -564,14 +577,17 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}",
             struct_meth = method_name.rsplit("Z", 1)[0][1:] + "Z"
             expected_struct = "LDKC" + struct_meth
             struct_meth_name = method_name[len(struct_meth) + 1:].strip("_")
             struct_meth = method_name.rsplit("Z", 1)[0][1:] + "Z"
             expected_struct = "LDKC" + struct_meth
             struct_meth_name = method_name[len(struct_meth) + 1:].strip("_")
-        elif method_name.startswith("C2Tuple") or method_name.startswith("C3Tuple"):
+        elif method_name.startswith("C2Tuple") or method_name.startswith("C3Tuple") or method_name.startswith("C4Tuple"):
             tuple_name = method_name.rsplit("Z", 1)[0][2:] + "Z"
             if method_name.startswith("C2Tuple"):
                 struct_meth = "Two" + tuple_name
                 expected_struct = "LDKC2" + tuple_name
             tuple_name = method_name.rsplit("Z", 1)[0][2:] + "Z"
             if method_name.startswith("C2Tuple"):
                 struct_meth = "Two" + tuple_name
                 expected_struct = "LDKC2" + tuple_name
-            else:
+            elif method_name.startswith("C3Tuple"):
                 struct_meth = "Three" + tuple_name
                 expected_struct = "LDKC3" + tuple_name
                 struct_meth = "Three" + tuple_name
                 expected_struct = "LDKC3" + tuple_name
+            else:
+                struct_meth = "Four" + tuple_name
+                expected_struct = "LDKC4" + tuple_name
             struct_meth_name = method_name[len(tuple_name) + 2:].strip("_")
         else:
             struct_meth = method_name.split("_")[0]
             struct_meth_name = method_name[len(tuple_name) + 2:].strip("_")
         else:
             struct_meth = method_name.split("_")[0]
@@ -655,10 +671,11 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}",
             expected_struct in result_types or expected_struct in tuple_types) and not is_free
         impl_on_utils = not impl_on_struct and (not is_free and not method_name.endswith("_clone") and
             not method_name.startswith("TxOut") and not method_name.startswith("TxIn") and
             expected_struct in result_types or expected_struct in tuple_types) and not is_free
         impl_on_utils = not impl_on_struct and (not is_free and not method_name.endswith("_clone") and
             not method_name.startswith("TxOut") and not method_name.startswith("TxIn") and
-            not method_name.startswith("BigEndianScalar") and not method_name.startswith("_") and
+            not method_name.startswith("BigEndianScalar") and not method_name.startswith("WitnessProgram") and
+            not method_name.startswith("_") and
             method_name != "check_platform" and method_name != "Result_read" and
             not expected_struct in unitary_enums and
             method_name != "check_platform" and method_name != "Result_read" and
             not expected_struct in unitary_enums and
-            ((not method_name.startswith("C2Tuple_") and not method_name.startswith("C3Tuple_"))
+            ((not method_name.startswith("C2Tuple_") and not method_name.startswith("C3Tuple_") and not method_name.startswith("C4Tuple_"))
               or method_name.endswith("_read")))
 
         # If we're adding a static method, and it returns a primitive or an array of primitives,
               or method_name.endswith("_read")))
 
         # If we're adding a static method, and it returns a primitive or an array of primitives,
@@ -901,7 +918,7 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}",
         map_fn_with_ref_option(dummy_line, reg_fn_regex.match(dummy_line), None, None, "", holds_ref)
 
     def map_tuple(struct_name, field_lines):
         map_fn_with_ref_option(dummy_line, reg_fn_regex.match(dummy_line), None, None, "", holds_ref)
 
     def map_tuple(struct_name, field_lines):
-        human_ty = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple")
+        human_ty = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDKC4Tuple", "FourTuple")
         with open(f"{sys.argv[3]}/structs/{human_ty}{consts.file_ext}", "w") as out_java_struct:
             out_java_struct.write(consts.map_tuple(struct_name))
             ty_list = []
         with open(f"{sys.argv[3]}/structs/{human_ty}{consts.file_ext}", "w") as out_java_struct:
             out_java_struct.write(consts.map_tuple(struct_name))
             ty_list = []
@@ -1000,7 +1017,7 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}",
                         vec_ty_match = line_indicates_vec_regex.match(struct_line)
                         if vec_ty_match is not None and struct_name.startswith("LDKCVec_"):
                             vec_ty = vec_ty_match.group(2)
                         vec_ty_match = line_indicates_vec_regex.match(struct_line)
                         if vec_ty_match is not None and struct_name.startswith("LDKCVec_"):
                             vec_ty = vec_ty_match.group(2)
-                        elif struct_name.startswith("LDKC2Tuple_") or struct_name.startswith("LDKC3Tuple_"):
+                        elif struct_name.startswith("LDKC2Tuple_") or struct_name.startswith("LDKC3Tuple_") or struct_name.startswith("LDKC4Tuple_"):
                             is_tuple = True
                         trait_fn_match = line_indicates_trait_regex.match(struct_line)
                         if trait_fn_match is not None:
                             is_tuple = True
                         trait_fn_match = line_indicates_trait_regex.match(struct_line)
                         if trait_fn_match is not None:
@@ -1099,46 +1116,11 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}",
                         out_java_struct.write(consts.hu_struct_file_prefix)
                         out_java_struct.write(consts.txout_defn)
                         out_java_struct.write(consts.hu_struct_file_suffix)
                         out_java_struct.write(consts.hu_struct_file_prefix)
                         out_java_struct.write(consts.txout_defn)
                         out_java_struct.write(consts.hu_struct_file_suffix)
-                        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);")
-                        write_c("}")
-                        map_fn(fn_line + "\n", re.compile("(.*) (TxOut_get_script_pubkey) \((.*)\)").match(fn_line), None, None, None)
-                        fn_line = "uint64_t TxOut_get_value (struct LDKTxOut* thing)"
-                        write_c(fn_line + " {")
-                        write_c("\treturn thing->value;")
-                        write_c("}")
-                        map_fn(fn_line + "\n", re.compile("(.*) (TxOut_get_value) \((.*)\)").match(fn_line), None, None, None)
                 elif struct_name == "LDKTxIn":
                     with open(f"{sys.argv[3]}/structs/TxIn{consts.file_ext}", "w") as out_java_struct:
                         out_java_struct.write(consts.hu_struct_file_prefix)
                         out_java_struct.write(consts.txin_defn)
                         out_java_struct.write(consts.hu_struct_file_suffix)
                 elif struct_name == "LDKTxIn":
                     with open(f"{sys.argv[3]}/structs/TxIn{consts.file_ext}", "w") as out_java_struct:
                         out_java_struct.write(consts.hu_struct_file_prefix)
                         out_java_struct.write(consts.txin_defn)
                         out_java_struct.write(consts.hu_struct_file_suffix)
-                        fn_line = "struct LDKWitness TxIn_get_witness (struct LDKTxIn* thing)"
-                        write_c(fn_line + " {")
-                        write_c("\treturn Witness_clone(&thing->witness);")
-                        write_c("}")
-                        map_fn(fn_line + "\n", re.compile("(.*) (TxIn_get_witness) \((.*)\)").match(fn_line), None, None, None)
-                        fn_line = "struct LDKCVec_u8Z TxIn_get_script_sig (struct LDKTxIn* thing)"
-                        write_c(fn_line + " {")
-                        write_c("\treturn CVec_u8Z_clone(&thing->script_sig);")
-                        write_c("}")
-                        map_fn(fn_line + "\n", re.compile("(.*) (TxIn_get_script_sig) \((.*)\)").match(fn_line), None, None, None)
-                        fn_line = "LDKThirtyTwoBytes TxIn_get_previous_txid (struct LDKTxIn* thing)"
-                        write_c(fn_line + " {")
-                        write_c("\treturn thing->previous_txid;")
-                        write_c("}")
-                        map_fn(fn_line + "\n", re.compile("(.*) (TxIn_get_previous_txid) \((.*)\)").match(fn_line), None, None, None)
-                        fn_line = "uint32_t TxIn_get_previous_vout (struct LDKTxIn* thing)"
-                        write_c(fn_line + " {")
-                        write_c("\treturn thing->previous_vout;")
-                        write_c("}")
-                        map_fn(fn_line + "\n", re.compile("(.*) (TxIn_get_previous_vout) \((.*)\)").match(fn_line), None, None, None)
-                        fn_line = "uint32_t TxIn_get_sequence (struct LDKTxIn* thing)"
-                        write_c(fn_line + " {")
-                        write_c("\treturn thing->sequence;")
-                        write_c("}")
-                        map_fn(fn_line + "\n", re.compile("(.*) (TxIn_get_sequence) \((.*)\)").match(fn_line), None, None, None)
                 elif struct_name == "LDKBigEndianScalar":
                     with open(f"{sys.argv[3]}/structs/BigEndianScalar{consts.file_ext}", "w") as out_java_struct:
                         out_java_struct.write(consts.hu_struct_file_prefix)
                 elif struct_name == "LDKBigEndianScalar":
                     with open(f"{sys.argv[3]}/structs/BigEndianScalar{consts.file_ext}", "w") as out_java_struct:
                         out_java_struct.write(consts.hu_struct_file_prefix)
@@ -1159,6 +1141,11 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}",
                         fn_line = "static void BigEndianScalar_free (struct LDKBigEndianScalar thing)"
                         write_c(fn_line + " {}\n")
                         map_fn(fn_line + "\n", re.compile("static (.*) (BigEndianScalar_free) \((.*)\)").match(fn_line), None, None, None)
                         fn_line = "static void BigEndianScalar_free (struct LDKBigEndianScalar thing)"
                         write_c(fn_line + " {}\n")
                         map_fn(fn_line + "\n", re.compile("static (.*) (BigEndianScalar_free) \((.*)\)").match(fn_line), None, None, None)
+                elif struct_name == "LDKWitnessProgram":
+                    with open(f"{sys.argv[3]}/structs/WitnessProgram{consts.file_ext}", "w") as out_java_struct:
+                        out_java_struct.write(consts.hu_struct_file_prefix)
+                        out_java_struct.write(consts.witness_program_defn)
+                        out_java_struct.write(consts.hu_struct_file_suffix)
                 else:
                     pass # Everything remaining is a byte[] of some form
                 cur_block_obj = None
                 else:
                     pass # Everything remaining is a byte[] of some form
                 cur_block_obj = None
@@ -1208,7 +1195,7 @@ with open(sys.argv[1]) as in_h, open(f"{sys.argv[2]}/bindings{consts.file_ext}",
         with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDKCResult', 'Result')}{consts.file_ext}", "a") as out_java_struct:
             out_java_struct.write("}\n" + consts.hu_struct_file_suffix)
     for struct_name in tuple_types:
         with open(f"{sys.argv[3]}/structs/{struct_name.replace('LDKCResult', 'Result')}{consts.file_ext}", "a") as out_java_struct:
             out_java_struct.write("}\n" + consts.hu_struct_file_suffix)
     for struct_name in tuple_types:
-        struct_hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple")
+        struct_hu_name = struct_name.replace("LDKC2Tuple", "TwoTuple").replace("LDKC3Tuple", "ThreeTuple").replace("LDKC4Tuple", "FourTuple")
         with open(f"{sys.argv[3]}/structs/{struct_hu_name}{consts.file_ext}", "a") as out_java_struct:
             out_java_struct.write("}\n" + consts.hu_struct_file_suffix)
 
         with open(f"{sys.argv[3]}/structs/{struct_hu_name}{consts.file_ext}", "a") as out_java_struct:
             out_java_struct.write("}\n" + consts.hu_struct_file_suffix)