Add a new manual type - UnqualifiedError/LDKError
authorMatt Corallo <git@bluematt.me>
Tue, 5 Apr 2022 18:07:12 +0000 (18:07 +0000)
committerMatt Corallo <git@bluematt.me>
Thu, 14 Apr 2022 14:44:09 +0000 (14:44 +0000)
gen_type_mapping.py
genbindings.py
src/main/java/org/ldk/util/UnqualifiedError.java [new file with mode: 0644]
typescript_strings.py

index 9cee9ab454773332293ae6711bf8b5b6e5e2159f..ad7d46fcfa5b8ce1628503f8e33fe6bac83c7b9e 100644 (file)
@@ -486,7 +486,15 @@ class TypeMappingGenerator:
                         to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_hu_conv", "new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ")") + ";" + to_hu_conv_sfx,
                         to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = from_hu_conv)
 
-                # The manually-defined types - TxOut and u5
+                # The manually-defined types - TxOut, u5, and Error
+                if ty_info.rust_obj == "LDKError":
+                    assert from_hu_conv is None
+                    return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
+                        arg_conv = "", arg_conv_name = "(LDKError){ ._dummy = 0 }", arg_conv_cleanup = None,
+                        ret_conv = ("/*", "*/"), ret_conv_name = "0",
+                        to_hu_conv = self.consts.var_decl_statement(ty_info.java_hu_ty, ty_info.var_name + "_conv", "new " + ty_info.java_hu_ty + "(" + ty_info.var_name + ")") + ";",
+                        to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = ("0", ""))
+
                 if ty_info.rust_obj == "LDKu5":
                     assert from_hu_conv is None
                     return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
index a3ea7d40c57052da323b53301ba1aac1c11fe8c5..2d69168ef89fef95411b4a608a9120c7e2cb323e 100755 (executable)
@@ -320,6 +320,14 @@ def java_c_types(fn_arg, ret_arr_len):
         fn_arg = fn_arg[6:].strip()
         arr_access = "chars"
         arr_len = "len"
+    elif fn_arg.startswith("LDKError ") or fn_arg == "LDKError":
+        java_ty = consts.c_type_map['uint32_t'][0]
+        java_hu_ty = "UnqualifiedError"
+        rust_obj = "LDKError"
+        c_ty = "int32_t"
+        arr_ty = "uint32_t"
+        fn_ty_arg = "I"
+        fn_arg = fn_arg[8:].strip()
     else:
         ma = var_ty_regex.match(fn_arg)
         arr_ty = ma.group(1).strip()
diff --git a/src/main/java/org/ldk/util/UnqualifiedError.java b/src/main/java/org/ldk/util/UnqualifiedError.java
new file mode 100644 (file)
index 0000000..9f6cc1f
--- /dev/null
@@ -0,0 +1,9 @@
+package org.ldk.util;
+
+/**
+ * An type for cases where no additional information is available.
+ * In general, if you've gotten this far the cause of the error should already be clear.
+ */
+public class UnqualifiedError {
+    public UnqualifiedError(int _dummy) {}
+}
index 76e43828913cc71225f65eebfab8d336a5c1a574..670eb2ae73124346a41e919247f43d601e12a63f 100644 (file)
@@ -326,6 +326,10 @@ export class UInt5 {
                return this.val;
        }
 }
+
+export class UnqualifiedError {
+       public constructor(val: number) {}
+}
 """
 
         self.txout_defn = """export class TxOut extends CommonBase {
@@ -592,7 +596,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, UnqualifiedError } from './CommonBase.mjs';
 import * as bindings from '../bindings.mjs'
 
 """