[C#] Check in initial 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                         this.node_id = bindings.LDKNetworkUpdate_NodeFailure_get_node_id(ptr);
73                         this.is_permanent = bindings.LDKNetworkUpdate_NodeFailure_get_is_permanent(ptr);
74                 }
75         }
76         internal long clone_ptr() {
77                 long ret = bindings.NetworkUpdate_clone_ptr(this.ptr);
78                 GC.KeepAlive(this);
79                 return ret;
80         }
81
82         /**
83          * Creates a copy of the NetworkUpdate
84          */
85         public NetworkUpdate clone() {
86                 long ret = bindings.NetworkUpdate_clone(this.ptr);
87                 GC.KeepAlive(this);
88                 if (ret >= 0 && ret <= 4096) { return null; }
89                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
90                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(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(org.ldk.structs.ChannelUpdate msg) {
98                 long ret = bindings.NetworkUpdate_channel_update_message(msg == null ? 0 : msg.ptr);
99                 GC.KeepAlive(msg);
100                 if (ret >= 0 && ret <= 4096) { return null; }
101                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
102                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
103                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(msg); };
104                 return ret_hu_conv;
105         }
106
107         /**
108          * Utility method to constructs a new ChannelFailure-variant NetworkUpdate
109          */
110         public static NetworkUpdate channel_failure(long short_channel_id, bool is_permanent) {
111                 long ret = bindings.NetworkUpdate_channel_failure(short_channel_id, is_permanent);
112                 GC.KeepAlive(short_channel_id);
113                 GC.KeepAlive(is_permanent);
114                 if (ret >= 0 && ret <= 4096) { return null; }
115                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
116                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
117                 return ret_hu_conv;
118         }
119
120         /**
121          * Utility method to constructs a new NodeFailure-variant NetworkUpdate
122          */
123         public static NetworkUpdate node_failure(byte[] node_id, bool is_permanent) {
124                 long ret = bindings.NetworkUpdate_node_failure(InternalUtils.check_arr_len(node_id, 33), is_permanent);
125                 GC.KeepAlive(node_id);
126                 GC.KeepAlive(is_permanent);
127                 if (ret >= 0 && ret <= 4096) { return null; }
128                 org.ldk.structs.NetworkUpdate ret_hu_conv = org.ldk.structs.NetworkUpdate.constr_from_ptr(ret);
129                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
130                 return ret_hu_conv;
131         }
132
133         /**
134          * Checks if two NetworkUpdates contain equal inner contents.
135          * This ignores pointers and is_owned flags and looks at the values in fields.
136          */
137         public bool eq(org.ldk.structs.NetworkUpdate b) {
138                 bool ret = bindings.NetworkUpdate_eq(this.ptr, b == null ? 0 : b.ptr);
139                 GC.KeepAlive(this);
140                 GC.KeepAlive(b);
141                 return ret;
142         }
143
144         public override bool Equals(object o) {
145                 if (!(o is NetworkUpdate)) return false;
146                 return this.eq((NetworkUpdate)o);
147         }
148         /**
149          * Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
150          */
151         public byte[] write() {
152                 byte[] ret = bindings.NetworkUpdate_write(this.ptr);
153                 GC.KeepAlive(this);
154                 return ret;
155         }
156
157 }
158 } } }