Update auto-generated bindings to 0.0.103
[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         public final static class ChannelUpdateMessage extends NetworkUpdate {
39                 /**
40                  * The update to apply via [`NetworkGraph::update_channel`].
41                 */
42                 public final ChannelUpdate msg;
43                 private ChannelUpdateMessage(long ptr, bindings.LDKNetworkUpdate.ChannelUpdateMessage obj) {
44                         super(null, ptr);
45                         long msg = obj.msg;
46                         ChannelUpdate msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new ChannelUpdate(null, msg); }
47                         msg_hu_conv.ptrs_to.add(this);
48                         this.msg = msg_hu_conv;
49                 }
50         }
51         public final static class ChannelClosed extends NetworkUpdate {
52                 /**
53                  * The short channel id of the closed channel.
54                 */
55                 public final long short_channel_id;
56                 /**
57                  * Whether the channel should be permanently removed or temporarily disabled until a new
58                  * `channel_update` message is received.
59                 */
60                 public final boolean is_permanent;
61                 private ChannelClosed(long ptr, bindings.LDKNetworkUpdate.ChannelClosed obj) {
62                         super(null, ptr);
63                         this.short_channel_id = obj.short_channel_id;
64                         this.is_permanent = obj.is_permanent;
65                 }
66         }
67         public final static class NodeFailure extends NetworkUpdate {
68                 /**
69                  * The node id of the failed node.
70                 */
71                 public final byte[] node_id;
72                 /**
73                  * Whether the node should be permanently removed from consideration or can be restored
74                  * when a new `channel_update` message is received.
75                 */
76                 public final boolean is_permanent;
77                 private NodeFailure(long ptr, bindings.LDKNetworkUpdate.NodeFailure obj) {
78                         super(null, ptr);
79                         this.node_id = obj.node_id;
80                         this.is_permanent = obj.is_permanent;
81                 }
82         }
83         /**
84          * Creates a copy of the NetworkUpdate
85          */
86         public NetworkUpdate clone() {
87                 long ret = bindings.NetworkUpdate_clone(this.ptr);
88                 if (ret >= 0 && ret <= 4096) { return null; }
89                 NetworkUpdate ret_hu_conv = NetworkUpdate.constr_from_ptr(ret);
90                 ret_hu_conv.ptrs_to.add(this);
91                 return ret_hu_conv;
92         }
93
94         /**
95          * Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
96          */
97         public static NetworkUpdate channel_update_message(ChannelUpdate msg) {
98                 long ret = bindings.NetworkUpdate_channel_update_message(msg == null ? 0 : msg.ptr & ~1);
99                 if (ret >= 0 && ret <= 4096) { return null; }
100                 NetworkUpdate ret_hu_conv = NetworkUpdate.constr_from_ptr(ret);
101                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
102                 return ret_hu_conv;
103         }
104
105         /**
106          * Utility method to constructs a new ChannelClosed-variant NetworkUpdate
107          */
108         public static NetworkUpdate channel_closed(long short_channel_id, boolean is_permanent) {
109                 long ret = bindings.NetworkUpdate_channel_closed(short_channel_id, is_permanent);
110                 if (ret >= 0 && ret <= 4096) { return null; }
111                 NetworkUpdate ret_hu_conv = NetworkUpdate.constr_from_ptr(ret);
112                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
113                 return ret_hu_conv;
114         }
115
116         /**
117          * Utility method to constructs a new NodeFailure-variant NetworkUpdate
118          */
119         public static NetworkUpdate node_failure(byte[] node_id, boolean is_permanent) {
120                 long ret = bindings.NetworkUpdate_node_failure(node_id, is_permanent);
121                 if (ret >= 0 && ret <= 4096) { return null; }
122                 NetworkUpdate ret_hu_conv = NetworkUpdate.constr_from_ptr(ret);
123                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
124                 return ret_hu_conv;
125         }
126
127         /**
128          * Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
129          */
130         public byte[] write() {
131                 byte[] ret = bindings.NetworkUpdate_write(this.ptr);
132                 return ret;
133         }
134
135 }