6 namespace org { namespace ldk { namespace structs {
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.
12 * [BOLT #4]: https://github.com/lightning/bolts/blob/master/04-onion-routing.md
14 public class NetworkUpdate : CommonBase {
15 protected NetworkUpdate(object _dummy, long ptr) : base(ptr) { }
17 if (ptr != 0) { bindings.NetworkUpdate_free(ptr); }
20 internal static NetworkUpdate constr_from_ptr(long ptr) {
21 long raw_ty = bindings.LDKNetworkUpdate_ty_from_ptr(ptr);
23 case 0: return new NetworkUpdate_ChannelUpdateMessage(ptr);
24 case 1: return new NetworkUpdate_ChannelFailure(ptr);
25 case 2: return new NetworkUpdate_NodeFailure(ptr);
27 throw new ArgumentException("Impossible enum variant");
31 /** A NetworkUpdate of type ChannelUpdateMessage */
32 public class NetworkUpdate_ChannelUpdateMessage : NetworkUpdate {
34 * The update to apply via [`NetworkGraph::update_channel`].
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;
44 /** A NetworkUpdate of type ChannelFailure */
45 public class NetworkUpdate_ChannelFailure : NetworkUpdate {
47 * The short channel id of the closed channel.
49 public long short_channel_id;
51 * Whether the channel should be permanently removed or temporarily disabled until a new
52 * `channel_update` message is received.
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);
60 /** A NetworkUpdate of type NodeFailure */
61 public class NetworkUpdate_NodeFailure : NetworkUpdate {
63 * The node id of the failed node.
65 public byte[] node_id;
67 * Whether the node should be permanently removed from consideration or can be restored
68 * when a new `channel_update` message is received.
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);
78 internal long clone_ptr() {
79 long ret = bindings.NetworkUpdate_clone_ptr(this.ptr);
85 * Creates a copy of the NetworkUpdate
87 public NetworkUpdate clone() {
88 long ret = bindings.NetworkUpdate_clone(this.ptr);
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); };
97 * Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
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);
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); };
110 * Utility method to constructs a new ChannelFailure-variant NetworkUpdate
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); };
123 * Utility method to constructs a new NodeFailure-variant NetworkUpdate
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); };
136 * Checks if two NetworkUpdates contain equal inner contents.
137 * This ignores pointers and is_owned flags and looks at the values in fields.
139 public bool eq(org.ldk.structs.NetworkUpdate b) {
140 bool ret = bindings.NetworkUpdate_eq(this.ptr, b == null ? 0 : b.ptr);
146 public override bool Equals(object o) {
147 if (!(o is NetworkUpdate)) return false;
148 return this.eq((NetworkUpdate)o);
151 * Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
153 public byte[] write() {
154 long ret = bindings.NetworkUpdate_write(this.ptr);
156 if (ret >= 0 && ret <= 4096) { return null; }
157 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);