]> git.bitcoin.ninja Git - ldk-java/commitdiff
Move enums into their own (non-impl) folder
authorMatt Corallo <git@bluematt.me>
Wed, 7 Oct 2020 21:39:05 +0000 (17:39 -0400)
committerMatt Corallo <git@bluematt.me>
Wed, 7 Oct 2020 22:15:06 +0000 (18:15 -0400)
13 files changed:
genbindings.py
genbindings.sh
src/main/java/org/ldk/enums/LDKAccessError.java [new file with mode: 0644]
src/main/java/org/ldk/enums/LDKChannelMonitorUpdateErr.java [new file with mode: 0644]
src/main/java/org/ldk/enums/LDKConfirmationTarget.java [new file with mode: 0644]
src/main/java/org/ldk/enums/LDKLevel.java [new file with mode: 0644]
src/main/java/org/ldk/enums/LDKNetwork.java [new file with mode: 0644]
src/main/java/org/ldk/enums/LDKSecp256k1Error.java [new file with mode: 0644]
src/main/java/org/ldk/impl/bindings.java
src/main/jni/bindings.c
src/main/jni/org_ldk_impl_bindings.h
src/test/java/org/ldk/ManualMsgHandlingPeerTest.java
src/test/java/org/ldk/PeerTest.java

index a9d91be801b3a1c6bd32481ad12ed05ce22b89e7..d9999d963516d923377cbb821bc887cd1e03c78d 100755 (executable)
@@ -1,8 +1,8 @@
 #!/usr/bin/env python3
 import sys, re
 
-if len(sys.argv) != 5:
-    print("USAGE: /path/to/lightning.h /path/to/bindings/output.java /path/to/bindings/output.c debug")
+if len(sys.argv) != 6:
+    print("USAGE: /path/to/lightning.h /path/to/bindings/output.java /path/to/bindings/enums/ /path/to/bindings/output.c debug")
     print("debug should be true or false and indicates whether to track allocations and ensure we don't leak")
     sys.exit(1)
 
@@ -43,7 +43,7 @@ class ConvInfo:
             out_java.write(" arg")
             out_c.write(" arg")
 
-with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.argv[3], "w") as out_c:
+with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.argv[4], "w") as out_c:
     opaque_structs = set()
     trait_structs = set()
     unitary_enums = set()
@@ -105,7 +105,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
             if ma.group(1).strip() in unitary_enums:
                 java_ty = ma.group(1).strip()
                 c_ty = "jclass"
-                fn_ty_arg = "Lorg/ldk/impl/bindings$" + ma.group(1).strip() + ";"
+                fn_ty_arg = "Lorg/ldk/enums/" + ma.group(1).strip() + ";"
                 fn_arg = ma.group(2).strip()
                 rust_obj = ma.group(1).strip()
                 take_by_ptr = True
@@ -528,6 +528,7 @@ void __attribute__((destructor)) check_leaks() {
 }
 """)
     out_java.write("""package org.ldk.impl;
+import org.ldk.enums.*;
 
 public class bindings {
        public static class VecOrSliceDef {
@@ -700,11 +701,13 @@ _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen),
                         field_lines.append(struct_line)
 
                 assert(struct_name is not None)
-                assert(len(trait_fn_lines) == 0 or not (is_opaque or is_unitary_enum or is_union_enum or is_union))
-                assert(not is_opaque or not (len(trait_fn_lines) != 0 or is_unitary_enum or is_union_enum or is_union))
-                assert(not is_unitary_enum or not (len(trait_fn_lines) != 0 or is_opaque or is_union_enum or is_union))
-                assert(not is_union_enum or not (len(trait_fn_lines) != 0 or is_unitary_enum or is_opaque or is_union))
-                assert(not is_union or not (len(trait_fn_lines) != 0 or is_unitary_enum or is_union_enum or is_opaque))
+                assert(len(trait_fn_lines) == 0 or not (is_opaque or is_unitary_enum or is_union_enum or is_union or is_result or vec_ty is not None))
+                assert(not is_opaque or not (len(trait_fn_lines) != 0 or is_unitary_enum or is_union_enum or is_union or is_result or vec_ty is not None))
+                assert(not is_unitary_enum or not (len(trait_fn_lines) != 0 or is_opaque or is_union_enum or is_union or is_result or vec_ty is not None))
+                assert(not is_union_enum or not (len(trait_fn_lines) != 0 or is_unitary_enum or is_opaque or is_union or is_result or vec_ty is not None))
+                assert(not is_union or not (len(trait_fn_lines) != 0 or is_unitary_enum or is_union_enum or is_opaque or is_result or vec_ty is not None))
+                assert(not is_result or not (len(trait_fn_lines) != 0 or is_unitary_enum or is_union_enum or is_opaque or is_union or vec_ty is not None))
+                assert(vec_ty is None or not (len(trait_fn_lines) != 0 or is_unitary_enum or is_union_enum or is_opaque or is_union or is_result))
                 if is_opaque:
                     opaque_structs.add(struct_name)
                     out_java.write("\tpublic static native long " + struct_name + "_optional_none();\n")
@@ -722,45 +725,47 @@ _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen),
                     out_c.write("\treturn (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(" + vec_ty + "));\n")
                     out_c.write("}\n")
                 elif is_unitary_enum:
-                    unitary_enums.add(struct_name)
-                    out_c.write("static inline " + struct_name + " " + struct_name + "_from_java(JNIEnv *env, jclass val) {\n")
-                    out_c.write("\tswitch ((*env)->CallIntMethod(env, val, ordinal_meth)) {\n")
-                    ord_v = 0
-                    for idx, struct_line in enumerate(field_lines):
-                        if idx == 0:
-                            out_java.write("\tpublic enum " + struct_name + " {\n")
-                        elif idx == len(field_lines) - 3:
-                            assert(struct_line.endswith("_Sentinel,"))
-                        elif idx == len(field_lines) - 2:
-                            out_java.write("\t}\n")
-                        elif idx == len(field_lines) - 1:
-                            assert(struct_line == "")
-                        else:
-                            out_java.write("\t" + struct_line + "\n")
-                            out_c.write("\t\tcase %d: return %s;\n" % (ord_v, struct_line.strip().strip(",")))
-                            ord_v = ord_v + 1
-                    out_c.write("\t}\n")
-                    out_c.write("\tabort();\n")
-                    out_c.write("}\n")
-
-                    ord_v = 0
-                    out_c.write("static inline jclass " + struct_name + "_to_java(JNIEnv *env, " + struct_name + " val) {\n")
-                    out_c.write("\t// TODO: This is pretty inefficient, we really need to cache the field IDs and class\n")
-                    out_c.write("\tjclass enum_class = (*env)->FindClass(env, \"Lorg/ldk/impl/bindings$" + struct_name + ";\");\n")
-                    out_c.write("\tDO_ASSERT(enum_class != NULL);\n")
-                    out_c.write("\tswitch (val) {\n")
-                    for idx, struct_line in enumerate(field_lines):
-                        if idx > 0 and idx < len(field_lines) - 3:
-                            variant = struct_line.strip().strip(",")
-                            out_c.write("\t\tcase " + variant + ": {\n")
-                            out_c.write("\t\t\tjfieldID field = (*env)->GetStaticFieldID(env, enum_class, \"" + variant + "\", \"Lorg/ldk/impl/bindings$" + struct_name + ";\");\n")
-                            out_c.write("\t\t\tDO_ASSERT(field != NULL);\n")
-                            out_c.write("\t\t\treturn (*env)->GetStaticObjectField(env, enum_class, field);\n")
-                            out_c.write("\t\t}\n")
-                            ord_v = ord_v + 1
-                    out_c.write("\t\tdefault: abort();\n")
-                    out_c.write("\t}\n")
-                    out_c.write("}\n\n")
+                    with open(sys.argv[3] + "/" + struct_name + ".java", "w") as out_java_enum:
+                        out_java_enum.write("package org.ldk.enums;\n\n")
+                        unitary_enums.add(struct_name)
+                        out_c.write("static inline " + struct_name + " " + struct_name + "_from_java(JNIEnv *env, jclass val) {\n")
+                        out_c.write("\tswitch ((*env)->CallIntMethod(env, val, ordinal_meth)) {\n")
+                        ord_v = 0
+                        for idx, struct_line in enumerate(field_lines):
+                            if idx == 0:
+                                out_java_enum.write("public enum " + struct_name + " {\n")
+                            elif idx == len(field_lines) - 3:
+                                assert(struct_line.endswith("_Sentinel,"))
+                            elif idx == len(field_lines) - 2:
+                                out_java_enum.write("}")
+                            elif idx == len(field_lines) - 1:
+                                assert(struct_line == "")
+                            else:
+                                out_java_enum.write(struct_line + "\n")
+                                out_c.write("\t\tcase %d: return %s;\n" % (ord_v, struct_line.strip().strip(",")))
+                                ord_v = ord_v + 1
+                        out_c.write("\t}\n")
+                        out_c.write("\tabort();\n")
+                        out_c.write("}\n")
+
+                        ord_v = 0
+                        out_c.write("static inline jclass " + struct_name + "_to_java(JNIEnv *env, " + struct_name + " val) {\n")
+                        out_c.write("\t// TODO: This is pretty inefficient, we really need to cache the field IDs and class\n")
+                        out_c.write("\tjclass enum_class = (*env)->FindClass(env, \"Lorg/ldk/enums/" + struct_name + ";\");\n")
+                        out_c.write("\tDO_ASSERT(enum_class != NULL);\n")
+                        out_c.write("\tswitch (val) {\n")
+                        for idx, struct_line in enumerate(field_lines):
+                            if idx > 0 and idx < len(field_lines) - 3:
+                                variant = struct_line.strip().strip(",")
+                                out_c.write("\t\tcase " + variant + ": {\n")
+                                out_c.write("\t\t\tjfieldID field = (*env)->GetStaticFieldID(env, enum_class, \"" + variant + "\", \"Lorg/ldk/enums/" + struct_name + ";\");\n")
+                                out_c.write("\t\t\tDO_ASSERT(field != NULL);\n")
+                                out_c.write("\t\t\treturn (*env)->GetStaticObjectField(env, enum_class, field);\n")
+                                out_c.write("\t\t}\n")
+                                ord_v = ord_v + 1
+                        out_c.write("\t\tdefault: abort();\n")
+                        out_c.write("\t}\n")
+                        out_c.write("}\n\n")
                 elif len(trait_fn_lines) > 0:
                     trait_structs.add(struct_name)
                     map_trait(struct_name, field_var_lines, trait_fn_lines)
index ab04c9cefd4da1a6b92952e151b4d8dc46e1c87f..567638797c505f269157e3bbd43a461a28e368df 100755 (executable)
@@ -9,9 +9,11 @@ usage() {
 [ "$3" != "true" -a "$3" != "false" ] && usage
 
 set -e
-./genbindings.py "$1/lightning-c-bindings/include/lightning.h" src/main/java/org/ldk/impl/bindings.java src/main/jni/bindings.c $3
-javac -h src/main/jni src/main/java/org/ldk/impl/bindings.java
-rm src/main/java/org/ldk/impl/bindings*.class
+mkdir -p src/main/java/org/ldk/enums
+rm -f src/main/java/org/ldk/enums/*.java
+./genbindings.py "$1/lightning-c-bindings/include/lightning.h" src/main/java/org/ldk/impl/bindings.java src/main/java/org/ldk/enums src/main/jni/bindings.c $3
+javac -h src/main/jni src/main/java/org/ldk/enums/*.java src/main/java/org/ldk/impl/bindings.java
+rm src/main/java/org/ldk/enums/*.class src/main/java/org/ldk/impl/bindings*.class
 COMPILE="clang -std=c11 -Wall -Wno-unused-function -Wl,--no-undefined -pthread -ldl -o liblightningjni.so -shared -fPIC -Wno-pointer-sign -Isrc/main/jni"
 if [ "$3" = "true" ]; then
        $COMPILE -g -fsanitize=address -shared-libasan -I"$1"/lightning-c-bindings/include/ $2 src/main/jni/bindings.c "$1"/lightning-c-bindings/target/debug/libldk.a
diff --git a/src/main/java/org/ldk/enums/LDKAccessError.java b/src/main/java/org/ldk/enums/LDKAccessError.java
new file mode 100644 (file)
index 0000000..35f4cfe
--- /dev/null
@@ -0,0 +1,6 @@
+package org.ldk.enums;
+
+public enum LDKAccessError {
+   LDKAccessError_UnknownChain,
+   LDKAccessError_UnknownTx,
+}
\ No newline at end of file
diff --git a/src/main/java/org/ldk/enums/LDKChannelMonitorUpdateErr.java b/src/main/java/org/ldk/enums/LDKChannelMonitorUpdateErr.java
new file mode 100644 (file)
index 0000000..b46efad
--- /dev/null
@@ -0,0 +1,6 @@
+package org.ldk.enums;
+
+public enum LDKChannelMonitorUpdateErr {
+   LDKChannelMonitorUpdateErr_TemporaryFailure,
+   LDKChannelMonitorUpdateErr_PermanentFailure,
+}
\ No newline at end of file
diff --git a/src/main/java/org/ldk/enums/LDKConfirmationTarget.java b/src/main/java/org/ldk/enums/LDKConfirmationTarget.java
new file mode 100644 (file)
index 0000000..2a5be54
--- /dev/null
@@ -0,0 +1,7 @@
+package org.ldk.enums;
+
+public enum LDKConfirmationTarget {
+   LDKConfirmationTarget_Background,
+   LDKConfirmationTarget_Normal,
+   LDKConfirmationTarget_HighPriority,
+}
\ No newline at end of file
diff --git a/src/main/java/org/ldk/enums/LDKLevel.java b/src/main/java/org/ldk/enums/LDKLevel.java
new file mode 100644 (file)
index 0000000..f947ee2
--- /dev/null
@@ -0,0 +1,10 @@
+package org.ldk.enums;
+
+public enum LDKLevel {
+   LDKLevel_Off,
+   LDKLevel_Error,
+   LDKLevel_Warn,
+   LDKLevel_Info,
+   LDKLevel_Debug,
+   LDKLevel_Trace,
+}
\ No newline at end of file
diff --git a/src/main/java/org/ldk/enums/LDKNetwork.java b/src/main/java/org/ldk/enums/LDKNetwork.java
new file mode 100644 (file)
index 0000000..38eb2b2
--- /dev/null
@@ -0,0 +1,7 @@
+package org.ldk.enums;
+
+public enum LDKNetwork {
+   LDKNetwork_Bitcoin,
+   LDKNetwork_Testnet,
+   LDKNetwork_Regtest,
+}
\ No newline at end of file
diff --git a/src/main/java/org/ldk/enums/LDKSecp256k1Error.java b/src/main/java/org/ldk/enums/LDKSecp256k1Error.java
new file mode 100644 (file)
index 0000000..4857a95
--- /dev/null
@@ -0,0 +1,13 @@
+package org.ldk.enums;
+
+public enum LDKSecp256k1Error {
+   LDKSecp256k1Error_IncorrectSignature,
+   LDKSecp256k1Error_InvalidMessage,
+   LDKSecp256k1Error_InvalidPublicKey,
+   LDKSecp256k1Error_InvalidSignature,
+   LDKSecp256k1Error_InvalidSecretKey,
+   LDKSecp256k1Error_InvalidRecoveryId,
+   LDKSecp256k1Error_InvalidTweak,
+   LDKSecp256k1Error_NotEnoughMemory,
+   LDKSecp256k1Error_CallbackPanicked,
+}
\ No newline at end of file
index 5a39627796a2368a1ff2ee9a26184133dab79493..cdf23173e53bb327ec417186273d0823ee076833 100644 (file)
@@ -1,4 +1,5 @@
 package org.ldk.impl;
+import org.ldk.enums.*;
 
 public class bindings {
        public static class VecOrSliceDef {
@@ -25,43 +26,6 @@ public class bindings {
 
        public static native long LDKSecretKey_new();
 
-       public enum LDKAccessError {
-          LDKAccessError_UnknownChain,
-          LDKAccessError_UnknownTx,
-       }
-       public enum LDKChannelMonitorUpdateErr {
-          LDKChannelMonitorUpdateErr_TemporaryFailure,
-          LDKChannelMonitorUpdateErr_PermanentFailure,
-       }
-       public enum LDKConfirmationTarget {
-          LDKConfirmationTarget_Background,
-          LDKConfirmationTarget_Normal,
-          LDKConfirmationTarget_HighPriority,
-       }
-       public enum LDKLevel {
-          LDKLevel_Off,
-          LDKLevel_Error,
-          LDKLevel_Warn,
-          LDKLevel_Info,
-          LDKLevel_Debug,
-          LDKLevel_Trace,
-       }
-       public enum LDKNetwork {
-          LDKNetwork_Bitcoin,
-          LDKNetwork_Testnet,
-          LDKNetwork_Regtest,
-       }
-       public enum LDKSecp256k1Error {
-          LDKSecp256k1Error_IncorrectSignature,
-          LDKSecp256k1Error_InvalidMessage,
-          LDKSecp256k1Error_InvalidPublicKey,
-          LDKSecp256k1Error_InvalidSignature,
-          LDKSecp256k1Error_InvalidSecretKey,
-          LDKSecp256k1Error_InvalidRecoveryId,
-          LDKSecp256k1Error_InvalidTweak,
-          LDKSecp256k1Error_NotEnoughMemory,
-          LDKSecp256k1Error_CallbackPanicked,
-       }
        public static native VecOrSliceDef LDKCVecTempl_u8_arr_info(long vec_ptr);
        public static native boolean LDKCResult_NoneChannelMonitorUpdateErrZ_result_ok(long arg);
        public static native long LDKCResult_NoneChannelMonitorUpdateErrZ_get_inner(long arg);
index 6a6b8c81c6659164238ad8129691800c418be6c6..7b83eff6f416bd8582f1303e8865f176540ec5b7 100644 (file)
@@ -122,16 +122,16 @@ static inline LDKAccessError LDKAccessError_from_java(JNIEnv *env, jclass val) {
 }
 static inline jclass LDKAccessError_to_java(JNIEnv *env, LDKAccessError val) {
        // TODO: This is pretty inefficient, we really need to cache the field IDs and class
-       jclass enum_class = (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKAccessError;");
+       jclass enum_class = (*env)->FindClass(env, "Lorg/ldk/enums/LDKAccessError;");
        DO_ASSERT(enum_class != NULL);
        switch (val) {
                case LDKAccessError_UnknownChain: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKAccessError_UnknownChain", "Lorg/ldk/impl/bindings$LDKAccessError;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKAccessError_UnknownChain", "Lorg/ldk/enums/LDKAccessError;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKAccessError_UnknownTx: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKAccessError_UnknownTx", "Lorg/ldk/impl/bindings$LDKAccessError;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKAccessError_UnknownTx", "Lorg/ldk/enums/LDKAccessError;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
@@ -148,16 +148,16 @@ static inline LDKChannelMonitorUpdateErr LDKChannelMonitorUpdateErr_from_java(JN
 }
 static inline jclass LDKChannelMonitorUpdateErr_to_java(JNIEnv *env, LDKChannelMonitorUpdateErr val) {
        // TODO: This is pretty inefficient, we really need to cache the field IDs and class
-       jclass enum_class = (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKChannelMonitorUpdateErr;");
+       jclass enum_class = (*env)->FindClass(env, "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
        DO_ASSERT(enum_class != NULL);
        switch (val) {
                case LDKChannelMonitorUpdateErr_TemporaryFailure: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKChannelMonitorUpdateErr_TemporaryFailure", "Lorg/ldk/impl/bindings$LDKChannelMonitorUpdateErr;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKChannelMonitorUpdateErr_TemporaryFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKChannelMonitorUpdateErr_PermanentFailure: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKChannelMonitorUpdateErr_PermanentFailure", "Lorg/ldk/impl/bindings$LDKChannelMonitorUpdateErr;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKChannelMonitorUpdateErr_PermanentFailure", "Lorg/ldk/enums/LDKChannelMonitorUpdateErr;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
@@ -175,21 +175,21 @@ static inline LDKConfirmationTarget LDKConfirmationTarget_from_java(JNIEnv *env,
 }
 static inline jclass LDKConfirmationTarget_to_java(JNIEnv *env, LDKConfirmationTarget val) {
        // TODO: This is pretty inefficient, we really need to cache the field IDs and class
-       jclass enum_class = (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKConfirmationTarget;");
+       jclass enum_class = (*env)->FindClass(env, "Lorg/ldk/enums/LDKConfirmationTarget;");
        DO_ASSERT(enum_class != NULL);
        switch (val) {
                case LDKConfirmationTarget_Background: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKConfirmationTarget_Background", "Lorg/ldk/impl/bindings$LDKConfirmationTarget;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKConfirmationTarget_Background", "Lorg/ldk/enums/LDKConfirmationTarget;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKConfirmationTarget_Normal: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKConfirmationTarget_Normal", "Lorg/ldk/impl/bindings$LDKConfirmationTarget;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKConfirmationTarget_Normal", "Lorg/ldk/enums/LDKConfirmationTarget;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKConfirmationTarget_HighPriority: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKConfirmationTarget_HighPriority", "Lorg/ldk/impl/bindings$LDKConfirmationTarget;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKConfirmationTarget_HighPriority", "Lorg/ldk/enums/LDKConfirmationTarget;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
@@ -210,36 +210,36 @@ static inline LDKLevel LDKLevel_from_java(JNIEnv *env, jclass val) {
 }
 static inline jclass LDKLevel_to_java(JNIEnv *env, LDKLevel val) {
        // TODO: This is pretty inefficient, we really need to cache the field IDs and class
-       jclass enum_class = (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKLevel;");
+       jclass enum_class = (*env)->FindClass(env, "Lorg/ldk/enums/LDKLevel;");
        DO_ASSERT(enum_class != NULL);
        switch (val) {
                case LDKLevel_Off: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKLevel_Off", "Lorg/ldk/impl/bindings$LDKLevel;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKLevel_Off", "Lorg/ldk/enums/LDKLevel;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKLevel_Error: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKLevel_Error", "Lorg/ldk/impl/bindings$LDKLevel;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKLevel_Error", "Lorg/ldk/enums/LDKLevel;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKLevel_Warn: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKLevel_Warn", "Lorg/ldk/impl/bindings$LDKLevel;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKLevel_Warn", "Lorg/ldk/enums/LDKLevel;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKLevel_Info: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKLevel_Info", "Lorg/ldk/impl/bindings$LDKLevel;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKLevel_Info", "Lorg/ldk/enums/LDKLevel;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKLevel_Debug: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKLevel_Debug", "Lorg/ldk/impl/bindings$LDKLevel;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKLevel_Debug", "Lorg/ldk/enums/LDKLevel;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKLevel_Trace: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKLevel_Trace", "Lorg/ldk/impl/bindings$LDKLevel;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKLevel_Trace", "Lorg/ldk/enums/LDKLevel;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
@@ -257,21 +257,21 @@ static inline LDKNetwork LDKNetwork_from_java(JNIEnv *env, jclass val) {
 }
 static inline jclass LDKNetwork_to_java(JNIEnv *env, LDKNetwork val) {
        // TODO: This is pretty inefficient, we really need to cache the field IDs and class
-       jclass enum_class = (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKNetwork;");
+       jclass enum_class = (*env)->FindClass(env, "Lorg/ldk/enums/LDKNetwork;");
        DO_ASSERT(enum_class != NULL);
        switch (val) {
                case LDKNetwork_Bitcoin: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKNetwork_Bitcoin", "Lorg/ldk/impl/bindings$LDKNetwork;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKNetwork_Bitcoin", "Lorg/ldk/enums/LDKNetwork;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKNetwork_Testnet: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKNetwork_Testnet", "Lorg/ldk/impl/bindings$LDKNetwork;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKNetwork_Testnet", "Lorg/ldk/enums/LDKNetwork;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKNetwork_Regtest: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKNetwork_Regtest", "Lorg/ldk/impl/bindings$LDKNetwork;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKNetwork_Regtest", "Lorg/ldk/enums/LDKNetwork;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
@@ -295,51 +295,51 @@ static inline LDKSecp256k1Error LDKSecp256k1Error_from_java(JNIEnv *env, jclass
 }
 static inline jclass LDKSecp256k1Error_to_java(JNIEnv *env, LDKSecp256k1Error val) {
        // TODO: This is pretty inefficient, we really need to cache the field IDs and class
-       jclass enum_class = (*env)->FindClass(env, "Lorg/ldk/impl/bindings$LDKSecp256k1Error;");
+       jclass enum_class = (*env)->FindClass(env, "Lorg/ldk/enums/LDKSecp256k1Error;");
        DO_ASSERT(enum_class != NULL);
        switch (val) {
                case LDKSecp256k1Error_IncorrectSignature: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_IncorrectSignature", "Lorg/ldk/impl/bindings$LDKSecp256k1Error;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_IncorrectSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKSecp256k1Error_InvalidMessage: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_InvalidMessage", "Lorg/ldk/impl/bindings$LDKSecp256k1Error;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_InvalidMessage", "Lorg/ldk/enums/LDKSecp256k1Error;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKSecp256k1Error_InvalidPublicKey: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_InvalidPublicKey", "Lorg/ldk/impl/bindings$LDKSecp256k1Error;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_InvalidPublicKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKSecp256k1Error_InvalidSignature: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_InvalidSignature", "Lorg/ldk/impl/bindings$LDKSecp256k1Error;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_InvalidSignature", "Lorg/ldk/enums/LDKSecp256k1Error;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKSecp256k1Error_InvalidSecretKey: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_InvalidSecretKey", "Lorg/ldk/impl/bindings$LDKSecp256k1Error;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_InvalidSecretKey", "Lorg/ldk/enums/LDKSecp256k1Error;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKSecp256k1Error_InvalidRecoveryId: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_InvalidRecoveryId", "Lorg/ldk/impl/bindings$LDKSecp256k1Error;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_InvalidRecoveryId", "Lorg/ldk/enums/LDKSecp256k1Error;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKSecp256k1Error_InvalidTweak: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_InvalidTweak", "Lorg/ldk/impl/bindings$LDKSecp256k1Error;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_InvalidTweak", "Lorg/ldk/enums/LDKSecp256k1Error;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKSecp256k1Error_NotEnoughMemory: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_NotEnoughMemory", "Lorg/ldk/impl/bindings$LDKSecp256k1Error;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_NotEnoughMemory", "Lorg/ldk/enums/LDKSecp256k1Error;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
                case LDKSecp256k1Error_CallbackPanicked: {
-                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_CallbackPanicked", "Lorg/ldk/impl/bindings$LDKSecp256k1Error;");
+                       jfieldID field = (*env)->GetStaticFieldID(env, enum_class, "LDKSecp256k1Error_CallbackPanicked", "Lorg/ldk/enums/LDKSecp256k1Error;");
                        DO_ASSERT(field != NULL);
                        return (*env)->GetStaticObjectField(env, enum_class, field);
                }
@@ -1442,7 +1442,7 @@ static inline LDKFeeEstimator LDKFeeEstimator_init (JNIEnv * env, jclass _a, job
        atomic_init(&calls->refcnt, 1);
        DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
        calls->o = (*env)->NewGlobalRef(env, o);
-       calls->get_est_sat_per_1000_weight_meth = (*env)->GetMethodID(env, c, "get_est_sat_per_1000_weight", "(Lorg/ldk/impl/bindings$LDKConfirmationTarget;)I");
+       calls->get_est_sat_per_1000_weight_meth = (*env)->GetMethodID(env, c, "get_est_sat_per_1000_weight", "(Lorg/ldk/enums/LDKConfirmationTarget;)I");
        DO_ASSERT(calls->get_est_sat_per_1000_weight_meth != NULL);
 
        LDKFeeEstimator ret = {
index 9771fe2687cd5e5d5296232b08d1cd9289bd9eec..da0ba30a310e937f25f51452d025073455bf4f71 100644 (file)
@@ -842,7 +842,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1get_1obj_1
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    LDKFeeEstimator_call_get_est_sat_per_1000_weight
- * Signature: (JLorg/ldk/impl/bindings/LDKConfirmationTarget;)I
+ * Signature: (JLorg/ldk/enums/LDKConfirmationTarget;)I
  */
 JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1call_1get_1est_1sat_1per_11000_1weight
   (JNIEnv *, jclass, jlong, jobject);
@@ -1914,7 +1914,7 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NoneAPIErrorZ_1free
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    CResult_NoneChannelMonitorUpdateErrZ_err
- * Signature: (Lorg/ldk/impl/bindings/LDKChannelMonitorUpdateErr;)J
+ * Signature: (Lorg/ldk/enums/LDKChannelMonitorUpdateErr;)J
  */
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1NoneChannelMonitorUpdateErrZ_1err
   (JNIEnv *, jclass, jobject);
@@ -1978,7 +1978,7 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1NonePeerHandleErrorZ_
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    CResult_PublicKeySecpErrorZ_err
- * Signature: (Lorg/ldk/impl/bindings/LDKSecp256k1Error;)J
+ * Signature: (Lorg/ldk/enums/LDKSecp256k1Error;)J
  */
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1PublicKeySecpErrorZ_1err
   (JNIEnv *, jclass, jobject);
@@ -2026,7 +2026,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1RouteLightningErrorZ
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    CResult_SecretKeySecpErrorZ_err
- * Signature: (Lorg/ldk/impl/bindings/LDKSecp256k1Error;)J
+ * Signature: (Lorg/ldk/enums/LDKSecp256k1Error;)J
  */
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1err
   (JNIEnv *, jclass, jobject);
@@ -2066,7 +2066,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SignatureNoneZ_1ok
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    CResult_TxCreationKeysSecpErrorZ_err
- * Signature: (Lorg/ldk/impl/bindings/LDKSecp256k1Error;)J
+ * Signature: (Lorg/ldk/enums/LDKSecp256k1Error;)J
  */
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpErrorZ_1err
   (JNIEnv *, jclass, jobject);
@@ -2090,7 +2090,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxCreationKeysSecpEr
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    CResult_TxOutAccessErrorZ_err
- * Signature: (Lorg/ldk/impl/bindings/LDKAccessError;)J
+ * Signature: (Lorg/ldk/enums/LDKAccessError;)J
  */
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1TxOutAccessErrorZ_1err
   (JNIEnv *, jclass, jobject);
@@ -2546,7 +2546,7 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_APIError_1free
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    Level_max
- * Signature: ()Lorg/ldk/impl/bindings/LDKLevel;
+ * Signature: ()Lorg/ldk/enums/LDKLevel;
  */
 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_Level_1max
   (JNIEnv *, jclass);
@@ -3482,7 +3482,7 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_KeysManager_1free
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    KeysManager_new
- * Signature: ([BLorg/ldk/impl/bindings/LDKNetwork;JI)J
+ * Signature: ([BLorg/ldk/enums/LDKNetwork;JI)J
  */
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_KeysManager_1new
   (JNIEnv *, jclass, jbyteArray, jobject, jlong, jint);
@@ -3658,7 +3658,7 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PaymentSendFailure_1free
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    ChannelManager_new
- * Signature: (Lorg/ldk/impl/bindings/LDKNetwork;JJJJJJJ)J
+ * Signature: (Lorg/ldk/enums/LDKNetwork;JJJJJJJ)J
  */
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1new
   (JNIEnv *, jclass, jobject, jlong, jlong, jlong, jlong, jlong, jlong, jlong);
index 38c73682eb8070d0d758e168c0988667b8c174ef..552d9eee2379b62dbe7c1dbe3574d3f1460760e5 100644 (file)
@@ -2,6 +2,7 @@ package org.ldk;
 
 import org.junit.jupiter.api.Test;
 import org.ldk.impl.bindings;
+import org.ldk.enums.*;
 
 public class ManualMsgHandlingPeerTest {
     @Test
@@ -136,7 +137,7 @@ public class ManualMsgHandlingPeerTest {
         long peer_manager = bindings.PeerManager_new(message_handler, our_node_secret, random_data, logger);
 
         // Test Level_max() since its the only place we create a java object from a Rust-returned enum.
-        assert bindings.Level_max() == bindings.LDKLevel.LDKLevel_Trace;
+        assert bindings.Level_max() == LDKLevel.LDKLevel_Trace;
 
         // Note that we can't rely on finalizer order, so don't bother trying to rely on it here
         bindings.Logger_free(logger);
index dc07c90911b9586add6923acc68400af5e92892c..8ff630d75b04d5d8d2f944bbfcc02092b1a8e65f 100644 (file)
@@ -2,6 +2,7 @@ package org.ldk;
 
 import org.junit.jupiter.api.Test;
 import org.ldk.impl.bindings;
+import org.ldk.enums.*;
 
 import java.util.concurrent.ConcurrentLinkedQueue;
 
@@ -47,10 +48,10 @@ public class PeerTest {
 
             byte[] key_seed = new byte[32];
             for (byte i = 0; i < 32; i++) { key_seed[i] = (byte) (i ^ seed); }
-            this.keys = bindings.KeysManager_new(key_seed, bindings.LDKNetwork.LDKNetwork_Bitcoin, System.currentTimeMillis() / 1000, (int)(System.currentTimeMillis() * 1000) & 0xffffffff);
+            this.keys = bindings.KeysManager_new(key_seed, LDKNetwork.LDKNetwork_Bitcoin, System.currentTimeMillis() / 1000, (int)(System.currentTimeMillis() * 1000) & 0xffffffff);
             this.keys_interface = bindings.KeysManager_as_KeysInterface(keys);
             this.config = bindings.UserConfig_default();
-            this.chan_manager = bindings.ChannelManager_new(bindings.LDKNetwork.LDKNetwork_Bitcoin, fee_estimator, chain_monitor, tx_broadcaster, logger, keys_interface, config, 1);
+            this.chan_manager = bindings.ChannelManager_new(LDKNetwork.LDKNetwork_Bitcoin, fee_estimator, chain_monitor, tx_broadcaster, logger, keys_interface, config, 1);
             this.chan_manager_events = bindings.ChannelManager_as_EventsProvider(chan_manager);
 
             this.chan_handler = bindings.ChannelManager_as_ChannelMessageHandler(chan_manager);