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 this.node_id = bindings.LDKNetworkUpdate_NodeFailure_get_node_id(ptr);
73 this.is_permanent = bindings.LDKNetworkUpdate_NodeFailure_get_is_permanent(ptr);
76 internal long clone_ptr() {
77 long ret = bindings.NetworkUpdate_clone_ptr(this.ptr);
83 * Creates a copy of the NetworkUpdate
85 public NetworkUpdate clone() {
86 long ret = bindings.NetworkUpdate_clone(this.ptr);
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); };
95 * Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
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);
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); };
108 * Utility method to constructs a new ChannelFailure-variant NetworkUpdate
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); };
121 * Utility method to constructs a new NodeFailure-variant NetworkUpdate
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); };
134 * Checks if two NetworkUpdates contain equal inner contents.
135 * This ignores pointers and is_owned flags and looks at the values in fields.
137 public bool eq(org.ldk.structs.NetworkUpdate b) {
138 bool ret = bindings.NetworkUpdate_eq(this.ptr, b == null ? 0 : b.ptr);
144 public override bool Equals(object o) {
145 if (!(o is NetworkUpdate)) return false;
146 return this.eq((NetworkUpdate)o);
149 * Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
151 public byte[] write() {
152 byte[] ret = bindings.NetworkUpdate_write(this.ptr);