1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * The information we received from a peer along the route of a payment we originated. This is
12 * returned by ChannelMessageHandler::handle_update_fail_htlc to be passed into
13 * RoutingMessageHandler::handle_htlc_fail_channel_update to update our network map.
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class HTLCFailChannelUpdate extends CommonBase {
17 private HTLCFailChannelUpdate(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.HTLCFailChannelUpdate_free(ptr); }
23 static HTLCFailChannelUpdate constr_from_ptr(long ptr) {
24 bindings.LDKHTLCFailChannelUpdate raw_val = bindings.LDKHTLCFailChannelUpdate_ref_from_ptr(ptr);
25 if (raw_val.getClass() == bindings.LDKHTLCFailChannelUpdate.ChannelUpdateMessage.class) {
26 return new ChannelUpdateMessage(ptr, (bindings.LDKHTLCFailChannelUpdate.ChannelUpdateMessage)raw_val);
28 if (raw_val.getClass() == bindings.LDKHTLCFailChannelUpdate.ChannelClosed.class) {
29 return new ChannelClosed(ptr, (bindings.LDKHTLCFailChannelUpdate.ChannelClosed)raw_val);
31 if (raw_val.getClass() == bindings.LDKHTLCFailChannelUpdate.NodeFailure.class) {
32 return new NodeFailure(ptr, (bindings.LDKHTLCFailChannelUpdate.NodeFailure)raw_val);
34 assert false; return null; // Unreachable without extending the (internal) bindings interface
37 public final static class ChannelUpdateMessage extends HTLCFailChannelUpdate {
39 * The unwrapped message we received
41 public final ChannelUpdate msg;
42 private ChannelUpdateMessage(long ptr, bindings.LDKHTLCFailChannelUpdate.ChannelUpdateMessage obj) {
45 ChannelUpdate msg_hu_conv = new ChannelUpdate(null, msg);
46 msg_hu_conv.ptrs_to.add(this);
47 this.msg = msg_hu_conv;
50 public final static class ChannelClosed extends HTLCFailChannelUpdate {
52 * The short_channel_id which has now closed.
54 public final long short_channel_id;
56 * when this true, this channel should be permanently removed from the
57 * consideration. Otherwise, this channel can be restored as new channel_update is received
59 public final boolean is_permanent;
60 private ChannelClosed(long ptr, bindings.LDKHTLCFailChannelUpdate.ChannelClosed obj) {
62 this.short_channel_id = obj.short_channel_id;
63 this.is_permanent = obj.is_permanent;
66 public final static class NodeFailure extends HTLCFailChannelUpdate {
68 * The node_id that has failed.
70 public final byte[] node_id;
72 * when this true, node should be permanently removed from the
73 * consideration. Otherwise, the channels connected to this node can be
74 * restored as new channel_update is received
76 public final boolean is_permanent;
77 private NodeFailure(long ptr, bindings.LDKHTLCFailChannelUpdate.NodeFailure obj) {
79 this.node_id = obj.node_id;
80 this.is_permanent = obj.is_permanent;
84 * Creates a copy of the HTLCFailChannelUpdate
86 public HTLCFailChannelUpdate clone() {
87 long ret = bindings.HTLCFailChannelUpdate_clone(this.ptr);
88 if (ret < 1024) { return null; }
89 HTLCFailChannelUpdate ret_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(ret);
90 ret_hu_conv.ptrs_to.add(this);
95 * Utility method to constructs a new ChannelUpdateMessage-variant HTLCFailChannelUpdate
97 public static HTLCFailChannelUpdate channel_update_message(ChannelUpdate msg) {
98 long ret = bindings.HTLCFailChannelUpdate_channel_update_message(msg == null ? 0 : msg.ptr & ~1);
99 if (ret < 1024) { return null; }
100 HTLCFailChannelUpdate ret_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(ret);
101 ret_hu_conv.ptrs_to.add(ret_hu_conv);
102 ret_hu_conv.ptrs_to.add(msg);
107 * Utility method to constructs a new ChannelClosed-variant HTLCFailChannelUpdate
109 public static HTLCFailChannelUpdate channel_closed(long short_channel_id, boolean is_permanent) {
110 long ret = bindings.HTLCFailChannelUpdate_channel_closed(short_channel_id, is_permanent);
111 if (ret < 1024) { return null; }
112 HTLCFailChannelUpdate ret_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(ret);
113 ret_hu_conv.ptrs_to.add(ret_hu_conv);
118 * Utility method to constructs a new NodeFailure-variant HTLCFailChannelUpdate
120 public static HTLCFailChannelUpdate node_failure(byte[] node_id, boolean is_permanent) {
121 long ret = bindings.HTLCFailChannelUpdate_node_failure(node_id, is_permanent);
122 if (ret < 1024) { return null; }
123 HTLCFailChannelUpdate ret_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(ret);
124 ret_hu_conv.ptrs_to.add(ret_hu_conv);