Update CI references to 0.0.122
[ldk-java] / src / main / java / org / ldk / structs / NetworkUpdate.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
13  * return packet by a node along the route. See [BOLT #4] for details.
14  * 
15  * [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class NetworkUpdate extends CommonBase {
19         private NetworkUpdate(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.NetworkUpdate_free(ptr); }
24         }
25         static NetworkUpdate constr_from_ptr(long ptr) {
26                 bindings.LDKNetworkUpdate raw_val = bindings.LDKNetworkUpdate_ref_from_ptr(ptr);
27                 if (raw_val.getClass() == bindings.LDKNetworkUpdate.ChannelUpdateMessage.class) {
28                         return new ChannelUpdateMessage(ptr, (bindings.LDKNetworkUpdate.ChannelUpdateMessage)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKNetworkUpdate.ChannelFailure.class) {
31                         return new ChannelFailure(ptr, (bindings.LDKNetworkUpdate.ChannelFailure)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKNetworkUpdate.NodeFailure.class) {
34                         return new NodeFailure(ptr, (bindings.LDKNetworkUpdate.NodeFailure)raw_val);
35                 }
36                 assert false; return null; // Unreachable without extending the (internal) bindings interface
37         }
38
39         /**
40          * An error indicating a `channel_update` messages should be applied via
41          * [`NetworkGraph::update_channel`].
42          */
43         public final static class ChannelUpdateMessage extends NetworkUpdate {
44                 /**
45                  * The update to apply via [`NetworkGraph::update_channel`].
46                 */
47                 public final org.ldk.structs.ChannelUpdate msg;
48                 private ChannelUpdateMessage(long ptr, bindings.LDKNetworkUpdate.ChannelUpdateMessage obj) {
49                         super(null, ptr);
50                         long msg = obj.msg;
51                         org.ldk.structs.ChannelUpdate msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ChannelUpdate(null, msg); }
52                         if (msg_hu_conv != null) { msg_hu_conv.ptrs_to.add(this); };
53                         this.msg = msg_hu_conv;
54                 }
55         }
56         /**
57          * An error indicating that a channel failed to route a payment, which should be applied via
58          * [`NetworkGraph::channel_failed_permanent`] if permanent.
59          */
60         public final static class ChannelFailure extends NetworkUpdate {
61                 /**
62                  * The short channel id of the closed channel.
63                 */
64                 public final long short_channel_id;
65                 /**
66                  * Whether the channel should be permanently removed or temporarily disabled until a new
67                  * `channel_update` message is received.
68                 */
69                 public final boolean is_permanent;
70                 private ChannelFailure(long ptr, bindings.LDKNetworkUpdate.ChannelFailure obj) {
71                         super(null, ptr);
72                         this.short_channel_id = obj.short_channel_id;
73                         this.is_permanent = obj.is_permanent;
74                 }
75         }
76         /**
77          * An error indicating that a node failed to route a payment, which should be applied via
78          * [`NetworkGraph::node_failed_permanent`] if permanent.
79          */
80         public final static class NodeFailure extends NetworkUpdate {
81                 /**
82                  * The node id of the failed node.
83                 */
84                 public final byte[] node_id;
85                 /**
86                  * Whether the node should be permanently removed from consideration or can be restored
87                  * when a new `channel_update` message is received.
88                 */
89                 public final boolean is_permanent;
90                 private NodeFailure(long ptr, bindings.LDKNetworkUpdate.NodeFailure obj) {
91                         super(null, ptr);
92                         this.node_id = obj.node_id;
93                         this.is_permanent = obj.is_permanent;
94                 }
95         }
96         long clone_ptr() {
97                 long ret = bindings.NetworkUpdate_clone_ptr(this.ptr);
98                 Reference.reachabilityFence(this);
99                 return ret;
100         }
101
102         /**
103          * Creates a copy of the NetworkUpdate
104          */
105         public NetworkUpdate clone() {
106                 long ret = bindings.NetworkUpdate_clone(this.ptr);
107                 Reference.reachabilityFence(this);
108                 if (ret >= 0 && ret <= 4096) { return null; }
109                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
110                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
111                 return ret_hu_conv;
112         }
113
114         /**
115          * Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
116          */
117         public static NetworkUpdate channel_update_message(org.ldk.structs.ChannelUpdate msg) {
118                 long ret = bindings.NetworkUpdate_channel_update_message(msg == null ? 0 : msg.ptr);
119                 Reference.reachabilityFence(msg);
120                 if (ret >= 0 && ret <= 4096) { return null; }
121                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
122                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
123                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(msg); };
124                 return ret_hu_conv;
125         }
126
127         /**
128          * Utility method to constructs a new ChannelFailure-variant NetworkUpdate
129          */
130         public static NetworkUpdate channel_failure(long short_channel_id, boolean is_permanent) {
131                 long ret = bindings.NetworkUpdate_channel_failure(short_channel_id, is_permanent);
132                 Reference.reachabilityFence(short_channel_id);
133                 Reference.reachabilityFence(is_permanent);
134                 if (ret >= 0 && ret <= 4096) { return null; }
135                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
136                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
137                 return ret_hu_conv;
138         }
139
140         /**
141          * Utility method to constructs a new NodeFailure-variant NetworkUpdate
142          */
143         public static NetworkUpdate node_failure(byte[] node_id, boolean is_permanent) {
144                 long ret = bindings.NetworkUpdate_node_failure(InternalUtils.check_arr_len(node_id, 33), is_permanent);
145                 Reference.reachabilityFence(node_id);
146                 Reference.reachabilityFence(is_permanent);
147                 if (ret >= 0 && ret <= 4096) { return null; }
148                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
149                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
150                 return ret_hu_conv;
151         }
152
153         /**
154          * Checks if two NetworkUpdates contain equal inner contents.
155          * This ignores pointers and is_owned flags and looks at the values in fields.
156          */
157         public boolean eq(org.ldk.structs.NetworkUpdate b) {
158                 boolean ret = bindings.NetworkUpdate_eq(this.ptr, b == null ? 0 : b.ptr);
159                 Reference.reachabilityFence(this);
160                 Reference.reachabilityFence(b);
161                 return ret;
162         }
163
164         @Override public boolean equals(Object o) {
165                 if (!(o instanceof NetworkUpdate)) return false;
166                 return this.eq((NetworkUpdate)o);
167         }
168         /**
169          * Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
170          */
171         public byte[] write() {
172                 byte[] ret = bindings.NetworkUpdate_write(this.ptr);
173                 Reference.reachabilityFence(this);
174                 return ret;
175         }
176
177 }