From: Matt Corallo Date: Thu, 22 Oct 2020 04:09:49 +0000 (-0400) Subject: Provide human versions of trait interfaces, with a bunch of fixes to make it work X-Git-Tag: v0.0.1~94 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=aa0e2aade37133339f4113a0cd7465b111f0a0d0;p=ldk-java Provide human versions of trait interfaces, with a bunch of fixes to make it work Sadly gave up trying to get returns to be sane, so now returning an object from a trait implies that object is now unusable :(. --- diff --git a/genbindings.py b/genbindings.py index b70b0e48..b09d930b 100755 --- a/genbindings.py +++ b/genbindings.py @@ -98,6 +98,9 @@ trait_structs = set() result_types = set() tuple_types = {} +def is_common_base_ext(struct_name): + return struct_name in complex_enums or struct_name in opaque_structs or struct_name in trait_structs or struct_name in result_types + var_is_arr_regex = re.compile("\(\*([A-za-z0-9_]*)\)\[([a-z0-9]*)\]") var_ty_regex = re.compile("([A-za-z_0-9]*)(.*)") java_c_types_none_allowed = True # Unset when we do the real pass that populates the above sets @@ -562,7 +565,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg ret_conv = ("CANT PASS TRAIT TO Java?", ""), ret_conv_name = "NO CONV POSSIBLE", to_hu_conv = "DUMMY", to_hu_conv_name = None, from_hu_conv = (ty_info.var_name + " == null ? 0 : " + ty_info.var_name + ".ptr", "this.ptrs_to.add(" + ty_info.var_name + ")")) - if ty_info.rust_obj != "LDKu8slice": + if ty_info.rust_obj != "LDKu8slice" and ty_info.rust_obj != "LDKTransaction": # Don't bother free'ing slices passed in - Rust doesn't auto-free the # underlying unlike Vecs, and it gives Java more freedom. base_conv = base_conv + "\nFREE((void*)" + ty_info.var_name + ");"; @@ -576,38 +579,64 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None, 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()", "")) + to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = (ty_info.var_name + ".ptr", "")) if ty_info.rust_obj in tuple_types: + from_hu_conv = "bindings." + tuple_types[ty_info.rust_obj][1].replace("LDK", "") + "_new(" to_hu_conv_pfx = "" to_hu_conv_sfx = ty_info.java_hu_ty + " " + ty_info.var_name + "_conv = new " + ty_info.java_hu_ty + "(" for idx, conv in enumerate(tuple_types[ty_info.rust_obj][0]): if idx != 0: to_hu_conv_sfx = to_hu_conv_sfx + ", " + from_hu_conv = from_hu_conv + ", " conv.var_name = ty_info.var_name + "_" + chr(idx + ord("a")) 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" - to_hu_conv_sfx = to_hu_conv_sfx + conv_map.to_hu_conv_name; + to_hu_conv_sfx = to_hu_conv_sfx + conv_map.to_hu_conv_name + else: + to_hu_conv_sfx = to_hu_conv_sfx + ty_info.var_name + "_" + chr(idx + ord("a")) + if conv_map.from_hu_conv is not None: + from_hu_conv = from_hu_conv + conv_map.from_hu_conv[0].replace(ty_info.var_name + "_" + chr(idx + ord("a")), ty_info.var_name + "." + chr(idx + ord("a"))) + if conv_map.from_hu_conv[1] != "": + from_hu_conv = from_hu_conv + "/*XXX: Need to call " + conv_map.from_hu_conv[1] + "*/" else: - to_hu_conv_sfx = to_hu_conv_sfx + ty_info.var_name + "_" + chr(idx + ord("a")); + from_hu_conv = from_hu_conv + ty_info.var_name + "." + chr(idx + ord("a")) 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", - to_hu_conv = to_hu_conv_pfx + to_hu_conv_sfx + ");", to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = ("/*TODO b*/0", "")) + to_hu_conv = to_hu_conv_pfx + to_hu_conv_sfx + ");", to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = (from_hu_conv + ")", "")) # The manually-defined types - TxOut and Transaction + assert ty_info.rust_obj == "LDKTransaction" or ty_info.rust_obj == "LDKTxOut" + if ty_info.rust_obj == "LDKTransaction": + 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 = ("LDKTransaction *" + ty_info.var_name + "_copy = MALLOC(sizeof(LDKTransaction), \"LDKTransaction\");\n*" + ty_info.var_name + "_copy = ", ";\nlong " + ty_info.var_name + "_ref = (long)" + ty_info.var_name + "_copy;"), + ret_conv_name = ty_info.var_name + "_ref", + to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_conv = new " +ty_info.java_hu_ty + "(null, " + ty_info.var_name + ");", + to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = (ty_info.var_name + ".ptr", "")) 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", - to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_conv = new " +ty_info.java_hu_ty + "(null, " + ty_info.var_name + ");", - to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = ("/*TODO 1*/0", "")) + 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", + to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_conv = new " +ty_info.java_hu_ty + "(null, " + ty_info.var_name + ");", + to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = (ty_info.var_name + ".ptr", "")) else: assert(not is_free) if ty_info.rust_obj in opaque_structs: 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 = None, ret_conv_name = None, to_hu_conv = "TODO 2", to_hu_conv_name = None, + ret_conv = None, ret_conv_name = None, + to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_hu_conv = new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ");", + to_hu_conv_name = ty_info.var_name + "_hu_conv", + from_hu_conv = (ty_info.var_name + " == null ? 0 : " + ty_info.var_name + ".ptr & ~1", "this.ptrs_to.add(" + ty_info.var_name + ")")) # its a pointer, no conv needed + elif ty_info.rust_obj in complex_enums: + return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, + arg_conv = ty_info.rust_obj + "* " + ty_info.var_name + "_conv = (" + ty_info.rust_obj + "*)" + ty_info.var_name + ";", + arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None, + ret_conv = None, ret_conv_name = None, + 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 + " == null ? 0 : " + ty_info.var_name + ".ptr & ~1", "this.ptrs_to.add(" + ty_info.var_name + ")")) # its a pointer, no conv needed elif ty_info.rust_obj in trait_structs: return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, @@ -622,7 +651,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg elif ty_info.is_ptr: return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = None, arg_conv_name = ty_info.var_name, arg_conv_cleanup = None, - ret_conv = None, ret_conv_name = None, to_hu_conv = "TODO 4", to_hu_conv_name = None, from_hu_conv = None) + ret_conv = None, ret_conv_name = None, to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None) else: return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = None, arg_conv_name = ty_info.var_name, arg_conv_cleanup = None, @@ -656,7 +685,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg ret_conv_name = "(long)ret", arg_conv = None, arg_conv_name = None, arg_conv_cleanup = None, to_hu_conv = ty_info.java_hu_ty + " ret_hu_conv = " + ty_info.java_hu_ty + ".constr_from_ptr(ret);\nret_hu_conv.ptrs_to.add(this);", - to_hu_conv_name = "ret_hu_conv", from_hu_conv = (ty_info.var_name + ".conv_to_c()", "")) + to_hu_conv_name = "ret_hu_conv", from_hu_conv = ("ret != null ? ret.ptr : 0", "")) if ty_info.rust_obj in opaque_structs: # If we're returning a newly-allocated struct, we don't want Rust to ever # free, instead relying on the Java GC to lose the ref. We undo this in @@ -674,7 +703,14 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg ret_conv_name = "(long)ret", arg_conv = None, arg_conv_name = None, arg_conv_cleanup = None, to_hu_conv = ty_info.java_hu_ty + " ret_hu_conv = new " + ty_info.java_hu_ty + "(null, ret);\nret_hu_conv.ptrs_to.add(this);", - to_hu_conv_name = "ret_hu_conv", from_hu_conv = None) + to_hu_conv_name = "ret_hu_conv", from_hu_conv = ("ret.ptr", "")) + elif ty_info.rust_obj in tuple_types: + return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, + ret_conv = (ty_info.rust_obj + "* ret = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n*ret = ", ";"), + ret_conv_name = "(long)ret", + arg_conv = None, arg_conv_name = None, arg_conv_cleanup = None, + to_hu_conv = ty_info.java_hu_ty + " ret_hu_conv = new " + ty_info.java_hu_ty + "(null, ret);\nret_hu_conv.ptrs_to.add(this);", + to_hu_conv_name = "ret_hu_conv", from_hu_conv = ("bindings." + ty_info.rust_obj.replace("LDK", "") + "_new(ret.a, ret.b)", "")) else: return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, ret_conv = (ty_info.rust_obj + "* ret = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n*ret = ", ";"), @@ -932,9 +968,8 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg 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\tif (ptr != 0) { bindings." + 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") java_hu_subclasses = "" @@ -970,7 +1005,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg if idx != 0 and idx < len(enum_var_lines) - 2: 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" + java_hu_subclasses = java_hu_subclasses + "\t\tpublic final " + 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" @@ -989,8 +1024,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg out_java_enum.write("\t\t}\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" + java_hu_subclasses = java_hu_subclasses + "\t\t}\n\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") out_java_enum.write(java_hu_subclasses) @@ -1049,8 +1083,9 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg out_java_trait.write(hu_struct_file_prefix) out_java_trait.write("public class " + struct_name.replace("LDK","") + " extends CommonBase {\n") - out_java_trait.write("\t" + struct_name.replace("LDK", "") + "(Object _dummy, long ptr) { super(ptr); }\n") - out_java_trait.write("\tpublic " + struct_name.replace("LDK", "") + "(bindings." + struct_name + " arg") # XXX: Should be priv ( but is currently used in tests + out_java_trait.write("\tfinal bindings." + struct_name + " bindings_instance;\n") + out_java_trait.write("\t" + struct_name.replace("LDK", "") + "(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }\n") + out_java_trait.write("\tprivate " + struct_name.replace("LDK", "") + "(bindings." + struct_name + " arg") for var_line in field_var_lines: if var_line.group(1) in trait_structs: out_java_trait.write(", bindings." + var_line.group(1) + " " + var_line.group(2)) @@ -1061,15 +1096,21 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg out_java_trait.write(", " + var_line.group(2)) out_java_trait.write("));\n") out_java_trait.write("\t\tthis.ptrs_to.add(arg);\n") + out_java_trait.write("\t\tthis.bindings_instance = arg;\n") out_java_trait.write("\t}\n") out_java_trait.write("\t@Override @SuppressWarnings(\"deprecation\")\n") out_java_trait.write("\tprotected void finalize() throws Throwable {\n") - out_java_trait.write("\t\tbindings." + struct_name.replace("LDK","") + "_free(ptr); super.finalize();\n") + out_java_trait.write("\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); } super.finalize();\n") out_java_trait.write("\t}\n\n") - java_trait_constr = "\tpublic " + struct_name.replace("LDK", "") + "(" + struct_name.replace("LDK", "") + "Interface arg) {\n" - java_trait_constr = java_trait_constr + "\t\tthis(new bindings." + struct_name + "() {\n" - #out_java_trait.write("\tpublic static interface " + struct_name.replace("LDK", "") + "Interface {\n") + java_trait_constr = "\tpublic " + struct_name.replace("LDK", "") + "(" + struct_name.replace("LDK", "") + "Interface arg" + for var_line in field_var_lines: + if var_line.group(1) in trait_structs: + # Ideally we'd be able to take any instance of the interface, but our C code can only represent + # Java-implemented version, so we require users pass a Java implementation here :/ + java_trait_constr = java_trait_constr + ", " + var_line.group(1).replace("LDK", "") + "." + var_line.group(1).replace("LDK", "") + "Interface " + var_line.group(2) + java_trait_constr = java_trait_constr + ") {\n\t\tthis(new bindings." + struct_name + "() {\n" + out_java_trait.write("\tpublic static interface " + struct_name.replace("LDK", "") + "Interface {\n") out_java.write("\tpublic interface " + struct_name + " {\n") java_meths = [] for fn_line in trait_fn_lines: @@ -1079,7 +1120,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg 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) + "(" - #out_java_trait.write("\t\t" + ret_ty_info.java_hu_ty + " " + fn_line.group(2) + "(") + out_java_trait.write("\t\t" + ret_ty_info.java_hu_ty + " " + fn_line.group(2) + "(") is_const = fn_line.group(3) is not None out_c.write(fn_line.group(1) + fn_line.group(2) + "_jcall(") if is_const: @@ -1094,12 +1135,12 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg if idx >= 2: out_java.write(", ") java_trait_constr = java_trait_constr + ", " - #out_java_trait.write(", ") + out_java_trait.write(", ") out_c.write(", ") 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) + out_java_trait.write(arg_conv_info.java_hu_ty + " " + arg_conv_info.arg_name) java_trait_constr = java_trait_constr + arg_conv_info.java_ty + " " + arg_conv_info.arg_name arg_names.append(arg_conv_info) java_meth_descr = java_meth_descr + arg_conv_info.java_fn_ty_arg @@ -1107,7 +1148,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg java_meths.append(java_meth_descr) out_java.write(");\n") - #out_java_trait.write(");\n") + out_java_trait.write(");\n") java_trait_constr = java_trait_constr + ") {\n" out_c.write(") {\n") out_c.write("\t" + struct_name + "_JCalls *j_calls = (" + struct_name + "_JCalls*) this_arg;\n") @@ -1119,6 +1160,8 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg out_c.write("\t" + arg_info.ret_conv[0].replace('\n', '\n\t')); out_c.write(arg_info.arg_name) out_c.write(arg_info.ret_conv[1].replace('\n', '\n\t') + "\n") + if arg_info.to_hu_conv is not None: + java_trait_constr = java_trait_constr + "\t\t\t\t" + arg_info.to_hu_conv.replace("\n", "\n\t\t\t\t") + "\n" out_c.write("\tjobject obj = (*_env)->NewLocalRef(_env, j_calls->o);\n\tCHECK(obj != NULL);\n") if ret_ty_info.c_ty.endswith("Array"): @@ -1128,15 +1171,21 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg else: out_c.write("\t" + fn_line.group(1).strip() + "* ret = (" + fn_line.group(1).strip() + "*)(*_env)->CallLongMethod(_env, obj, j_calls->" + fn_line.group(2) + "_meth"); if ret_ty_info.java_ty != "void": - java_trait_constr = java_trait_constr + "\t\t\t\treturn arg." + fn_line.group(2) + "(" + java_trait_constr = java_trait_constr + "\t\t\t\t" + ret_ty_info.java_hu_ty + " ret = arg." + fn_line.group(2) + "(" else: java_trait_constr = java_trait_constr + "\t\t\t\targ." + fn_line.group(2) + "(" - for arg_info in arg_names: + for idx, arg_info in enumerate(arg_names): if arg_info.ret_conv is not None: out_c.write(", " + arg_info.ret_conv_name) else: out_c.write(", " + arg_info.arg_name) + if idx != 0: + java_trait_constr = java_trait_constr + ", " + if arg_info.to_hu_conv_name is not None: + java_trait_constr = java_trait_constr + arg_info.to_hu_conv_name + else: + java_trait_constr = java_trait_constr + arg_info.arg_name out_c.write(");\n"); if ret_ty_info.arg_conv is not None: out_c.write("\t" + ret_ty_info.arg_conv.replace("\n", "\n\t").replace("arg", "ret") + "\n\treturn " + ret_ty_info.arg_conv_name.replace("arg", "ret") + ";\n") @@ -1146,7 +1195,18 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg out_c.write("\tFREE(ret);\n") out_c.write("\treturn res;\n") out_c.write("}\n") - java_trait_constr = java_trait_constr + ");\n\t\t\t}\n" + java_trait_constr = java_trait_constr + ");\n" + if ret_ty_info.java_ty != "void": + if ret_ty_info.from_hu_conv is not None: + java_trait_constr = java_trait_constr + "\t\t\t\t" + ret_ty_info.java_ty + " result = " + ret_ty_info.from_hu_conv[0] + ";\n" + if ret_ty_info.from_hu_conv[1] != "": + java_trait_constr = java_trait_constr + "\t\t\t\t" + ret_ty_info.from_hu_conv[1] + "\n" + if is_common_base_ext(ret_ty_info.rust_obj): + java_trait_constr = java_trait_constr + "\t\t\t\tret.ptr = 0;\n" + java_trait_constr = java_trait_constr + "\t\t\t\treturn result;\n" + else: + java_trait_constr = java_trait_constr + "\t\t\t\treturn ret;\n" + java_trait_constr = java_trait_constr + "\t\t\t}\n" elif fn_line.group(2) == "free": out_c.write("static void " + struct_name + "_JCalls_free(void* this_arg) {\n") out_c.write("\t" + struct_name + "_JCalls *j_calls = (" + struct_name + "_JCalls*) this_arg;\n") @@ -1156,8 +1216,12 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg out_c.write("\t\t(*env)->DeleteWeakGlobalRef(env, j_calls->o);\n") out_c.write("\t\tFREE(j_calls);\n") out_c.write("\t}\n}\n") - #out_java_trait.write("\t}\n") - #out_java_trait.write(java_trait_constr + "\t\t});\n\t}\n") + java_trait_constr = java_trait_constr + "\t\t}" + for var_line in field_var_lines: + if var_line.group(1) in trait_structs: + java_trait_constr = java_trait_constr + ", new " + var_line.group(2) + "(" + var_line.group(2) + ").bindings_instance" + out_java_trait.write("\t}\n") + out_java_trait.write(java_trait_constr + ");\n\t}\n") # Write out a clone function whether we need one or not, as we use them in moving to rust out_c.write("static void* " + struct_name + "_JCalls_clone(const void* this_arg) {\n") @@ -1302,7 +1366,13 @@ static void alloc_freed(void* ptr) { allocation* p = NULL; DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success); allocation* it = allocation_ll; - while (it->ptr != ptr) { p = it; it = it->next; } + while (it->ptr != ptr) { + p = it; it = it->next; + if (it == NULL) { + fprintf(stderr, "Tried to free unknown pointer %p!\\n", ptr); + return; // addrsan should catch malloc-unknown and print more info than we have + } + } if (p) { p->next = it->next; } else { allocation_ll = it->next; } DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success); DO_ASSERT(it->ptr == ptr); @@ -1375,6 +1445,7 @@ public class bindings { public static native byte[] get_u8_slice_bytes(long slice_ptr); public static native long bytes_to_u8_vec(byte[] bytes); public static native long new_txpointer_copy_data(byte[] txdata); + public static native void txpointer_free(long ptr); public static native long vec_slice_len(long vec); public static native long new_empty_slice_vec(); @@ -1423,12 +1494,18 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data (JN LDKTransaction *txdata = (LDKTransaction*)MALLOC(sizeof(LDKTransaction), "LDKTransaction"); txdata->datalen = (*env)->GetArrayLength(env, bytes); txdata->data = (uint8_t*)MALLOC(txdata->datalen, "Tx Data Bytes"); - txdata->data_is_owned = true; + txdata->data_is_owned = false; (*env)->GetByteArrayRegion (env, bytes, 0, txdata->datalen, txdata->data); return (long)txdata; } +JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_txpointer_1free (JNIEnv * env, jclass _b, jlong ptr) { + LDKTransaction *tx = (LDKTransaction*)ptr; + tx->data_is_owned = true; + Transaction_free(*tx); + FREE((void*)ptr); +} JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) { - // Check offsets of a few Vec types are all consistent as we're meant to be generic across types + // Check offsets of a few Vec types are all consistent as we're meant to be generic across types _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically"); _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically"); _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically"); @@ -1437,7 +1514,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env return (long)vec->datalen; } JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec (JNIEnv * _env, jclass _b) { - // Check sizes of a few Vec types are all consistent as we're meant to be generic across types + // Check sizes of a few Vec types are all consistent as we're meant to be generic across types _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_SignatureZ), "Vec<*> needs to be mapped identically"); _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_MessageSendEventZ), "Vec<*> needs to be mapped identically"); _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_EventZ), "Vec<*> needs to be mapped identically"); @@ -1459,7 +1536,7 @@ _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen), out_java_struct.write("""package org.ldk.structs; import java.util.LinkedList; class CommonBase { - final long ptr; + long ptr; LinkedList ptrs_to = new LinkedList(); protected CommonBase(long ptr) { this.ptr = ptr; } public long _test_only_get_ptr() { return this.ptr; } @@ -1568,7 +1645,7 @@ class CommonBase { out_java_struct.write("\t@Override @SuppressWarnings(\"deprecation\")\n") out_java_struct.write("\tprotected void finalize() throws Throwable {\n") out_java_struct.write("\t\tsuper.finalize();\n") - out_java_struct.write("\t\tbindings." + struct_name.replace("LDK","") + "_free(ptr);\n") + out_java_struct.write("\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); }\n") out_java_struct.write("\t}\n\n") elif result_contents is not None: result_templ_structs.add(struct_name) @@ -1674,6 +1751,7 @@ class CommonBase { out_java_struct.write(hu_struct_file_prefix) out_java_struct.write("public class TxOut extends CommonBase{\n") out_java_struct.write("\tTxOut(java.lang.Object _dummy, long ptr) { super(ptr); }\n") + out_java_struct.write("\tlong to_c_ptr() { return 0; }\n") # TODO: TxOut body out_java_struct.write("}") elif struct_name == "LDKTransaction": @@ -1681,6 +1759,8 @@ class CommonBase { out_java_struct.write(hu_struct_file_prefix) out_java_struct.write("public class Transaction extends CommonBase{\n") out_java_struct.write("\tTransaction(java.lang.Object _dummy, long ptr) { super(ptr); }\n") + out_java_struct.write("\tpublic Transaction(byte[] data) { super(bindings.new_txpointer_copy_data(data)); }\n") + out_java_struct.write("\t@Override public void finalize() throws Throwable { super.finalize(); bindings.txpointer_free(ptr); }\n") # TODO: Transaction body out_java_struct.write("}") else: @@ -1721,7 +1801,7 @@ class CommonBase { out_java_struct.write("public class " + human_ty + " extends CommonBase {\n") out_java_struct.write("\tprivate " + human_ty + "(Object _dummy, long ptr) { super(ptr); }\n") out_java_struct.write("\tprotected void finalize() throws Throwable {\n") - out_java_struct.write("\t\tbindings." + alias_match.group(2).replace("LDK","") + "_free(ptr); super.finalize();\n") + out_java_struct.write("\t\tif (ptr != 0) { bindings." + alias_match.group(2).replace("LDK","") + "_free(ptr); } super.finalize();\n") out_java_struct.write("\t}\n\n") out_java_struct.write("\tstatic " + human_ty + " constr_from_ptr(long ptr) {\n") out_java_struct.write("\t\tif (bindings." + alias_match.group(2) + "_result_ok(ptr)) {\n") @@ -1753,7 +1833,7 @@ class CommonBase { out_c.write("return *val->contents.result") out_c.write(";\n}\n") - out_java_struct.write("\t\tpublic " + res_map.java_hu_ty + " res;\n") + out_java_struct.write("\t\tpublic final " + res_map.java_hu_ty + " res;\n") out_java_struct.write("\t\tprivate " + human_ty + "_OK(Object _dummy, long ptr) {\n") out_java_struct.write("\t\t\tsuper(_dummy, ptr);\n") if res_map.to_hu_conv is not None: @@ -1762,13 +1842,24 @@ class CommonBase { out_java_struct.write("\n\t\t\tthis.res = " + res_map.to_hu_conv_name + ";\n") else: out_java_struct.write("\t\t\tthis.res = bindings." + alias_match.group(2) + "_get_ok(ptr);\n") - out_java_struct.write("\t\t}\n\n") + out_java_struct.write("\t\t}\n") + if alias_match.group(2).startswith("LDKCResult_None"): + out_java_struct.write("\t\tpublic " + human_ty + "_OK() {\n\t\t\tthis(null, bindings.C" + human_ty + "_ok());\n") + else: + out_java_struct.write("\t\tpublic " + human_ty + "_OK(" + res_map.java_hu_ty + " res) {\n") + if res_map.from_hu_conv is not None: + out_java_struct.write("\t\t\tthis(null, bindings.C" + human_ty + "_ok(" + res_map.from_hu_conv[0] + "));\n") + if res_map.from_hu_conv[1] != "": + out_java_struct.write("\t\t\t" + res_map.from_hu_conv[1] + ";\n") + else: + out_java_struct.write("\t\t\tthis(null, bindings.C" + human_ty + "_ok(res));\n") + out_java_struct.write("\t\t}\n\t}\n\n") out_java.write("\tpublic static native " + err_map.java_ty + " " + alias_match.group(2) + "_get_err(long arg);\n") out_c.write("JNIEXPORT " + err_map.c_ty + " JNICALL Java_org_ldk_impl_bindings_" + alias_match.group(2).replace("_", "_1") + "_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {\n") out_c.write("\t" + alias_match.group(2) + " *val = (" + alias_match.group(2) + "*)arg;\n") out_c.write("\tCHECK(!val->result_ok);\n\t") - out_java_struct.write("\t}\n\tpublic static final class " + human_ty + "_Err extends " + human_ty + " {\n") + out_java_struct.write("\tpublic static final class " + human_ty + "_Err extends " + human_ty + " {\n") if err_map.ret_conv is not None: out_c.write(err_map.ret_conv[0].replace("\n", "\n\t") + "(*val->contents.err)") out_c.write(err_map.ret_conv[1].replace("\n", "\n\t") + "\n\treturn " + err_map.ret_conv_name) @@ -1776,7 +1867,7 @@ class CommonBase { out_c.write("return *val->contents.err") out_c.write(";\n}\n") - out_java_struct.write("\t\tpublic " + err_map.java_hu_ty + " err;\n") + out_java_struct.write("\t\tpublic final " + err_map.java_hu_ty + " err;\n") out_java_struct.write("\t\tprivate " + human_ty + "_Err(Object _dummy, long ptr) {\n") out_java_struct.write("\t\t\tsuper(_dummy, ptr);\n") if err_map.to_hu_conv is not None: @@ -1785,6 +1876,18 @@ class CommonBase { out_java_struct.write("\n\t\t\tthis.err = " + err_map.to_hu_conv_name + ";\n") else: out_java_struct.write("\t\t\tthis.err = bindings." + alias_match.group(2) + "_get_err(ptr);\n") + out_java_struct.write("\t\t}\n") + + if alias_match.group(2).endswith("NoneZ"): + out_java_struct.write("\t\tpublic " + human_ty + "_Err() {\n\t\t\tthis(null, bindings.C" + human_ty + "_err());\n") + else: + out_java_struct.write("\t\tpublic " + human_ty + "_Err(" + err_map.java_hu_ty + " err) {\n") + if err_map.from_hu_conv is not None: + out_java_struct.write("\t\t\tthis(null, bindings.C" + human_ty + "_err(" + err_map.from_hu_conv[0] + "));\n") + if err_map.from_hu_conv[1] != "": + out_java_struct.write("\t\t\t" + err_map.from_hu_conv[1] + ";\n") + else: + out_java_struct.write("\t\t\tthis(null, bindings.C" + human_ty + "_err(err));\n") out_java_struct.write("\t\t}\n\t}\n}\n") elif fn_ptr is not None: map_fn(line, fn_ptr, None, None) diff --git a/src/main/java/org/ldk/impl/bindings.java b/src/main/java/org/ldk/impl/bindings.java index 6754b4af..f9c07cfb 100644 --- a/src/main/java/org/ldk/impl/bindings.java +++ b/src/main/java/org/ldk/impl/bindings.java @@ -23,6 +23,7 @@ public class bindings { public static native byte[] get_u8_slice_bytes(long slice_ptr); public static native long bytes_to_u8_vec(byte[] bytes); public static native long new_txpointer_copy_data(byte[] txdata); + public static native void txpointer_free(long ptr); public static native long vec_slice_len(long vec); public static native long new_empty_slice_vec(); diff --git a/src/main/java/org/ldk/structs/APIError.java b/src/main/java/org/ldk/structs/APIError.java index 40704400..fdcfc09b 100644 --- a/src/main/java/org/ldk/structs/APIError.java +++ b/src/main/java/org/ldk/structs/APIError.java @@ -11,9 +11,8 @@ public class APIError extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.APIError_free(ptr); + if (ptr != 0) { 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) { @@ -35,43 +34,38 @@ public class APIError extends CommonBase { } public final static class APIMisuseError extends APIError { - public byte[] err; + public final byte[] err; 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; + public final byte[] err; + public final int feerate; 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; + public final String err; 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; + public final byte[] err; 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(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/AcceptChannel.java b/src/main/java/org/ldk/structs/AcceptChannel.java index e53d364d..f0f0a39a 100644 --- a/src/main/java/org/ldk/structs/AcceptChannel.java +++ b/src/main/java/org/ldk/structs/AcceptChannel.java @@ -11,7 +11,7 @@ public class AcceptChannel extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.AcceptChannel_free(ptr); + if (ptr != 0) { bindings.AcceptChannel_free(ptr); } } public static AcceptChannel constructor_clone(AcceptChannel orig) { diff --git a/src/main/java/org/ldk/structs/Access.java b/src/main/java/org/ldk/structs/Access.java index 375dca92..15b3d742 100644 --- a/src/main/java/org/ldk/structs/Access.java +++ b/src/main/java/org/ldk/structs/Access.java @@ -7,16 +7,31 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class Access extends CommonBase { - Access(Object _dummy, long ptr) { super(ptr); } - public Access(bindings.LDKAccess arg) { + final bindings.LDKAccess bindings_instance; + Access(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private Access(bindings.LDKAccess arg) { super(bindings.LDKAccess_new(arg)); this.ptrs_to.add(arg); + this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.Access_free(ptr); super.finalize(); + if (ptr != 0) { bindings.Access_free(ptr); } super.finalize(); } + public static interface AccessInterface { + Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id); + } + public Access(AccessInterface arg) { + this(new bindings.LDKAccess() { + @Override public long get_utxo(byte[] genesis_hash, long short_channel_id) { + Result_TxOutAccessErrorZ ret = arg.get_utxo(genesis_hash, short_channel_id); + long result = ret != null ? ret.ptr : 0; + ret.ptr = 0; + return result; + } + }); + } public Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id) { long ret = bindings.Access_get_utxo(this.ptr, genesis_hash, short_channel_id); Result_TxOutAccessErrorZ ret_hu_conv = Result_TxOutAccessErrorZ.constr_from_ptr(ret); diff --git a/src/main/java/org/ldk/structs/AnnouncementSignatures.java b/src/main/java/org/ldk/structs/AnnouncementSignatures.java index f28ff8ad..a3bbf117 100644 --- a/src/main/java/org/ldk/structs/AnnouncementSignatures.java +++ b/src/main/java/org/ldk/structs/AnnouncementSignatures.java @@ -11,7 +11,7 @@ public class AnnouncementSignatures extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.AnnouncementSignatures_free(ptr); + if (ptr != 0) { bindings.AnnouncementSignatures_free(ptr); } } public static AnnouncementSignatures constructor_clone(AnnouncementSignatures orig) { diff --git a/src/main/java/org/ldk/structs/BroadcasterInterface.java b/src/main/java/org/ldk/structs/BroadcasterInterface.java index 8ba7bf4c..2af8bc66 100644 --- a/src/main/java/org/ldk/structs/BroadcasterInterface.java +++ b/src/main/java/org/ldk/structs/BroadcasterInterface.java @@ -7,15 +7,28 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class BroadcasterInterface extends CommonBase { - BroadcasterInterface(Object _dummy, long ptr) { super(ptr); } - public BroadcasterInterface(bindings.LDKBroadcasterInterface arg) { + final bindings.LDKBroadcasterInterface bindings_instance; + BroadcasterInterface(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private BroadcasterInterface(bindings.LDKBroadcasterInterface arg) { super(bindings.LDKBroadcasterInterface_new(arg)); this.ptrs_to.add(arg); + this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.BroadcasterInterface_free(ptr); super.finalize(); + if (ptr != 0) { bindings.BroadcasterInterface_free(ptr); } super.finalize(); } + public static interface BroadcasterInterfaceInterface { + void broadcast_transaction(Transaction tx); + } + public BroadcasterInterface(BroadcasterInterfaceInterface arg) { + this(new bindings.LDKBroadcasterInterface() { + @Override public void broadcast_transaction(long tx) { + Transaction tx_conv = new Transaction(null, tx); + arg.broadcast_transaction(tx_conv); + } + }); + } // Skipped BroadcasterInterface_broadcast_transaction } diff --git a/src/main/java/org/ldk/structs/ChainMonitor.java b/src/main/java/org/ldk/structs/ChainMonitor.java index 90a3aa75..236f8e39 100644 --- a/src/main/java/org/ldk/structs/ChainMonitor.java +++ b/src/main/java/org/ldk/structs/ChainMonitor.java @@ -11,11 +11,11 @@ public class ChainMonitor extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChainMonitor_free(ptr); + if (ptr != 0) { bindings.ChainMonitor_free(ptr); } } public void block_connected(byte[] header, TwoTuple[] txdata, int height) { - bindings.ChainMonitor_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_29 -> /*TODO b*/0).toArray(), height); + bindings.ChainMonitor_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_29 -> bindings.C2Tuple_usizeTransactionZ_new(arr_conv_29.a, arr_conv_29.b.ptr)).toArray(), height); /* TODO 2 TwoTuple */; } diff --git a/src/main/java/org/ldk/structs/ChannelAnnouncement.java b/src/main/java/org/ldk/structs/ChannelAnnouncement.java index a15f3619..1d481940 100644 --- a/src/main/java/org/ldk/structs/ChannelAnnouncement.java +++ b/src/main/java/org/ldk/structs/ChannelAnnouncement.java @@ -11,7 +11,7 @@ public class ChannelAnnouncement extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelAnnouncement_free(ptr); + if (ptr != 0) { bindings.ChannelAnnouncement_free(ptr); } } public static ChannelAnnouncement constructor_clone(ChannelAnnouncement orig) { diff --git a/src/main/java/org/ldk/structs/ChannelConfig.java b/src/main/java/org/ldk/structs/ChannelConfig.java index 6ac3d712..ed37eb1d 100644 --- a/src/main/java/org/ldk/structs/ChannelConfig.java +++ b/src/main/java/org/ldk/structs/ChannelConfig.java @@ -11,7 +11,7 @@ public class ChannelConfig extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelConfig_free(ptr); + if (ptr != 0) { bindings.ChannelConfig_free(ptr); } } public static ChannelConfig constructor_clone(ChannelConfig orig) { diff --git a/src/main/java/org/ldk/structs/ChannelDetails.java b/src/main/java/org/ldk/structs/ChannelDetails.java index 6e4f5bb8..dfc373e5 100644 --- a/src/main/java/org/ldk/structs/ChannelDetails.java +++ b/src/main/java/org/ldk/structs/ChannelDetails.java @@ -11,7 +11,7 @@ public class ChannelDetails extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelDetails_free(ptr); + if (ptr != 0) { bindings.ChannelDetails_free(ptr); } } public static ChannelDetails constructor_clone(ChannelDetails orig) { diff --git a/src/main/java/org/ldk/structs/ChannelFeatures.java b/src/main/java/org/ldk/structs/ChannelFeatures.java index 97bba12d..428ed8b7 100644 --- a/src/main/java/org/ldk/structs/ChannelFeatures.java +++ b/src/main/java/org/ldk/structs/ChannelFeatures.java @@ -11,7 +11,7 @@ public class ChannelFeatures extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelFeatures_free(ptr); + if (ptr != 0) { bindings.ChannelFeatures_free(ptr); } } } diff --git a/src/main/java/org/ldk/structs/ChannelHandshakeConfig.java b/src/main/java/org/ldk/structs/ChannelHandshakeConfig.java index 33cf8e71..98578edc 100644 --- a/src/main/java/org/ldk/structs/ChannelHandshakeConfig.java +++ b/src/main/java/org/ldk/structs/ChannelHandshakeConfig.java @@ -11,7 +11,7 @@ public class ChannelHandshakeConfig extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelHandshakeConfig_free(ptr); + if (ptr != 0) { bindings.ChannelHandshakeConfig_free(ptr); } } public static ChannelHandshakeConfig constructor_clone(ChannelHandshakeConfig orig) { diff --git a/src/main/java/org/ldk/structs/ChannelHandshakeLimits.java b/src/main/java/org/ldk/structs/ChannelHandshakeLimits.java index bc99da64..bf8249d0 100644 --- a/src/main/java/org/ldk/structs/ChannelHandshakeLimits.java +++ b/src/main/java/org/ldk/structs/ChannelHandshakeLimits.java @@ -11,7 +11,7 @@ public class ChannelHandshakeLimits extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelHandshakeLimits_free(ptr); + if (ptr != 0) { bindings.ChannelHandshakeLimits_free(ptr); } } public static ChannelHandshakeLimits constructor_clone(ChannelHandshakeLimits orig) { diff --git a/src/main/java/org/ldk/structs/ChannelInfo.java b/src/main/java/org/ldk/structs/ChannelInfo.java index 412f646e..ae95717d 100644 --- a/src/main/java/org/ldk/structs/ChannelInfo.java +++ b/src/main/java/org/ldk/structs/ChannelInfo.java @@ -11,7 +11,7 @@ public class ChannelInfo extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelInfo_free(ptr); + if (ptr != 0) { bindings.ChannelInfo_free(ptr); } } public ChannelFeatures get_features() { diff --git a/src/main/java/org/ldk/structs/ChannelKeys.java b/src/main/java/org/ldk/structs/ChannelKeys.java index 9dfce22c..2639799f 100644 --- a/src/main/java/org/ldk/structs/ChannelKeys.java +++ b/src/main/java/org/ldk/structs/ChannelKeys.java @@ -7,16 +7,110 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class ChannelKeys extends CommonBase { - ChannelKeys(Object _dummy, long ptr) { super(ptr); } - public ChannelKeys(bindings.LDKChannelKeys arg) { + final bindings.LDKChannelKeys bindings_instance; + ChannelKeys(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private ChannelKeys(bindings.LDKChannelKeys arg) { super(bindings.LDKChannelKeys_new(arg)); this.ptrs_to.add(arg); + this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.ChannelKeys_free(ptr); super.finalize(); + if (ptr != 0) { bindings.ChannelKeys_free(ptr); } super.finalize(); } + public static interface ChannelKeysInterface { + byte[] get_per_commitment_point(long idx); + byte[] release_commitment_secret(long idx); + TwoTuple key_derivation_params(); + Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(int feerate_per_kw, Transaction commitment_tx, PreCalculatedTxCreationKeys keys, HTLCOutputInCommitment[] htlcs); + Result_SignatureNoneZ sign_holder_commitment(HolderCommitmentTransaction holder_commitment_tx); + Result_CVec_SignatureZNoneZ sign_holder_commitment_htlc_transactions(HolderCommitmentTransaction holder_commitment_tx); + Result_SignatureNoneZ sign_justice_transaction(Transaction justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc); + Result_SignatureNoneZ sign_counterparty_htlc_transaction(Transaction htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc); + Result_SignatureNoneZ sign_closing_transaction(Transaction closing_tx); + Result_SignatureNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg); + void on_accept(ChannelPublicKeys channel_points, short counterparty_selected_contest_delay, short holder_selected_contest_delay); + } + public ChannelKeys(ChannelKeysInterface arg) { + this(new bindings.LDKChannelKeys() { + @Override public byte[] get_per_commitment_point(long idx) { + byte[] ret = arg.get_per_commitment_point(idx); + return ret; + } + @Override public byte[] release_commitment_secret(long idx) { + byte[] ret = arg.release_commitment_secret(idx); + return ret; + } + @Override public long key_derivation_params() { + TwoTuple ret = arg.key_derivation_params(); + long result = bindings.C2Tuple_u64u64Z_new(ret.a, ret.b); + return result; + } + @Override public long sign_counterparty_commitment(int feerate_per_kw, long commitment_tx, long keys, long[] htlcs) { + Transaction commitment_tx_conv = new Transaction(null, commitment_tx); + PreCalculatedTxCreationKeys keys_hu_conv = new PreCalculatedTxCreationKeys(null, keys); + HTLCOutputInCommitment[] arr_conv_24_arr = new HTLCOutputInCommitment[htlcs.length]; + for (int y = 0; y < htlcs.length; y++) { + long arr_conv_24 = htlcs[y]; + HTLCOutputInCommitment arr_conv_24_hu_conv = new HTLCOutputInCommitment(null, arr_conv_24); + arr_conv_24_arr[y] = arr_conv_24_hu_conv; + } + Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret = arg.sign_counterparty_commitment(feerate_per_kw, commitment_tx_conv, keys_hu_conv, arr_conv_24_arr); + long result = ret != null ? ret.ptr : 0; + ret.ptr = 0; + return result; + } + @Override public long sign_holder_commitment(long holder_commitment_tx) { + HolderCommitmentTransaction holder_commitment_tx_hu_conv = new HolderCommitmentTransaction(null, holder_commitment_tx); + Result_SignatureNoneZ ret = arg.sign_holder_commitment(holder_commitment_tx_hu_conv); + long result = ret != null ? ret.ptr : 0; + ret.ptr = 0; + return result; + } + @Override public long sign_holder_commitment_htlc_transactions(long holder_commitment_tx) { + HolderCommitmentTransaction holder_commitment_tx_hu_conv = new HolderCommitmentTransaction(null, holder_commitment_tx); + Result_CVec_SignatureZNoneZ ret = arg.sign_holder_commitment_htlc_transactions(holder_commitment_tx_hu_conv); + long result = ret != null ? ret.ptr : 0; + ret.ptr = 0; + return result; + } + @Override public long sign_justice_transaction(long justice_tx, long input, long amount, byte[] per_commitment_key, long htlc) { + Transaction justice_tx_conv = new Transaction(null, justice_tx); + HTLCOutputInCommitment htlc_hu_conv = new HTLCOutputInCommitment(null, htlc); + Result_SignatureNoneZ ret = arg.sign_justice_transaction(justice_tx_conv, input, amount, per_commitment_key, htlc_hu_conv); + long result = ret != null ? ret.ptr : 0; + ret.ptr = 0; + return result; + } + @Override public long sign_counterparty_htlc_transaction(long htlc_tx, long input, long amount, byte[] per_commitment_point, long htlc) { + Transaction htlc_tx_conv = new Transaction(null, htlc_tx); + HTLCOutputInCommitment htlc_hu_conv = new HTLCOutputInCommitment(null, htlc); + Result_SignatureNoneZ ret = arg.sign_counterparty_htlc_transaction(htlc_tx_conv, input, amount, per_commitment_point, htlc_hu_conv); + long result = ret != null ? ret.ptr : 0; + ret.ptr = 0; + return result; + } + @Override public long sign_closing_transaction(long closing_tx) { + Transaction closing_tx_conv = new Transaction(null, closing_tx); + Result_SignatureNoneZ ret = arg.sign_closing_transaction(closing_tx_conv); + long result = ret != null ? ret.ptr : 0; + ret.ptr = 0; + return result; + } + @Override public long sign_channel_announcement(long msg) { + UnsignedChannelAnnouncement msg_hu_conv = new UnsignedChannelAnnouncement(null, msg); + Result_SignatureNoneZ ret = arg.sign_channel_announcement(msg_hu_conv); + long result = ret != null ? ret.ptr : 0; + ret.ptr = 0; + return result; + } + @Override public void on_accept(long channel_points, short counterparty_selected_contest_delay, short holder_selected_contest_delay) { + ChannelPublicKeys channel_points_hu_conv = new ChannelPublicKeys(null, channel_points); + arg.on_accept(channel_points_hu_conv, counterparty_selected_contest_delay, holder_selected_contest_delay); + } + }); + } public byte[] get_per_commitment_point(long idx) { byte[] ret = bindings.ChannelKeys_get_per_commitment_point(this.ptr, idx); return ret; diff --git a/src/main/java/org/ldk/structs/ChannelManager.java b/src/main/java/org/ldk/structs/ChannelManager.java index 56198363..10dc95a2 100644 --- a/src/main/java/org/ldk/structs/ChannelManager.java +++ b/src/main/java/org/ldk/structs/ChannelManager.java @@ -11,7 +11,7 @@ public class ChannelManager extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelManager_free(ptr); + if (ptr != 0) { bindings.ChannelManager_free(ptr); } } public static ChannelManager constructor_new(LDKNetwork network, FeeEstimator fee_est, Watch chain_monitor, BroadcasterInterface tx_broadcaster, Logger logger, KeysInterface keys_manager, UserConfig config, long current_blockchain_height) { @@ -85,7 +85,7 @@ public class ChannelManager extends CommonBase { } public void broadcast_node_announcement(byte[] rgb, byte[] alias, NetAddress[] addresses) { - bindings.ChannelManager_broadcast_node_announcement(this.ptr, rgb, alias, Arrays.stream(addresses).mapToLong(arr_conv_12 -> arr_conv_12.conv_to_c()).toArray()); + bindings.ChannelManager_broadcast_node_announcement(this.ptr, rgb, alias, Arrays.stream(addresses).mapToLong(arr_conv_12 -> arr_conv_12.ptr).toArray()); /* TODO 2 NetAddress */; } @@ -132,7 +132,7 @@ public class ChannelManager extends CommonBase { } public void block_connected(byte[] header, TwoTuple[] txdata, int height) { - bindings.ChannelManager_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_29 -> /*TODO b*/0).toArray(), height); + bindings.ChannelManager_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_29 -> bindings.C2Tuple_usizeTransactionZ_new(arr_conv_29.a, arr_conv_29.b.ptr)).toArray(), height); /* TODO 2 TwoTuple */; } diff --git a/src/main/java/org/ldk/structs/ChannelManagerReadArgs.java b/src/main/java/org/ldk/structs/ChannelManagerReadArgs.java index 26dc48ae..de589498 100644 --- a/src/main/java/org/ldk/structs/ChannelManagerReadArgs.java +++ b/src/main/java/org/ldk/structs/ChannelManagerReadArgs.java @@ -11,7 +11,7 @@ public class ChannelManagerReadArgs extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelManagerReadArgs_free(ptr); + if (ptr != 0) { bindings.ChannelManagerReadArgs_free(ptr); } } public KeysInterface get_keys_manager() { diff --git a/src/main/java/org/ldk/structs/ChannelMessageHandler.java b/src/main/java/org/ldk/structs/ChannelMessageHandler.java index 4ad07c9a..d920f2d4 100644 --- a/src/main/java/org/ldk/structs/ChannelMessageHandler.java +++ b/src/main/java/org/ldk/structs/ChannelMessageHandler.java @@ -7,16 +7,120 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class ChannelMessageHandler extends CommonBase { - ChannelMessageHandler(Object _dummy, long ptr) { super(ptr); } - public ChannelMessageHandler(bindings.LDKChannelMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) { + final bindings.LDKChannelMessageHandler bindings_instance; + ChannelMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private ChannelMessageHandler(bindings.LDKChannelMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) { super(bindings.LDKChannelMessageHandler_new(arg, MessageSendEventsProvider)); this.ptrs_to.add(arg); + this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.ChannelMessageHandler_free(ptr); super.finalize(); + if (ptr != 0) { bindings.ChannelMessageHandler_free(ptr); } super.finalize(); + } + + public static interface ChannelMessageHandlerInterface { + void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg); + void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg); + void handle_funding_created(byte[] their_node_id, FundingCreated msg); + void handle_funding_signed(byte[] their_node_id, FundingSigned msg); + void handle_funding_locked(byte[] their_node_id, FundingLocked msg); + void handle_shutdown(byte[] their_node_id, Shutdown msg); + void handle_closing_signed(byte[] their_node_id, ClosingSigned msg); + void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg); + void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg); + void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg); + void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg); + void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg); + void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg); + void handle_update_fee(byte[] their_node_id, UpdateFee msg); + void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg); + void peer_disconnected(byte[] their_node_id, boolean no_connection_possible); + void peer_connected(byte[] their_node_id, Init msg); + void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg); + void handle_error(byte[] their_node_id, ErrorMessage msg); + } + public ChannelMessageHandler(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider) { + this(new bindings.LDKChannelMessageHandler() { + @Override public void handle_open_channel(byte[] their_node_id, long their_features, long msg) { + InitFeatures their_features_hu_conv = new InitFeatures(null, their_features); + OpenChannel msg_hu_conv = new OpenChannel(null, msg); + arg.handle_open_channel(their_node_id, their_features_hu_conv, msg_hu_conv); + } + @Override public void handle_accept_channel(byte[] their_node_id, long their_features, long msg) { + InitFeatures their_features_hu_conv = new InitFeatures(null, their_features); + AcceptChannel msg_hu_conv = new AcceptChannel(null, msg); + arg.handle_accept_channel(their_node_id, their_features_hu_conv, msg_hu_conv); + } + @Override public void handle_funding_created(byte[] their_node_id, long msg) { + FundingCreated msg_hu_conv = new FundingCreated(null, msg); + arg.handle_funding_created(their_node_id, msg_hu_conv); + } + @Override public void handle_funding_signed(byte[] their_node_id, long msg) { + FundingSigned msg_hu_conv = new FundingSigned(null, msg); + arg.handle_funding_signed(their_node_id, msg_hu_conv); + } + @Override public void handle_funding_locked(byte[] their_node_id, long msg) { + FundingLocked msg_hu_conv = new FundingLocked(null, msg); + arg.handle_funding_locked(their_node_id, msg_hu_conv); + } + @Override public void handle_shutdown(byte[] their_node_id, long msg) { + Shutdown msg_hu_conv = new Shutdown(null, msg); + arg.handle_shutdown(their_node_id, msg_hu_conv); + } + @Override public void handle_closing_signed(byte[] their_node_id, long msg) { + ClosingSigned msg_hu_conv = new ClosingSigned(null, msg); + arg.handle_closing_signed(their_node_id, msg_hu_conv); + } + @Override public void handle_update_add_htlc(byte[] their_node_id, long msg) { + UpdateAddHTLC msg_hu_conv = new UpdateAddHTLC(null, msg); + arg.handle_update_add_htlc(their_node_id, msg_hu_conv); + } + @Override public void handle_update_fulfill_htlc(byte[] their_node_id, long msg) { + UpdateFulfillHTLC msg_hu_conv = new UpdateFulfillHTLC(null, msg); + arg.handle_update_fulfill_htlc(their_node_id, msg_hu_conv); + } + @Override public void handle_update_fail_htlc(byte[] their_node_id, long msg) { + UpdateFailHTLC msg_hu_conv = new UpdateFailHTLC(null, msg); + arg.handle_update_fail_htlc(their_node_id, msg_hu_conv); + } + @Override public void handle_update_fail_malformed_htlc(byte[] their_node_id, long msg) { + UpdateFailMalformedHTLC msg_hu_conv = new UpdateFailMalformedHTLC(null, msg); + arg.handle_update_fail_malformed_htlc(their_node_id, msg_hu_conv); + } + @Override public void handle_commitment_signed(byte[] their_node_id, long msg) { + CommitmentSigned msg_hu_conv = new CommitmentSigned(null, msg); + arg.handle_commitment_signed(their_node_id, msg_hu_conv); + } + @Override public void handle_revoke_and_ack(byte[] their_node_id, long msg) { + RevokeAndACK msg_hu_conv = new RevokeAndACK(null, msg); + arg.handle_revoke_and_ack(their_node_id, msg_hu_conv); + } + @Override public void handle_update_fee(byte[] their_node_id, long msg) { + UpdateFee msg_hu_conv = new UpdateFee(null, msg); + arg.handle_update_fee(their_node_id, msg_hu_conv); + } + @Override public void handle_announcement_signatures(byte[] their_node_id, long msg) { + AnnouncementSignatures msg_hu_conv = new AnnouncementSignatures(null, msg); + arg.handle_announcement_signatures(their_node_id, msg_hu_conv); + } + @Override public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) { + arg.peer_disconnected(their_node_id, no_connection_possible); + } + @Override public void peer_connected(byte[] their_node_id, long msg) { + Init msg_hu_conv = new Init(null, msg); + arg.peer_connected(their_node_id, msg_hu_conv); + } + @Override public void handle_channel_reestablish(byte[] their_node_id, long msg) { + ChannelReestablish msg_hu_conv = new ChannelReestablish(null, msg); + arg.handle_channel_reestablish(their_node_id, msg_hu_conv); + } + @Override public void handle_error(byte[] their_node_id, long msg) { + ErrorMessage msg_hu_conv = new ErrorMessage(null, msg); + arg.handle_error(their_node_id, msg_hu_conv); + } + }, new MessageSendEventsProvider(MessageSendEventsProvider).bindings_instance); } - // Skipped ChannelMessageHandler_handle_open_channel // Skipped ChannelMessageHandler_handle_accept_channel public void handle_funding_created(byte[] their_node_id, FundingCreated msg) { diff --git a/src/main/java/org/ldk/structs/ChannelMonitor.java b/src/main/java/org/ldk/structs/ChannelMonitor.java index 1e95a1b5..a641c59f 100644 --- a/src/main/java/org/ldk/structs/ChannelMonitor.java +++ b/src/main/java/org/ldk/structs/ChannelMonitor.java @@ -11,7 +11,7 @@ public class ChannelMonitor extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelMonitor_free(ptr); + if (ptr != 0) { bindings.ChannelMonitor_free(ptr); } } public Result_NoneMonitorUpdateErrorZ update_monitor(ChannelMonitorUpdate updates, BroadcasterInterface broadcaster, Logger logger) { @@ -65,7 +65,7 @@ public class ChannelMonitor extends CommonBase { } public TwoTuple[] block_connected(byte[] header, TwoTuple[] txdata, int height, BroadcasterInterface broadcaster, FeeEstimator fee_estimator, Logger logger) { - long[] ret = bindings.ChannelMonitor_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_29 -> /*TODO b*/0).toArray(), height, broadcaster == null ? 0 : broadcaster.ptr, fee_estimator == null ? 0 : fee_estimator.ptr, logger == null ? 0 : logger.ptr); + long[] ret = bindings.ChannelMonitor_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_29 -> bindings.C2Tuple_usizeTransactionZ_new(arr_conv_29.a, arr_conv_29.b.ptr)).toArray(), height, broadcaster == null ? 0 : broadcaster.ptr, fee_estimator == null ? 0 : fee_estimator.ptr, logger == null ? 0 : logger.ptr); TwoTuple[] arr_conv_27_arr = new TwoTuple[ret.length]; for (int b = 0; b < ret.length; b++) { long arr_conv_27 = ret[b]; diff --git a/src/main/java/org/ldk/structs/ChannelMonitorUpdate.java b/src/main/java/org/ldk/structs/ChannelMonitorUpdate.java index 9cc36c1a..59c53a73 100644 --- a/src/main/java/org/ldk/structs/ChannelMonitorUpdate.java +++ b/src/main/java/org/ldk/structs/ChannelMonitorUpdate.java @@ -11,7 +11,7 @@ public class ChannelMonitorUpdate extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelMonitorUpdate_free(ptr); + if (ptr != 0) { bindings.ChannelMonitorUpdate_free(ptr); } } public static ChannelMonitorUpdate constructor_clone(ChannelMonitorUpdate orig) { diff --git a/src/main/java/org/ldk/structs/ChannelPublicKeys.java b/src/main/java/org/ldk/structs/ChannelPublicKeys.java index 882bdd08..3dfd7c06 100644 --- a/src/main/java/org/ldk/structs/ChannelPublicKeys.java +++ b/src/main/java/org/ldk/structs/ChannelPublicKeys.java @@ -11,7 +11,7 @@ public class ChannelPublicKeys extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelPublicKeys_free(ptr); + if (ptr != 0) { bindings.ChannelPublicKeys_free(ptr); } } public static ChannelPublicKeys constructor_clone(ChannelPublicKeys orig) { diff --git a/src/main/java/org/ldk/structs/ChannelReestablish.java b/src/main/java/org/ldk/structs/ChannelReestablish.java index ceb78ed4..1869145a 100644 --- a/src/main/java/org/ldk/structs/ChannelReestablish.java +++ b/src/main/java/org/ldk/structs/ChannelReestablish.java @@ -11,7 +11,7 @@ public class ChannelReestablish extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelReestablish_free(ptr); + if (ptr != 0) { bindings.ChannelReestablish_free(ptr); } } public static ChannelReestablish constructor_clone(ChannelReestablish orig) { diff --git a/src/main/java/org/ldk/structs/ChannelUpdate.java b/src/main/java/org/ldk/structs/ChannelUpdate.java index 3fe97d5a..2409134c 100644 --- a/src/main/java/org/ldk/structs/ChannelUpdate.java +++ b/src/main/java/org/ldk/structs/ChannelUpdate.java @@ -11,7 +11,7 @@ public class ChannelUpdate extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ChannelUpdate_free(ptr); + if (ptr != 0) { bindings.ChannelUpdate_free(ptr); } } public static ChannelUpdate constructor_clone(ChannelUpdate orig) { diff --git a/src/main/java/org/ldk/structs/ClosingSigned.java b/src/main/java/org/ldk/structs/ClosingSigned.java index a8a0063e..fe05ebef 100644 --- a/src/main/java/org/ldk/structs/ClosingSigned.java +++ b/src/main/java/org/ldk/structs/ClosingSigned.java @@ -11,7 +11,7 @@ public class ClosingSigned extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ClosingSigned_free(ptr); + if (ptr != 0) { bindings.ClosingSigned_free(ptr); } } public static ClosingSigned constructor_clone(ClosingSigned orig) { diff --git a/src/main/java/org/ldk/structs/CommitmentSigned.java b/src/main/java/org/ldk/structs/CommitmentSigned.java index bffa91b7..a29b4623 100644 --- a/src/main/java/org/ldk/structs/CommitmentSigned.java +++ b/src/main/java/org/ldk/structs/CommitmentSigned.java @@ -11,7 +11,7 @@ public class CommitmentSigned extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.CommitmentSigned_free(ptr); + if (ptr != 0) { bindings.CommitmentSigned_free(ptr); } } public static CommitmentSigned constructor_clone(CommitmentSigned orig) { diff --git a/src/main/java/org/ldk/structs/CommitmentUpdate.java b/src/main/java/org/ldk/structs/CommitmentUpdate.java index b78bf907..01e7a975 100644 --- a/src/main/java/org/ldk/structs/CommitmentUpdate.java +++ b/src/main/java/org/ldk/structs/CommitmentUpdate.java @@ -11,7 +11,7 @@ public class CommitmentUpdate extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.CommitmentUpdate_free(ptr); + if (ptr != 0) { bindings.CommitmentUpdate_free(ptr); } } public static CommitmentUpdate constructor_clone(CommitmentUpdate orig) { diff --git a/src/main/java/org/ldk/structs/CommonBase.java b/src/main/java/org/ldk/structs/CommonBase.java index 42971b3f..acff6661 100644 --- a/src/main/java/org/ldk/structs/CommonBase.java +++ b/src/main/java/org/ldk/structs/CommonBase.java @@ -1,7 +1,7 @@ package org.ldk.structs; import java.util.LinkedList; class CommonBase { - final long ptr; + long ptr; LinkedList ptrs_to = new LinkedList(); protected CommonBase(long ptr) { this.ptr = ptr; } public long _test_only_get_ptr() { return this.ptr; } diff --git a/src/main/java/org/ldk/structs/DataLossProtect.java b/src/main/java/org/ldk/structs/DataLossProtect.java index 2a5438e1..fa0cd512 100644 --- a/src/main/java/org/ldk/structs/DataLossProtect.java +++ b/src/main/java/org/ldk/structs/DataLossProtect.java @@ -11,7 +11,7 @@ public class DataLossProtect extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.DataLossProtect_free(ptr); + if (ptr != 0) { bindings.DataLossProtect_free(ptr); } } public static DataLossProtect constructor_clone(DataLossProtect orig) { diff --git a/src/main/java/org/ldk/structs/DecodeError.java b/src/main/java/org/ldk/structs/DecodeError.java index 4ed9f4de..e8cec470 100644 --- a/src/main/java/org/ldk/structs/DecodeError.java +++ b/src/main/java/org/ldk/structs/DecodeError.java @@ -11,7 +11,7 @@ public class DecodeError extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.DecodeError_free(ptr); + if (ptr != 0) { bindings.DecodeError_free(ptr); } } } diff --git a/src/main/java/org/ldk/structs/DirectionalChannelInfo.java b/src/main/java/org/ldk/structs/DirectionalChannelInfo.java index 0b638356..6120b30e 100644 --- a/src/main/java/org/ldk/structs/DirectionalChannelInfo.java +++ b/src/main/java/org/ldk/structs/DirectionalChannelInfo.java @@ -11,7 +11,7 @@ public class DirectionalChannelInfo extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.DirectionalChannelInfo_free(ptr); + if (ptr != 0) { bindings.DirectionalChannelInfo_free(ptr); } } public int get_last_update() { diff --git a/src/main/java/org/ldk/structs/ErrorAction.java b/src/main/java/org/ldk/structs/ErrorAction.java index e5ccec8d..efe34dd5 100644 --- a/src/main/java/org/ldk/structs/ErrorAction.java +++ b/src/main/java/org/ldk/structs/ErrorAction.java @@ -11,9 +11,8 @@ public class ErrorAction extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ErrorAction_free(ptr); + if (ptr != 0) { 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) { @@ -29,29 +28,26 @@ public class ErrorAction extends CommonBase { } public final static class DisconnectPeer extends ErrorAction { - public ErrorMessage msg; + public final ErrorMessage msg; 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(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; + public final ErrorMessage msg; 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/ErrorMessage.java b/src/main/java/org/ldk/structs/ErrorMessage.java index d0182f31..73788d48 100644 --- a/src/main/java/org/ldk/structs/ErrorMessage.java +++ b/src/main/java/org/ldk/structs/ErrorMessage.java @@ -11,7 +11,7 @@ public class ErrorMessage extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ErrorMessage_free(ptr); + if (ptr != 0) { bindings.ErrorMessage_free(ptr); } } public static ErrorMessage constructor_clone(ErrorMessage orig) { diff --git a/src/main/java/org/ldk/structs/Event.java b/src/main/java/org/ldk/structs/Event.java index 01a59a8f..9e3ee3f2 100644 --- a/src/main/java/org/ldk/structs/Event.java +++ b/src/main/java/org/ldk/structs/Event.java @@ -11,9 +11,8 @@ public class Event extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.Event_free(ptr); + if (ptr != 0) { 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) { @@ -41,10 +40,10 @@ public class Event extends CommonBase { } public final static class FundingGenerationReady extends Event { - public byte[] temporary_channel_id; - public long channel_value_satoshis; - public byte[] output_script; - public long user_channel_id; + public final byte[] temporary_channel_id; + public final long channel_value_satoshis; + public final byte[] output_script; + public final long user_channel_id; private FundingGenerationReady(long ptr, bindings.LDKEvent.FundingGenerationReady obj) { super(null, ptr); this.temporary_channel_id = obj.temporary_channel_id; @@ -52,11 +51,10 @@ public class Event extends CommonBase { 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; + public final OutPoint funding_txo; + public final long user_channel_id; private FundingBroadcastSafe(long ptr, bindings.LDKEvent.FundingBroadcastSafe obj) { super(null, ptr); long funding_txo = obj.funding_txo; @@ -64,48 +62,43 @@ public class Event extends CommonBase { 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; + public final byte[] payment_hash; + public final byte[] payment_secret; + public final long amt; 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; + public final byte[] payment_preimage; 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; + public final byte[] payment_hash; + public final boolean rejected_by_dest; 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; + public final long time_forwardable; 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; + public final SpendableOutputDescriptor[] outputs; private SpendableOutputs(long ptr, bindings.LDKEvent.SpendableOutputs obj) { super(null, ptr); long[] outputs = obj.outputs; @@ -117,6 +110,5 @@ public class Event extends CommonBase { } this.outputs = arr_conv_27_arr; } - @Override long conv_to_c() { return 0; /*XXX*/ } } } diff --git a/src/main/java/org/ldk/structs/EventsProvider.java b/src/main/java/org/ldk/structs/EventsProvider.java index ed6ef602..960ab449 100644 --- a/src/main/java/org/ldk/structs/EventsProvider.java +++ b/src/main/java/org/ldk/structs/EventsProvider.java @@ -7,16 +7,31 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class EventsProvider extends CommonBase { - EventsProvider(Object _dummy, long ptr) { super(ptr); } - public EventsProvider(bindings.LDKEventsProvider arg) { + final bindings.LDKEventsProvider bindings_instance; + EventsProvider(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private EventsProvider(bindings.LDKEventsProvider arg) { super(bindings.LDKEventsProvider_new(arg)); this.ptrs_to.add(arg); + this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.EventsProvider_free(ptr); super.finalize(); + if (ptr != 0) { bindings.EventsProvider_free(ptr); } super.finalize(); } + public static interface EventsProviderInterface { + Event[] get_and_clear_pending_events(); + } + public EventsProvider(EventsProviderInterface arg) { + this(new bindings.LDKEventsProvider() { + @Override public long[] get_and_clear_pending_events() { + Event[] ret = arg.get_and_clear_pending_events(); + long[] result = Arrays.stream(ret).mapToLong(arr_conv_7 -> arr_conv_7.ptr).toArray(); + /* TODO 2 Event */ + return result; + } + }); + } public Event[] get_and_clear_pending_events() { long[] ret = bindings.EventsProvider_get_and_clear_pending_events(this.ptr); Event[] arr_conv_7_arr = new Event[ret.length]; diff --git a/src/main/java/org/ldk/structs/FeeEstimator.java b/src/main/java/org/ldk/structs/FeeEstimator.java index 13c16315..dd7c05f2 100644 --- a/src/main/java/org/ldk/structs/FeeEstimator.java +++ b/src/main/java/org/ldk/structs/FeeEstimator.java @@ -7,16 +7,29 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class FeeEstimator extends CommonBase { - FeeEstimator(Object _dummy, long ptr) { super(ptr); } - public FeeEstimator(bindings.LDKFeeEstimator arg) { + final bindings.LDKFeeEstimator bindings_instance; + FeeEstimator(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private FeeEstimator(bindings.LDKFeeEstimator arg) { super(bindings.LDKFeeEstimator_new(arg)); this.ptrs_to.add(arg); + this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.FeeEstimator_free(ptr); super.finalize(); + if (ptr != 0) { bindings.FeeEstimator_free(ptr); } super.finalize(); } + public static interface FeeEstimatorInterface { + int get_est_sat_per_1000_weight(LDKConfirmationTarget confirmation_target); + } + public FeeEstimator(FeeEstimatorInterface arg) { + this(new bindings.LDKFeeEstimator() { + @Override public int get_est_sat_per_1000_weight(LDKConfirmationTarget confirmation_target) { + int ret = arg.get_est_sat_per_1000_weight(confirmation_target); + return ret; + } + }); + } public int get_est_sat_per_1000_weight(LDKConfirmationTarget confirmation_target) { int ret = bindings.FeeEstimator_get_est_sat_per_1000_weight(this.ptr, confirmation_target); return ret; diff --git a/src/main/java/org/ldk/structs/Filter.java b/src/main/java/org/ldk/structs/Filter.java index b4094bd1..6ec794e6 100644 --- a/src/main/java/org/ldk/structs/Filter.java +++ b/src/main/java/org/ldk/structs/Filter.java @@ -7,16 +7,33 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class Filter extends CommonBase { - Filter(Object _dummy, long ptr) { super(ptr); } - public Filter(bindings.LDKFilter arg) { + final bindings.LDKFilter bindings_instance; + Filter(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private Filter(bindings.LDKFilter arg) { super(bindings.LDKFilter_new(arg)); this.ptrs_to.add(arg); + this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.Filter_free(ptr); super.finalize(); + if (ptr != 0) { bindings.Filter_free(ptr); } super.finalize(); } + public static interface FilterInterface { + void register_tx(byte[] txid, byte[] script_pubkey); + void register_output(OutPoint outpoint, byte[] script_pubkey); + } + public Filter(FilterInterface arg) { + this(new bindings.LDKFilter() { + @Override public void register_tx(byte[] txid, byte[] script_pubkey) { + arg.register_tx(txid, script_pubkey); + } + @Override public void register_output(long outpoint, byte[] script_pubkey) { + OutPoint outpoint_hu_conv = new OutPoint(null, outpoint); + arg.register_output(outpoint_hu_conv, script_pubkey); + } + }); + } public void register_tx(byte[] txid, byte[] script_pubkey) { bindings.Filter_register_tx(this.ptr, txid, script_pubkey); } diff --git a/src/main/java/org/ldk/structs/FundingCreated.java b/src/main/java/org/ldk/structs/FundingCreated.java index f45f2c68..e5e0ff9a 100644 --- a/src/main/java/org/ldk/structs/FundingCreated.java +++ b/src/main/java/org/ldk/structs/FundingCreated.java @@ -11,7 +11,7 @@ public class FundingCreated extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.FundingCreated_free(ptr); + if (ptr != 0) { bindings.FundingCreated_free(ptr); } } public static FundingCreated constructor_clone(FundingCreated orig) { diff --git a/src/main/java/org/ldk/structs/FundingLocked.java b/src/main/java/org/ldk/structs/FundingLocked.java index 1cf7d7ac..e6e2eea5 100644 --- a/src/main/java/org/ldk/structs/FundingLocked.java +++ b/src/main/java/org/ldk/structs/FundingLocked.java @@ -11,7 +11,7 @@ public class FundingLocked extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.FundingLocked_free(ptr); + if (ptr != 0) { bindings.FundingLocked_free(ptr); } } public static FundingLocked constructor_clone(FundingLocked orig) { diff --git a/src/main/java/org/ldk/structs/FundingSigned.java b/src/main/java/org/ldk/structs/FundingSigned.java index 640c3c1e..9af23467 100644 --- a/src/main/java/org/ldk/structs/FundingSigned.java +++ b/src/main/java/org/ldk/structs/FundingSigned.java @@ -11,7 +11,7 @@ public class FundingSigned extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.FundingSigned_free(ptr); + if (ptr != 0) { bindings.FundingSigned_free(ptr); } } public static FundingSigned constructor_clone(FundingSigned orig) { diff --git a/src/main/java/org/ldk/structs/GossipTimestampFilter.java b/src/main/java/org/ldk/structs/GossipTimestampFilter.java index 5efcccf8..abc141b3 100644 --- a/src/main/java/org/ldk/structs/GossipTimestampFilter.java +++ b/src/main/java/org/ldk/structs/GossipTimestampFilter.java @@ -11,7 +11,7 @@ public class GossipTimestampFilter extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.GossipTimestampFilter_free(ptr); + if (ptr != 0) { bindings.GossipTimestampFilter_free(ptr); } } public static GossipTimestampFilter constructor_clone(GossipTimestampFilter orig) { diff --git a/src/main/java/org/ldk/structs/HTLCFailChannelUpdate.java b/src/main/java/org/ldk/structs/HTLCFailChannelUpdate.java index 69dccb8e..92a5c018 100644 --- a/src/main/java/org/ldk/structs/HTLCFailChannelUpdate.java +++ b/src/main/java/org/ldk/structs/HTLCFailChannelUpdate.java @@ -11,9 +11,8 @@ public class HTLCFailChannelUpdate extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.HTLCFailChannelUpdate_free(ptr); + if (ptr != 0) { 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) { @@ -29,33 +28,30 @@ public class HTLCFailChannelUpdate extends CommonBase { } public final static class ChannelUpdateMessage extends HTLCFailChannelUpdate { - public ChannelUpdate msg; + public final ChannelUpdate msg; 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; + public final long short_channel_id; + public final boolean is_permanent; 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; + public final byte[] node_id; + public final boolean is_permanent; 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/HTLCOutputInCommitment.java b/src/main/java/org/ldk/structs/HTLCOutputInCommitment.java index c6e730a7..54745ba9 100644 --- a/src/main/java/org/ldk/structs/HTLCOutputInCommitment.java +++ b/src/main/java/org/ldk/structs/HTLCOutputInCommitment.java @@ -11,7 +11,7 @@ public class HTLCOutputInCommitment extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.HTLCOutputInCommitment_free(ptr); + if (ptr != 0) { bindings.HTLCOutputInCommitment_free(ptr); } } public static HTLCOutputInCommitment constructor_clone(HTLCOutputInCommitment orig) { diff --git a/src/main/java/org/ldk/structs/HTLCUpdate.java b/src/main/java/org/ldk/structs/HTLCUpdate.java index 008ca802..2f5fb3e3 100644 --- a/src/main/java/org/ldk/structs/HTLCUpdate.java +++ b/src/main/java/org/ldk/structs/HTLCUpdate.java @@ -11,7 +11,7 @@ public class HTLCUpdate extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.HTLCUpdate_free(ptr); + if (ptr != 0) { bindings.HTLCUpdate_free(ptr); } } public static HTLCUpdate constructor_clone(HTLCUpdate orig) { diff --git a/src/main/java/org/ldk/structs/HolderCommitmentTransaction.java b/src/main/java/org/ldk/structs/HolderCommitmentTransaction.java index 5b26ba42..eb8dbe0c 100644 --- a/src/main/java/org/ldk/structs/HolderCommitmentTransaction.java +++ b/src/main/java/org/ldk/structs/HolderCommitmentTransaction.java @@ -11,7 +11,7 @@ public class HolderCommitmentTransaction extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.HolderCommitmentTransaction_free(ptr); + if (ptr != 0) { bindings.HolderCommitmentTransaction_free(ptr); } } public static HolderCommitmentTransaction constructor_clone(HolderCommitmentTransaction orig) { @@ -42,7 +42,7 @@ public class HolderCommitmentTransaction extends CommonBase { } public void set_per_htlc(TwoTuple[] val) { - bindings.HolderCommitmentTransaction_set_per_htlc(this.ptr, Arrays.stream(val).mapToLong(arr_conv_42 -> /*TODO b*/0).toArray()); + bindings.HolderCommitmentTransaction_set_per_htlc(this.ptr, Arrays.stream(val).mapToLong(arr_conv_42 -> bindings.C2Tuple_HTLCOutputInCommitmentSignatureZ_new(arr_conv_42.a == null ? 0 : arr_conv_42.a.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_42_a)*/, arr_conv_42.b)).toArray()); /* TODO 2 TwoTuple */; } diff --git a/src/main/java/org/ldk/structs/InMemoryChannelKeys.java b/src/main/java/org/ldk/structs/InMemoryChannelKeys.java index 00825ab3..10875ee7 100644 --- a/src/main/java/org/ldk/structs/InMemoryChannelKeys.java +++ b/src/main/java/org/ldk/structs/InMemoryChannelKeys.java @@ -11,7 +11,7 @@ public class InMemoryChannelKeys extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.InMemoryChannelKeys_free(ptr); + if (ptr != 0) { bindings.InMemoryChannelKeys_free(ptr); } } public static InMemoryChannelKeys constructor_clone(InMemoryChannelKeys orig) { diff --git a/src/main/java/org/ldk/structs/Init.java b/src/main/java/org/ldk/structs/Init.java index 37f87de7..12236335 100644 --- a/src/main/java/org/ldk/structs/Init.java +++ b/src/main/java/org/ldk/structs/Init.java @@ -11,7 +11,7 @@ public class Init extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.Init_free(ptr); + if (ptr != 0) { bindings.Init_free(ptr); } } public static Init constructor_clone(Init orig) { diff --git a/src/main/java/org/ldk/structs/InitFeatures.java b/src/main/java/org/ldk/structs/InitFeatures.java index c6184f09..f4d8a7e8 100644 --- a/src/main/java/org/ldk/structs/InitFeatures.java +++ b/src/main/java/org/ldk/structs/InitFeatures.java @@ -11,7 +11,7 @@ public class InitFeatures extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.InitFeatures_free(ptr); + if (ptr != 0) { bindings.InitFeatures_free(ptr); } } } diff --git a/src/main/java/org/ldk/structs/KeysInterface.java b/src/main/java/org/ldk/structs/KeysInterface.java index 589793e4..e60efc5a 100644 --- a/src/main/java/org/ldk/structs/KeysInterface.java +++ b/src/main/java/org/ldk/structs/KeysInterface.java @@ -7,16 +7,51 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class KeysInterface extends CommonBase { - KeysInterface(Object _dummy, long ptr) { super(ptr); } - public KeysInterface(bindings.LDKKeysInterface arg) { + final bindings.LDKKeysInterface bindings_instance; + KeysInterface(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private KeysInterface(bindings.LDKKeysInterface arg) { super(bindings.LDKKeysInterface_new(arg)); this.ptrs_to.add(arg); + this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.KeysInterface_free(ptr); super.finalize(); + if (ptr != 0) { bindings.KeysInterface_free(ptr); } super.finalize(); } + public static interface KeysInterfaceInterface { + byte[] get_node_secret(); + byte[] get_destination_script(); + byte[] get_shutdown_pubkey(); + ChannelKeys get_channel_keys(boolean inbound, long channel_value_satoshis); + byte[] get_secure_random_bytes(); + } + public KeysInterface(KeysInterfaceInterface arg) { + this(new bindings.LDKKeysInterface() { + @Override public byte[] get_node_secret() { + byte[] ret = arg.get_node_secret(); + return ret; + } + @Override public byte[] get_destination_script() { + byte[] ret = arg.get_destination_script(); + return ret; + } + @Override public byte[] get_shutdown_pubkey() { + byte[] ret = arg.get_shutdown_pubkey(); + return ret; + } + @Override public long get_channel_keys(boolean inbound, long channel_value_satoshis) { + ChannelKeys ret = arg.get_channel_keys(inbound, channel_value_satoshis); + long result = ret.ptr; + ret.ptr = 0; + return result; + } + @Override public byte[] get_secure_random_bytes() { + byte[] ret = arg.get_secure_random_bytes(); + return ret; + } + }); + } public byte[] get_node_secret() { byte[] ret = bindings.KeysInterface_get_node_secret(this.ptr); return ret; diff --git a/src/main/java/org/ldk/structs/KeysManager.java b/src/main/java/org/ldk/structs/KeysManager.java index 5269c40d..a208bfea 100644 --- a/src/main/java/org/ldk/structs/KeysManager.java +++ b/src/main/java/org/ldk/structs/KeysManager.java @@ -11,7 +11,7 @@ public class KeysManager extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.KeysManager_free(ptr); + if (ptr != 0) { bindings.KeysManager_free(ptr); } } public static KeysManager constructor_new(byte[] seed, LDKNetwork network, long starting_time_secs, int starting_time_nanos) { diff --git a/src/main/java/org/ldk/structs/LightningError.java b/src/main/java/org/ldk/structs/LightningError.java index b82c5711..cb89872c 100644 --- a/src/main/java/org/ldk/structs/LightningError.java +++ b/src/main/java/org/ldk/structs/LightningError.java @@ -11,7 +11,7 @@ public class LightningError extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.LightningError_free(ptr); + if (ptr != 0) { bindings.LightningError_free(ptr); } } public String get_err() { diff --git a/src/main/java/org/ldk/structs/LockedNetworkGraph.java b/src/main/java/org/ldk/structs/LockedNetworkGraph.java index 55f1dad8..2313ec9a 100644 --- a/src/main/java/org/ldk/structs/LockedNetworkGraph.java +++ b/src/main/java/org/ldk/structs/LockedNetworkGraph.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class LockedNetworkGraph extends CommonBase implements AutoCloseable { LockedNetworkGraph(Object _dummy, long ptr) { super(ptr); } @Override public void close() { - bindings.LockedNetworkGraph_free(ptr); + if (ptr != 0) { bindings.LockedNetworkGraph_free(ptr); } } public NetworkGraph graph() { diff --git a/src/main/java/org/ldk/structs/Logger.java b/src/main/java/org/ldk/structs/Logger.java index 1daafb3b..613273d4 100644 --- a/src/main/java/org/ldk/structs/Logger.java +++ b/src/main/java/org/ldk/structs/Logger.java @@ -7,14 +7,26 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class Logger extends CommonBase { - Logger(Object _dummy, long ptr) { super(ptr); } - public Logger(bindings.LDKLogger arg) { + final bindings.LDKLogger bindings_instance; + Logger(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private Logger(bindings.LDKLogger arg) { super(bindings.LDKLogger_new(arg)); this.ptrs_to.add(arg); + this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.Logger_free(ptr); super.finalize(); + if (ptr != 0) { bindings.Logger_free(ptr); } super.finalize(); } + public static interface LoggerInterface { + void log(String record); + } + public Logger(LoggerInterface arg) { + this(new bindings.LDKLogger() { + @Override public void log(String record) { + arg.log(record); + } + }); + } } diff --git a/src/main/java/org/ldk/structs/MessageHandler.java b/src/main/java/org/ldk/structs/MessageHandler.java index d2f3892c..09578c89 100644 --- a/src/main/java/org/ldk/structs/MessageHandler.java +++ b/src/main/java/org/ldk/structs/MessageHandler.java @@ -11,7 +11,7 @@ public class MessageHandler extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.MessageHandler_free(ptr); + if (ptr != 0) { bindings.MessageHandler_free(ptr); } } public ChannelMessageHandler get_chan_handler() { diff --git a/src/main/java/org/ldk/structs/MessageSendEvent.java b/src/main/java/org/ldk/structs/MessageSendEvent.java index a19a60a2..5eb255af 100644 --- a/src/main/java/org/ldk/structs/MessageSendEvent.java +++ b/src/main/java/org/ldk/structs/MessageSendEvent.java @@ -11,9 +11,8 @@ public class MessageSendEvent extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.MessageSendEvent_free(ptr); + if (ptr != 0) { 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) { @@ -68,8 +67,8 @@ public class MessageSendEvent extends CommonBase { } public final static class SendAcceptChannel extends MessageSendEvent { - public byte[] node_id; - public AcceptChannel msg; + public final byte[] node_id; + public final AcceptChannel msg; private SendAcceptChannel(long ptr, bindings.LDKMessageSendEvent.SendAcceptChannel obj) { super(null, ptr); this.node_id = obj.node_id; @@ -77,11 +76,10 @@ public class MessageSendEvent extends CommonBase { 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; + public final byte[] node_id; + public final OpenChannel msg; private SendOpenChannel(long ptr, bindings.LDKMessageSendEvent.SendOpenChannel obj) { super(null, ptr); this.node_id = obj.node_id; @@ -89,11 +87,10 @@ public class MessageSendEvent extends CommonBase { 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; + public final byte[] node_id; + public final FundingCreated msg; private SendFundingCreated(long ptr, bindings.LDKMessageSendEvent.SendFundingCreated obj) { super(null, ptr); this.node_id = obj.node_id; @@ -101,11 +98,10 @@ public class MessageSendEvent extends CommonBase { 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; + public final byte[] node_id; + public final FundingSigned msg; private SendFundingSigned(long ptr, bindings.LDKMessageSendEvent.SendFundingSigned obj) { super(null, ptr); this.node_id = obj.node_id; @@ -113,11 +109,10 @@ public class MessageSendEvent extends CommonBase { 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; + public final byte[] node_id; + public final FundingLocked msg; private SendFundingLocked(long ptr, bindings.LDKMessageSendEvent.SendFundingLocked obj) { super(null, ptr); this.node_id = obj.node_id; @@ -125,11 +120,10 @@ public class MessageSendEvent extends CommonBase { 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; + public final byte[] node_id; + public final AnnouncementSignatures msg; private SendAnnouncementSignatures(long ptr, bindings.LDKMessageSendEvent.SendAnnouncementSignatures obj) { super(null, ptr); this.node_id = obj.node_id; @@ -137,11 +131,10 @@ public class MessageSendEvent extends CommonBase { 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; + public final byte[] node_id; + public final CommitmentUpdate updates; private UpdateHTLCs(long ptr, bindings.LDKMessageSendEvent.UpdateHTLCs obj) { super(null, ptr); this.node_id = obj.node_id; @@ -149,11 +142,10 @@ public class MessageSendEvent extends CommonBase { 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; + public final byte[] node_id; + public final RevokeAndACK msg; private SendRevokeAndACK(long ptr, bindings.LDKMessageSendEvent.SendRevokeAndACK obj) { super(null, ptr); this.node_id = obj.node_id; @@ -161,11 +153,10 @@ public class MessageSendEvent extends CommonBase { 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; + public final byte[] node_id; + public final ClosingSigned msg; private SendClosingSigned(long ptr, bindings.LDKMessageSendEvent.SendClosingSigned obj) { super(null, ptr); this.node_id = obj.node_id; @@ -173,11 +164,10 @@ public class MessageSendEvent extends CommonBase { 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; + public final byte[] node_id; + public final Shutdown msg; private SendShutdown(long ptr, bindings.LDKMessageSendEvent.SendShutdown obj) { super(null, ptr); this.node_id = obj.node_id; @@ -185,11 +175,10 @@ public class MessageSendEvent extends CommonBase { 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; + public final byte[] node_id; + public final ChannelReestablish msg; private SendChannelReestablish(long ptr, bindings.LDKMessageSendEvent.SendChannelReestablish obj) { super(null, ptr); this.node_id = obj.node_id; @@ -197,11 +186,10 @@ public class MessageSendEvent extends CommonBase { 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; + public final ChannelAnnouncement msg; + public final ChannelUpdate update_msg; private BroadcastChannelAnnouncement(long ptr, bindings.LDKMessageSendEvent.BroadcastChannelAnnouncement obj) { super(null, ptr); long msg = obj.msg; @@ -211,31 +199,28 @@ public class MessageSendEvent extends CommonBase { 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; + public final NodeAnnouncement msg; 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; + public final ChannelUpdate msg; 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; + public final byte[] node_id; + public final ErrorAction action; private HandleError(long ptr, bindings.LDKMessageSendEvent.HandleError obj) { super(null, ptr); this.node_id = obj.node_id; @@ -243,16 +228,14 @@ public class MessageSendEvent extends CommonBase { 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; + public final HTLCFailChannelUpdate update; 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/MessageSendEventsProvider.java b/src/main/java/org/ldk/structs/MessageSendEventsProvider.java index 6073cb64..e02769e3 100644 --- a/src/main/java/org/ldk/structs/MessageSendEventsProvider.java +++ b/src/main/java/org/ldk/structs/MessageSendEventsProvider.java @@ -7,16 +7,31 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class MessageSendEventsProvider extends CommonBase { - MessageSendEventsProvider(Object _dummy, long ptr) { super(ptr); } - public MessageSendEventsProvider(bindings.LDKMessageSendEventsProvider arg) { + final bindings.LDKMessageSendEventsProvider bindings_instance; + MessageSendEventsProvider(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private MessageSendEventsProvider(bindings.LDKMessageSendEventsProvider arg) { super(bindings.LDKMessageSendEventsProvider_new(arg)); this.ptrs_to.add(arg); + this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.MessageSendEventsProvider_free(ptr); super.finalize(); + if (ptr != 0) { bindings.MessageSendEventsProvider_free(ptr); } super.finalize(); } + public static interface MessageSendEventsProviderInterface { + MessageSendEvent[] get_and_clear_pending_msg_events(); + } + public MessageSendEventsProvider(MessageSendEventsProviderInterface arg) { + this(new bindings.LDKMessageSendEventsProvider() { + @Override public long[] get_and_clear_pending_msg_events() { + MessageSendEvent[] ret = arg.get_and_clear_pending_msg_events(); + long[] result = Arrays.stream(ret).mapToLong(arr_conv_18 -> arr_conv_18.ptr).toArray(); + /* TODO 2 MessageSendEvent */ + return result; + } + }); + } public MessageSendEvent[] get_and_clear_pending_msg_events() { long[] ret = bindings.MessageSendEventsProvider_get_and_clear_pending_msg_events(this.ptr); MessageSendEvent[] arr_conv_18_arr = new MessageSendEvent[ret.length]; diff --git a/src/main/java/org/ldk/structs/MonitorEvent.java b/src/main/java/org/ldk/structs/MonitorEvent.java index 030ef699..5837f072 100644 --- a/src/main/java/org/ldk/structs/MonitorEvent.java +++ b/src/main/java/org/ldk/structs/MonitorEvent.java @@ -11,7 +11,7 @@ public class MonitorEvent extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.MonitorEvent_free(ptr); + if (ptr != 0) { bindings.MonitorEvent_free(ptr); } } } diff --git a/src/main/java/org/ldk/structs/MonitorUpdateError.java b/src/main/java/org/ldk/structs/MonitorUpdateError.java index 4537e5fa..b6589a9f 100644 --- a/src/main/java/org/ldk/structs/MonitorUpdateError.java +++ b/src/main/java/org/ldk/structs/MonitorUpdateError.java @@ -11,7 +11,7 @@ public class MonitorUpdateError extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.MonitorUpdateError_free(ptr); + if (ptr != 0) { bindings.MonitorUpdateError_free(ptr); } } } diff --git a/src/main/java/org/ldk/structs/NetAddress.java b/src/main/java/org/ldk/structs/NetAddress.java index 32e333f2..6dd3708a 100644 --- a/src/main/java/org/ldk/structs/NetAddress.java +++ b/src/main/java/org/ldk/structs/NetAddress.java @@ -11,9 +11,8 @@ public class NetAddress extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.NetAddress_free(ptr); + if (ptr != 0) { 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) { @@ -32,40 +31,37 @@ public class NetAddress extends CommonBase { } public final static class IPv4 extends NetAddress { - public byte[] addr; - public short port; + public final byte[] addr; + public final short port; 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; + public final byte[] addr; + public final short port; 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; + public final byte[] addr; + public final short port; 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 { - public byte[] ed25519_pubkey; - public short checksum; - public byte version; - public short port; + public final byte[] ed25519_pubkey; + public final short checksum; + public final byte version; + public final short port; private OnionV3(long ptr, bindings.LDKNetAddress.OnionV3 obj) { super(null, ptr); this.ed25519_pubkey = obj.ed25519_pubkey; @@ -73,6 +69,5 @@ public class NetAddress extends CommonBase { 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/NetGraphMsgHandler.java b/src/main/java/org/ldk/structs/NetGraphMsgHandler.java index d5d4780e..4327d100 100644 --- a/src/main/java/org/ldk/structs/NetGraphMsgHandler.java +++ b/src/main/java/org/ldk/structs/NetGraphMsgHandler.java @@ -11,7 +11,7 @@ public class NetGraphMsgHandler extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.NetGraphMsgHandler_free(ptr); + if (ptr != 0) { bindings.NetGraphMsgHandler_free(ptr); } } public static NetGraphMsgHandler constructor_new(Access chain_access, Logger logger) { diff --git a/src/main/java/org/ldk/structs/NetworkGraph.java b/src/main/java/org/ldk/structs/NetworkGraph.java index 1bb8f5d8..cb8f31f9 100644 --- a/src/main/java/org/ldk/structs/NetworkGraph.java +++ b/src/main/java/org/ldk/structs/NetworkGraph.java @@ -11,7 +11,7 @@ public class NetworkGraph extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.NetworkGraph_free(ptr); + if (ptr != 0) { bindings.NetworkGraph_free(ptr); } } public byte[] write(NetworkGraph obj) { diff --git a/src/main/java/org/ldk/structs/NodeAnnouncement.java b/src/main/java/org/ldk/structs/NodeAnnouncement.java index f75a8c3d..55b76655 100644 --- a/src/main/java/org/ldk/structs/NodeAnnouncement.java +++ b/src/main/java/org/ldk/structs/NodeAnnouncement.java @@ -11,7 +11,7 @@ public class NodeAnnouncement extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.NodeAnnouncement_free(ptr); + if (ptr != 0) { bindings.NodeAnnouncement_free(ptr); } } public static NodeAnnouncement constructor_clone(NodeAnnouncement orig) { diff --git a/src/main/java/org/ldk/structs/NodeAnnouncementInfo.java b/src/main/java/org/ldk/structs/NodeAnnouncementInfo.java index e426a0e2..b180a509 100644 --- a/src/main/java/org/ldk/structs/NodeAnnouncementInfo.java +++ b/src/main/java/org/ldk/structs/NodeAnnouncementInfo.java @@ -11,7 +11,7 @@ public class NodeAnnouncementInfo extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.NodeAnnouncementInfo_free(ptr); + if (ptr != 0) { bindings.NodeAnnouncementInfo_free(ptr); } } public NodeFeatures get_features() { @@ -49,7 +49,7 @@ public class NodeAnnouncementInfo extends CommonBase { } public void set_addresses(NetAddress[] val) { - bindings.NodeAnnouncementInfo_set_addresses(this.ptr, Arrays.stream(val).mapToLong(arr_conv_12 -> arr_conv_12.conv_to_c()).toArray()); + bindings.NodeAnnouncementInfo_set_addresses(this.ptr, Arrays.stream(val).mapToLong(arr_conv_12 -> arr_conv_12.ptr).toArray()); /* TODO 2 NetAddress */; } diff --git a/src/main/java/org/ldk/structs/NodeFeatures.java b/src/main/java/org/ldk/structs/NodeFeatures.java index 71281dd7..d1dfb5b4 100644 --- a/src/main/java/org/ldk/structs/NodeFeatures.java +++ b/src/main/java/org/ldk/structs/NodeFeatures.java @@ -11,7 +11,7 @@ public class NodeFeatures extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.NodeFeatures_free(ptr); + if (ptr != 0) { bindings.NodeFeatures_free(ptr); } } } diff --git a/src/main/java/org/ldk/structs/NodeInfo.java b/src/main/java/org/ldk/structs/NodeInfo.java index bc453609..1916d9ec 100644 --- a/src/main/java/org/ldk/structs/NodeInfo.java +++ b/src/main/java/org/ldk/structs/NodeInfo.java @@ -11,7 +11,7 @@ public class NodeInfo extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.NodeInfo_free(ptr); + if (ptr != 0) { bindings.NodeInfo_free(ptr); } } public void set_channels(long[] val) { diff --git a/src/main/java/org/ldk/structs/OpenChannel.java b/src/main/java/org/ldk/structs/OpenChannel.java index 8dfe7bf5..32fe0ec7 100644 --- a/src/main/java/org/ldk/structs/OpenChannel.java +++ b/src/main/java/org/ldk/structs/OpenChannel.java @@ -11,7 +11,7 @@ public class OpenChannel extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.OpenChannel_free(ptr); + if (ptr != 0) { bindings.OpenChannel_free(ptr); } } public static OpenChannel constructor_clone(OpenChannel orig) { diff --git a/src/main/java/org/ldk/structs/OutPoint.java b/src/main/java/org/ldk/structs/OutPoint.java index 0d9085c9..74af3416 100644 --- a/src/main/java/org/ldk/structs/OutPoint.java +++ b/src/main/java/org/ldk/structs/OutPoint.java @@ -11,7 +11,7 @@ public class OutPoint extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.OutPoint_free(ptr); + if (ptr != 0) { bindings.OutPoint_free(ptr); } } public static OutPoint constructor_clone(OutPoint orig) { diff --git a/src/main/java/org/ldk/structs/PaymentSendFailure.java b/src/main/java/org/ldk/structs/PaymentSendFailure.java index 5db694ee..7b7f3632 100644 --- a/src/main/java/org/ldk/structs/PaymentSendFailure.java +++ b/src/main/java/org/ldk/structs/PaymentSendFailure.java @@ -11,7 +11,7 @@ public class PaymentSendFailure extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.PaymentSendFailure_free(ptr); + if (ptr != 0) { bindings.PaymentSendFailure_free(ptr); } } } diff --git a/src/main/java/org/ldk/structs/PeerHandleError.java b/src/main/java/org/ldk/structs/PeerHandleError.java index a7240bc6..1b7b3987 100644 --- a/src/main/java/org/ldk/structs/PeerHandleError.java +++ b/src/main/java/org/ldk/structs/PeerHandleError.java @@ -11,7 +11,7 @@ public class PeerHandleError extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.PeerHandleError_free(ptr); + if (ptr != 0) { bindings.PeerHandleError_free(ptr); } } public boolean get_no_connection_possible() { diff --git a/src/main/java/org/ldk/structs/PeerManager.java b/src/main/java/org/ldk/structs/PeerManager.java index 93837b5e..2bb4ba9b 100644 --- a/src/main/java/org/ldk/structs/PeerManager.java +++ b/src/main/java/org/ldk/structs/PeerManager.java @@ -11,7 +11,7 @@ public class PeerManager extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.PeerManager_free(ptr); + if (ptr != 0) { bindings.PeerManager_free(ptr); } } public static PeerManager constructor_new(ChannelMessageHandler message_handler_chan_handler_arg, RoutingMessageHandler message_handler_route_handler_arg, byte[] our_node_secret, byte[] ephemeral_random_data, Logger logger) { diff --git a/src/main/java/org/ldk/structs/Ping.java b/src/main/java/org/ldk/structs/Ping.java index 5ca952f1..7159f0f4 100644 --- a/src/main/java/org/ldk/structs/Ping.java +++ b/src/main/java/org/ldk/structs/Ping.java @@ -11,7 +11,7 @@ public class Ping extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.Ping_free(ptr); + if (ptr != 0) { bindings.Ping_free(ptr); } } public static Ping constructor_clone(Ping orig) { diff --git a/src/main/java/org/ldk/structs/Pong.java b/src/main/java/org/ldk/structs/Pong.java index 80f2995d..54b83e7a 100644 --- a/src/main/java/org/ldk/structs/Pong.java +++ b/src/main/java/org/ldk/structs/Pong.java @@ -11,7 +11,7 @@ public class Pong extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.Pong_free(ptr); + if (ptr != 0) { bindings.Pong_free(ptr); } } public static Pong constructor_clone(Pong orig) { diff --git a/src/main/java/org/ldk/structs/PreCalculatedTxCreationKeys.java b/src/main/java/org/ldk/structs/PreCalculatedTxCreationKeys.java index 1f4bae79..4f71b567 100644 --- a/src/main/java/org/ldk/structs/PreCalculatedTxCreationKeys.java +++ b/src/main/java/org/ldk/structs/PreCalculatedTxCreationKeys.java @@ -11,7 +11,7 @@ public class PreCalculatedTxCreationKeys extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.PreCalculatedTxCreationKeys_free(ptr); + if (ptr != 0) { bindings.PreCalculatedTxCreationKeys_free(ptr); } } public static PreCalculatedTxCreationKeys constructor_new(TxCreationKeys keys) { diff --git a/src/main/java/org/ldk/structs/QueryChannelRange.java b/src/main/java/org/ldk/structs/QueryChannelRange.java index fe205872..f12c69aa 100644 --- a/src/main/java/org/ldk/structs/QueryChannelRange.java +++ b/src/main/java/org/ldk/structs/QueryChannelRange.java @@ -11,7 +11,7 @@ public class QueryChannelRange extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.QueryChannelRange_free(ptr); + if (ptr != 0) { bindings.QueryChannelRange_free(ptr); } } public static QueryChannelRange constructor_clone(QueryChannelRange orig) { diff --git a/src/main/java/org/ldk/structs/QueryShortChannelIds.java b/src/main/java/org/ldk/structs/QueryShortChannelIds.java index c68d4209..3fb87651 100644 --- a/src/main/java/org/ldk/structs/QueryShortChannelIds.java +++ b/src/main/java/org/ldk/structs/QueryShortChannelIds.java @@ -11,7 +11,7 @@ public class QueryShortChannelIds extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.QueryShortChannelIds_free(ptr); + if (ptr != 0) { bindings.QueryShortChannelIds_free(ptr); } } public static QueryShortChannelIds constructor_clone(QueryShortChannelIds orig) { diff --git a/src/main/java/org/ldk/structs/ReplyChannelRange.java b/src/main/java/org/ldk/structs/ReplyChannelRange.java index 939620ba..ac5bb1b1 100644 --- a/src/main/java/org/ldk/structs/ReplyChannelRange.java +++ b/src/main/java/org/ldk/structs/ReplyChannelRange.java @@ -11,7 +11,7 @@ public class ReplyChannelRange extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ReplyChannelRange_free(ptr); + if (ptr != 0) { bindings.ReplyChannelRange_free(ptr); } } public static ReplyChannelRange constructor_clone(ReplyChannelRange orig) { diff --git a/src/main/java/org/ldk/structs/ReplyShortChannelIdsEnd.java b/src/main/java/org/ldk/structs/ReplyShortChannelIdsEnd.java index 947ca85a..6e3163c3 100644 --- a/src/main/java/org/ldk/structs/ReplyShortChannelIdsEnd.java +++ b/src/main/java/org/ldk/structs/ReplyShortChannelIdsEnd.java @@ -11,7 +11,7 @@ public class ReplyShortChannelIdsEnd extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.ReplyShortChannelIdsEnd_free(ptr); + if (ptr != 0) { bindings.ReplyShortChannelIdsEnd_free(ptr); } } public static ReplyShortChannelIdsEnd constructor_clone(ReplyShortChannelIdsEnd orig) { diff --git a/src/main/java/org/ldk/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.java b/src/main/java/org/ldk/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.java index 8fbfa386..db81132c 100644 --- a/src/main/java/org/ldk/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.java +++ b/src/main/java/org/ldk/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ extends CommonBase { private Result_C2Tuple_SignatureCVec_SignatureZZNoneZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(ptr); } super.finalize(); } static Result_C2Tuple_SignatureCVec_SignatureZZNoneZ constr_from_ptr(long ptr) { @@ -20,7 +20,7 @@ public class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ extends CommonBase { } } public static final class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK extends Result_C2Tuple_SignatureCVec_SignatureZZNoneZ { - public TwoTuple res; + public final TwoTuple res; private Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); long res = bindings.LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_get_ok(ptr); @@ -29,13 +29,19 @@ public class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ extends CommonBase { TwoTuple res_conv = new TwoTuple(res_a, res_b); this.res = res_conv; } - + public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK(TwoTuple res) { + this(null, bindings.CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(bindings.C2Tuple_SignatureCVec_SignatureZZ_new(res.a, res.b))); + } } + public static final class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_Err extends Result_C2Tuple_SignatureCVec_SignatureZZNoneZ { - public byte err; + public final byte err; private Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); this.err = bindings.LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_get_err(ptr); } + public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_Err() { + this(null, bindings.CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err()); + } } } diff --git a/src/main/java/org/ldk/structs/Result_CVec_SignatureZNoneZ.java b/src/main/java/org/ldk/structs/Result_CVec_SignatureZNoneZ.java index 1d709cf1..b1bc15c9 100644 --- a/src/main/java/org/ldk/structs/Result_CVec_SignatureZNoneZ.java +++ b/src/main/java/org/ldk/structs/Result_CVec_SignatureZNoneZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_CVec_SignatureZNoneZ extends CommonBase { private Result_CVec_SignatureZNoneZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_CVec_SignatureZNoneZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_CVec_SignatureZNoneZ_free(ptr); } super.finalize(); } static Result_CVec_SignatureZNoneZ constr_from_ptr(long ptr) { @@ -20,18 +20,24 @@ public class Result_CVec_SignatureZNoneZ extends CommonBase { } } public static final class Result_CVec_SignatureZNoneZ_OK extends Result_CVec_SignatureZNoneZ { - public byte[][] res; + public final byte[][] res; private Result_CVec_SignatureZNoneZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); this.res = bindings.LDKCResult_CVec_SignatureZNoneZ_get_ok(ptr); } - + public Result_CVec_SignatureZNoneZ_OK(byte[][] res) { + this(null, bindings.CResult_CVec_SignatureZNoneZ_ok(res)); + } } + public static final class Result_CVec_SignatureZNoneZ_Err extends Result_CVec_SignatureZNoneZ { - public byte err; + public final byte err; private Result_CVec_SignatureZNoneZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); this.err = bindings.LDKCResult_CVec_SignatureZNoneZ_get_err(ptr); } + public Result_CVec_SignatureZNoneZ_Err() { + this(null, bindings.CResult_CVec_SignatureZNoneZ_err()); + } } } diff --git a/src/main/java/org/ldk/structs/Result_CVec_u8ZPeerHandleErrorZ.java b/src/main/java/org/ldk/structs/Result_CVec_u8ZPeerHandleErrorZ.java index 490b7afc..3ef723e6 100644 --- a/src/main/java/org/ldk/structs/Result_CVec_u8ZPeerHandleErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_CVec_u8ZPeerHandleErrorZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_CVec_u8ZPeerHandleErrorZ extends CommonBase { private Result_CVec_u8ZPeerHandleErrorZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_CVec_u8ZPeerHandleErrorZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_CVec_u8ZPeerHandleErrorZ_free(ptr); } super.finalize(); } static Result_CVec_u8ZPeerHandleErrorZ constr_from_ptr(long ptr) { @@ -20,20 +20,27 @@ public class Result_CVec_u8ZPeerHandleErrorZ extends CommonBase { } } public static final class Result_CVec_u8ZPeerHandleErrorZ_OK extends Result_CVec_u8ZPeerHandleErrorZ { - public byte[] res; + public final byte[] res; private Result_CVec_u8ZPeerHandleErrorZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); this.res = bindings.LDKCResult_CVec_u8ZPeerHandleErrorZ_get_ok(ptr); } - + public Result_CVec_u8ZPeerHandleErrorZ_OK(byte[] res) { + this(null, bindings.CResult_CVec_u8ZPeerHandleErrorZ_ok(res)); + } } + public static final class Result_CVec_u8ZPeerHandleErrorZ_Err extends Result_CVec_u8ZPeerHandleErrorZ { - public PeerHandleError err; + public final PeerHandleError err; private Result_CVec_u8ZPeerHandleErrorZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); long err = bindings.LDKCResult_CVec_u8ZPeerHandleErrorZ_get_err(ptr); PeerHandleError err_hu_conv = new PeerHandleError(null, err); this.err = err_hu_conv; } + public Result_CVec_u8ZPeerHandleErrorZ_Err(PeerHandleError err) { + this(null, bindings.CResult_CVec_u8ZPeerHandleErrorZ_err(err == null ? 0 : err.ptr & ~1)); + this.ptrs_to.add(err); + } } } diff --git a/src/main/java/org/ldk/structs/Result_NoneAPIErrorZ.java b/src/main/java/org/ldk/structs/Result_NoneAPIErrorZ.java index 5935b647..846cc797 100644 --- a/src/main/java/org/ldk/structs/Result_NoneAPIErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_NoneAPIErrorZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_NoneAPIErrorZ extends CommonBase { private Result_NoneAPIErrorZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_NoneAPIErrorZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_NoneAPIErrorZ_free(ptr); } super.finalize(); } static Result_NoneAPIErrorZ constr_from_ptr(long ptr) { @@ -20,20 +20,26 @@ public class Result_NoneAPIErrorZ extends CommonBase { } } public static final class Result_NoneAPIErrorZ_OK extends Result_NoneAPIErrorZ { - public byte res; + public final byte res; private Result_NoneAPIErrorZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); this.res = bindings.LDKCResult_NoneAPIErrorZ_get_ok(ptr); } - + public Result_NoneAPIErrorZ_OK() { + this(null, bindings.CResult_NoneAPIErrorZ_ok()); + } } + public static final class Result_NoneAPIErrorZ_Err extends Result_NoneAPIErrorZ { - public APIError err; + public final APIError err; private Result_NoneAPIErrorZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); long err = bindings.LDKCResult_NoneAPIErrorZ_get_err(ptr); APIError err_hu_conv = APIError.constr_from_ptr(err); this.err = err_hu_conv; } + public Result_NoneAPIErrorZ_Err(APIError err) { + this(null, bindings.CResult_NoneAPIErrorZ_err(err.ptr)); + } } } diff --git a/src/main/java/org/ldk/structs/Result_NoneChannelMonitorUpdateErrZ.java b/src/main/java/org/ldk/structs/Result_NoneChannelMonitorUpdateErrZ.java index 3c18a0bf..68d715e3 100644 --- a/src/main/java/org/ldk/structs/Result_NoneChannelMonitorUpdateErrZ.java +++ b/src/main/java/org/ldk/structs/Result_NoneChannelMonitorUpdateErrZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_NoneChannelMonitorUpdateErrZ extends CommonBase { private Result_NoneChannelMonitorUpdateErrZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_NoneChannelMonitorUpdateErrZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_NoneChannelMonitorUpdateErrZ_free(ptr); } super.finalize(); } static Result_NoneChannelMonitorUpdateErrZ constr_from_ptr(long ptr) { @@ -20,18 +20,24 @@ public class Result_NoneChannelMonitorUpdateErrZ extends CommonBase { } } public static final class Result_NoneChannelMonitorUpdateErrZ_OK extends Result_NoneChannelMonitorUpdateErrZ { - public byte res; + public final byte res; private Result_NoneChannelMonitorUpdateErrZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); this.res = bindings.LDKCResult_NoneChannelMonitorUpdateErrZ_get_ok(ptr); } - + public Result_NoneChannelMonitorUpdateErrZ_OK() { + this(null, bindings.CResult_NoneChannelMonitorUpdateErrZ_ok()); + } } + public static final class Result_NoneChannelMonitorUpdateErrZ_Err extends Result_NoneChannelMonitorUpdateErrZ { - public LDKChannelMonitorUpdateErr err; + public final LDKChannelMonitorUpdateErr err; private Result_NoneChannelMonitorUpdateErrZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); this.err = bindings.LDKCResult_NoneChannelMonitorUpdateErrZ_get_err(ptr); } + public Result_NoneChannelMonitorUpdateErrZ_Err(LDKChannelMonitorUpdateErr err) { + this(null, bindings.CResult_NoneChannelMonitorUpdateErrZ_err(err)); + } } } diff --git a/src/main/java/org/ldk/structs/Result_NoneMonitorUpdateErrorZ.java b/src/main/java/org/ldk/structs/Result_NoneMonitorUpdateErrorZ.java index c071d7b0..281dce01 100644 --- a/src/main/java/org/ldk/structs/Result_NoneMonitorUpdateErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_NoneMonitorUpdateErrorZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_NoneMonitorUpdateErrorZ extends CommonBase { private Result_NoneMonitorUpdateErrorZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_NoneMonitorUpdateErrorZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_NoneMonitorUpdateErrorZ_free(ptr); } super.finalize(); } static Result_NoneMonitorUpdateErrorZ constr_from_ptr(long ptr) { @@ -20,20 +20,27 @@ public class Result_NoneMonitorUpdateErrorZ extends CommonBase { } } public static final class Result_NoneMonitorUpdateErrorZ_OK extends Result_NoneMonitorUpdateErrorZ { - public byte res; + public final byte res; private Result_NoneMonitorUpdateErrorZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); this.res = bindings.LDKCResult_NoneMonitorUpdateErrorZ_get_ok(ptr); } - + public Result_NoneMonitorUpdateErrorZ_OK() { + this(null, bindings.CResult_NoneMonitorUpdateErrorZ_ok()); + } } + public static final class Result_NoneMonitorUpdateErrorZ_Err extends Result_NoneMonitorUpdateErrorZ { - public MonitorUpdateError err; + public final MonitorUpdateError err; private Result_NoneMonitorUpdateErrorZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); long err = bindings.LDKCResult_NoneMonitorUpdateErrorZ_get_err(ptr); MonitorUpdateError err_hu_conv = new MonitorUpdateError(null, err); this.err = err_hu_conv; } + public Result_NoneMonitorUpdateErrorZ_Err(MonitorUpdateError err) { + this(null, bindings.CResult_NoneMonitorUpdateErrorZ_err(err == null ? 0 : err.ptr & ~1)); + this.ptrs_to.add(err); + } } } diff --git a/src/main/java/org/ldk/structs/Result_NonePaymentSendFailureZ.java b/src/main/java/org/ldk/structs/Result_NonePaymentSendFailureZ.java index b9496fd0..b6a47720 100644 --- a/src/main/java/org/ldk/structs/Result_NonePaymentSendFailureZ.java +++ b/src/main/java/org/ldk/structs/Result_NonePaymentSendFailureZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_NonePaymentSendFailureZ extends CommonBase { private Result_NonePaymentSendFailureZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_NonePaymentSendFailureZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_NonePaymentSendFailureZ_free(ptr); } super.finalize(); } static Result_NonePaymentSendFailureZ constr_from_ptr(long ptr) { @@ -20,20 +20,27 @@ public class Result_NonePaymentSendFailureZ extends CommonBase { } } public static final class Result_NonePaymentSendFailureZ_OK extends Result_NonePaymentSendFailureZ { - public byte res; + public final byte res; private Result_NonePaymentSendFailureZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); this.res = bindings.LDKCResult_NonePaymentSendFailureZ_get_ok(ptr); } - + public Result_NonePaymentSendFailureZ_OK() { + this(null, bindings.CResult_NonePaymentSendFailureZ_ok()); + } } + public static final class Result_NonePaymentSendFailureZ_Err extends Result_NonePaymentSendFailureZ { - public PaymentSendFailure err; + public final PaymentSendFailure err; private Result_NonePaymentSendFailureZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); long err = bindings.LDKCResult_NonePaymentSendFailureZ_get_err(ptr); PaymentSendFailure err_hu_conv = new PaymentSendFailure(null, err); this.err = err_hu_conv; } + public Result_NonePaymentSendFailureZ_Err(PaymentSendFailure err) { + this(null, bindings.CResult_NonePaymentSendFailureZ_err(err == null ? 0 : err.ptr & ~1)); + this.ptrs_to.add(err); + } } } diff --git a/src/main/java/org/ldk/structs/Result_NonePeerHandleErrorZ.java b/src/main/java/org/ldk/structs/Result_NonePeerHandleErrorZ.java index 385e571b..c7b31e13 100644 --- a/src/main/java/org/ldk/structs/Result_NonePeerHandleErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_NonePeerHandleErrorZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_NonePeerHandleErrorZ extends CommonBase { private Result_NonePeerHandleErrorZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_NonePeerHandleErrorZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_NonePeerHandleErrorZ_free(ptr); } super.finalize(); } static Result_NonePeerHandleErrorZ constr_from_ptr(long ptr) { @@ -20,20 +20,27 @@ public class Result_NonePeerHandleErrorZ extends CommonBase { } } public static final class Result_NonePeerHandleErrorZ_OK extends Result_NonePeerHandleErrorZ { - public byte res; + public final byte res; private Result_NonePeerHandleErrorZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); this.res = bindings.LDKCResult_NonePeerHandleErrorZ_get_ok(ptr); } - + public Result_NonePeerHandleErrorZ_OK() { + this(null, bindings.CResult_NonePeerHandleErrorZ_ok()); + } } + public static final class Result_NonePeerHandleErrorZ_Err extends Result_NonePeerHandleErrorZ { - public PeerHandleError err; + public final PeerHandleError err; private Result_NonePeerHandleErrorZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); long err = bindings.LDKCResult_NonePeerHandleErrorZ_get_err(ptr); PeerHandleError err_hu_conv = new PeerHandleError(null, err); this.err = err_hu_conv; } + public Result_NonePeerHandleErrorZ_Err(PeerHandleError err) { + this(null, bindings.CResult_NonePeerHandleErrorZ_err(err == null ? 0 : err.ptr & ~1)); + this.ptrs_to.add(err); + } } } diff --git a/src/main/java/org/ldk/structs/Result_PublicKeySecpErrorZ.java b/src/main/java/org/ldk/structs/Result_PublicKeySecpErrorZ.java index 0f0bcc31..15c27f43 100644 --- a/src/main/java/org/ldk/structs/Result_PublicKeySecpErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_PublicKeySecpErrorZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_PublicKeySecpErrorZ extends CommonBase { private Result_PublicKeySecpErrorZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_PublicKeySecpErrorZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_PublicKeySecpErrorZ_free(ptr); } super.finalize(); } static Result_PublicKeySecpErrorZ constr_from_ptr(long ptr) { @@ -20,18 +20,24 @@ public class Result_PublicKeySecpErrorZ extends CommonBase { } } public static final class Result_PublicKeySecpErrorZ_OK extends Result_PublicKeySecpErrorZ { - public byte[] res; + public final byte[] res; private Result_PublicKeySecpErrorZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); this.res = bindings.LDKCResult_PublicKeySecpErrorZ_get_ok(ptr); } - + public Result_PublicKeySecpErrorZ_OK(byte[] res) { + this(null, bindings.CResult_PublicKeySecpErrorZ_ok(res)); + } } + public static final class Result_PublicKeySecpErrorZ_Err extends Result_PublicKeySecpErrorZ { - public LDKSecp256k1Error err; + public final LDKSecp256k1Error err; private Result_PublicKeySecpErrorZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); this.err = bindings.LDKCResult_PublicKeySecpErrorZ_get_err(ptr); } + public Result_PublicKeySecpErrorZ_Err(LDKSecp256k1Error err) { + this(null, bindings.CResult_PublicKeySecpErrorZ_err(err)); + } } } diff --git a/src/main/java/org/ldk/structs/Result_RouteLightningErrorZ.java b/src/main/java/org/ldk/structs/Result_RouteLightningErrorZ.java index b4d43664..09c430f2 100644 --- a/src/main/java/org/ldk/structs/Result_RouteLightningErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_RouteLightningErrorZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_RouteLightningErrorZ extends CommonBase { private Result_RouteLightningErrorZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_RouteLightningErrorZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_RouteLightningErrorZ_free(ptr); } super.finalize(); } static Result_RouteLightningErrorZ constr_from_ptr(long ptr) { @@ -20,22 +20,30 @@ public class Result_RouteLightningErrorZ extends CommonBase { } } public static final class Result_RouteLightningErrorZ_OK extends Result_RouteLightningErrorZ { - public Route res; + public final Route res; private Result_RouteLightningErrorZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); long res = bindings.LDKCResult_RouteLightningErrorZ_get_ok(ptr); Route res_hu_conv = new Route(null, res); this.res = res_hu_conv; } - + public Result_RouteLightningErrorZ_OK(Route res) { + this(null, bindings.CResult_RouteLightningErrorZ_ok(res == null ? 0 : res.ptr & ~1)); + this.ptrs_to.add(res); + } } + public static final class Result_RouteLightningErrorZ_Err extends Result_RouteLightningErrorZ { - public LightningError err; + public final LightningError err; private Result_RouteLightningErrorZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); long err = bindings.LDKCResult_RouteLightningErrorZ_get_err(ptr); LightningError err_hu_conv = new LightningError(null, err); this.err = err_hu_conv; } + public Result_RouteLightningErrorZ_Err(LightningError err) { + this(null, bindings.CResult_RouteLightningErrorZ_err(err == null ? 0 : err.ptr & ~1)); + this.ptrs_to.add(err); + } } } diff --git a/src/main/java/org/ldk/structs/Result_SecretKeySecpErrorZ.java b/src/main/java/org/ldk/structs/Result_SecretKeySecpErrorZ.java index 04bb874a..01744bee 100644 --- a/src/main/java/org/ldk/structs/Result_SecretKeySecpErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_SecretKeySecpErrorZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_SecretKeySecpErrorZ extends CommonBase { private Result_SecretKeySecpErrorZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_SecretKeySecpErrorZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_SecretKeySecpErrorZ_free(ptr); } super.finalize(); } static Result_SecretKeySecpErrorZ constr_from_ptr(long ptr) { @@ -20,18 +20,24 @@ public class Result_SecretKeySecpErrorZ extends CommonBase { } } public static final class Result_SecretKeySecpErrorZ_OK extends Result_SecretKeySecpErrorZ { - public byte[] res; + public final byte[] res; private Result_SecretKeySecpErrorZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); this.res = bindings.LDKCResult_SecretKeySecpErrorZ_get_ok(ptr); } - + public Result_SecretKeySecpErrorZ_OK(byte[] res) { + this(null, bindings.CResult_SecretKeySecpErrorZ_ok(res)); + } } + public static final class Result_SecretKeySecpErrorZ_Err extends Result_SecretKeySecpErrorZ { - public LDKSecp256k1Error err; + public final LDKSecp256k1Error err; private Result_SecretKeySecpErrorZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); this.err = bindings.LDKCResult_SecretKeySecpErrorZ_get_err(ptr); } + public Result_SecretKeySecpErrorZ_Err(LDKSecp256k1Error err) { + this(null, bindings.CResult_SecretKeySecpErrorZ_err(err)); + } } } diff --git a/src/main/java/org/ldk/structs/Result_SignatureNoneZ.java b/src/main/java/org/ldk/structs/Result_SignatureNoneZ.java index 877a9b30..0e054a3b 100644 --- a/src/main/java/org/ldk/structs/Result_SignatureNoneZ.java +++ b/src/main/java/org/ldk/structs/Result_SignatureNoneZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_SignatureNoneZ extends CommonBase { private Result_SignatureNoneZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_SignatureNoneZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_SignatureNoneZ_free(ptr); } super.finalize(); } static Result_SignatureNoneZ constr_from_ptr(long ptr) { @@ -20,18 +20,24 @@ public class Result_SignatureNoneZ extends CommonBase { } } public static final class Result_SignatureNoneZ_OK extends Result_SignatureNoneZ { - public byte[] res; + public final byte[] res; private Result_SignatureNoneZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); this.res = bindings.LDKCResult_SignatureNoneZ_get_ok(ptr); } - + public Result_SignatureNoneZ_OK(byte[] res) { + this(null, bindings.CResult_SignatureNoneZ_ok(res)); + } } + public static final class Result_SignatureNoneZ_Err extends Result_SignatureNoneZ { - public byte err; + public final byte err; private Result_SignatureNoneZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); this.err = bindings.LDKCResult_SignatureNoneZ_get_err(ptr); } + public Result_SignatureNoneZ_Err() { + this(null, bindings.CResult_SignatureNoneZ_err()); + } } } diff --git a/src/main/java/org/ldk/structs/Result_TxCreationKeysSecpErrorZ.java b/src/main/java/org/ldk/structs/Result_TxCreationKeysSecpErrorZ.java index dfe085cd..86e637aa 100644 --- a/src/main/java/org/ldk/structs/Result_TxCreationKeysSecpErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_TxCreationKeysSecpErrorZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_TxCreationKeysSecpErrorZ extends CommonBase { private Result_TxCreationKeysSecpErrorZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_TxCreationKeysSecpErrorZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_TxCreationKeysSecpErrorZ_free(ptr); } super.finalize(); } static Result_TxCreationKeysSecpErrorZ constr_from_ptr(long ptr) { @@ -20,20 +20,27 @@ public class Result_TxCreationKeysSecpErrorZ extends CommonBase { } } public static final class Result_TxCreationKeysSecpErrorZ_OK extends Result_TxCreationKeysSecpErrorZ { - public TxCreationKeys res; + public final TxCreationKeys res; private Result_TxCreationKeysSecpErrorZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); long res = bindings.LDKCResult_TxCreationKeysSecpErrorZ_get_ok(ptr); TxCreationKeys res_hu_conv = new TxCreationKeys(null, res); this.res = res_hu_conv; } - + public Result_TxCreationKeysSecpErrorZ_OK(TxCreationKeys res) { + this(null, bindings.CResult_TxCreationKeysSecpErrorZ_ok(res == null ? 0 : res.ptr & ~1)); + this.ptrs_to.add(res); + } } + public static final class Result_TxCreationKeysSecpErrorZ_Err extends Result_TxCreationKeysSecpErrorZ { - public LDKSecp256k1Error err; + public final LDKSecp256k1Error err; private Result_TxCreationKeysSecpErrorZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); this.err = bindings.LDKCResult_TxCreationKeysSecpErrorZ_get_err(ptr); } + public Result_TxCreationKeysSecpErrorZ_Err(LDKSecp256k1Error err) { + this(null, bindings.CResult_TxCreationKeysSecpErrorZ_err(err)); + } } } diff --git a/src/main/java/org/ldk/structs/Result_TxOutAccessErrorZ.java b/src/main/java/org/ldk/structs/Result_TxOutAccessErrorZ.java index 1c1f7e90..e4851630 100644 --- a/src/main/java/org/ldk/structs/Result_TxOutAccessErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_TxOutAccessErrorZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_TxOutAccessErrorZ extends CommonBase { private Result_TxOutAccessErrorZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_TxOutAccessErrorZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_TxOutAccessErrorZ_free(ptr); } super.finalize(); } static Result_TxOutAccessErrorZ constr_from_ptr(long ptr) { @@ -20,20 +20,26 @@ public class Result_TxOutAccessErrorZ extends CommonBase { } } public static final class Result_TxOutAccessErrorZ_OK extends Result_TxOutAccessErrorZ { - public TxOut res; + public final TxOut res; private Result_TxOutAccessErrorZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); long res = bindings.LDKCResult_TxOutAccessErrorZ_get_ok(ptr); TxOut res_conv = new TxOut(null, res); this.res = res_conv; } - + public Result_TxOutAccessErrorZ_OK(TxOut res) { + this(null, bindings.CResult_TxOutAccessErrorZ_ok(res.ptr)); + } } + public static final class Result_TxOutAccessErrorZ_Err extends Result_TxOutAccessErrorZ { - public LDKAccessError err; + public final LDKAccessError err; private Result_TxOutAccessErrorZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); this.err = bindings.LDKCResult_TxOutAccessErrorZ_get_err(ptr); } + public Result_TxOutAccessErrorZ_Err(LDKAccessError err) { + this(null, bindings.CResult_TxOutAccessErrorZ_err(err)); + } } } diff --git a/src/main/java/org/ldk/structs/Result_boolLightningErrorZ.java b/src/main/java/org/ldk/structs/Result_boolLightningErrorZ.java index bb9597f7..5eb4ab80 100644 --- a/src/main/java/org/ldk/structs/Result_boolLightningErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_boolLightningErrorZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_boolLightningErrorZ extends CommonBase { private Result_boolLightningErrorZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_boolLightningErrorZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_boolLightningErrorZ_free(ptr); } super.finalize(); } static Result_boolLightningErrorZ constr_from_ptr(long ptr) { @@ -20,20 +20,27 @@ public class Result_boolLightningErrorZ extends CommonBase { } } public static final class Result_boolLightningErrorZ_OK extends Result_boolLightningErrorZ { - public boolean res; + public final boolean res; private Result_boolLightningErrorZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); this.res = bindings.LDKCResult_boolLightningErrorZ_get_ok(ptr); } - + public Result_boolLightningErrorZ_OK(boolean res) { + this(null, bindings.CResult_boolLightningErrorZ_ok(res)); + } } + public static final class Result_boolLightningErrorZ_Err extends Result_boolLightningErrorZ { - public LightningError err; + public final LightningError err; private Result_boolLightningErrorZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); long err = bindings.LDKCResult_boolLightningErrorZ_get_err(ptr); LightningError err_hu_conv = new LightningError(null, err); this.err = err_hu_conv; } + public Result_boolLightningErrorZ_Err(LightningError err) { + this(null, bindings.CResult_boolLightningErrorZ_err(err == null ? 0 : err.ptr & ~1)); + this.ptrs_to.add(err); + } } } diff --git a/src/main/java/org/ldk/structs/Result_boolPeerHandleErrorZ.java b/src/main/java/org/ldk/structs/Result_boolPeerHandleErrorZ.java index ac33e40c..e29335b6 100644 --- a/src/main/java/org/ldk/structs/Result_boolPeerHandleErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_boolPeerHandleErrorZ.java @@ -9,7 +9,7 @@ import java.util.Arrays; public class Result_boolPeerHandleErrorZ extends CommonBase { private Result_boolPeerHandleErrorZ(Object _dummy, long ptr) { super(ptr); } protected void finalize() throws Throwable { - bindings.CResult_boolPeerHandleErrorZ_free(ptr); super.finalize(); + if (ptr != 0) { bindings.CResult_boolPeerHandleErrorZ_free(ptr); } super.finalize(); } static Result_boolPeerHandleErrorZ constr_from_ptr(long ptr) { @@ -20,20 +20,27 @@ public class Result_boolPeerHandleErrorZ extends CommonBase { } } public static final class Result_boolPeerHandleErrorZ_OK extends Result_boolPeerHandleErrorZ { - public boolean res; + public final boolean res; private Result_boolPeerHandleErrorZ_OK(Object _dummy, long ptr) { super(_dummy, ptr); this.res = bindings.LDKCResult_boolPeerHandleErrorZ_get_ok(ptr); } - + public Result_boolPeerHandleErrorZ_OK(boolean res) { + this(null, bindings.CResult_boolPeerHandleErrorZ_ok(res)); + } } + public static final class Result_boolPeerHandleErrorZ_Err extends Result_boolPeerHandleErrorZ { - public PeerHandleError err; + public final PeerHandleError err; private Result_boolPeerHandleErrorZ_Err(Object _dummy, long ptr) { super(_dummy, ptr); long err = bindings.LDKCResult_boolPeerHandleErrorZ_get_err(ptr); PeerHandleError err_hu_conv = new PeerHandleError(null, err); this.err = err_hu_conv; } + public Result_boolPeerHandleErrorZ_Err(PeerHandleError err) { + this(null, bindings.CResult_boolPeerHandleErrorZ_err(err == null ? 0 : err.ptr & ~1)); + this.ptrs_to.add(err); + } } } diff --git a/src/main/java/org/ldk/structs/RevokeAndACK.java b/src/main/java/org/ldk/structs/RevokeAndACK.java index 5409d3b9..176f5db7 100644 --- a/src/main/java/org/ldk/structs/RevokeAndACK.java +++ b/src/main/java/org/ldk/structs/RevokeAndACK.java @@ -11,7 +11,7 @@ public class RevokeAndACK extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.RevokeAndACK_free(ptr); + if (ptr != 0) { bindings.RevokeAndACK_free(ptr); } } public static RevokeAndACK constructor_clone(RevokeAndACK orig) { diff --git a/src/main/java/org/ldk/structs/Route.java b/src/main/java/org/ldk/structs/Route.java index b7864b49..7e2387cd 100644 --- a/src/main/java/org/ldk/structs/Route.java +++ b/src/main/java/org/ldk/structs/Route.java @@ -11,7 +11,7 @@ public class Route extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.Route_free(ptr); + if (ptr != 0) { bindings.Route_free(ptr); } } public static Route constructor_clone(Route orig) { diff --git a/src/main/java/org/ldk/structs/RouteHint.java b/src/main/java/org/ldk/structs/RouteHint.java index 9c6e0f79..e5c54d69 100644 --- a/src/main/java/org/ldk/structs/RouteHint.java +++ b/src/main/java/org/ldk/structs/RouteHint.java @@ -11,7 +11,7 @@ public class RouteHint extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.RouteHint_free(ptr); + if (ptr != 0) { bindings.RouteHint_free(ptr); } } public static RouteHint constructor_clone(RouteHint orig) { diff --git a/src/main/java/org/ldk/structs/RouteHop.java b/src/main/java/org/ldk/structs/RouteHop.java index 74e5816d..e54845e5 100644 --- a/src/main/java/org/ldk/structs/RouteHop.java +++ b/src/main/java/org/ldk/structs/RouteHop.java @@ -11,7 +11,7 @@ public class RouteHop extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.RouteHop_free(ptr); + if (ptr != 0) { bindings.RouteHop_free(ptr); } } public static RouteHop constructor_clone(RouteHop orig) { diff --git a/src/main/java/org/ldk/structs/RoutingFees.java b/src/main/java/org/ldk/structs/RoutingFees.java index a182fea6..8ea88fca 100644 --- a/src/main/java/org/ldk/structs/RoutingFees.java +++ b/src/main/java/org/ldk/structs/RoutingFees.java @@ -11,7 +11,7 @@ public class RoutingFees extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.RoutingFees_free(ptr); + if (ptr != 0) { bindings.RoutingFees_free(ptr); } } public static RoutingFees constructor_clone(RoutingFees orig) { diff --git a/src/main/java/org/ldk/structs/RoutingMessageHandler.java b/src/main/java/org/ldk/structs/RoutingMessageHandler.java index e547b766..23fd8c9f 100644 --- a/src/main/java/org/ldk/structs/RoutingMessageHandler.java +++ b/src/main/java/org/ldk/structs/RoutingMessageHandler.java @@ -7,16 +7,72 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class RoutingMessageHandler extends CommonBase { - RoutingMessageHandler(Object _dummy, long ptr) { super(ptr); } - public RoutingMessageHandler(bindings.LDKRoutingMessageHandler arg) { + final bindings.LDKRoutingMessageHandler bindings_instance; + RoutingMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private RoutingMessageHandler(bindings.LDKRoutingMessageHandler arg) { super(bindings.LDKRoutingMessageHandler_new(arg)); this.ptrs_to.add(arg); + this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.RoutingMessageHandler_free(ptr); super.finalize(); + if (ptr != 0) { bindings.RoutingMessageHandler_free(ptr); } super.finalize(); } + public static interface RoutingMessageHandlerInterface { + Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg); + Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg); + Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg); + void handle_htlc_fail_channel_update(HTLCFailChannelUpdate update); + ThreeTuple[] get_next_channel_announcements(long starting_point, byte batch_amount); + NodeAnnouncement[] get_next_node_announcements(byte[] starting_point, byte batch_amount); + boolean should_request_full_sync(byte[] node_id); + } + public RoutingMessageHandler(RoutingMessageHandlerInterface arg) { + this(new bindings.LDKRoutingMessageHandler() { + @Override public long handle_node_announcement(long msg) { + NodeAnnouncement msg_hu_conv = new NodeAnnouncement(null, msg); + Result_boolLightningErrorZ ret = arg.handle_node_announcement(msg_hu_conv); + long result = ret != null ? ret.ptr : 0; + ret.ptr = 0; + return result; + } + @Override public long handle_channel_announcement(long msg) { + ChannelAnnouncement msg_hu_conv = new ChannelAnnouncement(null, msg); + Result_boolLightningErrorZ ret = arg.handle_channel_announcement(msg_hu_conv); + long result = ret != null ? ret.ptr : 0; + ret.ptr = 0; + return result; + } + @Override public long handle_channel_update(long msg) { + ChannelUpdate msg_hu_conv = new ChannelUpdate(null, msg); + Result_boolLightningErrorZ ret = arg.handle_channel_update(msg_hu_conv); + long result = ret != null ? ret.ptr : 0; + ret.ptr = 0; + return result; + } + @Override public void handle_htlc_fail_channel_update(long update) { + HTLCFailChannelUpdate update_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(update); + arg.handle_htlc_fail_channel_update(update_hu_conv); + } + @Override public long[] get_next_channel_announcements(long starting_point, byte batch_amount) { + ThreeTuple[] ret = arg.get_next_channel_announcements(starting_point, batch_amount); + long[] result = Arrays.stream(ret).mapToLong(arr_conv_63 -> bindings.C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(arr_conv_63.a == null ? 0 : arr_conv_63.a.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_63_a)*/, arr_conv_63.b == null ? 0 : arr_conv_63.b.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_63_b)*/, arr_conv_63.c == null ? 0 : arr_conv_63.c.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_63_c)*/)).toArray(); + /* TODO 2 ThreeTuple */ + return result; + } + @Override public long[] get_next_node_announcements(byte[] starting_point, byte batch_amount) { + NodeAnnouncement[] ret = arg.get_next_node_announcements(starting_point, batch_amount); + long[] result = Arrays.stream(ret).mapToLong(arr_conv_18 -> arr_conv_18 == null ? 0 : arr_conv_18.ptr & ~1).toArray(); + /* TODO 2 NodeAnnouncement */ + return result; + } + @Override public boolean should_request_full_sync(byte[] node_id) { + boolean ret = arg.should_request_full_sync(node_id); + return ret; + } + }); + } public Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg) { long ret = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1); Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret); diff --git a/src/main/java/org/ldk/structs/Shutdown.java b/src/main/java/org/ldk/structs/Shutdown.java index 6b95b568..1d1c91d5 100644 --- a/src/main/java/org/ldk/structs/Shutdown.java +++ b/src/main/java/org/ldk/structs/Shutdown.java @@ -11,7 +11,7 @@ public class Shutdown extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.Shutdown_free(ptr); + if (ptr != 0) { bindings.Shutdown_free(ptr); } } public static Shutdown constructor_clone(Shutdown orig) { diff --git a/src/main/java/org/ldk/structs/SocketDescriptor.java b/src/main/java/org/ldk/structs/SocketDescriptor.java index ae56a983..9c4f9e7b 100644 --- a/src/main/java/org/ldk/structs/SocketDescriptor.java +++ b/src/main/java/org/ldk/structs/SocketDescriptor.java @@ -7,16 +7,43 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class SocketDescriptor extends CommonBase { - SocketDescriptor(Object _dummy, long ptr) { super(ptr); } - public SocketDescriptor(bindings.LDKSocketDescriptor arg) { + final bindings.LDKSocketDescriptor bindings_instance; + SocketDescriptor(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private SocketDescriptor(bindings.LDKSocketDescriptor arg) { super(bindings.LDKSocketDescriptor_new(arg)); this.ptrs_to.add(arg); + this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.SocketDescriptor_free(ptr); super.finalize(); + if (ptr != 0) { bindings.SocketDescriptor_free(ptr); } super.finalize(); } + public static interface SocketDescriptorInterface { + long send_data(byte[] data, boolean resume_read); + void disconnect_socket(); + boolean eq(long other_arg); + long hash(); + } + public SocketDescriptor(SocketDescriptorInterface arg) { + this(new bindings.LDKSocketDescriptor() { + @Override public long send_data(byte[] data, boolean resume_read) { + long ret = arg.send_data(data, resume_read); + return ret; + } + @Override public void disconnect_socket() { + arg.disconnect_socket(); + } + @Override public boolean eq(long other_arg) { + boolean ret = arg.eq(other_arg); + return ret; + } + @Override public long hash() { + long ret = arg.hash(); + return ret; + } + }); + } public long send_data(byte[] data, boolean resume_read) { long ret = bindings.SocketDescriptor_send_data(this.ptr, data, resume_read); return ret; diff --git a/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java b/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java index c812679b..74c70391 100644 --- a/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java +++ b/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java @@ -11,9 +11,8 @@ public class SpendableOutputDescriptor extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.SpendableOutputDescriptor_free(ptr); + if (ptr != 0) { 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) { @@ -29,8 +28,8 @@ public class SpendableOutputDescriptor extends CommonBase { } public final static class StaticOutput extends SpendableOutputDescriptor { - public OutPoint outpoint; - public TxOut output; + public final OutPoint outpoint; + public final TxOut output; private StaticOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutput obj) { super(null, ptr); long outpoint = obj.outpoint; @@ -40,15 +39,14 @@ public class SpendableOutputDescriptor extends CommonBase { 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 { - public OutPoint outpoint; - public byte[] per_commitment_point; - public short to_self_delay; - public TxOut output; - public TwoTuple key_derivation_params; - public byte[] revocation_pubkey; + public final OutPoint outpoint; + public final byte[] per_commitment_point; + public final short to_self_delay; + public final TxOut output; + public final TwoTuple key_derivation_params; + public final byte[] revocation_pubkey; private DynamicOutputP2WSH(long ptr, bindings.LDKSpendableOutputDescriptor.DynamicOutputP2WSH obj) { super(null, ptr); long outpoint = obj.outpoint; @@ -66,12 +64,11 @@ public class SpendableOutputDescriptor extends CommonBase { 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; + public final OutPoint outpoint; + public final TxOut output; + public final TwoTuple key_derivation_params; private StaticOutputCounterpartyPayment(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutputCounterpartyPayment obj) { super(null, ptr); long outpoint = obj.outpoint; @@ -86,6 +83,5 @@ public class SpendableOutputDescriptor extends CommonBase { 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/java/org/ldk/structs/Transaction.java b/src/main/java/org/ldk/structs/Transaction.java index 203c34c3..91f19373 100644 --- a/src/main/java/org/ldk/structs/Transaction.java +++ b/src/main/java/org/ldk/structs/Transaction.java @@ -8,4 +8,6 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class Transaction extends CommonBase{ Transaction(java.lang.Object _dummy, long ptr) { super(ptr); } + public Transaction(byte[] data) { super(bindings.new_txpointer_copy_data(data)); } + @Override public void finalize() throws Throwable { super.finalize(); bindings.txpointer_free(ptr); } } \ No newline at end of file diff --git a/src/main/java/org/ldk/structs/TxCreationKeys.java b/src/main/java/org/ldk/structs/TxCreationKeys.java index 9cc92e5b..eda469d9 100644 --- a/src/main/java/org/ldk/structs/TxCreationKeys.java +++ b/src/main/java/org/ldk/structs/TxCreationKeys.java @@ -11,7 +11,7 @@ public class TxCreationKeys extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.TxCreationKeys_free(ptr); + if (ptr != 0) { bindings.TxCreationKeys_free(ptr); } } public static TxCreationKeys constructor_clone(TxCreationKeys orig) { diff --git a/src/main/java/org/ldk/structs/TxOut.java b/src/main/java/org/ldk/structs/TxOut.java index 438c92a0..709450f8 100644 --- a/src/main/java/org/ldk/structs/TxOut.java +++ b/src/main/java/org/ldk/structs/TxOut.java @@ -8,4 +8,5 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class TxOut extends CommonBase{ TxOut(java.lang.Object _dummy, long ptr) { super(ptr); } + long to_c_ptr() { return 0; } } \ No newline at end of file diff --git a/src/main/java/org/ldk/structs/UnsignedChannelAnnouncement.java b/src/main/java/org/ldk/structs/UnsignedChannelAnnouncement.java index a5b624b1..67c3d2e9 100644 --- a/src/main/java/org/ldk/structs/UnsignedChannelAnnouncement.java +++ b/src/main/java/org/ldk/structs/UnsignedChannelAnnouncement.java @@ -11,7 +11,7 @@ public class UnsignedChannelAnnouncement extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.UnsignedChannelAnnouncement_free(ptr); + if (ptr != 0) { bindings.UnsignedChannelAnnouncement_free(ptr); } } public static UnsignedChannelAnnouncement constructor_clone(UnsignedChannelAnnouncement orig) { diff --git a/src/main/java/org/ldk/structs/UnsignedChannelUpdate.java b/src/main/java/org/ldk/structs/UnsignedChannelUpdate.java index 0fa6b1e5..d9ca1444 100644 --- a/src/main/java/org/ldk/structs/UnsignedChannelUpdate.java +++ b/src/main/java/org/ldk/structs/UnsignedChannelUpdate.java @@ -11,7 +11,7 @@ public class UnsignedChannelUpdate extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.UnsignedChannelUpdate_free(ptr); + if (ptr != 0) { bindings.UnsignedChannelUpdate_free(ptr); } } public static UnsignedChannelUpdate constructor_clone(UnsignedChannelUpdate orig) { diff --git a/src/main/java/org/ldk/structs/UnsignedNodeAnnouncement.java b/src/main/java/org/ldk/structs/UnsignedNodeAnnouncement.java index 4c905aa1..8a38275f 100644 --- a/src/main/java/org/ldk/structs/UnsignedNodeAnnouncement.java +++ b/src/main/java/org/ldk/structs/UnsignedNodeAnnouncement.java @@ -11,7 +11,7 @@ public class UnsignedNodeAnnouncement extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.UnsignedNodeAnnouncement_free(ptr); + if (ptr != 0) { bindings.UnsignedNodeAnnouncement_free(ptr); } } public static UnsignedNodeAnnouncement constructor_clone(UnsignedNodeAnnouncement orig) { @@ -65,7 +65,7 @@ public class UnsignedNodeAnnouncement extends CommonBase { } public void set_addresses(NetAddress[] val) { - bindings.UnsignedNodeAnnouncement_set_addresses(this.ptr, Arrays.stream(val).mapToLong(arr_conv_12 -> arr_conv_12.conv_to_c()).toArray()); + bindings.UnsignedNodeAnnouncement_set_addresses(this.ptr, Arrays.stream(val).mapToLong(arr_conv_12 -> arr_conv_12.ptr).toArray()); /* TODO 2 NetAddress */; } diff --git a/src/main/java/org/ldk/structs/UpdateAddHTLC.java b/src/main/java/org/ldk/structs/UpdateAddHTLC.java index 7e33edf0..c4aa0936 100644 --- a/src/main/java/org/ldk/structs/UpdateAddHTLC.java +++ b/src/main/java/org/ldk/structs/UpdateAddHTLC.java @@ -11,7 +11,7 @@ public class UpdateAddHTLC extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.UpdateAddHTLC_free(ptr); + if (ptr != 0) { bindings.UpdateAddHTLC_free(ptr); } } public static UpdateAddHTLC constructor_clone(UpdateAddHTLC orig) { diff --git a/src/main/java/org/ldk/structs/UpdateFailHTLC.java b/src/main/java/org/ldk/structs/UpdateFailHTLC.java index f533eb37..171cbaff 100644 --- a/src/main/java/org/ldk/structs/UpdateFailHTLC.java +++ b/src/main/java/org/ldk/structs/UpdateFailHTLC.java @@ -11,7 +11,7 @@ public class UpdateFailHTLC extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.UpdateFailHTLC_free(ptr); + if (ptr != 0) { bindings.UpdateFailHTLC_free(ptr); } } public static UpdateFailHTLC constructor_clone(UpdateFailHTLC orig) { diff --git a/src/main/java/org/ldk/structs/UpdateFailMalformedHTLC.java b/src/main/java/org/ldk/structs/UpdateFailMalformedHTLC.java index 1a6c8aea..3009fcbd 100644 --- a/src/main/java/org/ldk/structs/UpdateFailMalformedHTLC.java +++ b/src/main/java/org/ldk/structs/UpdateFailMalformedHTLC.java @@ -11,7 +11,7 @@ public class UpdateFailMalformedHTLC extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.UpdateFailMalformedHTLC_free(ptr); + if (ptr != 0) { bindings.UpdateFailMalformedHTLC_free(ptr); } } public static UpdateFailMalformedHTLC constructor_clone(UpdateFailMalformedHTLC orig) { diff --git a/src/main/java/org/ldk/structs/UpdateFee.java b/src/main/java/org/ldk/structs/UpdateFee.java index 77f14f6c..ecc9f0f0 100644 --- a/src/main/java/org/ldk/structs/UpdateFee.java +++ b/src/main/java/org/ldk/structs/UpdateFee.java @@ -11,7 +11,7 @@ public class UpdateFee extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.UpdateFee_free(ptr); + if (ptr != 0) { bindings.UpdateFee_free(ptr); } } public static UpdateFee constructor_clone(UpdateFee orig) { diff --git a/src/main/java/org/ldk/structs/UpdateFulfillHTLC.java b/src/main/java/org/ldk/structs/UpdateFulfillHTLC.java index cf1a60c1..d28bf460 100644 --- a/src/main/java/org/ldk/structs/UpdateFulfillHTLC.java +++ b/src/main/java/org/ldk/structs/UpdateFulfillHTLC.java @@ -11,7 +11,7 @@ public class UpdateFulfillHTLC extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.UpdateFulfillHTLC_free(ptr); + if (ptr != 0) { bindings.UpdateFulfillHTLC_free(ptr); } } public static UpdateFulfillHTLC constructor_clone(UpdateFulfillHTLC orig) { diff --git a/src/main/java/org/ldk/structs/UserConfig.java b/src/main/java/org/ldk/structs/UserConfig.java index 446270d4..4967fbf3 100644 --- a/src/main/java/org/ldk/structs/UserConfig.java +++ b/src/main/java/org/ldk/structs/UserConfig.java @@ -11,7 +11,7 @@ public class UserConfig extends CommonBase { @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { super.finalize(); - bindings.UserConfig_free(ptr); + if (ptr != 0) { bindings.UserConfig_free(ptr); } } public static UserConfig constructor_clone(UserConfig orig) { diff --git a/src/main/java/org/ldk/structs/Watch.java b/src/main/java/org/ldk/structs/Watch.java index 7ed2211f..e1bf3751 100644 --- a/src/main/java/org/ldk/structs/Watch.java +++ b/src/main/java/org/ldk/structs/Watch.java @@ -7,16 +7,49 @@ import java.util.Arrays; @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class Watch extends CommonBase { - Watch(Object _dummy, long ptr) { super(ptr); } - public Watch(bindings.LDKWatch arg) { + final bindings.LDKWatch bindings_instance; + Watch(Object _dummy, long ptr) { super(ptr); bindings_instance = null; } + private Watch(bindings.LDKWatch arg) { super(bindings.LDKWatch_new(arg)); this.ptrs_to.add(arg); + this.bindings_instance = arg; } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.Watch_free(ptr); super.finalize(); + if (ptr != 0) { bindings.Watch_free(ptr); } super.finalize(); } + public static interface WatchInterface { + Result_NoneChannelMonitorUpdateErrZ watch_channel(OutPoint funding_txo, ChannelMonitor monitor); + Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update); + MonitorEvent[] release_pending_monitor_events(); + } + public Watch(WatchInterface arg) { + this(new bindings.LDKWatch() { + @Override public long watch_channel(long funding_txo, long monitor) { + OutPoint funding_txo_hu_conv = new OutPoint(null, funding_txo); + ChannelMonitor monitor_hu_conv = new ChannelMonitor(null, monitor); + Result_NoneChannelMonitorUpdateErrZ ret = arg.watch_channel(funding_txo_hu_conv, monitor_hu_conv); + long result = ret != null ? ret.ptr : 0; + ret.ptr = 0; + return result; + } + @Override public long update_channel(long funding_txo, long update) { + OutPoint funding_txo_hu_conv = new OutPoint(null, funding_txo); + ChannelMonitorUpdate update_hu_conv = new ChannelMonitorUpdate(null, update); + Result_NoneChannelMonitorUpdateErrZ ret = arg.update_channel(funding_txo_hu_conv, update_hu_conv); + long result = ret != null ? ret.ptr : 0; + ret.ptr = 0; + return result; + } + @Override public long[] release_pending_monitor_events() { + MonitorEvent[] ret = arg.release_pending_monitor_events(); + long[] result = Arrays.stream(ret).mapToLong(arr_conv_14 -> arr_conv_14 == null ? 0 : arr_conv_14.ptr & ~1).toArray(); + /* TODO 2 MonitorEvent */ + return result; + } + }); + } // Skipped Watch_watch_channel public Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update) { long ret = bindings.Watch_update_channel(this.ptr, funding_txo == null ? 0 : funding_txo.ptr & ~1, update == null ? 0 : update.ptr & ~1); diff --git a/src/main/jni/bindings.c b/src/main/jni/bindings.c index 6f0b606a..f949d878 100644 --- a/src/main/jni/bindings.c +++ b/src/main/jni/bindings.c @@ -54,7 +54,13 @@ static void alloc_freed(void* ptr) { allocation* p = NULL; DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success); allocation* it = allocation_ll; - while (it->ptr != ptr) { p = it; it = it->next; } + while (it->ptr != ptr) { + p = it; it = it->next; + if (it == NULL) { + fprintf(stderr, "Tried to free unknown pointer %p!\n", ptr); + return; // addrsan should catch malloc-unknown and print more info than we have + } + } if (p) { p->next = it->next; } else { allocation_ll = it->next; } DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success); DO_ASSERT(it->ptr == ptr); @@ -145,12 +151,18 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data (JN LDKTransaction *txdata = (LDKTransaction*)MALLOC(sizeof(LDKTransaction), "LDKTransaction"); txdata->datalen = (*env)->GetArrayLength(env, bytes); txdata->data = (uint8_t*)MALLOC(txdata->datalen, "Tx Data Bytes"); - txdata->data_is_owned = true; + txdata->data_is_owned = false; (*env)->GetByteArrayRegion (env, bytes, 0, txdata->datalen, txdata->data); return (long)txdata; } +JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_txpointer_1free (JNIEnv * env, jclass _b, jlong ptr) { + LDKTransaction *tx = (LDKTransaction*)ptr; + tx->data_is_owned = true; + Transaction_free(*tx); + FREE((void*)ptr); +} JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) { - // Check offsets of a few Vec types are all consistent as we're meant to be generic across types + // Check offsets of a few Vec types are all consistent as we're meant to be generic across types _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically"); _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically"); _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically"); @@ -159,7 +171,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env return (long)vec->datalen; } JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec (JNIEnv * _env, jclass _b) { - // Check sizes of a few Vec types are all consistent as we're meant to be generic across types + // Check sizes of a few Vec types are all consistent as we're meant to be generic across types _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_SignatureZ), "Vec<*> needs to be mapped identically"); _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_MessageSendEventZ), "Vec<*> needs to be mapped identically"); _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_EventZ), "Vec<*> needs to be mapped identically"); @@ -444,7 +456,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1usize_1_1Tra LDKC2TupleTempl_usize__Transaction* ret = MALLOC(sizeof(LDKC2TupleTempl_usize__Transaction), "LDKC2TupleTempl_usize__Transaction"); ret->a = a; LDKTransaction b_conv = *(LDKTransaction*)b; - FREE((void*)b); ret->b = b_conv; return (long)ret; } @@ -1750,7 +1761,9 @@ LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment_j LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg; JNIEnv *_env; DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK); - long commitment_tx_ref = (long)&commitment_tx; + LDKTransaction *commitment_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); + *commitment_tx_copy = commitment_tx; + long commitment_tx_ref = (long)commitment_tx_copy; LDKCVec_HTLCOutputInCommitmentZ htlcs_var = htlcs; jlongArray htlcs_arr = (*_env)->NewLongArray(_env, htlcs_var.datalen); jlong *htlcs_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, htlcs_arr, NULL); @@ -1801,7 +1814,9 @@ LDKCResult_SignatureNoneZ sign_justice_transaction_jcall(const void* this_arg, L LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg; JNIEnv *_env; DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK); - long justice_tx_ref = (long)&justice_tx; + LDKTransaction *justice_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); + *justice_tx_copy = justice_tx; + long justice_tx_ref = (long)justice_tx_copy; jbyteArray per_commitment_key_arr = (*_env)->NewByteArray(_env, 32); (*_env)->SetByteArrayRegion(_env, per_commitment_key_arr, 0, 32, *per_commitment_key); jobject obj = (*_env)->NewLocalRef(_env, j_calls->o); @@ -1815,7 +1830,9 @@ LDKCResult_SignatureNoneZ sign_counterparty_htlc_transaction_jcall(const void* t LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg; JNIEnv *_env; DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK); - long htlc_tx_ref = (long)&htlc_tx; + LDKTransaction *htlc_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); + *htlc_tx_copy = htlc_tx; + long htlc_tx_ref = (long)htlc_tx_copy; jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33); (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, per_commitment_point.compressed_form); jobject obj = (*_env)->NewLocalRef(_env, j_calls->o); @@ -1829,7 +1846,9 @@ LDKCResult_SignatureNoneZ sign_closing_transaction_jcall(const void* this_arg, L LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg; JNIEnv *_env; DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK); - long closing_tx_ref = (long)&closing_tx; + LDKTransaction *closing_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); + *closing_tx_copy = closing_tx; + long closing_tx_ref = (long)closing_tx_copy; jobject obj = (*_env)->NewLocalRef(_env, j_calls->o); CHECK(obj != NULL); LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_closing_transaction_meth, closing_tx_ref); @@ -1952,7 +1971,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1key_1derivation_ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jint feerate_per_kw, jlong commitment_tx, jlong keys, jlongArray htlcs) { LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg; LDKTransaction commitment_tx_conv = *(LDKTransaction*)commitment_tx; - FREE((void*)commitment_tx); LDKPreCalculatedTxCreationKeys keys_conv; keys_conv.inner = (void*)(keys & (~1)); keys_conv.is_owned = (keys & 1) || (keys == 0); @@ -2001,7 +2019,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1co JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1justice_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong justice_tx, jlong input, jlong amount, jbyteArray per_commitment_key, jlong htlc) { LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg; LDKTransaction justice_tx_conv = *(LDKTransaction*)justice_tx; - FREE((void*)justice_tx); unsigned char per_commitment_key_arr[32]; CHECK((*_env)->GetArrayLength (_env, per_commitment_key) == 32); (*_env)->GetByteArrayRegion (_env, per_commitment_key, 0, 32, per_commitment_key_arr); @@ -2017,7 +2034,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1justice_1t JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1htlc_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong htlc_tx, jlong input, jlong amount, jbyteArray per_commitment_point, jlong htlc) { LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg; LDKTransaction htlc_tx_conv = *(LDKTransaction*)htlc_tx; - FREE((void*)htlc_tx); LDKPublicKey per_commitment_point_ref; CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33); (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form); @@ -2032,7 +2048,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterpar JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1closing_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong closing_tx) { LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg; LDKTransaction closing_tx_conv = *(LDKTransaction*)closing_tx; - FREE((void*)closing_tx); LDKCResult_SignatureNoneZ* ret = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ"); *ret = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_conv); return (long)ret; @@ -2390,7 +2405,9 @@ void broadcast_transaction_jcall(const void* this_arg, LDKTransaction tx) { LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg; JNIEnv *_env; DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK); - long tx_ref = (long)&tx; + LDKTransaction *tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); + *tx_copy = tx; + long tx_ref = (long)tx_copy; jobject obj = (*_env)->NewLocalRef(_env, j_calls->o); CHECK(obj != NULL); return (*_env)->CallVoidMethod(_env, obj, j_calls->broadcast_transaction_meth, tx_ref); @@ -2439,7 +2456,6 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1ge JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1broadcast_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong tx) { LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg; LDKTransaction tx_conv = *(LDKTransaction*)tx; - FREE((void*)tx); (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_conv); } @@ -2543,7 +2559,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Transaction_1ne for (size_t i = 0; i < ret->datalen; i++) { jlong arr_elem = java_elems[i]; LDKTransaction arr_elem_conv = *(LDKTransaction*)arr_elem; - FREE((void*)arr_elem); ret->data[i] = arr_elem_conv; } (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0); @@ -4903,7 +4918,6 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TransactionZ_1free(JNIEn for (size_t n = 0; n < arg_constr.datalen; n++) { long arr_conv_13 = arg_vals[n]; LDKTransaction arr_conv_13_conv = *(LDKTransaction*)arr_conv_13; - FREE((void*)arr_conv_13); arg_constr.data[n] = arr_conv_13_conv; } (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0); @@ -5030,7 +5044,6 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u8Z_1free(JNIEnv * _env, JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Transaction_1free(JNIEnv * _env, jclass _b, jlong _res) { LDKTransaction _res_conv = *(LDKTransaction*)_res; - FREE((void*)_res); Transaction_free(_res_conv); } @@ -5042,7 +5055,6 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxOut_1free(JNIEnv * _env, jcl JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1new(JNIEnv * _env, jclass _b, jlong a, jlong b) { LDKTransaction b_conv = *(LDKTransaction*)b; - FREE((void*)b); LDKC2Tuple_usizeTransactionZ* ret = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ"); *ret = C2Tuple_usizeTransactionZ_new(a, b_conv); return (long)ret; @@ -6020,7 +6032,9 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1lat jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen); jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL); for (size_t n = 0; n < ret_var.datalen; n++) { - long arr_conv_13_ref = (long)&ret_var.data[n]; + LDKTransaction *arr_conv_13_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); + *arr_conv_13_copy = ret_var.data[n]; + long arr_conv_13_ref = (long)arr_conv_13_copy; ret_arr_ptr[n] = arr_conv_13_ref; } (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0); @@ -11847,7 +11861,6 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1s this_ptr_conv.inner = (void*)(this_ptr & (~1)); this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0); LDKTransaction val_conv = *(LDKTransaction*)val; - FREE((void*)val); HolderCommitmentTransaction_set_unsigned_tx(&this_ptr_conv, val_conv); } @@ -11908,7 +11921,6 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1s JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1new_1missing_1holder_1sig(JNIEnv * _env, jclass _b, jlong unsigned_tx, jbyteArray counterparty_sig, jbyteArray holder_funding_key, jbyteArray counterparty_funding_key, jlong keys, jint feerate_per_kw, jlongArray htlc_data) { LDKTransaction unsigned_tx_conv = *(LDKTransaction*)unsigned_tx; - FREE((void*)unsigned_tx); LDKSignature counterparty_sig_ref; CHECK((*_env)->GetArrayLength (_env, counterparty_sig) == 64); (*_env)->GetByteArrayRegion (_env, counterparty_sig, 0, 64, counterparty_sig_ref.compact_form); diff --git a/src/main/jni/org_ldk_impl_bindings.h b/src/main/jni/org_ldk_impl_bindings.h index 8337a4ca..a371a5ca 100644 --- a/src/main/jni/org_ldk_impl_bindings.h +++ b/src/main/jni/org_ldk_impl_bindings.h @@ -71,6 +71,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data (JNIEnv *, jclass, jbyteArray); +/* + * Class: org_ldk_impl_bindings + * Method: txpointer_free + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_txpointer_1free + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: vec_slice_len diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index f3ba872f..a1a6f47b 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -7,67 +7,63 @@ import org.junit.jupiter.api.Test; import org.ldk.enums.LDKNetwork; import org.ldk.impl.bindings; import org.ldk.structs.*; +import org.ldk.util.TwoTuple; import java.lang.ref.WeakReference; import java.util.Arrays; import java.util.HashMap; +import java.util.LinkedList; import java.util.concurrent.ConcurrentLinkedQueue; public class HumanObjectPeerTest { class Peer { - final long logger; - final long fee_estimator; - final long tx_broadcaster; + final Logger logger; + final FeeEstimator fee_estimator; + final BroadcasterInterface tx_broadcaster; final KeysManager keys; final KeysInterface keys_interface; final ChannelManager chan_manager; final EventsProvider chan_manager_events; final NetGraphMsgHandler router; final PeerManager peer_manager; - HashMap monitors; // Wow I forgot just how terrible Java is - we can't put a byte array here. + final HashMap monitors; // Wow I forgot just how terrible Java is - we can't put a byte array here. byte[] node_id; + final LinkedList broadcast_set = new LinkedList<>(); Peer(byte seed) { - bindings.LDKLogger log_trait = (String arg) -> System.out.println(seed + ": " + arg); - logger = bindings.LDKLogger_new(log_trait); - this.fee_estimator = bindings.LDKFeeEstimator_new(confirmation_target -> 0); - this.tx_broadcaster = bindings.LDKBroadcasterInterface_new(tx -> { - // We should broadcast + logger = new Logger((String arg) -> System.out.println(seed + ": " + arg)); + fee_estimator = new FeeEstimator((confirmation_target -> 253)); + tx_broadcaster = new BroadcasterInterface(tx -> { + broadcast_set.add(tx); }); this.monitors = new HashMap<>(); - Watch chain_monitor = new Watch(new bindings.LDKWatch() { - @Override - public long watch_channel(long funding_txo, long monitor) { + Watch chain_monitor = new Watch(new Watch.WatchInterface() { + public Result_NoneChannelMonitorUpdateErrZ watch_channel(OutPoint funding_txo, ChannelMonitor monitor) { synchronized (monitors) { - assert monitors.put(Arrays.toString(bindings.OutPoint_get_txid(funding_txo)), monitor) == null; + assert monitors.put(Arrays.toString(funding_txo.get_txid()), monitor) == null; } - bindings.OutPoint_free(funding_txo); - return bindings.CResult_NoneChannelMonitorUpdateErrZ_ok(); + return new Result_NoneChannelMonitorUpdateErrZ.Result_NoneChannelMonitorUpdateErrZ_OK(); } - @Override - public long update_channel(long funding_txo, long update) { + public Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update) { synchronized (monitors) { - String txid = Arrays.toString(bindings.OutPoint_get_txid(funding_txo)); + String txid = Arrays.toString(funding_txo.get_txid()); assert monitors.containsKey(txid); - long update_res = bindings.ChannelMonitor_update_monitor(monitors.get(txid), update, tx_broadcaster, logger); - assert bindings.LDKCResult_NoneMonitorUpdateErrorZ_result_ok(update_res); - bindings.CResult_NoneMonitorUpdateErrorZ_free(update_res); + Result_NoneMonitorUpdateErrorZ update_res = monitors.get(txid).update_monitor(update, tx_broadcaster, logger); + assert update_res instanceof Result_NoneMonitorUpdateErrorZ.Result_NoneMonitorUpdateErrorZ_OK; } - bindings.OutPoint_free(funding_txo); - bindings.ChannelMonitorUpdate_free(update); - return bindings.CResult_NoneChannelMonitorUpdateErrZ_ok(); + return new Result_NoneChannelMonitorUpdateErrZ.Result_NoneChannelMonitorUpdateErrZ_OK(); } @Override - public long[] release_pending_monitor_events() { + public MonitorEvent[] release_pending_monitor_events() { synchronized (monitors) { assert monitors.size() <= 1; - for (Long mon : monitors.values()) { - return bindings.ChannelMonitor_get_and_clear_pending_monitor_events(mon); + for (ChannelMonitor mon : monitors.values()) { + return mon.get_and_clear_pending_monitor_events(); } } - return new long[0]; + return new MonitorEvent[0]; } }); @@ -77,49 +73,32 @@ public class HumanObjectPeerTest { } this.keys = KeysManager.constructor_new(key_seed, LDKNetwork.LDKNetwork_Bitcoin, System.currentTimeMillis() / 1000, (int) (System.currentTimeMillis() * 1000) & 0xffffffff); this.keys_interface = keys.as_KeysInterface(); - this.chan_manager = ChannelManager.constructor_new(LDKNetwork.LDKNetwork_Bitcoin, new FeeEstimator(confirmation_target -> 0), chain_monitor, - new BroadcasterInterface(tx -> { - }), new Logger(log_trait), keys.as_KeysInterface(), UserConfig.constructor_default(), 1); + this.chan_manager = ChannelManager.constructor_new(LDKNetwork.LDKNetwork_Bitcoin, new FeeEstimator(confirmation_target -> 0), chain_monitor, tx_broadcaster, logger, keys.as_KeysInterface(), UserConfig.constructor_default(), 1); this.node_id = chan_manager.get_our_node_id(); this.chan_manager_events = chan_manager.as_EventsProvider(); - this.router = NetGraphMsgHandler.constructor_new(null, new Logger(log_trait)); + this.router = NetGraphMsgHandler.constructor_new(null, logger); byte[] random_data = new byte[32]; for (byte i = 0; i < 32; i++) { random_data[i] = (byte) ((i ^ seed) ^ 0xf0); } - this.peer_manager = PeerManager.constructor_new(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, new Logger(log_trait)); + this.peer_manager = PeerManager.constructor_new(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger); System.gc(); } void connect_block(Block b, Transaction t, int height) { byte[] header = Arrays.copyOfRange(b.bitcoinSerialize(), 0, 80); - long[] txn; - if (t != null) - txn = new long[]{bindings.C2Tuple_usizeTransactionZ_new(1, bindings.new_txpointer_copy_data(t.bitcoinSerialize()))}; - else - txn = new long[0]; - bindings.ChannelManager_block_connected(chan_manager._test_only_get_ptr(), header, txn, height); - synchronized (monitors) { - for (Long mon : monitors.values()) { - if (t != null) - txn = new long[]{bindings.C2Tuple_usizeTransactionZ_new(1, bindings.new_txpointer_copy_data(t.bitcoinSerialize()))}; - else - txn = new long[0]; - long[] ret = bindings.ChannelMonitor_block_connected(mon, header, txn, height, tx_broadcaster, fee_estimator, logger); - for (long r : ret) bindings.C2Tuple_TxidCVec_TxOutZZ_free(r); - } - } - } - - void free() { - // Note that we can't rely on finalizer order, so don't bother trying to rely on it here - bindings.Logger_free(logger); - bindings.FeeEstimator_free(fee_estimator); - bindings.BroadcasterInterface_free(tx_broadcaster); + TwoTuple[] txn; + if (t != null) { + TwoTuple txp = new TwoTuple<>((long) 1, new org.ldk.structs.Transaction(t.bitcoinSerialize())); + txn = new TwoTuple[]{txp}; + } else + txn = new TwoTuple[0]; + chan_manager.block_connected(header, txn, height); synchronized (monitors) { - for (Long mon : monitors.values()) { - bindings.ChannelMonitor_free(mon); + for (ChannelMonitor mon : monitors.values()) { + TwoTuple[] ret = mon.block_connected(header, txn, height, tx_broadcaster, fee_estimator, logger); + assert ret.length == 0; } } } @@ -128,7 +107,7 @@ public class HumanObjectPeerTest { try (LockedNetworkGraph netgraph = this.router.read_locked_graph()) { NetworkGraph graph = netgraph.graph(); long res = bindings.get_route(this.node_id, graph._test_only_get_ptr(), dest_node, new long[] {our_chans[0]._test_only_get_ptr()}, - new long[0], 1000, 42, this.logger); + new long[0], 1000, 42, this.logger._test_only_get_ptr()); assert bindings.LDKCResult_RouteLightningErrorZ_result_ok(res); byte[] serialized_route = bindings.Route_write(bindings.LDKCResult_RouteLightningErrorZ_get_ok(res)); must_free_objs.add(new WeakReference<>(serialized_route)); @@ -293,14 +272,29 @@ public class HumanObjectPeerTest { while (!list.isEmpty()) { list.poll().join(); } peer1.peer_manager.process_events(); while (!list.isEmpty()) { list.poll().join(); } + peer2.peer_manager.process_events(); + while (!list.isEmpty()) { list.poll().join(); } events = peer1.chan_manager_events.get_and_clear_pending_events(); assert events.length == 1; assert events[0] instanceof Event.PaymentSent; assert Arrays.equals(((Event.PaymentSent) events[0]).payment_preimage, payment_preimage); - peer1.free(); - peer2.free(); + Result_NoneAPIErrorZ close_res = peer1.chan_manager.close_channel(peer1_chans[0].get_channel_id()); + assert close_res instanceof Result_NoneAPIErrorZ.Result_NoneAPIErrorZ_OK; + + peer1.peer_manager.process_events(); + while (!list.isEmpty()) { list.poll().join(); } + peer2.peer_manager.process_events(); + while (!list.isEmpty()) { list.poll().join(); } + peer1.peer_manager.process_events(); + while (!list.isEmpty()) { list.poll().join(); } + peer2.peer_manager.process_events(); + while (!list.isEmpty()) { list.poll().join(); } + + assert peer1.broadcast_set.size() == 1; + assert peer2.broadcast_set.size() == 1; + bindings.SocketDescriptor_free(descriptor2); bindings.SocketDescriptor_free(descriptor1.val); } @@ -315,4 +309,4 @@ public class HumanObjectPeerTest { for (WeakReference o : must_free_objs) assert o.get() == null; } -} \ No newline at end of file +} diff --git a/src/test/java/org/ldk/PeerTest.java b/src/test/java/org/ldk/PeerTest.java index 884a0830..74630786 100644 --- a/src/test/java/org/ldk/PeerTest.java +++ b/src/test/java/org/ldk/PeerTest.java @@ -102,18 +102,23 @@ public class PeerTest { void connect_block(Block b, Transaction t, int height) { byte[] header = Arrays.copyOfRange(b.bitcoinSerialize(), 0, 80); long[] txn; - if (t != null) - txn = new long[] {bindings.C2Tuple_usizeTransactionZ_new(1, bindings.new_txpointer_copy_data(t.bitcoinSerialize()))}; - else + long txdata = 0; + if (t != null) { + txdata = bindings.new_txpointer_copy_data(t.bitcoinSerialize()); + txn = new long[]{bindings.C2Tuple_usizeTransactionZ_new(1, txdata)}; + } else txn = new long[0]; bindings.ChannelManager_block_connected(chan_manager, header, txn, height); + if (txdata != 0) bindings.txpointer_free(txdata); synchronized (monitors) { for (Long mon : monitors.values()) { - if (t != null) - txn = new long[] {bindings.C2Tuple_usizeTransactionZ_new(1, bindings.new_txpointer_copy_data(t.bitcoinSerialize()))}; - else + if (t != null) { + txdata = bindings.new_txpointer_copy_data(t.bitcoinSerialize()); + txn = new long[]{bindings.C2Tuple_usizeTransactionZ_new(1, txdata)}; + } else txn = new long[0]; long[] ret = bindings.ChannelMonitor_block_connected(mon, header, txn, height, tx_broadcaster, fee_estimator, logger); + if (txdata != 0) bindings.txpointer_free(txdata); for (long r : ret) { bindings.C2Tuple_TxidCVec_TxOutZZ_free(r); }