[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / NetworkUpdate.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
10  * return packet by a node along the route. See [BOLT #4] for details.
11  * 
12  * [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
13  */
14 public class NetworkUpdate : CommonBase {
15         protected NetworkUpdate(object _dummy, long ptr) : base(ptr) { }
16         ~NetworkUpdate() {
17                 if (ptr != 0) { bindings.NetworkUpdate_free(ptr); }
18         }
19
20         internal static NetworkUpdate constr_from_ptr(long ptr) {
21                 long raw_ty = bindings.LDKNetworkUpdate_ty_from_ptr(ptr);
22                 switch (raw_ty) {
23                         case 0: return new NetworkUpdate_ChannelUpdateMessage(ptr);
24                         case 1: return new NetworkUpdate_ChannelFailure(ptr);
25                         case 2: return new NetworkUpdate_NodeFailure(ptr);
26                         default:
27                                 throw new ArgumentException("Impossible enum variant");
28                 }
29         }
30
31         /** A NetworkUpdate of type ChannelUpdateMessage */
32         public class NetworkUpdate_ChannelUpdateMessage : NetworkUpdate {
33                 /**
34                  * The update to apply via [`NetworkGraph::update_channel`].
35                  */
36                 public ChannelUpdate msg;
37                 internal NetworkUpdate_ChannelUpdateMessage(long ptr) : base(null, ptr) {
38                         long msg = bindings.LDKNetworkUpdate_ChannelUpdateMessage_get_msg(ptr);
39                         org.ldk.structs.ChannelUpdate msg_hu_conv = null; if (msg < 0 || msg > 4096) { msg_hu_conv = new org.ldk.structs.ChannelUpdate(null, msg); }
40                         if (msg_hu_conv != null) { msg_hu_conv.ptrs_to.AddLast(this); };
41                         this.msg = msg_hu_conv;
42                 }
43         }
44         /** A NetworkUpdate of type ChannelFailure */
45         public class NetworkUpdate_ChannelFailure : NetworkUpdate {
46                 /**
47                  * The short channel id of the closed channel.
48                  */
49                 public long short_channel_id;
50                 /**
51                  * Whether the channel should be permanently removed or temporarily disabled until a new
52                  * `channel_update` message is received.
53                  */
54                 public bool is_permanent;
55                 internal NetworkUpdate_ChannelFailure(long ptr) : base(null, ptr) {
56                         this.short_channel_id = bindings.LDKNetworkUpdate_ChannelFailure_get_short_channel_id(ptr);
57                         this.is_permanent = bindings.LDKNetworkUpdate_ChannelFailure_get_is_permanent(ptr);
58                 }
59         }
60         /** A NetworkUpdate of type NodeFailure */
61         public class NetworkUpdate_NodeFailure : NetworkUpdate {
62                 /**
63                  * The node id of the failed node.
64                  */
65                 public byte[] node_id;
66                 /**
67                  * Whether the node should be permanently removed from consideration or can be restored
68                  * when a new `channel_update` message is received.
69                  */
70                 public bool is_permanent;
71                 internal NetworkUpdate_NodeFailure(long ptr) : base(null, ptr) {
72                         long node_id = bindings.LDKNetworkUpdate_NodeFailure_get_node_id(ptr);
73                         byte[] node_id_conv = InternalUtils.decodeUint8Array(node_id);
74                         this.node_id = node_id_conv;
75                         this.is_permanent = bindings.LDKNetworkUpdate_NodeFailure_get_is_permanent(ptr);
76                 }
77         }
78         internal long clone_ptr() {
79                 long ret = bindings.NetworkUpdate_clone_ptr(this.ptr);
80                 GC.KeepAlive(this);
81                 return ret;
82         }
83
84         /**
85          * Creates a copy of the NetworkUpdate
86          */
87         public NetworkUpdate clone() {
88                 long ret = bindings.NetworkUpdate_clone(this.ptr);
89                 GC.KeepAlive(this);
90                 if (ret >= 0 && ret <= 4096) { return null; }
91                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
92                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
93                 return ret_hu_conv;
94         }
95
96         /**
97          * Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
98          */
99         public static NetworkUpdate channel_update_message(org.ldk.structs.ChannelUpdate msg) {
100                 long ret = bindings.NetworkUpdate_channel_update_message(msg == null ? 0 : msg.ptr);
101                 GC.KeepAlive(msg);
102                 if (ret >= 0 && ret <= 4096) { return null; }
103                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
104                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
105                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(msg); };
106                 return ret_hu_conv;
107         }
108
109         /**
110          * Utility method to constructs a new ChannelFailure-variant NetworkUpdate
111          */
112         public static NetworkUpdate channel_failure(long short_channel_id, bool is_permanent) {
113                 long ret = bindings.NetworkUpdate_channel_failure(short_channel_id, is_permanent);
114                 GC.KeepAlive(short_channel_id);
115                 GC.KeepAlive(is_permanent);
116                 if (ret >= 0 && ret <= 4096) { return null; }
117                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
118                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
119                 return ret_hu_conv;
120         }
121
122         /**
123          * Utility method to constructs a new NodeFailure-variant NetworkUpdate
124          */
125         public static NetworkUpdate node_failure(byte[] node_id, bool is_permanent) {
126                 long ret = bindings.NetworkUpdate_node_failure(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(node_id, 33)), is_permanent);
127                 GC.KeepAlive(node_id);
128                 GC.KeepAlive(is_permanent);
129                 if (ret >= 0 && ret <= 4096) { return null; }
130                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
131                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
132                 return ret_hu_conv;
133         }
134
135         /**
136          * Checks if two NetworkUpdates contain equal inner contents.
137          * This ignores pointers and is_owned flags and looks at the values in fields.
138          */
139         public bool eq(org.ldk.structs.NetworkUpdate b) {
140                 bool ret = bindings.NetworkUpdate_eq(this.ptr, b == null ? 0 : b.ptr);
141                 GC.KeepAlive(this);
142                 GC.KeepAlive(b);
143                 return ret;
144         }
145
146         public override bool Equals(object o) {
147                 if (!(o is NetworkUpdate)) return false;
148                 return this.eq((NetworkUpdate)o);
149         }
150         /**
151          * Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
152          */
153         public byte[] write() {
154                 long ret = bindings.NetworkUpdate_write(this.ptr);
155                 GC.KeepAlive(this);
156                 if (ret >= 0 && ret <= 4096) { return null; }
157                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
158                 return ret_conv;
159         }
160
161 }
162 } } }