]> git.bitcoin.ninja Git - ldk-java/commitdiff
Skip fewer fn's, support trait-contained objects
authorMatt Corallo <git@bluematt.me>
Thu, 22 Oct 2020 21:33:42 +0000 (17:33 -0400)
committerMatt Corallo <git@bluematt.me>
Thu, 22 Oct 2020 21:33:42 +0000 (17:33 -0400)
genbindings.py
src/main/java/org/ldk/impl/bindings.java
src/main/java/org/ldk/structs/BroadcasterInterface.java
src/main/java/org/ldk/structs/ChannelKeys.java
src/main/java/org/ldk/structs/ChannelMessageHandler.java
src/main/java/org/ldk/structs/HolderCommitmentTransaction.java
src/main/java/org/ldk/structs/InMemoryChannelKeys.java
src/main/java/org/ldk/structs/LightningError.java
src/main/java/org/ldk/structs/RoutingMessageHandler.java
src/main/jni/bindings.c
src/main/jni/org_ldk_impl_bindings.h

index b09d930b4e03992063e579c32f094dc7936c7b3e..79e41fd9008118fd267796f18d8c36ce9e526e5f 100755 (executable)
@@ -767,9 +767,6 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                 arg_conv_info.print_name()
             if arg_conv_info.arg_name == "this_ptr" or arg_conv_info.arg_name == "this_arg":
                 takes_self = True
-            if arg_conv_info.passed_as_ptr and not arg_conv_info.rust_obj in opaque_structs:
-                if not arg_conv_info.rust_obj in trait_structs and not arg_conv_info.rust_obj in unitary_enums:
-                    args_known = False
             if arg_conv_info.arg_conv is not None and "Warning" in arg_conv_info.arg_conv:
                 if arg_conv_info.rust_obj in constructor_fns:
                     assert not is_free
@@ -1073,9 +1070,13 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
             out_c.write("\tatomic_size_t refcnt;\n")
             out_c.write("\tJavaVM *vm;\n")
             out_c.write("\tjweak o;\n")
+            field_var_convs = []
             for var_line in field_var_lines:
                 if var_line.group(1) in trait_structs:
                     out_c.write("\t" + var_line.group(1) + "_JCalls* " + var_line.group(2) + ";\n")
+                    field_var_convs.append(None)
+                else:
+                    field_var_convs.append(map_type(var_line.group(1) + " " + var_line.group(2), False, None, False, False))
             for fn_line in trait_fn_lines:
                 if fn_line.group(2) != "free" and fn_line.group(2) != "clone":
                     out_c.write("\tjmethodID " + fn_line.group(2) + "_meth;\n")
@@ -1086,16 +1087,27 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
             out_java_trait.write("\tfinal bindings." + struct_name + " bindings_instance;\n")
             out_java_trait.write("\t" + struct_name.replace("LDK", "") + "(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }\n")
             out_java_trait.write("\tprivate " + struct_name.replace("LDK", "") + "(bindings." + struct_name + " arg")
-            for var_line in field_var_lines:
+            for idx, var_line in enumerate(field_var_lines):
                 if var_line.group(1) in trait_structs:
                     out_java_trait.write(", bindings." + var_line.group(1) + " " + var_line.group(2))
+                else:
+                    out_java_trait.write(", " + field_var_convs[idx].java_hu_ty + " " + var_line.group(2))
             out_java_trait.write(") {\n")
             out_java_trait.write("\t\tsuper(bindings." + struct_name + "_new(arg")
-            for var_line in field_var_lines:
+            for idx, var_line in enumerate(field_var_lines):
                 if var_line.group(1) in trait_structs:
                     out_java_trait.write(", " + var_line.group(2))
+                elif field_var_convs[idx].from_hu_conv is not None:
+                    out_java_trait.write(", " + field_var_convs[idx].from_hu_conv[0])
+                else:
+                    out_java_trait.write(", " + var_line.group(2))
             out_java_trait.write("));\n")
             out_java_trait.write("\t\tthis.ptrs_to.add(arg);\n")
+            for idx, var_line in enumerate(field_var_lines):
+                if var_line.group(1) in trait_structs:
+                    out_java_trait.write("\t\tthis.ptrs_to.add(" + var_line.group(2) + ");\n")
+                elif field_var_convs[idx].from_hu_conv is not None and field_var_convs[idx].from_hu_conv[1] != "":
+                    out_java_trait.write("\t\t" + field_var_convs[idx].from_hu_conv[1] + ";\n")
             out_java_trait.write("\t\tthis.bindings_instance = arg;\n")
             out_java_trait.write("\t}\n")
             out_java_trait.write("\t@Override @SuppressWarnings(\"deprecation\")\n")
@@ -1104,11 +1116,13 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
             out_java_trait.write("\t}\n\n")
 
             java_trait_constr = "\tpublic " + struct_name.replace("LDK", "") + "(" + struct_name.replace("LDK", "") + "Interface arg"
-            for var_line in field_var_lines:
+            for idx, var_line in enumerate(field_var_lines):
                 if var_line.group(1) in trait_structs:
                     # Ideally we'd be able to take any instance of the interface, but our C code can only represent
                     # Java-implemented version, so we require users pass a Java implementation here :/
                     java_trait_constr = java_trait_constr + ", " + var_line.group(1).replace("LDK", "") + "." + var_line.group(1).replace("LDK", "") + "Interface " + var_line.group(2)
+                else:
+                    java_trait_constr = java_trait_constr + ", " + field_var_convs[idx].java_hu_ty + " " + var_line.group(2)
             java_trait_constr = java_trait_constr + ") {\n\t\tthis(new bindings." + struct_name + "() {\n"
             out_java_trait.write("\tpublic static interface " + struct_name.replace("LDK", "") + "Interface {\n")
             out_java.write("\tpublic interface " + struct_name + " {\n")
@@ -1220,6 +1234,8 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
             for var_line in field_var_lines:
                 if var_line.group(1) in trait_structs:
                     java_trait_constr = java_trait_constr + ", new " + var_line.group(2) + "(" + var_line.group(2) + ").bindings_instance"
+                else:
+                    java_trait_constr = java_trait_constr + ", " + var_line.group(2)
             out_java_trait.write("\t}\n")
             out_java_trait.write(java_trait_constr + ");\n\t}\n")
 
@@ -1237,10 +1253,13 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
 
             out_java.write("\tpublic static native long " + struct_name + "_new(" + struct_name + " impl")
             out_c.write("static inline " + struct_name + " " + struct_name + "_init (JNIEnv * env, jclass _a, jobject o")
-            for var_line in field_var_lines:
+            for idx, var_line in enumerate(field_var_lines):
                 if var_line.group(1) in trait_structs:
                     out_java.write(", " + var_line.group(1) + " " + var_line.group(2))
                     out_c.write(", jobject " + var_line.group(2))
+                else:
+                    out_java.write(", " + field_var_convs[idx].java_ty + " " + var_line.group(2))
+                    out_c.write(", " + field_var_convs[idx].c_ty + " " + var_line.group(2))
             out_java.write(");\n")
             out_c.write(") {\n")
 
@@ -1254,6 +1273,9 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                 if fn_line.group(2) != "free" and fn_line.group(2) != "clone":
                     out_c.write("\tcalls->" + fn_line.group(2) + "_meth = (*env)->GetMethodID(env, c, \"" + fn_line.group(2) + "\", \"" + java_meth_descr + "\");\n")
                     out_c.write("\tCHECK(calls->" + fn_line.group(2) + "_meth != NULL);\n")
+            for idx, var_line in enumerate(field_var_lines):
+                if field_var_convs[idx] is not None and field_var_convs[idx].arg_conv is not None:
+                    out_c.write("\n\t" + field_var_convs[idx].arg_conv.replace("\n", "\n\t") +"\n")
             out_c.write("\n\t" + struct_name + " ret = {\n")
             out_c.write("\t\t.this_arg = (void*) calls,\n")
             for fn_line in trait_fn_lines:
@@ -1264,9 +1286,15 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                 else:
                     clone_fns.add(struct_name + "_clone")
                     out_c.write("\t\t.clone = " + struct_name + "_JCalls_clone,\n")
-            for var_line in field_var_lines:
+            for idx, var_line in enumerate(field_var_lines):
                 if var_line.group(1) in trait_structs:
                     out_c.write("\t\t." + var_line.group(2) + " = " + var_line.group(1) + "_init(env, _a, " + var_line.group(2) + "),\n")
+                elif field_var_convs[idx].arg_conv_name is not None:
+                    out_c.write("\t\t." + var_line.group(2) + " = " + field_var_convs[idx].arg_conv_name + ",\n")
+                    out_c.write("\t\t.set_" + var_line.group(2) + " = NULL,\n")
+                else:
+                    out_c.write("\t\t." + var_line.group(2) + " = " + var_line.group(2) + ",\n")
+                    out_c.write("\t\t.set_" + var_line.group(2) + " = NULL,\n")
             out_c.write("\t};\n")
             for var_line in field_var_lines:
                 if var_line.group(1) in trait_structs:
@@ -1275,15 +1303,16 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
             out_c.write("}\n")
 
             out_c.write("JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_" + struct_name.replace("_", "_1") + "_1new (JNIEnv * env, jclass _a, jobject o")
-            for var_line in field_var_lines:
+            for idx, var_line in enumerate(field_var_lines):
                 if var_line.group(1) in trait_structs:
                     out_c.write(", jobject " + var_line.group(2))
+                else:
+                    out_c.write(", " + field_var_convs[idx].c_ty + " " + var_line.group(2))
             out_c.write(") {\n")
             out_c.write("\t" + struct_name + " *res_ptr = MALLOC(sizeof(" + struct_name + "), \"" + struct_name + "\");\n")
             out_c.write("\t*res_ptr = " + struct_name + "_init(env, _a, o")
             for var_line in field_var_lines:
-                if var_line.group(1) in trait_structs:
-                    out_c.write(", " + var_line.group(2))
+                out_c.write(", " + var_line.group(2))
             out_c.write(");\n")
             out_c.write("\treturn (long)res_ptr;\n")
             out_c.write("}\n")
@@ -1301,6 +1330,15 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
             if fn_line.group(2) != "free" and fn_line.group(2) != "clone" and fn_line.group(2) != "eq" and not is_log:
                 dummy_line = fn_line.group(1) + struct_name.replace("LDK", "") + "_" + fn_line.group(2) + " " + struct_name + "* this_arg" + fn_line.group(4) + "\n"
                 map_fn(dummy_line, re.compile("([A-Za-z_0-9]*) *([A-Za-z_0-9]*) *(.*)").match(dummy_line), None, "(this_arg_conv->" + fn_line.group(2) + ")(this_arg_conv->this_arg")
+        for idx, var_line in enumerate(field_var_lines):
+            if var_line.group(1) not in trait_structs:
+                out_c.write(var_line.group(1) + " " + struct_name + "_set_get_" + var_line.group(2) + "(" + struct_name + "* this_arg) {\n")
+                out_c.write("\tif (this_arg->set_" + var_line.group(2) + " != NULL)\n")
+                out_c.write("\t\tthis_arg->set_" + var_line.group(2) + "(this_arg);\n")
+                out_c.write("\treturn this_arg->" + var_line.group(2) + ";\n")
+                out_c.write("}\n")
+                dummy_line = var_line.group(1) + " " + struct_name.replace("LDK", "") + "_get_" + var_line.group(2) + " " + struct_name + "* this_arg" + fn_line.group(4) + "\n"
+                map_fn(dummy_line, re.compile("([A-Za-z_0-9]*) *([A-Za-z_0-9]*) *(.*)").match(dummy_line), None, struct_name + "_set_get_" + var_line.group(2) + "(this_arg_conv")
 
     out_c.write("""#include \"org_ldk_impl_bindings.h\"
 #include <rust_types.h>
@@ -1369,7 +1407,12 @@ static void alloc_freed(void* ptr) {
        while (it->ptr != ptr) {
                p = it; it = it->next;
                if (it == NULL) {
-                       fprintf(stderr, "Tried to free unknown pointer %p!\\n", ptr);
+                       fprintf(stderr, "Tried to free unknown pointer %p at:\\n", ptr);
+                       void* bt[BT_MAX];
+                       int bt_len = backtrace(bt, BT_MAX);
+                       backtrace_symbols_fd(bt, bt_len, STDERR_FILENO);
+                       fprintf(stderr, "\\n\\n");
+                       DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
                        return; // addrsan should catch malloc-unknown and print more info than we have
                }
        }
@@ -1557,6 +1600,7 @@ class CommonBase {
     assert(line_indicates_trait_regex.match("   void *(*clone)(const void *this_arg);"))
     line_field_var_regex = re.compile("^   ([A-Za-z_0-9]*) ([A-Za-z_0-9]*);$")
     assert(line_field_var_regex.match("   LDKMessageSendEventsProvider MessageSendEventsProvider;"))
+    assert(line_field_var_regex.match("   LDKChannelPublicKeys pubkeys;"))
     struct_name_regex = re.compile("^typedef (struct|enum|union) (MUST_USE_STRUCT )?(LDK[A-Za-z_0-9]*) {$")
     assert(struct_name_regex.match("typedef struct LDKCVecTempl_u8 {"))
     assert(struct_name_regex.match("typedef enum LDKNetwork {"))
index f9c07cfb060809ae086b5a2d5d920b2083d35075..8752da08e4d55ebf4d95af39e3c80a8dfe029a1b 100644 (file)
@@ -345,7 +345,7 @@ public class bindings {
                 long sign_channel_announcement(long msg);
                 void on_accept(long channel_points, short counterparty_selected_contest_delay, short holder_selected_contest_delay);
        }
-       public static native long LDKChannelKeys_new(LDKChannelKeys impl);
+       public static native long LDKChannelKeys_new(LDKChannelKeys impl, long pubkeys);
        public static native LDKChannelKeys LDKChannelKeys_get_obj_from_jcalls(long val);
        // LDKPublicKey ChannelKeys_get_per_commitment_point LDKChannelKeys* this_arg, uint64_t idx
        public static native byte[] ChannelKeys_get_per_commitment_point(long this_arg, long idx);
@@ -369,6 +369,8 @@ public class bindings {
        public static native long ChannelKeys_sign_channel_announcement(long this_arg, long msg);
        // void ChannelKeys_on_accept LDKChannelKeys* this_arg, const LDKChannelPublicKeys *channel_points, uint16_t counterparty_selected_contest_delay, uint16_t holder_selected_contest_delay
        public static native void ChannelKeys_on_accept(long this_arg, long channel_points, short counterparty_selected_contest_delay, short holder_selected_contest_delay);
+       // LDKChannelPublicKeys ChannelKeys_get_pubkeys LDKChannelKeys* this_arg
+       public static native long ChannelKeys_get_pubkeys(long this_arg);
        public static native long[] LDKCVecTempl_MonitorEvent_arr_info(long vec_ptr);
        public static native long LDKCVecTempl_MonitorEvent_new(long[] elems);
        public interface LDKWatch {
index 2af8bc66510bfb991ba61eb2059eb0ffc944aafc..b2541a836105bb8dfcc617f3df4ebf5db249035a 100644 (file)
@@ -30,5 +30,8 @@ public class BroadcasterInterface extends CommonBase {
                        }
                });
        }
-       // Skipped BroadcasterInterface_broadcast_transaction
+       public void broadcast_transaction(Transaction tx) {
+               bindings.BroadcasterInterface_broadcast_transaction(this.ptr, tx.ptr);
+       }
+
 }
index 2639799f3f651d7653491274bd181b4b70a4b599..d2e8ff2221980b8b08ade8cddfdcc5901940dfaa 100644 (file)
@@ -9,9 +9,10 @@ import java.util.Arrays;
 public class ChannelKeys extends CommonBase {
        final bindings.LDKChannelKeys bindings_instance;
        ChannelKeys(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
-       private ChannelKeys(bindings.LDKChannelKeys arg) {
-               super(bindings.LDKChannelKeys_new(arg));
+       private ChannelKeys(bindings.LDKChannelKeys arg, ChannelPublicKeys pubkeys) {
+               super(bindings.LDKChannelKeys_new(arg, pubkeys == null ? 0 : pubkeys.ptr & ~1));
                this.ptrs_to.add(arg);
+               this.ptrs_to.add(pubkeys);
                this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
@@ -32,7 +33,7 @@ public class ChannelKeys extends CommonBase {
                Result_SignatureNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg);
                void on_accept(ChannelPublicKeys channel_points, short counterparty_selected_contest_delay, short holder_selected_contest_delay);
        }
-       public ChannelKeys(ChannelKeysInterface arg) {
+       public ChannelKeys(ChannelKeysInterface arg, ChannelPublicKeys pubkeys) {
                this(new bindings.LDKChannelKeys() {
                        @Override public byte[] get_per_commitment_point(long idx) {
                                byte[] ret = arg.get_per_commitment_point(idx);
@@ -109,7 +110,7 @@ public class ChannelKeys extends CommonBase {
                                ChannelPublicKeys channel_points_hu_conv = new ChannelPublicKeys(null, channel_points);
                                arg.on_accept(channel_points_hu_conv, counterparty_selected_contest_delay, holder_selected_contest_delay);
                        }
-               });
+               }, pubkeys);
        }
        public byte[] get_per_commitment_point(long idx) {
                byte[] ret = bindings.ChannelKeys_get_per_commitment_point(this.ptr, idx);
@@ -122,7 +123,15 @@ public class ChannelKeys extends CommonBase {
        }
 
        // Skipped ChannelKeys_key_derivation_params
-       // Skipped ChannelKeys_sign_counterparty_commitment
+       public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(int feerate_per_kw, Transaction commitment_tx, PreCalculatedTxCreationKeys keys, HTLCOutputInCommitment[] htlcs) {
+               long ret = bindings.ChannelKeys_sign_counterparty_commitment(this.ptr, feerate_per_kw, commitment_tx.ptr, keys == null ? 0 : keys.ptr & ~1, Arrays.stream(htlcs).mapToLong(arr_conv_24 -> arr_conv_24 == null ? 0 : arr_conv_24.ptr & ~1).toArray());
+               Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret);
+               ret_hu_conv.ptrs_to.add(this);
+               this.ptrs_to.add(keys);
+               /* TODO 2 HTLCOutputInCommitment  */;
+               return ret_hu_conv;
+       }
+
        public Result_SignatureNoneZ sign_holder_commitment(HolderCommitmentTransaction holder_commitment_tx) {
                long ret = bindings.ChannelKeys_sign_holder_commitment(this.ptr, holder_commitment_tx == null ? 0 : holder_commitment_tx.ptr & ~1);
                Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
@@ -139,9 +148,29 @@ public class ChannelKeys extends CommonBase {
                return ret_hu_conv;
        }
 
-       // Skipped ChannelKeys_sign_justice_transaction
-       // Skipped ChannelKeys_sign_counterparty_htlc_transaction
-       // Skipped ChannelKeys_sign_closing_transaction
+       public Result_SignatureNoneZ sign_justice_transaction(Transaction justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc) {
+               long ret = bindings.ChannelKeys_sign_justice_transaction(this.ptr, justice_tx.ptr, input, amount, per_commitment_key, htlc == null ? 0 : htlc.ptr & ~1);
+               Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
+               ret_hu_conv.ptrs_to.add(this);
+               this.ptrs_to.add(htlc);
+               return ret_hu_conv;
+       }
+
+       public Result_SignatureNoneZ sign_counterparty_htlc_transaction(Transaction htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc) {
+               long ret = bindings.ChannelKeys_sign_counterparty_htlc_transaction(this.ptr, htlc_tx.ptr, input, amount, per_commitment_point, htlc == null ? 0 : htlc.ptr & ~1);
+               Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
+               ret_hu_conv.ptrs_to.add(this);
+               this.ptrs_to.add(htlc);
+               return ret_hu_conv;
+       }
+
+       public Result_SignatureNoneZ sign_closing_transaction(Transaction closing_tx) {
+               long ret = bindings.ChannelKeys_sign_closing_transaction(this.ptr, closing_tx.ptr);
+               Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
+               ret_hu_conv.ptrs_to.add(this);
+               return ret_hu_conv;
+       }
+
        public Result_SignatureNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg) {
                long ret = bindings.ChannelKeys_sign_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
                Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret);
@@ -155,4 +184,10 @@ public class ChannelKeys extends CommonBase {
                this.ptrs_to.add(channel_points);
        }
 
+       public ChannelPublicKeys get_pubkeys() {
+               long ret = bindings.ChannelKeys_get_pubkeys(this.ptr);
+               ChannelPublicKeys ret_hu_conv = new ChannelPublicKeys(null, ret);
+               return ret_hu_conv;
+       }
+
 }
index d920f2d49697fd70003c19d85d13cc88c1280e80..5dc8103c30e56c5af069bf7f702bd7338a7ea7b5 100644 (file)
@@ -12,6 +12,7 @@ public class ChannelMessageHandler extends CommonBase {
        private ChannelMessageHandler(bindings.LDKChannelMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) {
                super(bindings.LDKChannelMessageHandler_new(arg, MessageSendEventsProvider));
                this.ptrs_to.add(arg);
+               this.ptrs_to.add(MessageSendEventsProvider);
                this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
index eb8dbe0c6a547d4d9f302916e4075c0ded30a9e2..acd07f36904ddb2438fc2229ee60f9e6f9546467 100644 (file)
@@ -22,7 +22,10 @@ public class HolderCommitmentTransaction extends CommonBase {
        }
 
        // Skipped HolderCommitmentTransaction_get_unsigned_tx
-       // Skipped HolderCommitmentTransaction_set_unsigned_tx
+       public void set_unsigned_tx(Transaction val) {
+               bindings.HolderCommitmentTransaction_set_unsigned_tx(this.ptr, val.ptr);
+       }
+
        public byte[] get_counterparty_sig() {
                byte[] ret = bindings.HolderCommitmentTransaction_get_counterparty_sig(this.ptr);
                return ret;
@@ -46,7 +49,14 @@ public class HolderCommitmentTransaction extends CommonBase {
                /* TODO 2 TwoTuple<HTLCOutputInCommitment, byte[]>  */;
        }
 
-       // Skipped HolderCommitmentTransaction_new_missing_holder_sig
+       public static HolderCommitmentTransaction constructor_new_missing_holder_sig(Transaction unsigned_tx, byte[] counterparty_sig, byte[] holder_funding_key, byte[] counterparty_funding_key, TxCreationKeys keys, int feerate_per_kw, TwoTuple<HTLCOutputInCommitment, byte[]>[] htlc_data) {
+               long ret = bindings.HolderCommitmentTransaction_new_missing_holder_sig(unsigned_tx.ptr, counterparty_sig, holder_funding_key, counterparty_funding_key, keys == null ? 0 : keys.ptr & ~1, feerate_per_kw, Arrays.stream(htlc_data).mapToLong(arr_conv_42 -> bindings.C2Tuple_HTLCOutputInCommitmentSignatureZ_new(arr_conv_42.a == null ? 0 : arr_conv_42.a.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_42_a)*/, arr_conv_42.b)).toArray());
+               HolderCommitmentTransaction ret_hu_conv = new HolderCommitmentTransaction(null, ret);
+               ret_hu_conv.ptrs_to.add(keys);
+               /* TODO 2 TwoTuple<HTLCOutputInCommitment, byte[]>  */;
+               return ret_hu_conv;
+       }
+
        public TxCreationKeys trust_key_derivation() {
                long ret = bindings.HolderCommitmentTransaction_trust_key_derivation(this.ptr);
                TxCreationKeys ret_hu_conv = new TxCreationKeys(null, ret);
index 10875ee7f84b038a1d7fa35dc6d4ed355145f110..0644fb59b715caf1aeefbdbf7206e68fa20d9b9f 100644 (file)
@@ -75,7 +75,12 @@ public class InMemoryChannelKeys extends CommonBase {
                bindings.InMemoryChannelKeys_set_commitment_seed(this.ptr, val);
        }
 
-       // Skipped InMemoryChannelKeys_new
+       public static InMemoryChannelKeys constructor_new(byte[] funding_key, byte[] revocation_base_key, byte[] payment_key, byte[] delayed_payment_base_key, byte[] htlc_base_key, byte[] commitment_seed, long channel_value_satoshis, TwoTuple<Long, Long> key_derivation_params) {
+               long ret = bindings.InMemoryChannelKeys_new(funding_key, revocation_base_key, payment_key, delayed_payment_base_key, htlc_base_key, commitment_seed, channel_value_satoshis, bindings.C2Tuple_u64u64Z_new(key_derivation_params.a, key_derivation_params.b));
+               InMemoryChannelKeys ret_hu_conv = new InMemoryChannelKeys(null, ret);
+               return ret_hu_conv;
+       }
+
        public ChannelPublicKeys counterparty_pubkeys() {
                long ret = bindings.InMemoryChannelKeys_counterparty_pubkeys(this.ptr);
                ChannelPublicKeys ret_hu_conv = new ChannelPublicKeys(null, ret);
index cb89872c906080dfde1bc106a10264bf7127c3dd..d5490f2bc567683412e919ec73a294746f958955 100644 (file)
@@ -30,6 +30,14 @@ public class LightningError extends CommonBase {
                return ret_hu_conv;
        }
 
-       // Skipped LightningError_set_action
-       // Skipped LightningError_new
+       public void set_action(ErrorAction val) {
+               bindings.LightningError_set_action(this.ptr, val.ptr);
+       }
+
+       public static LightningError constructor_new(byte[] err_arg, ErrorAction action_arg) {
+               long ret = bindings.LightningError_new(err_arg, action_arg.ptr);
+               LightningError ret_hu_conv = new LightningError(null, ret);
+               return ret_hu_conv;
+       }
+
 }
index 23fd8c9ff3855cd73a8d4c590eae0e8c10f3c852..0f3ad91d159d8c29cf2af9e254696f3dee364d8e 100644 (file)
@@ -97,7 +97,11 @@ public class RoutingMessageHandler extends CommonBase {
                return ret_hu_conv;
        }
 
-       // Skipped RoutingMessageHandler_handle_htlc_fail_channel_update
+       public void handle_htlc_fail_channel_update(HTLCFailChannelUpdate update) {
+               bindings.RoutingMessageHandler_handle_htlc_fail_channel_update(this.ptr, update == null ? 0 : update.ptr & ~1);
+               this.ptrs_to.add(update);
+       }
+
        public ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] get_next_channel_announcements(long starting_point, byte batch_amount) {
                long[] ret = bindings.RoutingMessageHandler_get_next_channel_announcements(this.ptr, starting_point, batch_amount);
                ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] arr_conv_63_arr = new ThreeTuple[ret.length];
index f949d8785c08715f9689cc2792db66f0548a465f..3747589afcc9fd006e1316b1fa325522f4a4d7a5 100644 (file)
@@ -57,7 +57,12 @@ static void alloc_freed(void* ptr) {
        while (it->ptr != ptr) {
                p = it; it = it->next;
                if (it == NULL) {
-                       fprintf(stderr, "Tried to free unknown pointer %p!\n", ptr);
+                       fprintf(stderr, "Tried to free unknown pointer %p at:\n", ptr);
+                       void* bt[BT_MAX];
+                       int bt_len = backtrace(bt, BT_MAX);
+                       backtrace_symbols_fd(bt, bt_len, STDERR_FILENO);
+                       fprintf(stderr, "\n\n");
+                       DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
                        return; // addrsan should catch malloc-unknown and print more info than we have
                }
        }
@@ -1889,7 +1894,7 @@ static void* LDKChannelKeys_JCalls_clone(const void* this_arg) {
        atomic_fetch_add_explicit(&j_calls->refcnt, 1, memory_order_release);
        return (void*) this_arg;
 }
-static inline LDKChannelKeys LDKChannelKeys_init (JNIEnv * env, jclass _a, jobject o) {
+static inline LDKChannelKeys LDKChannelKeys_init (JNIEnv * env, jclass _a, jobject o, jlong pubkeys) {
        jclass c = (*env)->GetObjectClass(env, o);
        CHECK(c != NULL);
        LDKChannelKeys_JCalls *calls = MALLOC(sizeof(LDKChannelKeys_JCalls), "LDKChannelKeys_JCalls");
@@ -1919,6 +1924,12 @@ static inline LDKChannelKeys LDKChannelKeys_init (JNIEnv * env, jclass _a, jobje
        calls->on_accept_meth = (*env)->GetMethodID(env, c, "on_accept", "(JSS)V");
        CHECK(calls->on_accept_meth != NULL);
 
+       LDKChannelPublicKeys pubkeys_conv;
+       pubkeys_conv.inner = (void*)(pubkeys & (~1));
+       pubkeys_conv.is_owned = (pubkeys & 1) || (pubkeys == 0);
+       if (pubkeys_conv.inner != NULL)
+               pubkeys_conv = ChannelPublicKeys_clone(&pubkeys_conv);
+
        LDKChannelKeys ret = {
                .this_arg = (void*) calls,
                .get_per_commitment_point = get_per_commitment_point_jcall,
@@ -1934,12 +1945,14 @@ static inline LDKChannelKeys LDKChannelKeys_init (JNIEnv * env, jclass _a, jobje
                .on_accept = on_accept_jcall,
                .clone = LDKChannelKeys_JCalls_clone,
                .free = LDKChannelKeys_JCalls_free,
+               .pubkeys = pubkeys_conv,
+               .set_pubkeys = NULL,
        };
        return ret;
 }
-JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1new (JNIEnv * env, jclass _a, jobject o) {
+JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1new (JNIEnv * env, jclass _a, jobject o, jlong pubkeys) {
        LDKChannelKeys *res_ptr = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
-       *res_ptr = LDKChannelKeys_init(env, _a, o);
+       *res_ptr = LDKChannelKeys_init(env, _a, o, pubkeys);
        return (long)res_ptr;
 }
 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {
@@ -2071,6 +2084,17 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1on_1accept(JNIEnv
        (this_arg_conv->on_accept)(this_arg_conv->this_arg, &channel_points_conv, counterparty_selected_contest_delay, holder_selected_contest_delay);
 }
 
+LDKChannelPublicKeys LDKChannelKeys_set_get_pubkeys(LDKChannelKeys* this_arg) {
+       if (this_arg->set_pubkeys != NULL)
+               this_arg->set_pubkeys(this_arg);
+       return this_arg->pubkeys;
+}
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1pubkeys(JNIEnv * _env, jclass _b, jlong this_arg) {
+       LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
+       LDKChannelPublicKeys ret = LDKChannelKeys_set_get_pubkeys(this_arg_conv);
+       return ((long)ret.inner) | (ret.is_owned ? 1 : 0);
+}
+
 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MonitorEvent_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
        LDKCVecTempl_MonitorEvent *vec = (LDKCVecTempl_MonitorEvent*)ptr;
        jlongArray ret = (*env)->NewLongArray(env, vec->datalen);
@@ -12409,6 +12433,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_get_1route(JNIEnv * _env, jcl
                LDKChannelDetails arr_conv_16_conv;
                arr_conv_16_conv.inner = (void*)(arr_conv_16 & (~1));
                arr_conv_16_conv.is_owned = (arr_conv_16 & 1) || (arr_conv_16 == 0);
+               if (arr_conv_16_conv.inner != NULL)
+                       arr_conv_16_conv = ChannelDetails_clone(&arr_conv_16_conv);
                first_hops_constr.data[q] = arr_conv_16_conv;
        }
        (*_env)->ReleaseLongArrayElements (_env, first_hops, first_hops_vals, 0);
index a371a5ca6835557716254a8bb0a1f2c0729c9d6b..431685477718aa88255aeb9e12c62f052bdd8ec1 100644 (file)
@@ -730,10 +730,10 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1HTLCOutputInCom
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    LDKChannelKeys_new
- * Signature: (Lorg/ldk/impl/bindings/LDKChannelKeys;)J
+ * Signature: (Lorg/ldk/impl/bindings/LDKChannelKeys;J)J
  */
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1new
-  (JNIEnv *, jclass, jobject);
+  (JNIEnv *, jclass, jobject, jlong);
 
 /*
  * Class:     org_ldk_impl_bindings
@@ -831,6 +831,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1channel_1a
 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1on_1accept
   (JNIEnv *, jclass, jlong, jlong, jshort, jshort);
 
+/*
+ * Class:     org_ldk_impl_bindings
+ * Method:    ChannelKeys_get_pubkeys
+ * Signature: (J)J
+ */
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1get_1pubkeys
+  (JNIEnv *, jclass, jlong);
+
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    LDKCVecTempl_MonitorEvent_arr_info