Update auto-generated bindings
[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 javax.annotation.Nullable;
8
9
10 /**
11  * Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
12  * return packet by a node along the route. See [BOLT #4] for details.
13  * 
14  * [BOLT #4]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md
15  */
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class NetworkUpdate extends CommonBase {
18         private NetworkUpdate(Object _dummy, long ptr) { super(ptr); }
19         @Override @SuppressWarnings("deprecation")
20         protected void finalize() throws Throwable {
21                 super.finalize();
22                 if (ptr != 0) { bindings.NetworkUpdate_free(ptr); }
23         }
24         static NetworkUpdate constr_from_ptr(long ptr) {
25                 bindings.LDKNetworkUpdate raw_val = bindings.LDKNetworkUpdate_ref_from_ptr(ptr);
26                 if (raw_val.getClass() == bindings.LDKNetworkUpdate.ChannelUpdateMessage.class) {
27                         return new ChannelUpdateMessage(ptr, (bindings.LDKNetworkUpdate.ChannelUpdateMessage)raw_val);
28                 }
29                 if (raw_val.getClass() == bindings.LDKNetworkUpdate.ChannelClosed.class) {
30                         return new ChannelClosed(ptr, (bindings.LDKNetworkUpdate.ChannelClosed)raw_val);
31                 }
32                 if (raw_val.getClass() == bindings.LDKNetworkUpdate.NodeFailure.class) {
33                         return new NodeFailure(ptr, (bindings.LDKNetworkUpdate.NodeFailure)raw_val);
34                 }
35                 assert false; return null; // Unreachable without extending the (internal) bindings interface
36         }
37
38         /**
39          * An error indicating a `channel_update` messages should be applied via
40          * [`NetworkGraph::update_channel`].
41          */
42         public final static class ChannelUpdateMessage extends NetworkUpdate {
43                 /**
44                  * The update to apply via [`NetworkGraph::update_channel`].
45                 */
46                 public final ChannelUpdate msg;
47                 private ChannelUpdateMessage(long ptr, bindings.LDKNetworkUpdate.ChannelUpdateMessage obj) {
48                         super(null, ptr);
49                         long msg = obj.msg;
50                         ChannelUpdate msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ChannelUpdate(null, msg); }
51                         msg_hu_conv.ptrs_to.add(this);
52                         this.msg = msg_hu_conv;
53                 }
54         }
55         /**
56          * An error indicating only that a channel has been closed, which should be applied via
57          * [`NetworkGraph::close_channel_from_update`].
58          */
59         public final static class ChannelClosed extends NetworkUpdate {
60                 /**
61                  * The short channel id of the closed channel.
62                 */
63                 public final long short_channel_id;
64                 /**
65                  * Whether the channel should be permanently removed or temporarily disabled until a new
66                  * `channel_update` message is received.
67                 */
68                 public final boolean is_permanent;
69                 private ChannelClosed(long ptr, bindings.LDKNetworkUpdate.ChannelClosed obj) {
70                         super(null, ptr);
71                         this.short_channel_id = obj.short_channel_id;
72                         this.is_permanent = obj.is_permanent;
73                 }
74         }
75         /**
76          * An error indicating only that a node has failed, which should be applied via
77          * [`NetworkGraph::fail_node`].
78          */
79         public final static class NodeFailure extends NetworkUpdate {
80                 /**
81                  * The node id of the failed node.
82                 */
83                 public final byte[] node_id;
84                 /**
85                  * Whether the node should be permanently removed from consideration or can be restored
86                  * when a new `channel_update` message is received.
87                 */
88                 public final boolean is_permanent;
89                 private NodeFailure(long ptr, bindings.LDKNetworkUpdate.NodeFailure obj) {
90                         super(null, ptr);
91                         this.node_id = obj.node_id;
92                         this.is_permanent = obj.is_permanent;
93                 }
94         }
95         long clone_ptr() {
96                 long ret = bindings.NetworkUpdate_clone_ptr(this.ptr);
97                 return ret;
98         }
99
100         /**
101          * Creates a copy of the NetworkUpdate
102          */
103         public NetworkUpdate clone() {
104                 long ret = bindings.NetworkUpdate_clone(this.ptr);
105                 if (ret >= 0 && ret <= 4096) { return null; }
106                 NetworkUpdate ret_hu_conv = NetworkUpdate.constr_from_ptr(ret);
107                 ret_hu_conv.ptrs_to.add(this);
108                 return ret_hu_conv;
109         }
110
111         /**
112          * Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
113          */
114         public static NetworkUpdate channel_update_message(ChannelUpdate msg) {
115                 long ret = bindings.NetworkUpdate_channel_update_message(msg == null ? 0 : msg.ptr & ~1);
116                 if (ret >= 0 && ret <= 4096) { return null; }
117                 NetworkUpdate ret_hu_conv = NetworkUpdate.constr_from_ptr(ret);
118                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
119                 return ret_hu_conv;
120         }
121
122         /**
123          * Utility method to constructs a new ChannelClosed-variant NetworkUpdate
124          */
125         public static NetworkUpdate channel_closed(long short_channel_id, boolean is_permanent) {
126                 long ret = bindings.NetworkUpdate_channel_closed(short_channel_id, is_permanent);
127                 if (ret >= 0 && ret <= 4096) { return null; }
128                 NetworkUpdate ret_hu_conv = NetworkUpdate.constr_from_ptr(ret);
129                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
130                 return ret_hu_conv;
131         }
132
133         /**
134          * Utility method to constructs a new NodeFailure-variant NetworkUpdate
135          */
136         public static NetworkUpdate node_failure(byte[] node_id, boolean is_permanent) {
137                 long ret = bindings.NetworkUpdate_node_failure(InternalUtils.check_arr_len(node_id, 33), is_permanent);
138                 if (ret >= 0 && ret <= 4096) { return null; }
139                 NetworkUpdate ret_hu_conv = NetworkUpdate.constr_from_ptr(ret);
140                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
141                 return ret_hu_conv;
142         }
143
144         /**
145          * Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
146          */
147         public byte[] write() {
148                 byte[] ret = bindings.NetworkUpdate_write(this.ptr);
149                 return ret;
150         }
151
152 }