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
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 + ");";
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,
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,
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
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 = ", ";"),
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 = ""
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"
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)
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))
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:
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:
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
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")
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"):
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")
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")
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")
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);
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();
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");
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");
out_java_struct.write("""package org.ldk.structs;
import java.util.LinkedList;
class CommonBase {
- final long ptr;
+ long ptr;
LinkedList<Object> ptrs_to = new LinkedList();
protected CommonBase(long ptr) { this.ptr = ptr; }
public long _test_only_get_ptr() { return this.ptr; }
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)
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":
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:
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")
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:
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)
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:
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)
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();
@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) {
}
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*/ }
}
}
@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) {
@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);
@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) {
@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
}
@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<Long, Transaction>[] 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<Long, Transaction> */;
}
@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) {
@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) {
@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) {
@Override @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();
- bindings.ChannelFeatures_free(ptr);
+ if (ptr != 0) { bindings.ChannelFeatures_free(ptr); }
}
}
@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) {
@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) {
@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() {
@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<Long, Long> 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<Long, Long> 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;
@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) {
}
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 */;
}
}
public void block_connected(byte[] header, TwoTuple<Long, Transaction>[] 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<Long, Transaction> */;
}
@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() {
@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) {
@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) {
}
public TwoTuple<byte[], TxOut[]>[] block_connected(byte[] header, TwoTuple<Long, Transaction>[] 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<byte[], TxOut[]>[] arr_conv_27_arr = new TwoTuple[ret.length];
for (int b = 0; b < ret.length; b++) {
long arr_conv_27 = ret[b];
@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) {
@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) {
@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) {
@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) {
@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) {
@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) {
@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) {
package org.ldk.structs;
import java.util.LinkedList;
class CommonBase {
- final long ptr;
+ long ptr;
LinkedList<Object> ptrs_to = new LinkedList();
protected CommonBase(long ptr) { this.ptr = ptr; }
public long _test_only_get_ptr() { return this.ptr; }
@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) {
@Override @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();
- bindings.DecodeError_free(ptr);
+ if (ptr != 0) { bindings.DecodeError_free(ptr); }
}
}
@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() {
@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) {
}
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*/ }
}
}
@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) {
@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) {
}
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;
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;
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;
}
this.outputs = arr_conv_27_arr;
}
- @Override long conv_to_c() { return 0; /*XXX*/ }
}
}
@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];
@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;
@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);
}
@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) {
@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) {
@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) {
@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) {
@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) {
}
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*/ }
}
}
@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) {
@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) {
@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) {
}
public void set_per_htlc(TwoTuple<HTLCOutputInCommitment, byte[]>[] 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<HTLCOutputInCommitment, byte[]> */;
}
@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) {
@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) {
@Override @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();
- bindings.InitFeatures_free(ptr);
+ if (ptr != 0) { bindings.InitFeatures_free(ptr); }
}
}
@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;
@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) {
@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() {
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() {
@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);
+ }
+ });
+ }
}
@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() {
@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) {
}
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
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*/ }
}
}
@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];
@Override @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();
- bindings.MonitorEvent_free(ptr);
+ if (ptr != 0) { bindings.MonitorEvent_free(ptr); }
}
}
@Override @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();
- bindings.MonitorUpdateError_free(ptr);
+ if (ptr != 0) { bindings.MonitorUpdateError_free(ptr); }
}
}
@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) {
}
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;
this.version = obj.version;
this.port = obj.port;
}
- @Override long conv_to_c() { return 0; /*XXX*/ }
}
}
@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) {
@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) {
@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) {
@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() {
}
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 */;
}
@Override @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();
- bindings.NodeFeatures_free(ptr);
+ if (ptr != 0) { bindings.NodeFeatures_free(ptr); }
}
}
@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) {
@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) {
@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) {
@Override @SuppressWarnings("deprecation")
protected void finalize() throws Throwable {
super.finalize();
- bindings.PaymentSendFailure_free(ptr);
+ if (ptr != 0) { bindings.PaymentSendFailure_free(ptr); }
}
}
@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() {
@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) {
@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) {
@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) {
@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) {
@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) {
@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) {
@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) {
@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) {
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) {
}
}
public static final class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK extends Result_C2Tuple_SignatureCVec_SignatureZZNoneZ {
- public TwoTuple<byte[], byte[][]> res;
+ public final TwoTuple<byte[], byte[][]> res;
private Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK(Object _dummy, long ptr) {
super(_dummy, ptr);
long res = bindings.LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_get_ok(ptr);
TwoTuple<byte[], byte[][]> res_conv = new TwoTuple<byte[], byte[][]>(res_a, res_b);
this.res = res_conv;
}
-
+ public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK(TwoTuple<byte[], byte[][]> 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());
+ }
}
}
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) {
}
}
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());
+ }
}
}
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) {
}
}
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);
+ }
}
}
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) {
}
}
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));
+ }
}
}
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) {
}
}
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));
+ }
}
}
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) {
}
}
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);
+ }
}
}
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) {
}
}
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);
+ }
}
}
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) {
}
}
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);
+ }
}
}
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) {
}
}
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));
+ }
}
}
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) {
}
}
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);
+ }
}
}
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) {
}
}
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));
+ }
}
}
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) {
}
}
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());
+ }
}
}
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) {
}
}
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));
+ }
}
}
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) {
}
}
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));
+ }
}
}
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) {
}
}
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);
+ }
}
}
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) {
}
}
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);
+ }
}
}
@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) {
@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) {
@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) {
@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) {
@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) {
@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<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] 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<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] 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<ChannelAnnouncement, ChannelUpdate, ChannelUpdate> */
+ 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);
@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) {
@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;
@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) {
}
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;
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<Long, Long> 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<Long, Long> key_derivation_params;
+ public final byte[] revocation_pubkey;
private DynamicOutputP2WSH(long ptr, bindings.LDKSpendableOutputDescriptor.DynamicOutputP2WSH obj) {
super(null, ptr);
long outpoint = obj.outpoint;
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<Long, Long> key_derivation_params;
+ public final OutPoint outpoint;
+ public final TxOut output;
+ public final TwoTuple<Long, Long> key_derivation_params;
private StaticOutputCounterpartyPayment(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutputCounterpartyPayment obj) {
super(null, ptr);
long outpoint = obj.outpoint;
TwoTuple<Long, Long> key_derivation_params_conv = new TwoTuple<Long, Long>(key_derivation_params_a, key_derivation_params_b);
this.key_derivation_params = key_derivation_params_conv;
}
- @Override long conv_to_c() { return 0; /*XXX*/ }
}
}
@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
@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) {
@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
@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) {
@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) {
@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) {
}
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 */;
}
@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) {
@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) {
@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) {
@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) {
@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) {
@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) {
@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);
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);
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");
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");
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;
}
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);
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);
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);
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);
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);
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);
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);
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;
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);
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);
}
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);
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);
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);
}
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;
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);
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);
}
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);
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
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<String, Long> monitors; // Wow I forgot just how terrible Java is - we can't put a byte array here.
+ final HashMap<String, ChannelMonitor> monitors; // Wow I forgot just how terrible Java is - we can't put a byte array here.
byte[] node_id;
+ final LinkedList<org.ldk.structs.Transaction> 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];
}
});
}
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<Long, org.ldk.structs.Transaction>[] txn;
+ if (t != null) {
+ TwoTuple<Long, org.ldk.structs.Transaction> 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<byte[], TxOut[]>[] ret = mon.block_connected(header, txn, height, tx_broadcaster, fee_estimator, logger);
+ assert ret.length == 0;
}
}
}
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));
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);
}
for (WeakReference<Object> o : must_free_objs)
assert o.get() == null;
}
-}
\ No newline at end of file
+}
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);
}