From: Matt Corallo Date: Wed, 21 Oct 2020 18:09:56 +0000 (-0400) Subject: Expose human functions that use Result objects X-Git-Tag: v0.0.1~96 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=f70bcf067b290c88dc9dc26f4aca86475e5f6ed7;p=ldk-java Expose human functions that use Result objects --- diff --git a/genbindings.py b/genbindings.py index f18b3b2e..b70b0e48 100755 --- a/genbindings.py +++ b/genbindings.py @@ -95,6 +95,7 @@ unitary_enums = set() complex_enums = set() opaque_structs = set() trait_structs = set() +result_types = set() tuple_types = {} var_is_arr_regex = re.compile("\(\*([A-za-z0-9_]*)\)\[([a-z0-9]*)\]") @@ -303,7 +304,7 @@ def java_c_types(fn_arg, ret_arr_len): take_by_ptr = True else: java_ty = "long" - java_hu_ty = ma.group(1).strip().replace("LDK", "") + java_hu_ty = ma.group(1).strip().replace("LDKCResult", "Result").replace("LDK", "") c_ty = "jlong" fn_ty_arg = "J" fn_arg = ma.group(2).strip() @@ -649,6 +650,13 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg arg_conv_name = "ret_conv", arg_conv_cleanup = None, ret_conv = ("jclass ret = " + ty_info.rust_obj + "_to_java(_env, ", ");"), ret_conv_name = "ret", to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None) + if ty_info.rust_obj in complex_enums or ty_info.rust_obj in result_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 = " + 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()", "")) 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 @@ -711,7 +719,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg arg_names = [] default_constructor_args = {} takes_self = False - args_known = not ret_info.passed_as_ptr or ret_info.rust_obj in opaque_structs or ret_info.rust_obj in trait_structs + args_known = not ret_info.passed_as_ptr or ret_info.rust_obj in opaque_structs or ret_info.rust_obj in trait_structs or ret_info.rust_obj in complex_enums or ret_info.rust_obj in result_types for idx, arg in enumerate(re_match.group(3).split(',')): if idx != 0: out_java.write(", ") @@ -1706,7 +1714,8 @@ class CommonBase { out_java.write("\tpublic static native " + ty_info.java_ty + " " + alias_match.group(2) + "_get_" + e + "(long ptr);\n") # XXX: Write C method! elif alias_match.group(1) in result_templ_structs: - human_ty = alias_match.group(2).replace("LDKCResult", "Result_").replace("__", "_").replace("Templ", "") + result_types.add(alias_match.group(2)) + human_ty = alias_match.group(2).replace("LDKCResult", "Result") with open(sys.argv[3] + "/structs/" + human_ty + ".java", "w") as out_java_struct: out_java_struct.write(hu_struct_file_prefix) out_java_struct.write("public class " + human_ty + " extends CommonBase {\n") @@ -1714,6 +1723,13 @@ class CommonBase { 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}\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_java_struct.write("\t\t\treturn new " + human_ty + "_OK(null, ptr);\n") + out_java_struct.write("\t\t} else {\n") + out_java_struct.write("\t\t\treturn new " + human_ty + "_Err(null, ptr);\n") + out_java_struct.write("\t\t}\n") + out_java_struct.write("\t}\n") contents_ty = alias_match.group(1).replace("LDKCResultTempl", "LDKCResultPtr") res_ty, err_ty = result_ptr_struct_items[contents_ty] diff --git a/src/main/java/org/ldk/structs/Access.java b/src/main/java/org/ldk/structs/Access.java index febbd35e..375dca92 100644 --- a/src/main/java/org/ldk/structs/Access.java +++ b/src/main/java/org/ldk/structs/Access.java @@ -17,5 +17,11 @@ public class Access extends CommonBase { bindings.Access_free(ptr); super.finalize(); } - // Skipped Access_get_utxo + 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); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; + } + } diff --git a/src/main/java/org/ldk/structs/ChannelKeys.java b/src/main/java/org/ldk/structs/ChannelKeys.java index 5b952032..9dfce22c 100644 --- a/src/main/java/org/ldk/structs/ChannelKeys.java +++ b/src/main/java/org/ldk/structs/ChannelKeys.java @@ -29,12 +29,33 @@ public class ChannelKeys extends CommonBase { // Skipped ChannelKeys_key_derivation_params // Skipped ChannelKeys_sign_counterparty_commitment - // Skipped ChannelKeys_sign_holder_commitment - // Skipped ChannelKeys_sign_holder_commitment_htlc_transactions + public Result_SignatureNoneZ sign_holder_commitment(HolderCommitmentTransaction holder_commitment_tx) { + long ret = bindings.ChannelKeys_sign_holder_commitment(this.ptr, holder_commitment_tx == null ? 0 : holder_commitment_tx.ptr & ~1); + Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(holder_commitment_tx); + return ret_hu_conv; + } + + public Result_CVec_SignatureZNoneZ sign_holder_commitment_htlc_transactions(HolderCommitmentTransaction holder_commitment_tx) { + long ret = bindings.ChannelKeys_sign_holder_commitment_htlc_transactions(this.ptr, holder_commitment_tx == null ? 0 : holder_commitment_tx.ptr & ~1); + Result_CVec_SignatureZNoneZ ret_hu_conv = Result_CVec_SignatureZNoneZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(holder_commitment_tx); + return ret_hu_conv; + } + // Skipped ChannelKeys_sign_justice_transaction // Skipped ChannelKeys_sign_counterparty_htlc_transaction // Skipped ChannelKeys_sign_closing_transaction - // Skipped ChannelKeys_sign_channel_announcement + public Result_SignatureNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg) { + long ret = bindings.ChannelKeys_sign_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1); + Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(msg); + return ret_hu_conv; + } + public void on_accept(ChannelPublicKeys channel_points, short counterparty_selected_contest_delay, short holder_selected_contest_delay) { bindings.ChannelKeys_on_accept(this.ptr, channel_points == null ? 0 : channel_points.ptr & ~1, counterparty_selected_contest_delay, holder_selected_contest_delay); this.ptrs_to.add(channel_points); diff --git a/src/main/java/org/ldk/structs/ChannelManager.java b/src/main/java/org/ldk/structs/ChannelManager.java index beadcad7..56198363 100644 --- a/src/main/java/org/ldk/structs/ChannelManager.java +++ b/src/main/java/org/ldk/structs/ChannelManager.java @@ -26,7 +26,14 @@ public class ChannelManager extends CommonBase { return ret_hu_conv; } - // Skipped ChannelManager_create_channel + public Result_NoneAPIErrorZ create_channel(byte[] their_network_key, long channel_value_satoshis, long push_msat, long user_id, UserConfig override_config) { + long ret = bindings.ChannelManager_create_channel(this.ptr, their_network_key, channel_value_satoshis, push_msat, user_id, override_config == null ? 0 : override_config.ptr & ~1); + Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(override_config); + return ret_hu_conv; + } + public ChannelDetails[] list_channels() { long[] ret = bindings.ChannelManager_list_channels(this.ptr); ChannelDetails[] arr_conv_16_arr = new ChannelDetails[ret.length]; @@ -49,7 +56,13 @@ public class ChannelManager extends CommonBase { return arr_conv_16_arr; } - // Skipped ChannelManager_close_channel + public Result_NoneAPIErrorZ close_channel(byte[] channel_id) { + long ret = bindings.ChannelManager_close_channel(this.ptr, channel_id); + Result_NoneAPIErrorZ ret_hu_conv = Result_NoneAPIErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; + } + public void force_close_channel(byte[] channel_id) { bindings.ChannelManager_force_close_channel(this.ptr, channel_id); } @@ -58,7 +71,14 @@ public class ChannelManager extends CommonBase { bindings.ChannelManager_force_close_all_channels(this.ptr); } - // Skipped ChannelManager_send_payment + public Result_NonePaymentSendFailureZ send_payment(Route route, byte[] payment_hash, byte[] payment_secret) { + long ret = bindings.ChannelManager_send_payment(this.ptr, route == null ? 0 : route.ptr & ~1, payment_hash, payment_secret); + Result_NonePaymentSendFailureZ ret_hu_conv = Result_NonePaymentSendFailureZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(route); + return ret_hu_conv; + } + public void funding_transaction_generated(byte[] temporary_channel_id, OutPoint funding_txo) { bindings.ChannelManager_funding_transaction_generated(this.ptr, temporary_channel_id, funding_txo == null ? 0 : funding_txo.ptr & ~1); this.ptrs_to.add(funding_txo); diff --git a/src/main/java/org/ldk/structs/ChannelMonitor.java b/src/main/java/org/ldk/structs/ChannelMonitor.java index ce25311f..1e95a1b5 100644 --- a/src/main/java/org/ldk/structs/ChannelMonitor.java +++ b/src/main/java/org/ldk/structs/ChannelMonitor.java @@ -14,7 +14,16 @@ public class ChannelMonitor extends CommonBase { bindings.ChannelMonitor_free(ptr); } - // Skipped ChannelMonitor_update_monitor + public Result_NoneMonitorUpdateErrorZ update_monitor(ChannelMonitorUpdate updates, BroadcasterInterface broadcaster, Logger logger) { + long ret = bindings.ChannelMonitor_update_monitor(this.ptr, updates == null ? 0 : updates.ptr & ~1, broadcaster == null ? 0 : broadcaster.ptr, logger == null ? 0 : logger.ptr); + Result_NoneMonitorUpdateErrorZ ret_hu_conv = Result_NoneMonitorUpdateErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(updates); + this.ptrs_to.add(broadcaster); + this.ptrs_to.add(logger); + return ret_hu_conv; + } + public long get_latest_update_id() { long ret = bindings.ChannelMonitor_get_latest_update_id(this.ptr); return ret; diff --git a/src/main/java/org/ldk/structs/HolderCommitmentTransaction.java b/src/main/java/org/ldk/structs/HolderCommitmentTransaction.java index 4dd599a5..5b26ba42 100644 --- a/src/main/java/org/ldk/structs/HolderCommitmentTransaction.java +++ b/src/main/java/org/ldk/structs/HolderCommitmentTransaction.java @@ -63,7 +63,13 @@ public class HolderCommitmentTransaction extends CommonBase { return ret; } - // Skipped HolderCommitmentTransaction_get_htlc_sigs + public Result_CVec_SignatureZNoneZ get_htlc_sigs(byte[] htlc_base_key, short counterparty_selected_contest_delay) { + long ret = bindings.HolderCommitmentTransaction_get_htlc_sigs(this.ptr, htlc_base_key, counterparty_selected_contest_delay); + Result_CVec_SignatureZNoneZ ret_hu_conv = Result_CVec_SignatureZNoneZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; + } + public byte[] write(HolderCommitmentTransaction obj) { byte[] ret = bindings.HolderCommitmentTransaction_write(obj == null ? 0 : obj.ptr & ~1); this.ptrs_to.add(obj); diff --git a/src/main/java/org/ldk/structs/LightningError.java b/src/main/java/org/ldk/structs/LightningError.java index be3d7593..b82c5711 100644 --- a/src/main/java/org/ldk/structs/LightningError.java +++ b/src/main/java/org/ldk/structs/LightningError.java @@ -23,7 +23,13 @@ public class LightningError extends CommonBase { bindings.LightningError_set_err(this.ptr, val); } - // Skipped LightningError_get_action + public ErrorAction get_action() { + long ret = bindings.LightningError_get_action(this.ptr); + ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; + } + // Skipped LightningError_set_action // Skipped LightningError_new } diff --git a/src/main/java/org/ldk/structs/PeerManager.java b/src/main/java/org/ldk/structs/PeerManager.java index 0a542cd3..93837b5e 100644 --- a/src/main/java/org/ldk/structs/PeerManager.java +++ b/src/main/java/org/ldk/structs/PeerManager.java @@ -28,10 +28,38 @@ public class PeerManager extends CommonBase { return ret; } - // Skipped PeerManager_new_outbound_connection - // Skipped PeerManager_new_inbound_connection - // Skipped PeerManager_write_buffer_space_avail - // Skipped PeerManager_read_event + public Result_CVec_u8ZPeerHandleErrorZ new_outbound_connection(byte[] their_node_id, SocketDescriptor descriptor) { + long ret = bindings.PeerManager_new_outbound_connection(this.ptr, their_node_id, descriptor == null ? 0 : descriptor.ptr); + Result_CVec_u8ZPeerHandleErrorZ ret_hu_conv = Result_CVec_u8ZPeerHandleErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(descriptor); + return ret_hu_conv; + } + + public Result_NonePeerHandleErrorZ new_inbound_connection(SocketDescriptor descriptor) { + long ret = bindings.PeerManager_new_inbound_connection(this.ptr, descriptor == null ? 0 : descriptor.ptr); + Result_NonePeerHandleErrorZ ret_hu_conv = Result_NonePeerHandleErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(descriptor); + return ret_hu_conv; + } + + public Result_NonePeerHandleErrorZ write_buffer_space_avail(SocketDescriptor descriptor) { + long ret = bindings.PeerManager_write_buffer_space_avail(this.ptr, descriptor == null ? 0 : descriptor.ptr); + Result_NonePeerHandleErrorZ ret_hu_conv = Result_NonePeerHandleErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(descriptor); + return ret_hu_conv; + } + + public Result_boolPeerHandleErrorZ read_event(SocketDescriptor peer_descriptor, byte[] data) { + long ret = bindings.PeerManager_read_event(this.ptr, peer_descriptor == null ? 0 : peer_descriptor.ptr, data); + Result_boolPeerHandleErrorZ ret_hu_conv = Result_boolPeerHandleErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(peer_descriptor); + return ret_hu_conv; + } + public void process_events() { bindings.PeerManager_process_events(this.ptr); } diff --git a/src/main/java/org/ldk/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.java b/src/main/java/org/ldk/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.java index 328451c4..8fbfa386 100644 --- a/src/main/java/org/ldk/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.java +++ b/src/main/java/org/ldk/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.java @@ -12,6 +12,13 @@ public class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ extends CommonBase { bindings.CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(ptr); super.finalize(); } + static Result_C2Tuple_SignatureCVec_SignatureZZNoneZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_result_ok(ptr)) { + return new Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK(null, ptr); + } else { + return new Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_Err(null, ptr); + } + } public static final class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK extends Result_C2Tuple_SignatureCVec_SignatureZZNoneZ { public TwoTuple res; private Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_CVec_SignatureZNoneZ.java b/src/main/java/org/ldk/structs/Result_CVec_SignatureZNoneZ.java index 3f9e4918..1d709cf1 100644 --- a/src/main/java/org/ldk/structs/Result_CVec_SignatureZNoneZ.java +++ b/src/main/java/org/ldk/structs/Result_CVec_SignatureZNoneZ.java @@ -12,6 +12,13 @@ public class Result_CVec_SignatureZNoneZ extends CommonBase { bindings.CResult_CVec_SignatureZNoneZ_free(ptr); super.finalize(); } + static Result_CVec_SignatureZNoneZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_CVec_SignatureZNoneZ_result_ok(ptr)) { + return new Result_CVec_SignatureZNoneZ_OK(null, ptr); + } else { + return new Result_CVec_SignatureZNoneZ_Err(null, ptr); + } + } public static final class Result_CVec_SignatureZNoneZ_OK extends Result_CVec_SignatureZNoneZ { public byte[][] res; private Result_CVec_SignatureZNoneZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_CVec_u8ZPeerHandleErrorZ.java b/src/main/java/org/ldk/structs/Result_CVec_u8ZPeerHandleErrorZ.java index e9df1bc4..490b7afc 100644 --- a/src/main/java/org/ldk/structs/Result_CVec_u8ZPeerHandleErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_CVec_u8ZPeerHandleErrorZ.java @@ -12,6 +12,13 @@ public class Result_CVec_u8ZPeerHandleErrorZ extends CommonBase { bindings.CResult_CVec_u8ZPeerHandleErrorZ_free(ptr); super.finalize(); } + static Result_CVec_u8ZPeerHandleErrorZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_CVec_u8ZPeerHandleErrorZ_result_ok(ptr)) { + return new Result_CVec_u8ZPeerHandleErrorZ_OK(null, ptr); + } else { + return new Result_CVec_u8ZPeerHandleErrorZ_Err(null, ptr); + } + } public static final class Result_CVec_u8ZPeerHandleErrorZ_OK extends Result_CVec_u8ZPeerHandleErrorZ { public byte[] res; private Result_CVec_u8ZPeerHandleErrorZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_NoneAPIErrorZ.java b/src/main/java/org/ldk/structs/Result_NoneAPIErrorZ.java index 21f66dd4..5935b647 100644 --- a/src/main/java/org/ldk/structs/Result_NoneAPIErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_NoneAPIErrorZ.java @@ -12,6 +12,13 @@ public class Result_NoneAPIErrorZ extends CommonBase { bindings.CResult_NoneAPIErrorZ_free(ptr); super.finalize(); } + static Result_NoneAPIErrorZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_NoneAPIErrorZ_result_ok(ptr)) { + return new Result_NoneAPIErrorZ_OK(null, ptr); + } else { + return new Result_NoneAPIErrorZ_Err(null, ptr); + } + } public static final class Result_NoneAPIErrorZ_OK extends Result_NoneAPIErrorZ { public byte res; private Result_NoneAPIErrorZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_NoneChannelMonitorUpdateErrZ.java b/src/main/java/org/ldk/structs/Result_NoneChannelMonitorUpdateErrZ.java index d1f26e93..3c18a0bf 100644 --- a/src/main/java/org/ldk/structs/Result_NoneChannelMonitorUpdateErrZ.java +++ b/src/main/java/org/ldk/structs/Result_NoneChannelMonitorUpdateErrZ.java @@ -12,6 +12,13 @@ public class Result_NoneChannelMonitorUpdateErrZ extends CommonBase { bindings.CResult_NoneChannelMonitorUpdateErrZ_free(ptr); super.finalize(); } + static Result_NoneChannelMonitorUpdateErrZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_NoneChannelMonitorUpdateErrZ_result_ok(ptr)) { + return new Result_NoneChannelMonitorUpdateErrZ_OK(null, ptr); + } else { + return new Result_NoneChannelMonitorUpdateErrZ_Err(null, ptr); + } + } public static final class Result_NoneChannelMonitorUpdateErrZ_OK extends Result_NoneChannelMonitorUpdateErrZ { public byte res; private Result_NoneChannelMonitorUpdateErrZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_NoneMonitorUpdateErrorZ.java b/src/main/java/org/ldk/structs/Result_NoneMonitorUpdateErrorZ.java index 2e063dc7..c071d7b0 100644 --- a/src/main/java/org/ldk/structs/Result_NoneMonitorUpdateErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_NoneMonitorUpdateErrorZ.java @@ -12,6 +12,13 @@ public class Result_NoneMonitorUpdateErrorZ extends CommonBase { bindings.CResult_NoneMonitorUpdateErrorZ_free(ptr); super.finalize(); } + static Result_NoneMonitorUpdateErrorZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_NoneMonitorUpdateErrorZ_result_ok(ptr)) { + return new Result_NoneMonitorUpdateErrorZ_OK(null, ptr); + } else { + return new Result_NoneMonitorUpdateErrorZ_Err(null, ptr); + } + } public static final class Result_NoneMonitorUpdateErrorZ_OK extends Result_NoneMonitorUpdateErrorZ { public byte res; private Result_NoneMonitorUpdateErrorZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_NonePaymentSendFailureZ.java b/src/main/java/org/ldk/structs/Result_NonePaymentSendFailureZ.java index 9b011510..b9496fd0 100644 --- a/src/main/java/org/ldk/structs/Result_NonePaymentSendFailureZ.java +++ b/src/main/java/org/ldk/structs/Result_NonePaymentSendFailureZ.java @@ -12,6 +12,13 @@ public class Result_NonePaymentSendFailureZ extends CommonBase { bindings.CResult_NonePaymentSendFailureZ_free(ptr); super.finalize(); } + static Result_NonePaymentSendFailureZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_NonePaymentSendFailureZ_result_ok(ptr)) { + return new Result_NonePaymentSendFailureZ_OK(null, ptr); + } else { + return new Result_NonePaymentSendFailureZ_Err(null, ptr); + } + } public static final class Result_NonePaymentSendFailureZ_OK extends Result_NonePaymentSendFailureZ { public byte res; private Result_NonePaymentSendFailureZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_NonePeerHandleErrorZ.java b/src/main/java/org/ldk/structs/Result_NonePeerHandleErrorZ.java index 6bbcd969..385e571b 100644 --- a/src/main/java/org/ldk/structs/Result_NonePeerHandleErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_NonePeerHandleErrorZ.java @@ -12,6 +12,13 @@ public class Result_NonePeerHandleErrorZ extends CommonBase { bindings.CResult_NonePeerHandleErrorZ_free(ptr); super.finalize(); } + static Result_NonePeerHandleErrorZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_NonePeerHandleErrorZ_result_ok(ptr)) { + return new Result_NonePeerHandleErrorZ_OK(null, ptr); + } else { + return new Result_NonePeerHandleErrorZ_Err(null, ptr); + } + } public static final class Result_NonePeerHandleErrorZ_OK extends Result_NonePeerHandleErrorZ { public byte res; private Result_NonePeerHandleErrorZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_PublicKeySecpErrorZ.java b/src/main/java/org/ldk/structs/Result_PublicKeySecpErrorZ.java index 39dd8247..0f0bcc31 100644 --- a/src/main/java/org/ldk/structs/Result_PublicKeySecpErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_PublicKeySecpErrorZ.java @@ -12,6 +12,13 @@ public class Result_PublicKeySecpErrorZ extends CommonBase { bindings.CResult_PublicKeySecpErrorZ_free(ptr); super.finalize(); } + static Result_PublicKeySecpErrorZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_PublicKeySecpErrorZ_result_ok(ptr)) { + return new Result_PublicKeySecpErrorZ_OK(null, ptr); + } else { + return new Result_PublicKeySecpErrorZ_Err(null, ptr); + } + } public static final class Result_PublicKeySecpErrorZ_OK extends Result_PublicKeySecpErrorZ { public byte[] res; private Result_PublicKeySecpErrorZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_RouteLightningErrorZ.java b/src/main/java/org/ldk/structs/Result_RouteLightningErrorZ.java index 865b4c9f..b4d43664 100644 --- a/src/main/java/org/ldk/structs/Result_RouteLightningErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_RouteLightningErrorZ.java @@ -12,6 +12,13 @@ public class Result_RouteLightningErrorZ extends CommonBase { bindings.CResult_RouteLightningErrorZ_free(ptr); super.finalize(); } + static Result_RouteLightningErrorZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_RouteLightningErrorZ_result_ok(ptr)) { + return new Result_RouteLightningErrorZ_OK(null, ptr); + } else { + return new Result_RouteLightningErrorZ_Err(null, ptr); + } + } public static final class Result_RouteLightningErrorZ_OK extends Result_RouteLightningErrorZ { public Route res; private Result_RouteLightningErrorZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_SecretKeySecpErrorZ.java b/src/main/java/org/ldk/structs/Result_SecretKeySecpErrorZ.java index 7df06e5d..04bb874a 100644 --- a/src/main/java/org/ldk/structs/Result_SecretKeySecpErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_SecretKeySecpErrorZ.java @@ -12,6 +12,13 @@ public class Result_SecretKeySecpErrorZ extends CommonBase { bindings.CResult_SecretKeySecpErrorZ_free(ptr); super.finalize(); } + static Result_SecretKeySecpErrorZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_SecretKeySecpErrorZ_result_ok(ptr)) { + return new Result_SecretKeySecpErrorZ_OK(null, ptr); + } else { + return new Result_SecretKeySecpErrorZ_Err(null, ptr); + } + } public static final class Result_SecretKeySecpErrorZ_OK extends Result_SecretKeySecpErrorZ { public byte[] res; private Result_SecretKeySecpErrorZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_SignatureNoneZ.java b/src/main/java/org/ldk/structs/Result_SignatureNoneZ.java index 18bf1690..877a9b30 100644 --- a/src/main/java/org/ldk/structs/Result_SignatureNoneZ.java +++ b/src/main/java/org/ldk/structs/Result_SignatureNoneZ.java @@ -12,6 +12,13 @@ public class Result_SignatureNoneZ extends CommonBase { bindings.CResult_SignatureNoneZ_free(ptr); super.finalize(); } + static Result_SignatureNoneZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_SignatureNoneZ_result_ok(ptr)) { + return new Result_SignatureNoneZ_OK(null, ptr); + } else { + return new Result_SignatureNoneZ_Err(null, ptr); + } + } public static final class Result_SignatureNoneZ_OK extends Result_SignatureNoneZ { public byte[] res; private Result_SignatureNoneZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_TxCreationKeysSecpErrorZ.java b/src/main/java/org/ldk/structs/Result_TxCreationKeysSecpErrorZ.java index f0f0a67a..dfe085cd 100644 --- a/src/main/java/org/ldk/structs/Result_TxCreationKeysSecpErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_TxCreationKeysSecpErrorZ.java @@ -12,6 +12,13 @@ public class Result_TxCreationKeysSecpErrorZ extends CommonBase { bindings.CResult_TxCreationKeysSecpErrorZ_free(ptr); super.finalize(); } + static Result_TxCreationKeysSecpErrorZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_TxCreationKeysSecpErrorZ_result_ok(ptr)) { + return new Result_TxCreationKeysSecpErrorZ_OK(null, ptr); + } else { + return new Result_TxCreationKeysSecpErrorZ_Err(null, ptr); + } + } public static final class Result_TxCreationKeysSecpErrorZ_OK extends Result_TxCreationKeysSecpErrorZ { public TxCreationKeys res; private Result_TxCreationKeysSecpErrorZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_TxOutAccessErrorZ.java b/src/main/java/org/ldk/structs/Result_TxOutAccessErrorZ.java index 3c2c3a2d..1c1f7e90 100644 --- a/src/main/java/org/ldk/structs/Result_TxOutAccessErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_TxOutAccessErrorZ.java @@ -12,6 +12,13 @@ public class Result_TxOutAccessErrorZ extends CommonBase { bindings.CResult_TxOutAccessErrorZ_free(ptr); super.finalize(); } + static Result_TxOutAccessErrorZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_TxOutAccessErrorZ_result_ok(ptr)) { + return new Result_TxOutAccessErrorZ_OK(null, ptr); + } else { + return new Result_TxOutAccessErrorZ_Err(null, ptr); + } + } public static final class Result_TxOutAccessErrorZ_OK extends Result_TxOutAccessErrorZ { public TxOut res; private Result_TxOutAccessErrorZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_boolLightningErrorZ.java b/src/main/java/org/ldk/structs/Result_boolLightningErrorZ.java index 67f766e4..bb9597f7 100644 --- a/src/main/java/org/ldk/structs/Result_boolLightningErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_boolLightningErrorZ.java @@ -12,6 +12,13 @@ public class Result_boolLightningErrorZ extends CommonBase { bindings.CResult_boolLightningErrorZ_free(ptr); super.finalize(); } + static Result_boolLightningErrorZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_boolLightningErrorZ_result_ok(ptr)) { + return new Result_boolLightningErrorZ_OK(null, ptr); + } else { + return new Result_boolLightningErrorZ_Err(null, ptr); + } + } public static final class Result_boolLightningErrorZ_OK extends Result_boolLightningErrorZ { public boolean res; private Result_boolLightningErrorZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/Result_boolPeerHandleErrorZ.java b/src/main/java/org/ldk/structs/Result_boolPeerHandleErrorZ.java index 1adf3491..ac33e40c 100644 --- a/src/main/java/org/ldk/structs/Result_boolPeerHandleErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_boolPeerHandleErrorZ.java @@ -12,6 +12,13 @@ public class Result_boolPeerHandleErrorZ extends CommonBase { bindings.CResult_boolPeerHandleErrorZ_free(ptr); super.finalize(); } + static Result_boolPeerHandleErrorZ constr_from_ptr(long ptr) { + if (bindings.LDKCResult_boolPeerHandleErrorZ_result_ok(ptr)) { + return new Result_boolPeerHandleErrorZ_OK(null, ptr); + } else { + return new Result_boolPeerHandleErrorZ_Err(null, ptr); + } + } public static final class Result_boolPeerHandleErrorZ_OK extends Result_boolPeerHandleErrorZ { public boolean res; private Result_boolPeerHandleErrorZ_OK(Object _dummy, long ptr) { diff --git a/src/main/java/org/ldk/structs/RoutingMessageHandler.java b/src/main/java/org/ldk/structs/RoutingMessageHandler.java index a4b61b97..e547b766 100644 --- a/src/main/java/org/ldk/structs/RoutingMessageHandler.java +++ b/src/main/java/org/ldk/structs/RoutingMessageHandler.java @@ -17,9 +17,30 @@ public class RoutingMessageHandler extends CommonBase { bindings.RoutingMessageHandler_free(ptr); super.finalize(); } - // Skipped RoutingMessageHandler_handle_node_announcement - // Skipped RoutingMessageHandler_handle_channel_announcement - // Skipped RoutingMessageHandler_handle_channel_update + 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); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(msg); + return ret_hu_conv; + } + + public Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg) { + long ret = bindings.RoutingMessageHandler_handle_channel_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1); + Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(msg); + return ret_hu_conv; + } + + public Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg) { + long ret = bindings.RoutingMessageHandler_handle_channel_update(this.ptr, msg == null ? 0 : msg.ptr & ~1); + Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(msg); + return ret_hu_conv; + } + // Skipped RoutingMessageHandler_handle_htlc_fail_channel_update public ThreeTuple[] get_next_channel_announcements(long starting_point, byte batch_amount) { long[] ret = bindings.RoutingMessageHandler_get_next_channel_announcements(this.ptr, starting_point, batch_amount); diff --git a/src/main/java/org/ldk/structs/TxCreationKeys.java b/src/main/java/org/ldk/structs/TxCreationKeys.java index cb025587..9cc92e5b 100644 --- a/src/main/java/org/ldk/structs/TxCreationKeys.java +++ b/src/main/java/org/ldk/structs/TxCreationKeys.java @@ -84,5 +84,11 @@ public class TxCreationKeys extends CommonBase { return ret_hu_conv; } - // Skipped TxCreationKeys_derive_new + public Result_TxCreationKeysSecpErrorZ derive_new(byte[] per_commitment_point, byte[] broadcaster_delayed_payment_base, byte[] broadcaster_htlc_base, byte[] countersignatory_revocation_base, byte[] countersignatory_htlc_base) { + long ret = bindings.TxCreationKeys_derive_new(per_commitment_point, broadcaster_delayed_payment_base, broadcaster_htlc_base, countersignatory_revocation_base, countersignatory_htlc_base); + Result_TxCreationKeysSecpErrorZ ret_hu_conv = Result_TxCreationKeysSecpErrorZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; + } + } diff --git a/src/main/java/org/ldk/structs/Watch.java b/src/main/java/org/ldk/structs/Watch.java index c237ed3e..7ed2211f 100644 --- a/src/main/java/org/ldk/structs/Watch.java +++ b/src/main/java/org/ldk/structs/Watch.java @@ -18,7 +18,15 @@ public class Watch extends CommonBase { } // Skipped Watch_watch_channel - // Skipped Watch_update_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); + Result_NoneChannelMonitorUpdateErrZ ret_hu_conv = Result_NoneChannelMonitorUpdateErrZ.constr_from_ptr(ret); + ret_hu_conv.ptrs_to.add(this); + this.ptrs_to.add(funding_txo); + this.ptrs_to.add(update); + return ret_hu_conv; + } + public MonitorEvent[] release_pending_monitor_events() { long[] ret = bindings.Watch_release_pending_monitor_events(this.ptr); MonitorEvent[] arr_conv_14_arr = new MonitorEvent[ret.length]; diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index 18e36c89..6f477d02 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -124,11 +124,15 @@ public class HumanObjectPeerTest { } } - long get_route(byte[] dest_node, ChannelDetails[] our_chans) { + Route get_route(byte[] dest_node, ChannelDetails[] our_chans) { try (LockedNetworkGraph netgraph = this.router.read_locked_graph()) { NetworkGraph graph = netgraph.graph(); - return bindings.get_route(this.node_id, graph._test_only_get_ptr(), dest_node, new long[] {our_chans[0]._test_only_get_ptr()}, + 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); + assert bindings.LDKCResult_RouteLightningErrorZ_result_ok(res); + Route copy = Route.constructor_read(bindings.Route_write(bindings.LDKCResult_RouteLightningErrorZ_get_ok(res))); + bindings.CResult_RouteLightningErrorZ_free(res); + return copy; } } } @@ -263,12 +267,9 @@ public class HumanObjectPeerTest { byte[] payment_preimage = new byte[32]; for (int i = 0; i < 32; i++) payment_preimage[i] = (byte) (i ^ 0x0f); byte[] payment_hash = Sha256Hash.hash(payment_preimage); - long route = peer1.get_route(peer2.node_id, peer1_chans); - assert bindings.LDKCResult_RouteLightningErrorZ_result_ok(route); - long payment_res = bindings.ChannelManager_send_payment(peer1.chan_manager._test_only_get_ptr(), bindings.LDKCResult_RouteLightningErrorZ_get_ok(route), payment_hash, new byte[32]); - bindings.CResult_RouteLightningErrorZ_free(route); - assert bindings.LDKCResult_NonePaymentSendFailureZ_result_ok(payment_res); - bindings.CResult_NonePaymentSendFailureZ_free(payment_res); + Route route = peer1.get_route(peer2.node_id, peer1_chans); + Result_NonePaymentSendFailureZ payment_res = peer1.chan_manager.send_payment(route, payment_hash, new byte[32]); + assert payment_res instanceof Result_NonePaymentSendFailureZ.Result_NonePaymentSendFailureZ_OK; peer1.peer_manager.process_events(); while (!list.isEmpty()) { list.poll().join(); }