[Java] 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 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/lightningnetwork/lightning-rfc/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.ChannelClosed.class) {
31                         return new ChannelClosed(ptr, (bindings.LDKNetworkUpdate.ChannelClosed)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                         ChannelUpdate msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ChannelUpdate(null, msg); }
52                         msg_hu_conv.ptrs_to.add(this);
53                         this.msg = msg_hu_conv;
54                 }
55         }
56         /**
57          * An error indicating only that a channel has been closed, which should be applied via
58          * [`NetworkGraph::close_channel_from_update`].
59          */
60         public final static class ChannelClosed 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 ChannelClosed(long ptr, bindings.LDKNetworkUpdate.ChannelClosed 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 only that a node has failed, which should be applied via
78          * [`NetworkGraph::fail_node`].
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                 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(ChannelUpdate msg) {
118                 long ret = bindings.NetworkUpdate_channel_update_message(msg == null ? 0 : msg.ptr & ~1);
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                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
123                 return ret_hu_conv;
124         }
125
126         /**
127          * Utility method to constructs a new ChannelClosed-variant NetworkUpdate
128          */
129         public static NetworkUpdate channel_closed(long short_channel_id, boolean is_permanent) {
130                 long ret = bindings.NetworkUpdate_channel_closed(short_channel_id, is_permanent);
131                 Reference.reachabilityFence(short_channel_id);
132                 Reference.reachabilityFence(is_permanent);
133                 if (ret >= 0 && ret <= 4096) { return null; }
134                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
135                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
136                 return ret_hu_conv;
137         }
138
139         /**
140          * Utility method to constructs a new NodeFailure-variant NetworkUpdate
141          */
142         public static NetworkUpdate node_failure(byte[] node_id, boolean is_permanent) {
143                 long ret = bindings.NetworkUpdate_node_failure(InternalUtils.check_arr_len(node_id, 33), is_permanent);
144                 Reference.reachabilityFence(node_id);
145                 Reference.reachabilityFence(is_permanent);
146                 if (ret >= 0 && ret <= 4096) { return null; }
147                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
148                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
149                 return ret_hu_conv;
150         }
151
152         /**
153          * Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
154          */
155         public byte[] write() {
156                 byte[] ret = bindings.NetworkUpdate_write(this.ptr);
157                 Reference.reachabilityFence(this);
158                 return ret;
159         }
160
161 }