From 371e82300e5de678404f0addc47a20636077df5d Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 20 Oct 2020 15:27:34 -0400 Subject: [PATCH] Make complex enums more complete, track reference-or-ownership by callsite --- genbindings.py | 92 +++-- src/main/java/org/ldk/impl/bindings.java | 22 ++ src/main/java/org/ldk/structs/APIError.java | 40 +- .../java/org/ldk/structs/ErrorAction.java | 29 +- src/main/java/org/ldk/structs/Event.java | 70 +++- .../ldk/structs/HTLCFailChannelUpdate.java | 30 +- .../org/ldk/structs/MessageSendEvent.java | 164 +++++++-- src/main/java/org/ldk/structs/NetAddress.java | 39 +- .../structs/SpendableOutputDescriptor.java | 54 ++- src/main/jni/bindings.c | 343 +++++++----------- src/main/jni/org_ldk_impl_bindings.h | 88 +++++ .../java/org/ldk/HumanObjectPeerTest.java | 21 +- 12 files changed, 659 insertions(+), 333 deletions(-) diff --git a/genbindings.py b/genbindings.py index e139af0c..e91a4d2a 100755 --- a/genbindings.py +++ b/genbindings.py @@ -361,11 +361,11 @@ with open(sys.argv[1]) as in_h: java_c_types_none_allowed = False # C structs created by cbindgen are declared in dependency order with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.argv[4], "w") as out_c: - def map_type(fn_arg, print_void, ret_arr_len, is_free): + def map_type(fn_arg, print_void, ret_arr_len, is_free, holds_ref): ty_info = java_c_types(fn_arg, ret_arr_len) - return map_type_with_info(ty_info, print_void, ret_arr_len, is_free) + return map_type_with_info(ty_info, print_void, ret_arr_len, is_free, holds_ref) - def map_type_with_info(ty_info, print_void, ret_arr_len, is_free): + def map_type_with_info(ty_info, print_void, ret_arr_len, is_free, holds_ref): if ty_info.c_ty == "void": if not print_void: return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, @@ -403,12 +403,12 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg arg_conv = arg_conv, arg_conv_name = arr_name + "_ref", arg_conv_cleanup = arg_conv_cleanup, ret_conv = ret_conv, ret_conv_name = arr_name + "_arr", to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None) else: - assert not arr_len.isdigit() # not implemented + assert not arr_len.isdigit() # fixed length arrays not implemented assert ty_info.java_ty[len(ty_info.java_ty) - 2:] == "[]" conv_name = "arr_conv_" + str(len(ty_info.java_hu_ty)) idxc = chr(ord('a') + (len(ty_info.java_hu_ty) % 26)) ty_info.subty.var_name = conv_name - subty = map_type_with_info(ty_info.subty, False, None, is_free) + subty = map_type_with_info(ty_info.subty, False, None, is_free, holds_ref) if arr_name == "": arr_name = "arg" arg_conv = ty_info.rust_obj + " " + arr_name + "_constr;\n" @@ -460,10 +460,13 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg ret_conv = (ret_conv[0], ret_conv[1] + "for (size_t " + idxc + " = 0; " + idxc + " < " + arr_name + "_var." + arr_len + "; " + idxc + "++) {\n") ret_conv = (ret_conv[0], ret_conv[1] + "\t" + subty.ret_conv[0].replace("\n", "\n\t")) ret_conv = (ret_conv[0], ret_conv[1] + arr_name + "_var." + ty_info.arr_access + "[" + idxc + "]" + subty.ret_conv[1].replace("\n", "\n\t")) - ret_conv = (ret_conv[0], ret_conv[1] + "\n\t(*_env)->SetObjectArrayElement(_env, " + arr_name + "_arr, " + idxc + ", " + subty.ret_conv_name + ");") + ret_conv = (ret_conv[0], ret_conv[1] + "\n\t(*_env)->SetObjectArrayElement(_env, " + arr_name + "_arr, " + idxc + ", " + subty.ret_conv_name + ");\n") ret_conv = (ret_conv[0], ret_conv[1] + "}") - if subty.rust_obj is not None and subty.rust_obj in opaque_structs: - ret_conv = (ret_conv[0], ret_conv[1] + "\nFREE(" + arr_name + "_var.data);") + if not holds_ref: + if subty.rust_obj is not None and subty.rust_obj in opaque_structs: + ret_conv = (ret_conv[0], ret_conv[1] + "\nFREE(" + arr_name + "_var." + ty_info.arr_access + ");") + else: + ret_conv = (ret_conv[0], ret_conv[1] + "\n" + ty_info.rust_obj.replace("LDK", "") + "_free(" + arr_name + "_var);") to_hu_conv = None to_hu_conv_name = None @@ -527,12 +530,15 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg if ty_info.rust_obj in opaque_structs: ret_conv_suf = ";\nCHECK((((long)" + ty_info.var_name + "_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this.\n" ret_conv_suf = ret_conv_suf + "CHECK((((long)&" + ty_info.var_name + "_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this.\n" - ret_conv_suf = ret_conv_suf + "long " + ty_info.var_name + "_ref;\n" - ret_conv_suf = ret_conv_suf + "if (" + ty_info.var_name + "_var.is_owned) {\n" - ret_conv_suf = ret_conv_suf + "\t" + ty_info.var_name + "_ref = (long)" + ty_info.var_name + "_var.inner | 1;\n" - ret_conv_suf = ret_conv_suf + "} else {\n" - ret_conv_suf = ret_conv_suf + "\t" + ty_info.var_name + "_ref = (long)&" + ty_info.var_name + "_var;\n" - ret_conv_suf = ret_conv_suf + "}" + if holds_ref: + ret_conv_suf = ret_conv_suf + "long " + ty_info.var_name + "_ref = (long)" + ty_info.var_name + "_var.inner & ~1;" + else: + ret_conv_suf = ret_conv_suf + "long " + ty_info.var_name + "_ref;\n" + ret_conv_suf = ret_conv_suf + "if (" + ty_info.var_name + "_var.is_owned) {\n" + ret_conv_suf = ret_conv_suf + "\t" + ty_info.var_name + "_ref = (long)" + ty_info.var_name + "_var.inner | 1;\n" + ret_conv_suf = ret_conv_suf + "} else {\n" + ret_conv_suf = ret_conv_suf + "\t" + ty_info.var_name + "_ref = (long)" + ty_info.var_name + "_var.inner & ~1;\n" + ret_conv_suf = ret_conv_suf + "}" return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = opaque_arg_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None, ret_conv = (ty_info.rust_obj + " " + ty_info.var_name + "_var = ", ret_conv_suf), @@ -558,9 +564,14 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg # underlying unlike Vecs, and it gives Java more freedom. base_conv = base_conv + "\nFREE((void*)" + ty_info.var_name + ");"; if ty_info.rust_obj in complex_enums: + ret_conv = ("long " + ty_info.var_name + "_ref = (long)&", ";") + if not ty_info.is_ptr and not holds_ref and (ty_info.java_hu_ty + "_clone") in clone_fns: + ret_conv = (ty_info.rust_obj + " *" + ty_info.var_name + "_copy = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n", "") + ret_conv = (ret_conv[0] + "*" + ty_info.var_name + "_copy = " + ty_info.java_hu_ty + "_clone(&", ");\n") + ret_conv = (ret_conv[0], ret_conv[1] + "long " + ty_info.var_name + "_ref = (long)" + ty_info.var_name + "_copy;") return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None, - ret_conv = ("long " + ty_info.var_name + "_ref = (long)&", ";"), ret_conv_name = ty_info.var_name + "_ref", + ret_conv = ret_conv, ret_conv_name = ty_info.var_name + "_ref", to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_hu_conv = " + ty_info.java_hu_ty + ".constr_from_ptr(" + ty_info.var_name + ");", to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = (ty_info.var_name + ".conv_to_c()", "")) if ty_info.rust_obj in tuple_types: @@ -570,7 +581,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg if idx != 0: to_hu_conv_sfx = to_hu_conv_sfx + ", " conv.var_name = ty_info.var_name + "_" + chr(idx + ord("a")) - conv_map = map_type_with_info(conv, False, None, is_free) + conv_map = map_type_with_info(conv, False, None, is_free, holds_ref) to_hu_conv_pfx = to_hu_conv_pfx + conv.java_ty + " " + ty_info.var_name + "_" + chr(idx + ord("a")) + " = " + "bindings." + tuple_types[ty_info.rust_obj][1] + "_get_" + chr(idx + ord("a")) + "(" + ty_info.var_name + ");\n" if conv_map.to_hu_conv is not None: to_hu_conv_pfx = to_hu_conv_pfx + conv_map.to_hu_conv + ";\n" @@ -686,7 +697,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg is_free = re_match.group(2).endswith("_free") struct_meth = re_match.group(2).split("_")[0] - ret_info = map_type(re_match.group(1), True, ret_arr_len, False) + ret_info = map_type(re_match.group(1), True, ret_arr_len, False, False) ret_info.print_ty() if ret_info.ret_conv is not None: @@ -704,7 +715,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg out_java.write(", ") if arg != "void": out_c.write(", ") - arg_conv_info = map_type(arg, False, None, is_free) + arg_conv_info = map_type(arg, False, None, is_free, False) if arg_conv_info.c_ty != "void": arg_conv_info.print_ty() arg_conv_info.print_name() @@ -717,7 +728,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg if arg_conv_info.rust_obj in constructor_fns: assert not is_free for explode_arg in constructor_fns[arg_conv_info.rust_obj].split(','): - explode_arg_conv = map_type(explode_arg, False, None, False) + explode_arg_conv = map_type(explode_arg, False, None, False, False) if explode_arg_conv.c_ty == "void": # We actually want to handle this case, but for now its only used in NetGraphMsgHandler::new() # which ends up resulting in a redundant constructor - both without arguments for the NetworkGraph. @@ -908,6 +919,11 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg out_java_enum.write(hu_struct_file_prefix) out_java_enum.write("public class " + java_hu_type + " extends CommonBase {\n") out_java_enum.write("\tprivate " + java_hu_type + "(Object _dummy, long ptr) { super(ptr); }\n") + out_java_enum.write("\t@Override @SuppressWarnings(\"deprecation\")\n") + out_java_enum.write("\tprotected void finalize() throws Throwable {\n") + out_java_enum.write("\t\tsuper.finalize();\n") + out_java_enum.write("\t\tbindings." + java_hu_type + "_free(ptr);\n") + out_java_enum.write("\t}\n") out_java_enum.write("\tlong conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ }\n") out_java_enum.write("\tstatic " + java_hu_type + " constr_from_ptr(long ptr) {\n") out_java_enum.write("\t\tbindings." + struct_name + " raw_val = bindings." + struct_name + "_ref_from_ptr(ptr);\n") @@ -931,31 +947,39 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg out_java.write("\t\tpublic final static class " + var_name + " extends " + struct_name + " {\n") java_hu_subclasses = java_hu_subclasses + "\tpublic final static class " + var_name + " extends " + java_hu_type + " {\n" out_java_enum.write("\t\tif (raw_val.getClass() == bindings." + struct_name + "." + var_name + ".class) {\n") - out_java_enum.write("\t\t\treturn new " + var_name + "(null, ptr);\n") # TODO: Conv values! + out_java_enum.write("\t\t\treturn new " + var_name + "(ptr, (bindings." + struct_name + "." + var_name + ")raw_val);\n") out_c.write("static jclass " + struct_name + "_" + var_name + "_class = NULL;\n") out_c.write("static jmethodID " + struct_name + "_" + var_name + "_meth = NULL;\n") init_meth_jty_str = "" init_meth_params = "" init_meth_body = "" + hu_conv_body = "" if "LDK" + var_name in union_enum_items: enum_var_lines = union_enum_items["LDK" + var_name] for idx, field in enumerate(enum_var_lines): if idx != 0 and idx < len(enum_var_lines) - 2: - field_ty = java_c_types(field.strip(' ;'), None) - out_java.write("\t\t\tpublic " + field_ty.java_ty + " " + field_ty.var_name + ";\n") - java_hu_subclasses = java_hu_subclasses + "\t\tpublic " + field_ty.java_hu_ty + " " + field_ty.var_name + ";\n" + field_ty = map_type(field.strip(' ;'), False, None, False, True) + out_java.write("\t\t\tpublic " + field_ty.java_ty + " " + field_ty.arg_name + ";\n") + java_hu_subclasses = java_hu_subclasses + "\t\tpublic " + field_ty.java_hu_ty + " " + field_ty.arg_name + ";\n" + if field_ty.to_hu_conv is not None: + hu_conv_body = hu_conv_body + "\t\t\t" + field_ty.java_ty + " " + field_ty.arg_name + " = obj." + field_ty.arg_name + ";\n" + hu_conv_body = hu_conv_body + "\t\t\t" + field_ty.to_hu_conv.replace("\n", "\n\t\t\t") + "\n" + hu_conv_body = hu_conv_body + "\t\t\tthis." + field_ty.arg_name + " = " + field_ty.to_hu_conv_name + ";\n" + else: + hu_conv_body = hu_conv_body + "\t\t\tthis." + field_ty.arg_name + " = obj." + field_ty.arg_name + ";\n" init_meth_jty_str = init_meth_jty_str + field_ty.java_fn_ty_arg if idx > 1: init_meth_params = init_meth_params + ", " - init_meth_params = init_meth_params + field_ty.java_ty + " " + field_ty.var_name - init_meth_body = init_meth_body + "this." + field_ty.var_name + " = " + field_ty.var_name + "; " + init_meth_params = init_meth_params + field_ty.java_ty + " " + field_ty.arg_name + init_meth_body = init_meth_body + "this." + field_ty.arg_name + " = " + field_ty.arg_name + "; " out_java.write("\t\t\t" + var_name + "(" + init_meth_params + ") { ") out_java.write(init_meth_body) out_java.write("}\n") out_java.write("\t\t}\n") out_java_enum.write("\t\t}\n") - java_hu_subclasses = java_hu_subclasses + "\t\tprivate " + var_name + "(Object _dummy, long ptr) { super(null, ptr); }\n" - java_hu_subclasses = java_hu_subclasses + "\t\t@Override long conv_to_c() { return 0; /*XXX*/ }\n" + java_hu_subclasses = java_hu_subclasses + "\t\tprivate " + var_name + "(long ptr, bindings." + struct_name + "." + var_name + " obj) {\n\t\t\tsuper(null, ptr);\n" + java_hu_subclasses = java_hu_subclasses + hu_conv_body + java_hu_subclasses = java_hu_subclasses + "\t\t}\n\t\t@Override long conv_to_c() { return 0; /*XXX*/ }\n" java_hu_subclasses = java_hu_subclasses + "\t}\n" init_meth_jty_strs[var_name] = init_meth_jty_str out_java_enum.write("\t\tassert false; return null; // Unreachable without extending the (internal) bindings interface\n\t}\n\n") @@ -985,7 +1009,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg enum_var_lines = union_enum_items["LDK" + var_name] for idx, field in enumerate(enum_var_lines): if idx != 0 and idx < len(enum_var_lines) - 2: - field_map = map_type(field.strip(' ;'), False, None, False) + field_map = map_type(field.strip(' ;'), False, None, False, True) if field_map.ret_conv is not None: out_c.write("\t\t\t" + field_map.ret_conv[0].replace("\n", "\n\t\t\t")) out_c.write("obj->" + camel_to_snake(var_name) + "." + field_map.arg_name) @@ -1041,7 +1065,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg for fn_line in trait_fn_lines: java_meth_descr = "(" if fn_line.group(2) != "free" and fn_line.group(2) != "clone": - ret_ty_info = map_type(fn_line.group(1), True, None, False) + ret_ty_info = map_type(fn_line.group(1), True, None, False, False) out_java.write("\t\t " + ret_ty_info.java_ty + " " + fn_line.group(2) + "(") java_trait_constr = java_trait_constr + "\t\t\t@Override public " + ret_ty_info.java_ty + " " + fn_line.group(2) + "(" @@ -1062,7 +1086,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg java_trait_constr = java_trait_constr + ", " #out_java_trait.write(", ") out_c.write(", ") - arg_conv_info = map_type(arg, True, None, False) + arg_conv_info = map_type(arg, True, None, False, False) out_c.write(arg.strip()) out_java.write(arg_conv_info.java_ty + " " + arg_conv_info.arg_name) #out_java_trait.write(arg_conv_info.java_ty + " " + arg_conv_info.arg_name) @@ -1565,7 +1589,7 @@ class CommonBase { out_c.write("\t" + struct_name + "* ret = MALLOC(sizeof(" + struct_name + "), \"" + struct_name + "\");\n") for idx, line in enumerate(field_lines): if idx != 0 and idx < len(field_lines) - 2: - ty_info = map_type(line.strip(';'), False, None, False) + ty_info = map_type(line.strip(';'), False, None, False, False) e = chr(ord('a') + idx - 1) if ty_info.arg_conv is not None: out_c.write("\t" + ty_info.arg_conv.replace("\n", "\n\t")) @@ -1597,7 +1621,7 @@ class CommonBase { 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") - ty_info = map_type(vec_ty + " arr_elem", False, None, False) + ty_info = map_type(vec_ty + " arr_elem", False, None, False, False) if len(ty_info.java_fn_ty_arg) == 1: # ie we're a primitive of some form out_java.write("\tpublic static native long " + struct_name + "_new(" + ty_info.java_ty + "[] elems);\n") out_c.write("JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_" + struct_name.replace("_", "_1") + "_1new(JNIEnv *env, jclass _b, j" + ty_info.java_ty + "Array elems){\n") @@ -1691,8 +1715,8 @@ class CommonBase { contents_ty = alias_match.group(1).replace("LDKCResultTempl", "LDKCResultPtr") res_ty, err_ty = result_ptr_struct_items[contents_ty] - res_map = map_type(res_ty + " res", True, None, False) - err_map = map_type(err_ty + " err", True, None, False) + res_map = map_type(res_ty + " res", True, None, False, True) + err_map = map_type(err_ty + " err", True, None, False, True) out_java.write("\tpublic static native boolean " + alias_match.group(2) + "_result_ok(long arg);\n") out_c.write("JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_" + alias_match.group(2).replace("_", "_1") + "_1result_1ok (JNIEnv * env, jclass _a, jlong arg) {\n") diff --git a/src/main/java/org/ldk/impl/bindings.java b/src/main/java/org/ldk/impl/bindings.java index f79ade37..6754b4af 100644 --- a/src/main/java/org/ldk/impl/bindings.java +++ b/src/main/java/org/ldk/impl/bindings.java @@ -791,14 +791,22 @@ public class bindings { public static native long C2Tuple_HTLCOutputInCommitmentSignatureZ_new(long a, byte[] b); // void Event_free(LDKEvent this_ptr); public static native void Event_free(long this_ptr); + // LDKEvent Event_clone(const LDKEvent *orig); + public static native long Event_clone(long orig); // void MessageSendEvent_free(LDKMessageSendEvent this_ptr); public static native void MessageSendEvent_free(long this_ptr); + // LDKMessageSendEvent MessageSendEvent_clone(const LDKMessageSendEvent *orig); + public static native long MessageSendEvent_clone(long orig); // void MessageSendEventsProvider_free(LDKMessageSendEventsProvider this_ptr); public static native void MessageSendEventsProvider_free(long this_ptr); // void EventsProvider_free(LDKEventsProvider this_ptr); public static native void EventsProvider_free(long this_ptr); // void APIError_free(LDKAPIError this_ptr); public static native void APIError_free(long this_ptr); + // LDKAPIError APIError_clone(const LDKAPIError *orig); + public static native long APIError_clone(long orig); + // LDKLevel Level_clone(const LDKLevel *orig); + public static native LDKLevel Level_clone(long orig); // MUST_USE_RES LDKLevel Level_max(void); public static native LDKLevel Level_max(); // void Logger_free(LDKLogger this_ptr); @@ -915,6 +923,8 @@ public class bindings { public static native long UserConfig_new(long own_channel_config_arg, long peer_channel_config_limits_arg, long channel_options_arg); // MUST_USE_RES LDKUserConfig UserConfig_default(void); public static native long UserConfig_default(); + // LDKAccessError AccessError_clone(const LDKAccessError *orig); + public static native LDKAccessError AccessError_clone(long orig); // void Access_free(LDKAccess this_ptr); public static native void Access_free(long this_ptr); // void Watch_free(LDKWatch this_ptr); @@ -923,6 +933,8 @@ public class bindings { public static native void Filter_free(long this_ptr); // void BroadcasterInterface_free(LDKBroadcasterInterface this_ptr); public static native void BroadcasterInterface_free(long this_ptr); + // LDKConfirmationTarget ConfirmationTarget_clone(const LDKConfirmationTarget *orig); + public static native LDKConfirmationTarget ConfirmationTarget_clone(long orig); // void FeeEstimator_free(LDKFeeEstimator this_ptr); public static native void FeeEstimator_free(long this_ptr); // void ChainMonitor_free(LDKChainMonitor this_ptr); @@ -949,6 +961,8 @@ public class bindings { public static native byte[] ChannelMonitorUpdate_write(long obj); // LDKChannelMonitorUpdate ChannelMonitorUpdate_read(LDKu8slice ser); public static native long ChannelMonitorUpdate_read(byte[] ser); + // LDKChannelMonitorUpdateErr ChannelMonitorUpdateErr_clone(const LDKChannelMonitorUpdateErr *orig); + public static native LDKChannelMonitorUpdateErr ChannelMonitorUpdateErr_clone(long orig); // void MonitorUpdateError_free(LDKMonitorUpdateError this_ptr); public static native void MonitorUpdateError_free(long this_ptr); // void MonitorEvent_free(LDKMonitorEvent this_ptr); @@ -1001,6 +1015,8 @@ public class bindings { public static native long OutPoint_read(byte[] ser); // void SpendableOutputDescriptor_free(LDKSpendableOutputDescriptor this_ptr); public static native void SpendableOutputDescriptor_free(long this_ptr); + // LDKSpendableOutputDescriptor SpendableOutputDescriptor_clone(const LDKSpendableOutputDescriptor *orig); + public static native long SpendableOutputDescriptor_clone(long orig); // void ChannelKeys_free(LDKChannelKeys this_ptr); public static native void ChannelKeys_free(long this_ptr); // void KeysInterface_free(LDKKeysInterface this_ptr); @@ -1599,6 +1615,8 @@ public class bindings { public static native long AnnouncementSignatures_new(byte[] channel_id_arg, long short_channel_id_arg, byte[] node_signature_arg, byte[] bitcoin_signature_arg); // void NetAddress_free(LDKNetAddress this_ptr); public static native void NetAddress_free(long this_ptr); + // LDKNetAddress NetAddress_clone(const LDKNetAddress *orig); + public static native long NetAddress_clone(long orig); // void UnsignedNodeAnnouncement_free(LDKUnsignedNodeAnnouncement this_ptr); public static native void UnsignedNodeAnnouncement_free(long this_ptr); // LDKUnsignedNodeAnnouncement UnsignedNodeAnnouncement_clone(const LDKUnsignedNodeAnnouncement *orig); @@ -1835,6 +1853,8 @@ public class bindings { public static native long GossipTimestampFilter_new(byte[] chain_hash_arg, int first_timestamp_arg, int timestamp_range_arg); // void ErrorAction_free(LDKErrorAction this_ptr); public static native void ErrorAction_free(long this_ptr); + // LDKErrorAction ErrorAction_clone(const LDKErrorAction *orig); + public static native long ErrorAction_clone(long orig); // void LightningError_free(LDKLightningError this_ptr); public static native void LightningError_free(long this_ptr); // LDKStr LightningError_get_err(const LDKLightningError *this_ptr); @@ -1871,6 +1891,8 @@ public class bindings { public static native long CommitmentUpdate_new(long[] update_add_htlcs_arg, long[] update_fulfill_htlcs_arg, long[] update_fail_htlcs_arg, long[] update_fail_malformed_htlcs_arg, long update_fee_arg, long commitment_signed_arg); // void HTLCFailChannelUpdate_free(LDKHTLCFailChannelUpdate this_ptr); public static native void HTLCFailChannelUpdate_free(long this_ptr); + // LDKHTLCFailChannelUpdate HTLCFailChannelUpdate_clone(const LDKHTLCFailChannelUpdate *orig); + public static native long HTLCFailChannelUpdate_clone(long orig); // void ChannelMessageHandler_free(LDKChannelMessageHandler this_ptr); public static native void ChannelMessageHandler_free(long this_ptr); // void RoutingMessageHandler_free(LDKRoutingMessageHandler this_ptr); diff --git a/src/main/java/org/ldk/structs/APIError.java b/src/main/java/org/ldk/structs/APIError.java index 61a7a4a5..40704400 100644 --- a/src/main/java/org/ldk/structs/APIError.java +++ b/src/main/java/org/ldk/structs/APIError.java @@ -8,50 +8,70 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class APIError extends CommonBase { private APIError(Object _dummy, long ptr) { super(ptr); } + @Override @SuppressWarnings("deprecation") + protected void finalize() throws Throwable { + super.finalize(); + bindings.APIError_free(ptr); + } long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ } static APIError constr_from_ptr(long ptr) { bindings.LDKAPIError raw_val = bindings.LDKAPIError_ref_from_ptr(ptr); if (raw_val.getClass() == bindings.LDKAPIError.APIMisuseError.class) { - return new APIMisuseError(null, ptr); + return new APIMisuseError(ptr, (bindings.LDKAPIError.APIMisuseError)raw_val); } if (raw_val.getClass() == bindings.LDKAPIError.FeeRateTooHigh.class) { - return new FeeRateTooHigh(null, ptr); + return new FeeRateTooHigh(ptr, (bindings.LDKAPIError.FeeRateTooHigh)raw_val); } if (raw_val.getClass() == bindings.LDKAPIError.RouteError.class) { - return new RouteError(null, ptr); + return new RouteError(ptr, (bindings.LDKAPIError.RouteError)raw_val); } if (raw_val.getClass() == bindings.LDKAPIError.ChannelUnavailable.class) { - return new ChannelUnavailable(null, ptr); + return new ChannelUnavailable(ptr, (bindings.LDKAPIError.ChannelUnavailable)raw_val); } if (raw_val.getClass() == bindings.LDKAPIError.MonitorUpdateFailed.class) { - return new MonitorUpdateFailed(null, ptr); + return new MonitorUpdateFailed(ptr, (bindings.LDKAPIError.MonitorUpdateFailed)raw_val); } assert false; return null; // Unreachable without extending the (internal) bindings interface } public final static class APIMisuseError extends APIError { public byte[] err; - private APIMisuseError(Object _dummy, long ptr) { super(null, ptr); } + private APIMisuseError(long ptr, bindings.LDKAPIError.APIMisuseError obj) { + super(null, ptr); + this.err = obj.err; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class FeeRateTooHigh extends APIError { public byte[] err; public int feerate; - private FeeRateTooHigh(Object _dummy, long ptr) { super(null, ptr); } + private FeeRateTooHigh(long ptr, bindings.LDKAPIError.FeeRateTooHigh obj) { + super(null, ptr); + this.err = obj.err; + this.feerate = obj.feerate; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class RouteError extends APIError { public String err; - private RouteError(Object _dummy, long ptr) { super(null, ptr); } + private RouteError(long ptr, bindings.LDKAPIError.RouteError obj) { + super(null, ptr); + this.err = obj.err; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class ChannelUnavailable extends APIError { public byte[] err; - private ChannelUnavailable(Object _dummy, long ptr) { super(null, ptr); } + private ChannelUnavailable(long ptr, bindings.LDKAPIError.ChannelUnavailable obj) { + super(null, ptr); + this.err = obj.err; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class MonitorUpdateFailed extends APIError { - private MonitorUpdateFailed(Object _dummy, long ptr) { super(null, ptr); } + private MonitorUpdateFailed(long ptr, bindings.LDKAPIError.MonitorUpdateFailed obj) { + super(null, ptr); + } @Override long conv_to_c() { return 0; /*XXX*/ } } } diff --git a/src/main/java/org/ldk/structs/ErrorAction.java b/src/main/java/org/ldk/structs/ErrorAction.java index 642fb0a4..e5ccec8d 100644 --- a/src/main/java/org/ldk/structs/ErrorAction.java +++ b/src/main/java/org/ldk/structs/ErrorAction.java @@ -8,33 +8,50 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class ErrorAction extends CommonBase { private ErrorAction(Object _dummy, long ptr) { super(ptr); } + @Override @SuppressWarnings("deprecation") + protected void finalize() throws Throwable { + super.finalize(); + bindings.ErrorAction_free(ptr); + } long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ } static ErrorAction constr_from_ptr(long ptr) { bindings.LDKErrorAction raw_val = bindings.LDKErrorAction_ref_from_ptr(ptr); if (raw_val.getClass() == bindings.LDKErrorAction.DisconnectPeer.class) { - return new DisconnectPeer(null, ptr); + return new DisconnectPeer(ptr, (bindings.LDKErrorAction.DisconnectPeer)raw_val); } if (raw_val.getClass() == bindings.LDKErrorAction.IgnoreError.class) { - return new IgnoreError(null, ptr); + return new IgnoreError(ptr, (bindings.LDKErrorAction.IgnoreError)raw_val); } if (raw_val.getClass() == bindings.LDKErrorAction.SendErrorMessage.class) { - return new SendErrorMessage(null, ptr); + return new SendErrorMessage(ptr, (bindings.LDKErrorAction.SendErrorMessage)raw_val); } assert false; return null; // Unreachable without extending the (internal) bindings interface } public final static class DisconnectPeer extends ErrorAction { public ErrorMessage msg; - private DisconnectPeer(Object _dummy, long ptr) { super(null, ptr); } + private DisconnectPeer(long ptr, bindings.LDKErrorAction.DisconnectPeer obj) { + super(null, ptr); + long msg = obj.msg; + ErrorMessage msg_hu_conv = new ErrorMessage(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class IgnoreError extends ErrorAction { - private IgnoreError(Object _dummy, long ptr) { super(null, ptr); } + private IgnoreError(long ptr, bindings.LDKErrorAction.IgnoreError obj) { + super(null, ptr); + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class SendErrorMessage extends ErrorAction { public ErrorMessage msg; - private SendErrorMessage(Object _dummy, long ptr) { super(null, ptr); } + private SendErrorMessage(long ptr, bindings.LDKErrorAction.SendErrorMessage obj) { + super(null, ptr); + long msg = obj.msg; + ErrorMessage msg_hu_conv = new ErrorMessage(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } } diff --git a/src/main/java/org/ldk/structs/Event.java b/src/main/java/org/ldk/structs/Event.java index d191cb0a..01a59a8f 100644 --- a/src/main/java/org/ldk/structs/Event.java +++ b/src/main/java/org/ldk/structs/Event.java @@ -8,29 +8,34 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class Event extends CommonBase { private Event(Object _dummy, long ptr) { super(ptr); } + @Override @SuppressWarnings("deprecation") + protected void finalize() throws Throwable { + super.finalize(); + bindings.Event_free(ptr); + } long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ } static Event constr_from_ptr(long ptr) { bindings.LDKEvent raw_val = bindings.LDKEvent_ref_from_ptr(ptr); if (raw_val.getClass() == bindings.LDKEvent.FundingGenerationReady.class) { - return new FundingGenerationReady(null, ptr); + return new FundingGenerationReady(ptr, (bindings.LDKEvent.FundingGenerationReady)raw_val); } if (raw_val.getClass() == bindings.LDKEvent.FundingBroadcastSafe.class) { - return new FundingBroadcastSafe(null, ptr); + return new FundingBroadcastSafe(ptr, (bindings.LDKEvent.FundingBroadcastSafe)raw_val); } if (raw_val.getClass() == bindings.LDKEvent.PaymentReceived.class) { - return new PaymentReceived(null, ptr); + return new PaymentReceived(ptr, (bindings.LDKEvent.PaymentReceived)raw_val); } if (raw_val.getClass() == bindings.LDKEvent.PaymentSent.class) { - return new PaymentSent(null, ptr); + return new PaymentSent(ptr, (bindings.LDKEvent.PaymentSent)raw_val); } if (raw_val.getClass() == bindings.LDKEvent.PaymentFailed.class) { - return new PaymentFailed(null, ptr); + return new PaymentFailed(ptr, (bindings.LDKEvent.PaymentFailed)raw_val); } if (raw_val.getClass() == bindings.LDKEvent.PendingHTLCsForwardable.class) { - return new PendingHTLCsForwardable(null, ptr); + return new PendingHTLCsForwardable(ptr, (bindings.LDKEvent.PendingHTLCsForwardable)raw_val); } if (raw_val.getClass() == bindings.LDKEvent.SpendableOutputs.class) { - return new SpendableOutputs(null, ptr); + return new SpendableOutputs(ptr, (bindings.LDKEvent.SpendableOutputs)raw_val); } assert false; return null; // Unreachable without extending the (internal) bindings interface } @@ -40,41 +45,78 @@ public class Event extends CommonBase { public long channel_value_satoshis; public byte[] output_script; public long user_channel_id; - private FundingGenerationReady(Object _dummy, long ptr) { super(null, ptr); } + private FundingGenerationReady(long ptr, bindings.LDKEvent.FundingGenerationReady obj) { + super(null, ptr); + this.temporary_channel_id = obj.temporary_channel_id; + this.channel_value_satoshis = obj.channel_value_satoshis; + this.output_script = obj.output_script; + this.user_channel_id = obj.user_channel_id; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class FundingBroadcastSafe extends Event { public OutPoint funding_txo; public long user_channel_id; - private FundingBroadcastSafe(Object _dummy, long ptr) { super(null, ptr); } + private FundingBroadcastSafe(long ptr, bindings.LDKEvent.FundingBroadcastSafe obj) { + super(null, ptr); + long funding_txo = obj.funding_txo; + OutPoint funding_txo_hu_conv = new OutPoint(null, funding_txo); + this.funding_txo = funding_txo_hu_conv; + this.user_channel_id = obj.user_channel_id; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class PaymentReceived extends Event { public byte[] payment_hash; public byte[] payment_secret; public long amt; - private PaymentReceived(Object _dummy, long ptr) { super(null, ptr); } + private PaymentReceived(long ptr, bindings.LDKEvent.PaymentReceived obj) { + super(null, ptr); + this.payment_hash = obj.payment_hash; + this.payment_secret = obj.payment_secret; + this.amt = obj.amt; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class PaymentSent extends Event { public byte[] payment_preimage; - private PaymentSent(Object _dummy, long ptr) { super(null, ptr); } + private PaymentSent(long ptr, bindings.LDKEvent.PaymentSent obj) { + super(null, ptr); + this.payment_preimage = obj.payment_preimage; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class PaymentFailed extends Event { public byte[] payment_hash; public boolean rejected_by_dest; - private PaymentFailed(Object _dummy, long ptr) { super(null, ptr); } + private PaymentFailed(long ptr, bindings.LDKEvent.PaymentFailed obj) { + super(null, ptr); + this.payment_hash = obj.payment_hash; + this.rejected_by_dest = obj.rejected_by_dest; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class PendingHTLCsForwardable extends Event { public long time_forwardable; - private PendingHTLCsForwardable(Object _dummy, long ptr) { super(null, ptr); } + private PendingHTLCsForwardable(long ptr, bindings.LDKEvent.PendingHTLCsForwardable obj) { + super(null, ptr); + this.time_forwardable = obj.time_forwardable; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class SpendableOutputs extends Event { public SpendableOutputDescriptor[] outputs; - private SpendableOutputs(Object _dummy, long ptr) { super(null, ptr); } + private SpendableOutputs(long ptr, bindings.LDKEvent.SpendableOutputs obj) { + super(null, ptr); + long[] outputs = obj.outputs; + SpendableOutputDescriptor[] arr_conv_27_arr = new SpendableOutputDescriptor[outputs.length]; + for (int b = 0; b < outputs.length; b++) { + long arr_conv_27 = outputs[b]; + SpendableOutputDescriptor arr_conv_27_hu_conv = SpendableOutputDescriptor.constr_from_ptr(arr_conv_27); + arr_conv_27_arr[b] = arr_conv_27_hu_conv; + } + this.outputs = arr_conv_27_arr; + } @Override long conv_to_c() { return 0; /*XXX*/ } } } diff --git a/src/main/java/org/ldk/structs/HTLCFailChannelUpdate.java b/src/main/java/org/ldk/structs/HTLCFailChannelUpdate.java index 63224cd8..69dccb8e 100644 --- a/src/main/java/org/ldk/structs/HTLCFailChannelUpdate.java +++ b/src/main/java/org/ldk/structs/HTLCFailChannelUpdate.java @@ -8,36 +8,54 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class HTLCFailChannelUpdate extends CommonBase { private HTLCFailChannelUpdate(Object _dummy, long ptr) { super(ptr); } + @Override @SuppressWarnings("deprecation") + protected void finalize() throws Throwable { + super.finalize(); + bindings.HTLCFailChannelUpdate_free(ptr); + } long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ } static HTLCFailChannelUpdate constr_from_ptr(long ptr) { bindings.LDKHTLCFailChannelUpdate raw_val = bindings.LDKHTLCFailChannelUpdate_ref_from_ptr(ptr); if (raw_val.getClass() == bindings.LDKHTLCFailChannelUpdate.ChannelUpdateMessage.class) { - return new ChannelUpdateMessage(null, ptr); + return new ChannelUpdateMessage(ptr, (bindings.LDKHTLCFailChannelUpdate.ChannelUpdateMessage)raw_val); } if (raw_val.getClass() == bindings.LDKHTLCFailChannelUpdate.ChannelClosed.class) { - return new ChannelClosed(null, ptr); + return new ChannelClosed(ptr, (bindings.LDKHTLCFailChannelUpdate.ChannelClosed)raw_val); } if (raw_val.getClass() == bindings.LDKHTLCFailChannelUpdate.NodeFailure.class) { - return new NodeFailure(null, ptr); + return new NodeFailure(ptr, (bindings.LDKHTLCFailChannelUpdate.NodeFailure)raw_val); } assert false; return null; // Unreachable without extending the (internal) bindings interface } public final static class ChannelUpdateMessage extends HTLCFailChannelUpdate { public ChannelUpdate msg; - private ChannelUpdateMessage(Object _dummy, long ptr) { super(null, ptr); } + private ChannelUpdateMessage(long ptr, bindings.LDKHTLCFailChannelUpdate.ChannelUpdateMessage obj) { + super(null, ptr); + long msg = obj.msg; + ChannelUpdate msg_hu_conv = new ChannelUpdate(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class ChannelClosed extends HTLCFailChannelUpdate { public long short_channel_id; public boolean is_permanent; - private ChannelClosed(Object _dummy, long ptr) { super(null, ptr); } + private ChannelClosed(long ptr, bindings.LDKHTLCFailChannelUpdate.ChannelClosed obj) { + super(null, ptr); + this.short_channel_id = obj.short_channel_id; + this.is_permanent = obj.is_permanent; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class NodeFailure extends HTLCFailChannelUpdate { public byte[] node_id; public boolean is_permanent; - private NodeFailure(Object _dummy, long ptr) { super(null, ptr); } + private NodeFailure(long ptr, bindings.LDKHTLCFailChannelUpdate.NodeFailure obj) { + super(null, ptr); + this.node_id = obj.node_id; + this.is_permanent = obj.is_permanent; + } @Override long conv_to_c() { return 0; /*XXX*/ } } } diff --git a/src/main/java/org/ldk/structs/MessageSendEvent.java b/src/main/java/org/ldk/structs/MessageSendEvent.java index 460ec3e8..a19a60a2 100644 --- a/src/main/java/org/ldk/structs/MessageSendEvent.java +++ b/src/main/java/org/ldk/structs/MessageSendEvent.java @@ -8,56 +8,61 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class MessageSendEvent extends CommonBase { private MessageSendEvent(Object _dummy, long ptr) { super(ptr); } + @Override @SuppressWarnings("deprecation") + protected void finalize() throws Throwable { + super.finalize(); + bindings.MessageSendEvent_free(ptr); + } long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ } static MessageSendEvent constr_from_ptr(long ptr) { bindings.LDKMessageSendEvent raw_val = bindings.LDKMessageSendEvent_ref_from_ptr(ptr); if (raw_val.getClass() == bindings.LDKMessageSendEvent.SendAcceptChannel.class) { - return new SendAcceptChannel(null, ptr); + return new SendAcceptChannel(ptr, (bindings.LDKMessageSendEvent.SendAcceptChannel)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.SendOpenChannel.class) { - return new SendOpenChannel(null, ptr); + return new SendOpenChannel(ptr, (bindings.LDKMessageSendEvent.SendOpenChannel)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.SendFundingCreated.class) { - return new SendFundingCreated(null, ptr); + return new SendFundingCreated(ptr, (bindings.LDKMessageSendEvent.SendFundingCreated)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.SendFundingSigned.class) { - return new SendFundingSigned(null, ptr); + return new SendFundingSigned(ptr, (bindings.LDKMessageSendEvent.SendFundingSigned)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.SendFundingLocked.class) { - return new SendFundingLocked(null, ptr); + return new SendFundingLocked(ptr, (bindings.LDKMessageSendEvent.SendFundingLocked)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.SendAnnouncementSignatures.class) { - return new SendAnnouncementSignatures(null, ptr); + return new SendAnnouncementSignatures(ptr, (bindings.LDKMessageSendEvent.SendAnnouncementSignatures)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.UpdateHTLCs.class) { - return new UpdateHTLCs(null, ptr); + return new UpdateHTLCs(ptr, (bindings.LDKMessageSendEvent.UpdateHTLCs)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.SendRevokeAndACK.class) { - return new SendRevokeAndACK(null, ptr); + return new SendRevokeAndACK(ptr, (bindings.LDKMessageSendEvent.SendRevokeAndACK)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.SendClosingSigned.class) { - return new SendClosingSigned(null, ptr); + return new SendClosingSigned(ptr, (bindings.LDKMessageSendEvent.SendClosingSigned)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.SendShutdown.class) { - return new SendShutdown(null, ptr); + return new SendShutdown(ptr, (bindings.LDKMessageSendEvent.SendShutdown)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.SendChannelReestablish.class) { - return new SendChannelReestablish(null, ptr); + return new SendChannelReestablish(ptr, (bindings.LDKMessageSendEvent.SendChannelReestablish)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.BroadcastChannelAnnouncement.class) { - return new BroadcastChannelAnnouncement(null, ptr); + return new BroadcastChannelAnnouncement(ptr, (bindings.LDKMessageSendEvent.BroadcastChannelAnnouncement)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.BroadcastNodeAnnouncement.class) { - return new BroadcastNodeAnnouncement(null, ptr); + return new BroadcastNodeAnnouncement(ptr, (bindings.LDKMessageSendEvent.BroadcastNodeAnnouncement)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.BroadcastChannelUpdate.class) { - return new BroadcastChannelUpdate(null, ptr); + return new BroadcastChannelUpdate(ptr, (bindings.LDKMessageSendEvent.BroadcastChannelUpdate)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.HandleError.class) { - return new HandleError(null, ptr); + return new HandleError(ptr, (bindings.LDKMessageSendEvent.HandleError)raw_val); } if (raw_val.getClass() == bindings.LDKMessageSendEvent.PaymentFailureNetworkUpdate.class) { - return new PaymentFailureNetworkUpdate(null, ptr); + return new PaymentFailureNetworkUpdate(ptr, (bindings.LDKMessageSendEvent.PaymentFailureNetworkUpdate)raw_val); } assert false; return null; // Unreachable without extending the (internal) bindings interface } @@ -65,94 +70,189 @@ public class MessageSendEvent extends CommonBase { public final static class SendAcceptChannel extends MessageSendEvent { public byte[] node_id; public AcceptChannel msg; - private SendAcceptChannel(Object _dummy, long ptr) { super(null, ptr); } + private SendAcceptChannel(long ptr, bindings.LDKMessageSendEvent.SendAcceptChannel obj) { + super(null, ptr); + this.node_id = obj.node_id; + long msg = obj.msg; + AcceptChannel msg_hu_conv = new AcceptChannel(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class SendOpenChannel extends MessageSendEvent { public byte[] node_id; public OpenChannel msg; - private SendOpenChannel(Object _dummy, long ptr) { super(null, ptr); } + private SendOpenChannel(long ptr, bindings.LDKMessageSendEvent.SendOpenChannel obj) { + super(null, ptr); + this.node_id = obj.node_id; + long msg = obj.msg; + OpenChannel msg_hu_conv = new OpenChannel(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class SendFundingCreated extends MessageSendEvent { public byte[] node_id; public FundingCreated msg; - private SendFundingCreated(Object _dummy, long ptr) { super(null, ptr); } + private SendFundingCreated(long ptr, bindings.LDKMessageSendEvent.SendFundingCreated obj) { + super(null, ptr); + this.node_id = obj.node_id; + long msg = obj.msg; + FundingCreated msg_hu_conv = new FundingCreated(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class SendFundingSigned extends MessageSendEvent { public byte[] node_id; public FundingSigned msg; - private SendFundingSigned(Object _dummy, long ptr) { super(null, ptr); } + private SendFundingSigned(long ptr, bindings.LDKMessageSendEvent.SendFundingSigned obj) { + super(null, ptr); + this.node_id = obj.node_id; + long msg = obj.msg; + FundingSigned msg_hu_conv = new FundingSigned(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class SendFundingLocked extends MessageSendEvent { public byte[] node_id; public FundingLocked msg; - private SendFundingLocked(Object _dummy, long ptr) { super(null, ptr); } + private SendFundingLocked(long ptr, bindings.LDKMessageSendEvent.SendFundingLocked obj) { + super(null, ptr); + this.node_id = obj.node_id; + long msg = obj.msg; + FundingLocked msg_hu_conv = new FundingLocked(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class SendAnnouncementSignatures extends MessageSendEvent { public byte[] node_id; public AnnouncementSignatures msg; - private SendAnnouncementSignatures(Object _dummy, long ptr) { super(null, ptr); } + private SendAnnouncementSignatures(long ptr, bindings.LDKMessageSendEvent.SendAnnouncementSignatures obj) { + super(null, ptr); + this.node_id = obj.node_id; + long msg = obj.msg; + AnnouncementSignatures msg_hu_conv = new AnnouncementSignatures(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class UpdateHTLCs extends MessageSendEvent { public byte[] node_id; public CommitmentUpdate updates; - private UpdateHTLCs(Object _dummy, long ptr) { super(null, ptr); } + private UpdateHTLCs(long ptr, bindings.LDKMessageSendEvent.UpdateHTLCs obj) { + super(null, ptr); + this.node_id = obj.node_id; + long updates = obj.updates; + CommitmentUpdate updates_hu_conv = new CommitmentUpdate(null, updates); + this.updates = updates_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class SendRevokeAndACK extends MessageSendEvent { public byte[] node_id; public RevokeAndACK msg; - private SendRevokeAndACK(Object _dummy, long ptr) { super(null, ptr); } + private SendRevokeAndACK(long ptr, bindings.LDKMessageSendEvent.SendRevokeAndACK obj) { + super(null, ptr); + this.node_id = obj.node_id; + long msg = obj.msg; + RevokeAndACK msg_hu_conv = new RevokeAndACK(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class SendClosingSigned extends MessageSendEvent { public byte[] node_id; public ClosingSigned msg; - private SendClosingSigned(Object _dummy, long ptr) { super(null, ptr); } + private SendClosingSigned(long ptr, bindings.LDKMessageSendEvent.SendClosingSigned obj) { + super(null, ptr); + this.node_id = obj.node_id; + long msg = obj.msg; + ClosingSigned msg_hu_conv = new ClosingSigned(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class SendShutdown extends MessageSendEvent { public byte[] node_id; public Shutdown msg; - private SendShutdown(Object _dummy, long ptr) { super(null, ptr); } + private SendShutdown(long ptr, bindings.LDKMessageSendEvent.SendShutdown obj) { + super(null, ptr); + this.node_id = obj.node_id; + long msg = obj.msg; + Shutdown msg_hu_conv = new Shutdown(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class SendChannelReestablish extends MessageSendEvent { public byte[] node_id; public ChannelReestablish msg; - private SendChannelReestablish(Object _dummy, long ptr) { super(null, ptr); } + private SendChannelReestablish(long ptr, bindings.LDKMessageSendEvent.SendChannelReestablish obj) { + super(null, ptr); + this.node_id = obj.node_id; + long msg = obj.msg; + ChannelReestablish msg_hu_conv = new ChannelReestablish(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class BroadcastChannelAnnouncement extends MessageSendEvent { public ChannelAnnouncement msg; public ChannelUpdate update_msg; - private BroadcastChannelAnnouncement(Object _dummy, long ptr) { super(null, ptr); } + private BroadcastChannelAnnouncement(long ptr, bindings.LDKMessageSendEvent.BroadcastChannelAnnouncement obj) { + super(null, ptr); + long msg = obj.msg; + ChannelAnnouncement msg_hu_conv = new ChannelAnnouncement(null, msg); + this.msg = msg_hu_conv; + long update_msg = obj.update_msg; + ChannelUpdate update_msg_hu_conv = new ChannelUpdate(null, update_msg); + this.update_msg = update_msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class BroadcastNodeAnnouncement extends MessageSendEvent { public NodeAnnouncement msg; - private BroadcastNodeAnnouncement(Object _dummy, long ptr) { super(null, ptr); } + private BroadcastNodeAnnouncement(long ptr, bindings.LDKMessageSendEvent.BroadcastNodeAnnouncement obj) { + super(null, ptr); + long msg = obj.msg; + NodeAnnouncement msg_hu_conv = new NodeAnnouncement(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class BroadcastChannelUpdate extends MessageSendEvent { public ChannelUpdate msg; - private BroadcastChannelUpdate(Object _dummy, long ptr) { super(null, ptr); } + private BroadcastChannelUpdate(long ptr, bindings.LDKMessageSendEvent.BroadcastChannelUpdate obj) { + super(null, ptr); + long msg = obj.msg; + ChannelUpdate msg_hu_conv = new ChannelUpdate(null, msg); + this.msg = msg_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class HandleError extends MessageSendEvent { public byte[] node_id; public ErrorAction action; - private HandleError(Object _dummy, long ptr) { super(null, ptr); } + private HandleError(long ptr, bindings.LDKMessageSendEvent.HandleError obj) { + super(null, ptr); + this.node_id = obj.node_id; + long action = obj.action; + ErrorAction action_hu_conv = ErrorAction.constr_from_ptr(action); + this.action = action_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class PaymentFailureNetworkUpdate extends MessageSendEvent { public HTLCFailChannelUpdate update; - private PaymentFailureNetworkUpdate(Object _dummy, long ptr) { super(null, ptr); } + private PaymentFailureNetworkUpdate(long ptr, bindings.LDKMessageSendEvent.PaymentFailureNetworkUpdate obj) { + super(null, ptr); + long update = obj.update; + HTLCFailChannelUpdate update_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(update); + this.update = update_hu_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } } diff --git a/src/main/java/org/ldk/structs/NetAddress.java b/src/main/java/org/ldk/structs/NetAddress.java index 73c93ae1..32e333f2 100644 --- a/src/main/java/org/ldk/structs/NetAddress.java +++ b/src/main/java/org/ldk/structs/NetAddress.java @@ -8,20 +8,25 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class NetAddress extends CommonBase { private NetAddress(Object _dummy, long ptr) { super(ptr); } + @Override @SuppressWarnings("deprecation") + protected void finalize() throws Throwable { + super.finalize(); + bindings.NetAddress_free(ptr); + } long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ } static NetAddress constr_from_ptr(long ptr) { bindings.LDKNetAddress raw_val = bindings.LDKNetAddress_ref_from_ptr(ptr); if (raw_val.getClass() == bindings.LDKNetAddress.IPv4.class) { - return new IPv4(null, ptr); + return new IPv4(ptr, (bindings.LDKNetAddress.IPv4)raw_val); } if (raw_val.getClass() == bindings.LDKNetAddress.IPv6.class) { - return new IPv6(null, ptr); + return new IPv6(ptr, (bindings.LDKNetAddress.IPv6)raw_val); } if (raw_val.getClass() == bindings.LDKNetAddress.OnionV2.class) { - return new OnionV2(null, ptr); + return new OnionV2(ptr, (bindings.LDKNetAddress.OnionV2)raw_val); } if (raw_val.getClass() == bindings.LDKNetAddress.OnionV3.class) { - return new OnionV3(null, ptr); + return new OnionV3(ptr, (bindings.LDKNetAddress.OnionV3)raw_val); } assert false; return null; // Unreachable without extending the (internal) bindings interface } @@ -29,19 +34,31 @@ public class NetAddress extends CommonBase { public final static class IPv4 extends NetAddress { public byte[] addr; public short port; - private IPv4(Object _dummy, long ptr) { super(null, ptr); } + private IPv4(long ptr, bindings.LDKNetAddress.IPv4 obj) { + super(null, ptr); + this.addr = obj.addr; + this.port = obj.port; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class IPv6 extends NetAddress { public byte[] addr; public short port; - private IPv6(Object _dummy, long ptr) { super(null, ptr); } + private IPv6(long ptr, bindings.LDKNetAddress.IPv6 obj) { + super(null, ptr); + this.addr = obj.addr; + this.port = obj.port; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class OnionV2 extends NetAddress { public byte[] addr; public short port; - private OnionV2(Object _dummy, long ptr) { super(null, ptr); } + private OnionV2(long ptr, bindings.LDKNetAddress.OnionV2 obj) { + super(null, ptr); + this.addr = obj.addr; + this.port = obj.port; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class OnionV3 extends NetAddress { @@ -49,7 +66,13 @@ public class NetAddress extends CommonBase { public short checksum; public byte version; public short port; - private OnionV3(Object _dummy, long ptr) { super(null, ptr); } + private OnionV3(long ptr, bindings.LDKNetAddress.OnionV3 obj) { + super(null, ptr); + this.ed25519_pubkey = obj.ed25519_pubkey; + this.checksum = obj.checksum; + this.version = obj.version; + this.port = obj.port; + } @Override long conv_to_c() { return 0; /*XXX*/ } } } diff --git a/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java b/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java index 42dd314b..c812679b 100644 --- a/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java +++ b/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java @@ -8,17 +8,22 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class SpendableOutputDescriptor extends CommonBase { private SpendableOutputDescriptor(Object _dummy, long ptr) { super(ptr); } + @Override @SuppressWarnings("deprecation") + protected void finalize() throws Throwable { + super.finalize(); + bindings.SpendableOutputDescriptor_free(ptr); + } long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ } static SpendableOutputDescriptor constr_from_ptr(long ptr) { bindings.LDKSpendableOutputDescriptor raw_val = bindings.LDKSpendableOutputDescriptor_ref_from_ptr(ptr); if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticOutput.class) { - return new StaticOutput(null, ptr); + return new StaticOutput(ptr, (bindings.LDKSpendableOutputDescriptor.StaticOutput)raw_val); } if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.DynamicOutputP2WSH.class) { - return new DynamicOutputP2WSH(null, ptr); + return new DynamicOutputP2WSH(ptr, (bindings.LDKSpendableOutputDescriptor.DynamicOutputP2WSH)raw_val); } if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticOutputCounterpartyPayment.class) { - return new StaticOutputCounterpartyPayment(null, ptr); + return new StaticOutputCounterpartyPayment(ptr, (bindings.LDKSpendableOutputDescriptor.StaticOutputCounterpartyPayment)raw_val); } assert false; return null; // Unreachable without extending the (internal) bindings interface } @@ -26,7 +31,15 @@ public class SpendableOutputDescriptor extends CommonBase { public final static class StaticOutput extends SpendableOutputDescriptor { public OutPoint outpoint; public TxOut output; - private StaticOutput(Object _dummy, long ptr) { super(null, ptr); } + private StaticOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutput obj) { + super(null, ptr); + long outpoint = obj.outpoint; + OutPoint outpoint_hu_conv = new OutPoint(null, outpoint); + this.outpoint = outpoint_hu_conv; + long output = obj.output; + TxOut output_conv = new TxOut(null, output); + this.output = output_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class DynamicOutputP2WSH extends SpendableOutputDescriptor { @@ -36,14 +49,43 @@ public class SpendableOutputDescriptor extends CommonBase { public TxOut output; public TwoTuple key_derivation_params; public byte[] revocation_pubkey; - private DynamicOutputP2WSH(Object _dummy, long ptr) { super(null, ptr); } + private DynamicOutputP2WSH(long ptr, bindings.LDKSpendableOutputDescriptor.DynamicOutputP2WSH obj) { + super(null, ptr); + long outpoint = obj.outpoint; + OutPoint outpoint_hu_conv = new OutPoint(null, outpoint); + this.outpoint = outpoint_hu_conv; + this.per_commitment_point = obj.per_commitment_point; + this.to_self_delay = obj.to_self_delay; + long output = obj.output; + TxOut output_conv = new TxOut(null, output); + this.output = output_conv; + long key_derivation_params = obj.key_derivation_params; + long key_derivation_params_a = bindings.LDKC2Tuple_u64u64Z_get_a(key_derivation_params); + long key_derivation_params_b = bindings.LDKC2Tuple_u64u64Z_get_b(key_derivation_params); + TwoTuple key_derivation_params_conv = new TwoTuple(key_derivation_params_a, key_derivation_params_b); + this.key_derivation_params = key_derivation_params_conv; + this.revocation_pubkey = obj.revocation_pubkey; + } @Override long conv_to_c() { return 0; /*XXX*/ } } public final static class StaticOutputCounterpartyPayment extends SpendableOutputDescriptor { public OutPoint outpoint; public TxOut output; public TwoTuple key_derivation_params; - private StaticOutputCounterpartyPayment(Object _dummy, long ptr) { super(null, ptr); } + private StaticOutputCounterpartyPayment(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutputCounterpartyPayment obj) { + super(null, ptr); + long outpoint = obj.outpoint; + OutPoint outpoint_hu_conv = new OutPoint(null, outpoint); + this.outpoint = outpoint_hu_conv; + long output = obj.output; + TxOut output_conv = new TxOut(null, output); + this.output = output_conv; + long key_derivation_params = obj.key_derivation_params; + long key_derivation_params_a = bindings.LDKC2Tuple_u64u64Z_get_a(key_derivation_params); + long key_derivation_params_b = bindings.LDKC2Tuple_u64u64Z_get_b(key_derivation_params); + TwoTuple key_derivation_params_conv = new TwoTuple(key_derivation_params_a, key_derivation_params_b); + this.key_derivation_params = key_derivation_params_conv; + } @Override long conv_to_c() { return 0; /*XXX*/ } } } diff --git a/src/main/jni/bindings.c b/src/main/jni/bindings.c index 57f35b9c..facddab9 100644 --- a/src/main/jni/bindings.c +++ b/src/main/jni/bindings.c @@ -476,12 +476,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneMonitorUpdate LDKMonitorUpdateError err_var = (*val->contents.err); CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long err_ref; - if (err_var.is_owned) { - err_ref = (long)err_var.inner | 1; - } else { - err_ref = (long)&err_var; - } + long err_ref = (long)err_var.inner & ~1; return err_ref; } JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1OutPoint_1_1CVec_1u8Z_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) { @@ -616,7 +611,8 @@ JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1Sign for (size_t i = 0; i < res_var.datalen; i++) { jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 64); (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 64, res_var.data[i].compact_form); - (*_env)->SetObjectArrayElement(_env, res_arr, i, arr_conv_8_arr);} + (*_env)->SetObjectArrayElement(_env, res_arr, i, arr_conv_8_arr); + } return res_arr; } JNIEXPORT jbyte JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1SignatureZNoneZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) { @@ -725,12 +721,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePaymentSendFa LDKPaymentSendFailure err_var = (*val->contents.err); CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long err_ref; - if (err_var.is_owned) { - err_ref = (long)err_var.inner | 1; - } else { - err_ref = (long)&err_var; - } + long err_ref = (long)err_var.inner & ~1; return err_ref; } JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3TupleTempl_1ChannelAnnouncement_1_1ChannelUpdate_1_1ChannelUpdate_1new(JNIEnv *_env, jclass _b, jlong a, jlong b, jlong c) { @@ -769,12 +760,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NonePeerHandleErr LDKPeerHandleError err_var = (*val->contents.err); CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long err_ref; - if (err_var.is_owned) { - err_ref = (long)err_var.inner | 1; - } else { - err_ref = (long)&err_var; - } + long err_ref = (long)err_var.inner & ~1; return err_ref; } JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1HTLCOutputInCommitment_1_1Signature_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) { @@ -821,12 +807,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSpendableOutputDescripto LDKOutPoint outpoint_var = obj->static_output.outpoint; CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long outpoint_ref; - if (outpoint_var.is_owned) { - outpoint_ref = (long)outpoint_var.inner | 1; - } else { - outpoint_ref = (long)&outpoint_var; - } + long outpoint_ref = (long)outpoint_var.inner & ~1; long output_ref = (long)&obj->static_output.output; return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_StaticOutput_class, LDKSpendableOutputDescriptor_StaticOutput_meth, outpoint_ref, output_ref); } @@ -834,12 +815,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSpendableOutputDescripto LDKOutPoint outpoint_var = obj->dynamic_output_p2wsh.outpoint; CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long outpoint_ref; - if (outpoint_var.is_owned) { - outpoint_ref = (long)outpoint_var.inner | 1; - } else { - outpoint_ref = (long)&outpoint_var; - } + long outpoint_ref = (long)outpoint_var.inner & ~1; jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33); (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, obj->dynamic_output_p2wsh.per_commitment_point.compressed_form); long output_ref = (long)&obj->dynamic_output_p2wsh.output; @@ -852,12 +828,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSpendableOutputDescripto LDKOutPoint outpoint_var = obj->static_output_counterparty_payment.outpoint; CHECK((((long)outpoint_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&outpoint_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long outpoint_ref; - if (outpoint_var.is_owned) { - outpoint_ref = (long)outpoint_var.inner | 1; - } else { - outpoint_ref = (long)&outpoint_var; - } + long outpoint_ref = (long)outpoint_var.inner & ~1; long output_ref = (long)&obj->static_output_counterparty_payment.output; long key_derivation_params_ref = (long)&obj->static_output_counterparty_payment.key_derivation_params; return (*_env)->NewObject(_env, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_class, LDKSpendableOutputDescriptor_StaticOutputCounterpartyPayment_meth, outpoint_ref, output_ref, key_derivation_params_ref); @@ -953,12 +924,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEvent_1ref_1from_1ptr (J LDKOutPoint funding_txo_var = obj->funding_broadcast_safe.funding_txo; CHECK((((long)funding_txo_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&funding_txo_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long funding_txo_ref; - if (funding_txo_var.is_owned) { - funding_txo_ref = (long)funding_txo_var.inner | 1; - } else { - funding_txo_ref = (long)&funding_txo_var; - } + long funding_txo_ref = (long)funding_txo_var.inner & ~1; return (*_env)->NewObject(_env, LDKEvent_FundingBroadcastSafe_class, LDKEvent_FundingBroadcastSafe_meth, funding_txo_ref, obj->funding_broadcast_safe.user_channel_id); } case LDKEvent_PaymentReceived: { @@ -1025,12 +991,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKErrorAction_1ref_1from_1 LDKErrorMessage msg_var = obj->disconnect_peer.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKErrorAction_DisconnectPeer_class, LDKErrorAction_DisconnectPeer_meth, msg_ref); } case LDKErrorAction_IgnoreError: { @@ -1040,12 +1001,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKErrorAction_1ref_1from_1 LDKErrorMessage msg_var = obj->send_error_message.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKErrorAction_SendErrorMessage_class, LDKErrorAction_SendErrorMessage_meth, msg_ref); } default: abort(); @@ -1081,12 +1037,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKHTLCFailChannelUpdate_1r LDKChannelUpdate msg_var = obj->channel_update_message.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_class, LDKHTLCFailChannelUpdate_ChannelUpdateMessage_meth, msg_ref); } case LDKHTLCFailChannelUpdate_ChannelClosed: { @@ -1223,12 +1174,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1f LDKAcceptChannel msg_var = obj->send_accept_channel.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_SendAcceptChannel_class, LDKMessageSendEvent_SendAcceptChannel_meth, node_id_arr, msg_ref); } case LDKMessageSendEvent_SendOpenChannel: { @@ -1237,12 +1183,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1f LDKOpenChannel msg_var = obj->send_open_channel.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_SendOpenChannel_class, LDKMessageSendEvent_SendOpenChannel_meth, node_id_arr, msg_ref); } case LDKMessageSendEvent_SendFundingCreated: { @@ -1251,12 +1192,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1f LDKFundingCreated msg_var = obj->send_funding_created.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingCreated_class, LDKMessageSendEvent_SendFundingCreated_meth, node_id_arr, msg_ref); } case LDKMessageSendEvent_SendFundingSigned: { @@ -1265,12 +1201,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1f LDKFundingSigned msg_var = obj->send_funding_signed.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingSigned_class, LDKMessageSendEvent_SendFundingSigned_meth, node_id_arr, msg_ref); } case LDKMessageSendEvent_SendFundingLocked: { @@ -1279,12 +1210,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1f LDKFundingLocked msg_var = obj->send_funding_locked.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_SendFundingLocked_class, LDKMessageSendEvent_SendFundingLocked_meth, node_id_arr, msg_ref); } case LDKMessageSendEvent_SendAnnouncementSignatures: { @@ -1293,12 +1219,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1f LDKAnnouncementSignatures msg_var = obj->send_announcement_signatures.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_SendAnnouncementSignatures_class, LDKMessageSendEvent_SendAnnouncementSignatures_meth, node_id_arr, msg_ref); } case LDKMessageSendEvent_UpdateHTLCs: { @@ -1307,12 +1228,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1f LDKCommitmentUpdate updates_var = obj->update_htl_cs.updates; CHECK((((long)updates_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&updates_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long updates_ref; - if (updates_var.is_owned) { - updates_ref = (long)updates_var.inner | 1; - } else { - updates_ref = (long)&updates_var; - } + long updates_ref = (long)updates_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_UpdateHTLCs_class, LDKMessageSendEvent_UpdateHTLCs_meth, node_id_arr, updates_ref); } case LDKMessageSendEvent_SendRevokeAndACK: { @@ -1321,12 +1237,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1f LDKRevokeAndACK msg_var = obj->send_revoke_and_ack.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_SendRevokeAndACK_class, LDKMessageSendEvent_SendRevokeAndACK_meth, node_id_arr, msg_ref); } case LDKMessageSendEvent_SendClosingSigned: { @@ -1335,12 +1246,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1f LDKClosingSigned msg_var = obj->send_closing_signed.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_SendClosingSigned_class, LDKMessageSendEvent_SendClosingSigned_meth, node_id_arr, msg_ref); } case LDKMessageSendEvent_SendShutdown: { @@ -1349,12 +1255,7 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1f LDKShutdown msg_var = obj->send_shutdown.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_SendShutdown_class, LDKMessageSendEvent_SendShutdown_meth, node_id_arr, msg_ref); } case LDKMessageSendEvent_SendChannelReestablish: { @@ -1363,57 +1264,32 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEvent_1ref_1f LDKChannelReestablish msg_var = obj->send_channel_reestablish.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_SendChannelReestablish_class, LDKMessageSendEvent_SendChannelReestablish_meth, node_id_arr, msg_ref); } case LDKMessageSendEvent_BroadcastChannelAnnouncement: { LDKChannelAnnouncement msg_var = obj->broadcast_channel_announcement.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; LDKChannelUpdate update_msg_var = obj->broadcast_channel_announcement.update_msg; CHECK((((long)update_msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&update_msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long update_msg_ref; - if (update_msg_var.is_owned) { - update_msg_ref = (long)update_msg_var.inner | 1; - } else { - update_msg_ref = (long)&update_msg_var; - } + long update_msg_ref = (long)update_msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastChannelAnnouncement_class, LDKMessageSendEvent_BroadcastChannelAnnouncement_meth, msg_ref, update_msg_ref); } case LDKMessageSendEvent_BroadcastNodeAnnouncement: { LDKNodeAnnouncement msg_var = obj->broadcast_node_announcement.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastNodeAnnouncement_class, LDKMessageSendEvent_BroadcastNodeAnnouncement_meth, msg_ref); } case LDKMessageSendEvent_BroadcastChannelUpdate: { LDKChannelUpdate msg_var = obj->broadcast_channel_update.msg; CHECK((((long)msg_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&msg_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long msg_ref; - if (msg_var.is_owned) { - msg_ref = (long)msg_var.inner | 1; - } else { - msg_ref = (long)&msg_var; - } + long msg_ref = (long)msg_var.inner & ~1; return (*_env)->NewObject(_env, LDKMessageSendEvent_BroadcastChannelUpdate_class, LDKMessageSendEvent_BroadcastChannelUpdate_meth, msg_ref); } case LDKMessageSendEvent_HandleError: { @@ -1527,10 +1403,13 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvide jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen); jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL); for (size_t s = 0; s < ret_var.datalen; s++) { - long arr_conv_18_ref = (long)&ret_var.data[s]; + LDKMessageSendEvent *arr_conv_18_copy = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent"); + *arr_conv_18_copy = MessageSendEvent_clone(&ret_var.data[s]); + long arr_conv_18_ref = (long)arr_conv_18_copy; ret_arr_ptr[s] = arr_conv_18_ref; } (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0); + CVec_MessageSendEventZ_free(ret_var); return ret_arr; } @@ -1632,10 +1511,13 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_EventsProvider_1get_1and jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen); jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL); for (size_t h = 0; h < ret_var.datalen; h++) { - long arr_conv_7_ref = (long)&ret_var.data[h]; + LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent"); + *arr_conv_7_copy = Event_clone(&ret_var.data[h]); + long arr_conv_7_ref = (long)arr_conv_7_copy; ret_arr_ptr[h] = arr_conv_7_ref; } (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0); + CVec_EventZ_free(ret_var); return ret_arr; } @@ -1880,7 +1762,7 @@ LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment_j if (arr_conv_24_var.is_owned) { arr_conv_24_ref = (long)arr_conv_24_var.inner | 1; } else { - arr_conv_24_ref = (long)&arr_conv_24_var; + arr_conv_24_ref = (long)arr_conv_24_var.inner & ~1; } htlcs_arr_ptr[y] = arr_conv_24_ref; } @@ -2224,7 +2106,7 @@ LDKCResult_NoneChannelMonitorUpdateErrZ watch_channel_jcall(const void* this_arg if (funding_txo_var.is_owned) { funding_txo_ref = (long)funding_txo_var.inner | 1; } else { - funding_txo_ref = (long)&funding_txo_var; + funding_txo_ref = (long)funding_txo_var.inner & ~1; } LDKChannelMonitor monitor_var = monitor; CHECK((((long)monitor_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. @@ -2233,7 +2115,7 @@ LDKCResult_NoneChannelMonitorUpdateErrZ watch_channel_jcall(const void* this_arg if (monitor_var.is_owned) { monitor_ref = (long)monitor_var.inner | 1; } else { - monitor_ref = (long)&monitor_var; + monitor_ref = (long)monitor_var.inner & ~1; } jobject obj = (*_env)->NewLocalRef(_env, j_calls->o); CHECK(obj != NULL); @@ -2253,7 +2135,7 @@ LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_jcall(const void* this_ar if (funding_txo_var.is_owned) { funding_txo_ref = (long)funding_txo_var.inner | 1; } else { - funding_txo_ref = (long)&funding_txo_var; + funding_txo_ref = (long)funding_txo_var.inner & ~1; } LDKChannelMonitorUpdate update_var = update; CHECK((((long)update_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. @@ -2262,7 +2144,7 @@ LDKCResult_NoneChannelMonitorUpdateErrZ update_channel_jcall(const void* this_ar if (update_var.is_owned) { update_ref = (long)update_var.inner | 1; } else { - update_ref = (long)&update_var; + update_ref = (long)update_var.inner & ~1; } jobject obj = (*_env)->NewLocalRef(_env, j_calls->o); CHECK(obj != NULL); @@ -2389,7 +2271,7 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_Watch_1release_1pending_ if (arr_conv_14_var.is_owned) { arr_conv_14_ref = (long)arr_conv_14_var.inner | 1; } else { - arr_conv_14_ref = (long)&arr_conv_14_var; + arr_conv_14_ref = (long)arr_conv_14_var.inner & ~1; } ret_arr_ptr[o] = arr_conv_14_ref; } @@ -2996,7 +2878,7 @@ void handle_open_channel_jcall(const void* this_arg, LDKPublicKey their_node_id, if (their_features_var.is_owned) { their_features_ref = (long)their_features_var.inner | 1; } else { - their_features_ref = (long)&their_features_var; + their_features_ref = (long)their_features_var.inner & ~1; } jobject obj = (*_env)->NewLocalRef(_env, j_calls->o); CHECK(obj != NULL); @@ -3015,7 +2897,7 @@ void handle_accept_channel_jcall(const void* this_arg, LDKPublicKey their_node_i if (their_features_var.is_owned) { their_features_ref = (long)their_features_var.inner | 1; } else { - their_features_ref = (long)&their_features_var; + their_features_ref = (long)their_features_var.inner & ~1; } jobject obj = (*_env)->NewLocalRef(_env, j_calls->o); CHECK(obj != NULL); @@ -3695,12 +3577,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolLightningErro LDKLightningError err_var = (*val->contents.err); CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long err_ref; - if (err_var.is_owned) { - err_ref = (long)err_var.inner | 1; - } else { - err_ref = (long)&err_var; - } + long err_ref = (long)err_var.inner & ~1; return err_ref; } JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C3TupleTempl_1ChannelAnnouncement_1_1ChannelUpdate_1_1ChannelUpdate_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) { @@ -3972,10 +3849,11 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1g jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen); jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL); for (size_t l = 0; l < ret_var.datalen; l++) { - long arr_conv_63_ref = (long)&ret_var.data[l]; + /*XXX False */long arr_conv_63_ref = (long)&ret_var.data[l]; ret_arr_ptr[l] = arr_conv_63_ref; } (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0); + CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ_free(ret_var); return ret_arr; } @@ -3995,7 +3873,7 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1g if (arr_conv_18_var.is_owned) { arr_conv_18_ref = (long)arr_conv_18_var.inner | 1; } else { - arr_conv_18_ref = (long)&arr_conv_18_var; + arr_conv_18_ref = (long)arr_conv_18_var.inner & ~1; } ret_arr_ptr[s] = arr_conv_18_ref; } @@ -4150,12 +4028,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1CVec_1u8ZPeerHand LDKPeerHandleError err_var = (*val->contents.err); CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long err_ref; - if (err_var.is_owned) { - err_ref = (long)err_var.inner | 1; - } else { - err_ref = (long)&err_var; - } + long err_ref = (long)err_var.inner & ~1; return err_ref; } JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) { @@ -4172,12 +4045,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1boolPeerHandleErr LDKPeerHandleError err_var = (*val->contents.err); CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long err_ref; - if (err_var.is_owned) { - err_ref = (long)err_var.inner | 1; - } else { - err_ref = (long)&err_var; - } + long err_ref = (long)err_var.inner & ~1; return err_ref; } JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1SecretKeySecpErrorZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) { @@ -4221,12 +4089,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSec LDKTxCreationKeys res_var = (*val->contents.result); CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long res_ref; - if (res_var.is_owned) { - res_ref = (long)res_var.inner | 1; - } else { - res_ref = (long)&res_var; - } + long res_ref = (long)res_var.inner & ~1; return res_ref; } JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_LDKCResult_1TxCreationKeysSecpErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) { @@ -4302,12 +4165,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErr LDKRoute res_var = (*val->contents.result); CHECK((((long)res_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&res_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long res_ref; - if (res_var.is_owned) { - res_ref = (long)res_var.inner | 1; - } else { - res_ref = (long)&res_var; - } + long res_ref = (long)res_var.inner & ~1; return res_ref; } JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErrorZ_1get_1err (JNIEnv * _env, jclass _a, jlong arg) { @@ -4316,12 +4174,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCResult_1RouteLightningErr LDKLightningError err_var = (*val->contents.err); CHECK((((long)err_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&err_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. - long err_ref; - if (err_var.is_owned) { - err_ref = (long)err_var.inner | 1; - } else { - err_ref = (long)&err_var; - } + long err_ref = (long)err_var.inner & ~1; return err_ref; } JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHint_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) { @@ -5349,12 +5202,26 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Event_1free(JNIEnv * _env, jcl Event_free(this_ptr_conv); } +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Event_1clone(JNIEnv * _env, jclass _b, jlong orig) { + LDKEvent* orig_conv = (LDKEvent*)orig; + LDKEvent* ret = MALLOC(sizeof(LDKEvent), "LDKEvent"); + *ret = Event_clone(orig_conv); + return (long)ret; +} + JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1free(JNIEnv * _env, jclass _b, jlong this_ptr) { LDKMessageSendEvent this_ptr_conv = *(LDKMessageSendEvent*)this_ptr; FREE((void*)this_ptr); MessageSendEvent_free(this_ptr_conv); } +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1clone(JNIEnv * _env, jclass _b, jlong orig) { + LDKMessageSendEvent* orig_conv = (LDKMessageSendEvent*)orig; + LDKMessageSendEvent* ret = MALLOC(sizeof(LDKMessageSendEvent), "LDKMessageSendEvent"); + *ret = MessageSendEvent_clone(orig_conv); + return (long)ret; +} + JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1free(JNIEnv * _env, jclass _b, jlong this_ptr) { LDKMessageSendEventsProvider this_ptr_conv = *(LDKMessageSendEventsProvider*)this_ptr; FREE((void*)this_ptr); @@ -5373,6 +5240,19 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_APIError_1free(JNIEnv * _env, APIError_free(this_ptr_conv); } +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_APIError_1clone(JNIEnv * _env, jclass _b, jlong orig) { + LDKAPIError* orig_conv = (LDKAPIError*)orig; + LDKAPIError* ret = MALLOC(sizeof(LDKAPIError), "LDKAPIError"); + *ret = APIError_clone(orig_conv); + return (long)ret; +} + +JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1clone(JNIEnv * _env, jclass _b, jlong orig) { + LDKLevel* orig_conv = (LDKLevel*)orig; + jclass ret = LDKLevel_to_java(_env, Level_clone(orig_conv)); + return ret; +} + JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_Level_1max(JNIEnv * _env, jclass _b) { jclass ret = LDKLevel_to_java(_env, Level_max()); return ret; @@ -5818,6 +5698,12 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1default(JNIEnv * return ((long)ret.inner) | (ret.is_owned ? 1 : 0); } +JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_AccessError_1clone(JNIEnv * _env, jclass _b, jlong orig) { + LDKAccessError* orig_conv = (LDKAccessError*)orig; + jclass ret = LDKAccessError_to_java(_env, AccessError_clone(orig_conv)); + return ret; +} + JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Access_1free(JNIEnv * _env, jclass _b, jlong this_ptr) { LDKAccess this_ptr_conv = *(LDKAccess*)this_ptr; FREE((void*)this_ptr); @@ -5842,6 +5728,12 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1free(JNI BroadcasterInterface_free(this_ptr_conv); } +JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ConfirmationTarget_1clone(JNIEnv * _env, jclass _b, jlong orig) { + LDKConfirmationTarget* orig_conv = (LDKConfirmationTarget*)orig; + jclass ret = LDKConfirmationTarget_to_java(_env, ConfirmationTarget_clone(orig_conv)); + return ret; +} + JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_FeeEstimator_1free(JNIEnv * _env, jclass _b, jlong this_ptr) { LDKFeeEstimator this_ptr_conv = *(LDKFeeEstimator*)this_ptr; FREE((void*)this_ptr); @@ -5979,6 +5871,12 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1read(JN return ((long)ret.inner) | (ret.is_owned ? 1 : 0); } +JNIEXPORT jclass JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdateErr_1clone(JNIEnv * _env, jclass _b, jlong orig) { + LDKChannelMonitorUpdateErr* orig_conv = (LDKChannelMonitorUpdateErr*)orig; + jclass ret = LDKChannelMonitorUpdateErr_to_java(_env, ChannelMonitorUpdateErr_clone(orig_conv)); + return ret; +} + JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MonitorUpdateError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) { LDKMonitorUpdateError this_ptr_conv; this_ptr_conv.inner = (void*)(this_ptr & (~1)); @@ -6082,7 +5980,7 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and if (arr_conv_14_var.is_owned) { arr_conv_14_ref = (long)arr_conv_14_var.inner | 1; } else { - arr_conv_14_ref = (long)&arr_conv_14_var; + arr_conv_14_ref = (long)arr_conv_14_var.inner & ~1; } ret_arr_ptr[o] = arr_conv_14_ref; } @@ -6099,10 +5997,13 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen); jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL); for (size_t h = 0; h < ret_var.datalen; h++) { - long arr_conv_7_ref = (long)&ret_var.data[h]; + LDKEvent *arr_conv_7_copy = MALLOC(sizeof(LDKEvent), "LDKEvent"); + *arr_conv_7_copy = Event_clone(&ret_var.data[h]); + long arr_conv_7_ref = (long)arr_conv_7_copy; ret_arr_ptr[h] = arr_conv_7_ref; } (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0); + CVec_EventZ_free(ret_var); return ret_arr; } @@ -6119,6 +6020,7 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1lat ret_arr_ptr[n] = arr_conv_13_ref; } (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0); + CVec_TransactionZ_free(ret_var); return ret_arr; } @@ -6163,10 +6065,11 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1block_1c jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen); jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL); for (size_t b = 0; b < ret_var.datalen; b++) { - long arr_conv_27_ref = (long)&ret_var.data[b]; + /*XXX False */long arr_conv_27_ref = (long)&ret_var.data[b]; ret_arr_ptr[b] = arr_conv_27_ref; } (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0); + CVec_C2Tuple_TxidCVec_TxOutZZZ_free(ret_var); return ret_arr; } @@ -6287,6 +6190,13 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1fre SpendableOutputDescriptor_free(this_ptr_conv); } +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1clone(JNIEnv * _env, jclass _b, jlong orig) { + LDKSpendableOutputDescriptor* orig_conv = (LDKSpendableOutputDescriptor*)orig; + LDKSpendableOutputDescriptor* ret = MALLOC(sizeof(LDKSpendableOutputDescriptor), "LDKSpendableOutputDescriptor"); + *ret = SpendableOutputDescriptor_clone(orig_conv); + return (long)ret; +} + JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1free(JNIEnv * _env, jclass _b, jlong this_ptr) { LDKChannelKeys this_ptr_conv = *(LDKChannelKeys*)this_ptr; FREE((void*)this_ptr); @@ -6768,7 +6678,7 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1ch if (arr_conv_16_var.is_owned) { arr_conv_16_ref = (long)arr_conv_16_var.inner | 1; } else { - arr_conv_16_ref = (long)&arr_conv_16_var; + arr_conv_16_ref = (long)arr_conv_16_var.inner & ~1; } ret_arr_ptr[q] = arr_conv_16_ref; } @@ -6792,7 +6702,7 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelManager_1list_1us if (arr_conv_16_var.is_owned) { arr_conv_16_ref = (long)arr_conv_16_var.inner | 1; } else { - arr_conv_16_ref = (long)&arr_conv_16_var; + arr_conv_16_ref = (long)arr_conv_16_var.inner & ~1; } ret_arr_ptr[q] = arr_conv_16_ref; } @@ -9083,6 +8993,13 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetAddress_1free(JNIEnv * _env NetAddress_free(this_ptr_conv); } +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetAddress_1clone(JNIEnv * _env, jclass _b, jlong orig) { + LDKNetAddress* orig_conv = (LDKNetAddress*)orig; + LDKNetAddress* ret = MALLOC(sizeof(LDKNetAddress), "LDKNetAddress"); + *ret = NetAddress_clone(orig_conv); + return (long)ret; +} + JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1free(JNIEnv * _env, jclass _b, jlong this_ptr) { LDKUnsignedNodeAnnouncement this_ptr_conv; this_ptr_conv.inner = (void*)(this_ptr & (~1)); @@ -10158,6 +10075,13 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorAction_1free(JNIEnv * _en ErrorAction_free(this_ptr_conv); } +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorAction_1clone(JNIEnv * _env, jclass _b, jlong orig) { + LDKErrorAction* orig_conv = (LDKErrorAction*)orig; + LDKErrorAction* ret = MALLOC(sizeof(LDKErrorAction), "LDKErrorAction"); + *ret = ErrorAction_clone(orig_conv); + return (long)ret; +} + JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1free(JNIEnv * _env, jclass _b, jlong this_ptr) { LDKLightningError this_ptr_conv; this_ptr_conv.inner = (void*)(this_ptr & (~1)); @@ -10458,6 +10382,13 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1free(JN HTLCFailChannelUpdate_free(this_ptr_conv); } +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1clone(JNIEnv * _env, jclass _b, jlong orig) { + LDKHTLCFailChannelUpdate* orig_conv = (LDKHTLCFailChannelUpdate*)orig; + LDKHTLCFailChannelUpdate* ret = MALLOC(sizeof(LDKHTLCFailChannelUpdate), "LDKHTLCFailChannelUpdate"); + *ret = HTLCFailChannelUpdate_clone(orig_conv); + return (long)ret; +} + JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1free(JNIEnv * _env, jclass _b, jlong this_ptr) { LDKChannelMessageHandler this_ptr_conv = *(LDKChannelMessageHandler*)this_ptr; FREE((void*)this_ptr); @@ -11191,7 +11122,9 @@ JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_PeerManager_1get_1peer for (size_t i = 0; i < ret_var.datalen; i++) { jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, 33); (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, 33, ret_var.data[i].compressed_form); - (*_env)->SetObjectArrayElement(_env, ret_arr, i, arr_conv_8_arr);} + (*_env)->SetObjectArrayElement(_env, ret_arr, i, arr_conv_8_arr); + } + CVec_PublicKeyZ_free(ret_var); return ret_arr; } diff --git a/src/main/jni/org_ldk_impl_bindings.h b/src/main/jni/org_ldk_impl_bindings.h index e1c4082e..8337a4ca 100644 --- a/src/main/jni/org_ldk_impl_bindings.h +++ b/src/main/jni/org_ldk_impl_bindings.h @@ -2471,6 +2471,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1HTLCOutputInCommitme JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Event_1free (JNIEnv *, jclass, jlong); +/* + * Class: org_ldk_impl_bindings + * Method: Event_clone + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Event_1clone + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: MessageSendEvent_free @@ -2479,6 +2487,14 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Event_1free JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1free (JNIEnv *, jclass, jlong); +/* + * Class: org_ldk_impl_bindings + * Method: MessageSendEvent_clone + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageSendEvent_1clone + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: MessageSendEventsProvider_free @@ -2503,6 +2519,22 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_EventsProvider_1free JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_APIError_1free (JNIEnv *, jclass, jlong); +/* + * Class: org_ldk_impl_bindings + * Method: APIError_clone + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_APIError_1clone + (JNIEnv *, jclass, jlong); + +/* + * Class: org_ldk_impl_bindings + * Method: Level_clone + * Signature: (J)Lorg/ldk/enums/LDKLevel; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_Level_1clone + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: Level_max @@ -2967,6 +2999,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1new JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1default (JNIEnv *, jclass); +/* + * Class: org_ldk_impl_bindings + * Method: AccessError_clone + * Signature: (J)Lorg/ldk/enums/LDKAccessError; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_AccessError_1clone + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: Access_free @@ -2999,6 +3039,14 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1free JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1free (JNIEnv *, jclass, jlong); +/* + * Class: org_ldk_impl_bindings + * Method: ConfirmationTarget_clone + * Signature: (J)Lorg/ldk/enums/LDKConfirmationTarget; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_ConfirmationTarget_1clone + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: FeeEstimator_free @@ -3103,6 +3151,14 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1wr JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1read (JNIEnv *, jclass, jbyteArray); +/* + * Class: org_ldk_impl_bindings + * Method: ChannelMonitorUpdateErr_clone + * Signature: (J)Lorg/ldk/enums/LDKChannelMonitorUpdateErr; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdateErr_1clone + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: MonitorUpdateError_free @@ -3311,6 +3367,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1read JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1free (JNIEnv *, jclass, jlong); +/* + * Class: org_ldk_impl_bindings + * Method: SpendableOutputDescriptor_clone + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SpendableOutputDescriptor_1clone + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: ChannelKeys_free @@ -5703,6 +5767,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1new JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NetAddress_1free (JNIEnv *, jclass, jlong); +/* + * Class: org_ldk_impl_bindings + * Method: NetAddress_clone + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetAddress_1clone + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: UnsignedNodeAnnouncement_free @@ -6647,6 +6719,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1new JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorAction_1free (JNIEnv *, jclass, jlong); +/* + * Class: org_ldk_impl_bindings + * Method: ErrorAction_clone + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorAction_1clone + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: LightningError_free @@ -6791,6 +6871,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1new JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1free (JNIEnv *, jclass, jlong); +/* + * Class: org_ldk_impl_bindings + * Method: HTLCFailChannelUpdate_clone + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCFailChannelUpdate_1clone + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: ChannelMessageHandler_free diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index 5dcc7a04..18e36c89 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -210,16 +210,14 @@ public class HumanObjectPeerTest { peer2.peer_manager.process_events(); while (!list.isEmpty()) { list.poll().join(); } - long[] events = bindings.EventsProvider_get_and_clear_pending_events(peer1.chan_manager_events._test_only_get_ptr()); + Event[] events = peer1.chan_manager_events.get_and_clear_pending_events(); assert events.length == 1; - bindings.LDKEvent event = bindings.LDKEvent_ref_from_ptr(events[0]); - assert event instanceof bindings.LDKEvent.FundingGenerationReady; - assert ((bindings.LDKEvent.FundingGenerationReady) event).channel_value_satoshis == 10000; - assert ((bindings.LDKEvent.FundingGenerationReady) event).user_channel_id == 42; - byte[] funding_spk = ((bindings.LDKEvent.FundingGenerationReady) event).output_script; + assert events[0] instanceof Event.FundingGenerationReady; + assert ((Event.FundingGenerationReady)events[0]).channel_value_satoshis == 10000; + assert ((Event.FundingGenerationReady)events[0]).user_channel_id == 42; + byte[] funding_spk = ((Event.FundingGenerationReady)events[0]).output_script; assert funding_spk.length == 34 && funding_spk[0] == 0 && funding_spk[1] == 32; // P2WSH - byte[] chan_id = ((bindings.LDKEvent.FundingGenerationReady) event).temporary_channel_id; - bindings.CVec_EventZ_free(events); + byte[] chan_id = ((Event.FundingGenerationReady)events[0]).temporary_channel_id; Transaction funding = new Transaction(NetworkParameters.fromID(NetworkParameters.ID_MAINNET)); funding.addInput(new TransactionInput(NetworkParameters.fromID(NetworkParameters.ID_MAINNET), funding, new byte[0])); @@ -233,11 +231,10 @@ public class HumanObjectPeerTest { peer2.peer_manager.process_events(); while (!list.isEmpty()) { list.poll().join(); } - events = bindings.EventsProvider_get_and_clear_pending_events(peer1.chan_manager_events._test_only_get_ptr()); + events = peer1.chan_manager_events.get_and_clear_pending_events(); assert events.length == 1; - event = bindings.LDKEvent_ref_from_ptr(events[0]); - assert event instanceof bindings.LDKEvent.FundingBroadcastSafe; - bindings.CVec_EventZ_free(events); + assert events[0] instanceof Event.FundingBroadcastSafe; + assert ((Event.FundingBroadcastSafe)events[0]).user_channel_id == 42; Block b = new Block(NetworkParameters.fromID(NetworkParameters.ID_MAINNET), 2, Sha256Hash.ZERO_HASH, Sha256Hash.ZERO_HASH, 42, 0, 0, Arrays.asList(new Transaction[]{funding})); peer1.connect_block(b, funding, 1); -- 2.39.5