[TS] Update auto-generated bindings to LDK-C-Bindings 0.0.123.1
[ldk-java] / c_sharp / src / org / ldk / structs / NetworkGraph.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 /**
10  * Represents the network as nodes and channels between them
11  */
12 public class NetworkGraph : CommonBase {
13         internal NetworkGraph(object _dummy, long ptr) : base(ptr) { }
14         ~NetworkGraph() {
15                 if (ptr != 0) { bindings.NetworkGraph_free(ptr); }
16         }
17
18         /**
19          * Handles any network updates originating from [`Event`]s.
20          * Note that this will skip applying any [`NetworkUpdate::ChannelUpdateMessage`] to avoid
21          * leaking possibly identifying information of the sender to the public network.
22          * 
23          * [`Event`]: crate::events::Event
24          */
25         public void handle_network_update(org.ldk.structs.NetworkUpdate network_update) {
26                 bindings.NetworkGraph_handle_network_update(this.ptr, network_update.ptr);
27                 GC.KeepAlive(this);
28                 GC.KeepAlive(network_update);
29         }
30
31         /**
32          * Gets the chain hash for this network graph.
33          */
34         public byte[] get_chain_hash() {
35                 long ret = bindings.NetworkGraph_get_chain_hash(this.ptr);
36                 GC.KeepAlive(this);
37                 if (ret >= 0 && ret <= 4096) { return null; }
38                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
39                 return ret_conv;
40         }
41
42         /**
43          * Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
44          */
45         public byte[] write() {
46                 long ret = bindings.NetworkGraph_write(this.ptr);
47                 GC.KeepAlive(this);
48                 if (ret >= 0 && ret <= 4096) { return null; }
49                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
50                 return ret_conv;
51         }
52
53         /**
54          * Read a NetworkGraph from a byte array, created by NetworkGraph_write
55          */
56         public static Result_NetworkGraphDecodeErrorZ read(byte[] ser, org.ldk.structs.Logger arg) {
57                 long ret = bindings.NetworkGraph_read(InternalUtils.encodeUint8Array(ser), arg.ptr);
58                 GC.KeepAlive(ser);
59                 GC.KeepAlive(arg);
60                 if (ret >= 0 && ret <= 4096) { return null; }
61                 Result_NetworkGraphDecodeErrorZ ret_hu_conv = Result_NetworkGraphDecodeErrorZ.constr_from_ptr(ret);
62                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(arg); };
63                 return ret_hu_conv;
64         }
65
66         /**
67          * Get the string representation of a NetworkGraph object
68          */
69         public string to_str() {
70                 long ret = bindings.NetworkGraph_to_str(this.ptr);
71                 GC.KeepAlive(this);
72                 if (ret >= 0 && ret <= 4096) { return null; }
73                 string ret_conv = InternalUtils.decodeString(ret);
74                 return ret_conv;
75         }
76
77         /**
78          * Creates a new, empty, network graph.
79          */
80         public static NetworkGraph of(Network network, org.ldk.structs.Logger logger) {
81                 long ret = bindings.NetworkGraph_new(network, logger.ptr);
82                 GC.KeepAlive(network);
83                 GC.KeepAlive(logger);
84                 if (ret >= 0 && ret <= 4096) { return null; }
85                 org.ldk.structs.NetworkGraph ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NetworkGraph(null, ret); }
86                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
87                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(logger); };
88                 return ret_hu_conv;
89         }
90
91         /**
92          * Returns a read-only view of the network graph.
93          */
94         public ReadOnlyNetworkGraph read_only() {
95                 long ret = bindings.NetworkGraph_read_only(this.ptr);
96                 GC.KeepAlive(this);
97                 if (ret >= 0 && ret <= 4096) { return null; }
98                 org.ldk.structs.ReadOnlyNetworkGraph ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ReadOnlyNetworkGraph(null, ret); }
99                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
100                 return ret_hu_conv;
101         }
102
103         /**
104          * The unix timestamp provided by the most recent rapid gossip sync.
105          * It will be set by the rapid sync process after every sync completion.
106          */
107         public Option_u32Z get_last_rapid_gossip_sync_timestamp() {
108                 long ret = bindings.NetworkGraph_get_last_rapid_gossip_sync_timestamp(this.ptr);
109                 GC.KeepAlive(this);
110                 if (ret >= 0 && ret <= 4096) { return null; }
111                 org.ldk.structs.Option_u32Z ret_hu_conv = org.ldk.structs.Option_u32Z.constr_from_ptr(ret);
112                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
113                 return ret_hu_conv;
114         }
115
116         /**
117          * Update the unix timestamp provided by the most recent rapid gossip sync.
118          * This should be done automatically by the rapid sync process after every sync completion.
119          */
120         public void set_last_rapid_gossip_sync_timestamp(int last_rapid_gossip_sync_timestamp) {
121                 bindings.NetworkGraph_set_last_rapid_gossip_sync_timestamp(this.ptr, last_rapid_gossip_sync_timestamp);
122                 GC.KeepAlive(this);
123                 GC.KeepAlive(last_rapid_gossip_sync_timestamp);
124         }
125
126         /**
127          * For an already known node (from channel announcements), update its stored properties from a
128          * given node announcement.
129          * 
130          * You probably don't want to call this directly, instead relying on a P2PGossipSync's
131          * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
132          * routing messages from a source using a protocol other than the lightning P2P protocol.
133          */
134         public Result_NoneLightningErrorZ update_node_from_announcement(org.ldk.structs.NodeAnnouncement msg) {
135                 long ret = bindings.NetworkGraph_update_node_from_announcement(this.ptr, msg.ptr);
136                 GC.KeepAlive(this);
137                 GC.KeepAlive(msg);
138                 if (ret >= 0 && ret <= 4096) { return null; }
139                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
140                 if (this != null) { this.ptrs_to.AddLast(msg); };
141                 return ret_hu_conv;
142         }
143
144         /**
145          * For an already known node (from channel announcements), update its stored properties from a
146          * given node announcement without verifying the associated signatures. Because we aren't
147          * given the associated signatures here we cannot relay the node announcement to any of our
148          * peers.
149          */
150         public Result_NoneLightningErrorZ update_node_from_unsigned_announcement(org.ldk.structs.UnsignedNodeAnnouncement msg) {
151                 long ret = bindings.NetworkGraph_update_node_from_unsigned_announcement(this.ptr, msg.ptr);
152                 GC.KeepAlive(this);
153                 GC.KeepAlive(msg);
154                 if (ret >= 0 && ret <= 4096) { return null; }
155                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
156                 if (this != null) { this.ptrs_to.AddLast(msg); };
157                 return ret_hu_conv;
158         }
159
160         /**
161          * Store or update channel info from a channel announcement.
162          * 
163          * You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
164          * [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
165          * routing messages from a source using a protocol other than the lightning P2P protocol.
166          * 
167          * If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
168          * the corresponding UTXO exists on chain and is correctly-formatted.
169          */
170         public Result_NoneLightningErrorZ update_channel_from_announcement(org.ldk.structs.ChannelAnnouncement msg, org.ldk.structs.Option_UtxoLookupZ utxo_lookup) {
171                 long ret = bindings.NetworkGraph_update_channel_from_announcement(this.ptr, msg.ptr, utxo_lookup.ptr);
172                 GC.KeepAlive(this);
173                 GC.KeepAlive(msg);
174                 GC.KeepAlive(utxo_lookup);
175                 if (ret >= 0 && ret <= 4096) { return null; }
176                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
177                 if (this != null) { this.ptrs_to.AddLast(msg); };
178                 if (this != null) { this.ptrs_to.AddLast(utxo_lookup); };
179                 return ret_hu_conv;
180         }
181
182         /**
183          * Store or update channel info from a channel announcement.
184          * 
185          * You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
186          * [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
187          * routing messages from a source using a protocol other than the lightning P2P protocol.
188          * 
189          * This will skip verification of if the channel is actually on-chain.
190          */
191         public Result_NoneLightningErrorZ update_channel_from_announcement_no_lookup(org.ldk.structs.ChannelAnnouncement msg) {
192                 long ret = bindings.NetworkGraph_update_channel_from_announcement_no_lookup(this.ptr, msg.ptr);
193                 GC.KeepAlive(this);
194                 GC.KeepAlive(msg);
195                 if (ret >= 0 && ret <= 4096) { return null; }
196                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
197                 if (this != null) { this.ptrs_to.AddLast(msg); };
198                 return ret_hu_conv;
199         }
200
201         /**
202          * Store or update channel info from a channel announcement without verifying the associated
203          * signatures. Because we aren't given the associated signatures here we cannot relay the
204          * channel announcement to any of our peers.
205          * 
206          * If a [`UtxoLookup`] object is provided via `utxo_lookup`, it will be called to verify
207          * the corresponding UTXO exists on chain and is correctly-formatted.
208          */
209         public Result_NoneLightningErrorZ update_channel_from_unsigned_announcement(org.ldk.structs.UnsignedChannelAnnouncement msg, org.ldk.structs.Option_UtxoLookupZ utxo_lookup) {
210                 long ret = bindings.NetworkGraph_update_channel_from_unsigned_announcement(this.ptr, msg.ptr, utxo_lookup.ptr);
211                 GC.KeepAlive(this);
212                 GC.KeepAlive(msg);
213                 GC.KeepAlive(utxo_lookup);
214                 if (ret >= 0 && ret <= 4096) { return null; }
215                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
216                 if (this != null) { this.ptrs_to.AddLast(msg); };
217                 if (this != null) { this.ptrs_to.AddLast(utxo_lookup); };
218                 return ret_hu_conv;
219         }
220
221         /**
222          * Update channel from partial announcement data received via rapid gossip sync
223          * 
224          * `timestamp: u64`: Timestamp emulating the backdated original announcement receipt (by the
225          * rapid gossip sync server)
226          * 
227          * All other parameters as used in [`msgs::UnsignedChannelAnnouncement`] fields.
228          */
229         public Result_NoneLightningErrorZ add_channel_from_partial_announcement(long short_channel_id, long timestamp, org.ldk.structs.ChannelFeatures features, byte[] node_id_1, byte[] node_id_2) {
230                 long ret = bindings.NetworkGraph_add_channel_from_partial_announcement(this.ptr, short_channel_id, timestamp, features.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(node_id_1, 33)), InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(node_id_2, 33)));
231                 GC.KeepAlive(this);
232                 GC.KeepAlive(short_channel_id);
233                 GC.KeepAlive(timestamp);
234                 GC.KeepAlive(features);
235                 GC.KeepAlive(node_id_1);
236                 GC.KeepAlive(node_id_2);
237                 if (ret >= 0 && ret <= 4096) { return null; }
238                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
239                 if (this != null) { this.ptrs_to.AddLast(features); };
240                 return ret_hu_conv;
241         }
242
243         /**
244          * Marks a channel in the graph as failed permanently.
245          * 
246          * The channel and any node for which this was their last channel are removed from the graph.
247          */
248         public void channel_failed_permanent(long short_channel_id) {
249                 bindings.NetworkGraph_channel_failed_permanent(this.ptr, short_channel_id);
250                 GC.KeepAlive(this);
251                 GC.KeepAlive(short_channel_id);
252         }
253
254         /**
255          * Marks a node in the graph as permanently failed, effectively removing it and its channels
256          * from local storage.
257          */
258         public void node_failed_permanent(byte[] node_id) {
259                 bindings.NetworkGraph_node_failed_permanent(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(node_id, 33)));
260                 GC.KeepAlive(this);
261                 GC.KeepAlive(node_id);
262         }
263
264         /**
265          * Removes information about channels that we haven't heard any updates about in some time.
266          * This can be used regularly to prune the network graph of channels that likely no longer
267          * exist.
268          * 
269          * While there is no formal requirement that nodes regularly re-broadcast their channel
270          * updates every two weeks, the non-normative section of BOLT 7 currently suggests that
271          * pruning occur for updates which are at least two weeks old, which we implement here.
272          * 
273          * Note that for users of the `lightning-background-processor` crate this method may be
274          * automatically called regularly for you.
275          * 
276          * This method will also cause us to stop tracking removed nodes and channels if they have been
277          * in the map for a while so that these can be resynced from gossip in the future.
278          * 
279          * This method is only available with the `std` feature. See
280          * [`NetworkGraph::remove_stale_channels_and_tracking_with_time`] for `no-std` use.
281          */
282         public void remove_stale_channels_and_tracking() {
283                 bindings.NetworkGraph_remove_stale_channels_and_tracking(this.ptr);
284                 GC.KeepAlive(this);
285         }
286
287         /**
288          * Removes information about channels that we haven't heard any updates about in some time.
289          * This can be used regularly to prune the network graph of channels that likely no longer
290          * exist.
291          * 
292          * While there is no formal requirement that nodes regularly re-broadcast their channel
293          * updates every two weeks, the non-normative section of BOLT 7 currently suggests that
294          * pruning occur for updates which are at least two weeks old, which we implement here.
295          * 
296          * This method will also cause us to stop tracking removed nodes and channels if they have been
297          * in the map for a while so that these can be resynced from gossip in the future.
298          * 
299          * This function takes the current unix time as an argument. For users with the `std` feature
300          * enabled, [`NetworkGraph::remove_stale_channels_and_tracking`] may be preferable.
301          */
302         public void remove_stale_channels_and_tracking_with_time(long current_time_unix) {
303                 bindings.NetworkGraph_remove_stale_channels_and_tracking_with_time(this.ptr, current_time_unix);
304                 GC.KeepAlive(this);
305                 GC.KeepAlive(current_time_unix);
306         }
307
308         /**
309          * For an already known (from announcement) channel, update info about one of the directions
310          * of the channel.
311          * 
312          * You probably don't want to call this directly, instead relying on a [`P2PGossipSync`]'s
313          * [`RoutingMessageHandler`] implementation to call it indirectly. This may be useful to accept
314          * routing messages from a source using a protocol other than the lightning P2P protocol.
315          * 
316          * If built with `no-std`, any updates with a timestamp more than two weeks in the past or
317          * materially in the future will be rejected.
318          */
319         public Result_NoneLightningErrorZ update_channel(org.ldk.structs.ChannelUpdate msg) {
320                 long ret = bindings.NetworkGraph_update_channel(this.ptr, msg.ptr);
321                 GC.KeepAlive(this);
322                 GC.KeepAlive(msg);
323                 if (ret >= 0 && ret <= 4096) { return null; }
324                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
325                 if (this != null) { this.ptrs_to.AddLast(msg); };
326                 return ret_hu_conv;
327         }
328
329         /**
330          * For an already known (from announcement) channel, update info about one of the directions
331          * of the channel without verifying the associated signatures. Because we aren't given the
332          * associated signatures here we cannot relay the channel update to any of our peers.
333          * 
334          * If built with `no-std`, any updates with a timestamp more than two weeks in the past or
335          * materially in the future will be rejected.
336          */
337         public Result_NoneLightningErrorZ update_channel_unsigned(org.ldk.structs.UnsignedChannelUpdate msg) {
338                 long ret = bindings.NetworkGraph_update_channel_unsigned(this.ptr, msg.ptr);
339                 GC.KeepAlive(this);
340                 GC.KeepAlive(msg);
341                 if (ret >= 0 && ret <= 4096) { return null; }
342                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
343                 if (this != null) { this.ptrs_to.AddLast(msg); };
344                 return ret_hu_conv;
345         }
346
347         /**
348          * For an already known (from announcement) channel, verify the given [`ChannelUpdate`].
349          * 
350          * This checks whether the update currently is applicable by [`Self::update_channel`].
351          * 
352          * If built with `no-std`, any updates with a timestamp more than two weeks in the past or
353          * materially in the future will be rejected.
354          */
355         public Result_NoneLightningErrorZ verify_channel_update(org.ldk.structs.ChannelUpdate msg) {
356                 long ret = bindings.NetworkGraph_verify_channel_update(this.ptr, msg.ptr);
357                 GC.KeepAlive(this);
358                 GC.KeepAlive(msg);
359                 if (ret >= 0 && ret <= 4096) { return null; }
360                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
361                 if (this != null) { this.ptrs_to.AddLast(msg); };
362                 return ret_hu_conv;
363         }
364
365 }
366 } } }