[Java] Update auto-generated Java bindings for 0.0.108
[ldk-java] / src / main / java / org / ldk / structs / NetworkGraph.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * Represents the network as nodes and channels between them
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class NetworkGraph extends CommonBase {
16         NetworkGraph(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.NetworkGraph_free(ptr); }
21         }
22
23         /**
24          * Constructs a new EventHandler which calls the relevant methods on this_arg.
25          * This copies the `inner` pointer in this_arg and thus the returned EventHandler must be freed before this_arg is
26          */
27         public EventHandler as_EventHandler() {
28                 long ret = bindings.NetworkGraph_as_EventHandler(this.ptr);
29                 Reference.reachabilityFence(this);
30                 if (ret >= 0 && ret <= 4096) { return null; }
31                 EventHandler ret_hu_conv = new EventHandler(null, ret);
32                 ret_hu_conv.ptrs_to.add(this);
33                 return ret_hu_conv;
34         }
35
36         /**
37          * Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
38          */
39         public byte[] write() {
40                 byte[] ret = bindings.NetworkGraph_write(this.ptr);
41                 Reference.reachabilityFence(this);
42                 return ret;
43         }
44
45         /**
46          * Read a NetworkGraph from a byte array, created by NetworkGraph_write
47          */
48         public static Result_NetworkGraphDecodeErrorZ read(byte[] ser, Logger arg) {
49                 long ret = bindings.NetworkGraph_read(ser, arg == null ? 0 : arg.ptr);
50                 Reference.reachabilityFence(ser);
51                 Reference.reachabilityFence(arg);
52                 if (ret >= 0 && ret <= 4096) { return null; }
53                 Result_NetworkGraphDecodeErrorZ ret_hu_conv = Result_NetworkGraphDecodeErrorZ.constr_from_ptr(ret);
54                 ret_hu_conv.ptrs_to.add(arg);
55                 return ret_hu_conv;
56         }
57
58         /**
59          * Creates a new, empty, network graph.
60          */
61         public static NetworkGraph of(byte[] genesis_hash, Logger logger) {
62                 long ret = bindings.NetworkGraph_new(InternalUtils.check_arr_len(genesis_hash, 32), logger == null ? 0 : logger.ptr);
63                 Reference.reachabilityFence(genesis_hash);
64                 Reference.reachabilityFence(logger);
65                 if (ret >= 0 && ret <= 4096) { return null; }
66                 org.ldk.structs.NetworkGraph ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NetworkGraph(null, ret); }
67                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
68                 ret_hu_conv.ptrs_to.add(logger);
69                 return ret_hu_conv;
70         }
71
72         /**
73          * Returns a read-only view of the network graph.
74          */
75         public ReadOnlyNetworkGraph read_only() {
76                 long ret = bindings.NetworkGraph_read_only(this.ptr);
77                 Reference.reachabilityFence(this);
78                 if (ret >= 0 && ret <= 4096) { return null; }
79                 org.ldk.structs.ReadOnlyNetworkGraph ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ReadOnlyNetworkGraph(null, ret); }
80                 ret_hu_conv.ptrs_to.add(this);
81                 return ret_hu_conv;
82         }
83
84         /**
85          * The unix timestamp provided by the most recent rapid gossip sync.
86          * It will be set by the rapid sync process after every sync completion.
87          */
88         public Option_u32Z get_last_rapid_gossip_sync_timestamp() {
89                 long ret = bindings.NetworkGraph_get_last_rapid_gossip_sync_timestamp(this.ptr);
90                 Reference.reachabilityFence(this);
91                 if (ret >= 0 && ret <= 4096) { return null; }
92                 org.ldk.structs.Option_u32Z ret_hu_conv = org.ldk.structs.Option_u32Z.constr_from_ptr(ret);
93                 ret_hu_conv.ptrs_to.add(this);
94                 return ret_hu_conv;
95         }
96
97         /**
98          * Update the unix timestamp provided by the most recent rapid gossip sync.
99          * This should be done automatically by the rapid sync process after every sync completion.
100          */
101         public void set_last_rapid_gossip_sync_timestamp(int last_rapid_gossip_sync_timestamp) {
102                 bindings.NetworkGraph_set_last_rapid_gossip_sync_timestamp(this.ptr, last_rapid_gossip_sync_timestamp);
103                 Reference.reachabilityFence(this);
104                 Reference.reachabilityFence(last_rapid_gossip_sync_timestamp);
105         }
106
107         /**
108          * For an already known node (from channel announcements), update its stored properties from a
109          * given node announcement.
110          * 
111          * You probably don't want to call this directly, instead relying on a P2PGossipSync's
112          * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
113          * routing messages from a source using a protocol other than the lightning P2P protocol.
114          */
115         public Result_NoneLightningErrorZ update_node_from_announcement(NodeAnnouncement msg) {
116                 long ret = bindings.NetworkGraph_update_node_from_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
117                 Reference.reachabilityFence(this);
118                 Reference.reachabilityFence(msg);
119                 if (ret >= 0 && ret <= 4096) { return null; }
120                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
121                 this.ptrs_to.add(msg);
122                 return ret_hu_conv;
123         }
124
125         /**
126          * For an already known node (from channel announcements), update its stored properties from a
127          * given node announcement without verifying the associated signatures. Because we aren't
128          * given the associated signatures here we cannot relay the node announcement to any of our
129          * peers.
130          */
131         public Result_NoneLightningErrorZ update_node_from_unsigned_announcement(UnsignedNodeAnnouncement msg) {
132                 long ret = bindings.NetworkGraph_update_node_from_unsigned_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
133                 Reference.reachabilityFence(this);
134                 Reference.reachabilityFence(msg);
135                 if (ret >= 0 && ret <= 4096) { return null; }
136                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
137                 this.ptrs_to.add(msg);
138                 return ret_hu_conv;
139         }
140
141         /**
142          * Store or update channel info from a channel announcement.
143          * 
144          * You probably don't want to call this directly, instead relying on a P2PGossipSync's
145          * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
146          * routing messages from a source using a protocol other than the lightning P2P protocol.
147          * 
148          * If a `chain::Access` object is provided via `chain_access`, it will be called to verify
149          * the corresponding UTXO exists on chain and is correctly-formatted.
150          */
151         public Result_NoneLightningErrorZ update_channel_from_announcement(ChannelAnnouncement msg, Option_AccessZ chain_access) {
152                 long ret = bindings.NetworkGraph_update_channel_from_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1, chain_access.ptr);
153                 Reference.reachabilityFence(this);
154                 Reference.reachabilityFence(msg);
155                 Reference.reachabilityFence(chain_access);
156                 if (ret >= 0 && ret <= 4096) { return null; }
157                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
158                 this.ptrs_to.add(msg);
159                 this.ptrs_to.add(chain_access);
160                 return ret_hu_conv;
161         }
162
163         /**
164          * Store or update channel info from a channel announcement without verifying the associated
165          * signatures. Because we aren't given the associated signatures here we cannot relay the
166          * channel announcement to any of our peers.
167          * 
168          * If a `chain::Access` object is provided via `chain_access`, it will be called to verify
169          * the corresponding UTXO exists on chain and is correctly-formatted.
170          */
171         public Result_NoneLightningErrorZ update_channel_from_unsigned_announcement(UnsignedChannelAnnouncement msg, Option_AccessZ chain_access) {
172                 long ret = bindings.NetworkGraph_update_channel_from_unsigned_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1, chain_access.ptr);
173                 Reference.reachabilityFence(this);
174                 Reference.reachabilityFence(msg);
175                 Reference.reachabilityFence(chain_access);
176                 if (ret >= 0 && ret <= 4096) { return null; }
177                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
178                 this.ptrs_to.add(msg);
179                 this.ptrs_to.add(chain_access);
180                 return ret_hu_conv;
181         }
182
183         /**
184          * Update channel from partial announcement data received via rapid gossip sync
185          * 
186          * `timestamp: u64`: Timestamp emulating the backdated original announcement receipt (by the
187          * rapid gossip sync server)
188          * 
189          * All other parameters as used in [`msgs::UnsignedChannelAnnouncement`] fields.
190          */
191         public Result_NoneLightningErrorZ add_channel_from_partial_announcement(long short_channel_id, long timestamp, ChannelFeatures features, byte[] node_id_1, byte[] node_id_2) {
192                 long ret = bindings.NetworkGraph_add_channel_from_partial_announcement(this.ptr, short_channel_id, timestamp, features == null ? 0 : features.ptr & ~1, InternalUtils.check_arr_len(node_id_1, 33), InternalUtils.check_arr_len(node_id_2, 33));
193                 Reference.reachabilityFence(this);
194                 Reference.reachabilityFence(short_channel_id);
195                 Reference.reachabilityFence(timestamp);
196                 Reference.reachabilityFence(features);
197                 Reference.reachabilityFence(node_id_1);
198                 Reference.reachabilityFence(node_id_2);
199                 if (ret >= 0 && ret <= 4096) { return null; }
200                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
201                 return ret_hu_conv;
202         }
203
204         /**
205          * Marks a channel in the graph as failed if a corresponding HTLC fail was sent.
206          * If permanent, removes a channel from the local storage.
207          * May cause the removal of nodes too, if this was their last channel.
208          * If not permanent, makes channels unavailable for routing.
209          */
210         public void channel_failed(long short_channel_id, boolean is_permanent) {
211                 bindings.NetworkGraph_channel_failed(this.ptr, short_channel_id, is_permanent);
212                 Reference.reachabilityFence(this);
213                 Reference.reachabilityFence(short_channel_id);
214                 Reference.reachabilityFence(is_permanent);
215         }
216
217         /**
218          * Marks a node in the graph as failed.
219          */
220         public void node_failed(byte[] _node_id, boolean is_permanent) {
221                 bindings.NetworkGraph_node_failed(this.ptr, InternalUtils.check_arr_len(_node_id, 33), is_permanent);
222                 Reference.reachabilityFence(this);
223                 Reference.reachabilityFence(_node_id);
224                 Reference.reachabilityFence(is_permanent);
225         }
226
227         /**
228          * Removes information about channels that we haven't heard any updates about in some time.
229          * This can be used regularly to prune the network graph of channels that likely no longer
230          * exist.
231          * 
232          * While there is no formal requirement that nodes regularly re-broadcast their channel
233          * updates every two weeks, the non-normative section of BOLT 7 currently suggests that
234          * pruning occur for updates which are at least two weeks old, which we implement here.
235          * 
236          * Note that for users of the `lightning-background-processor` crate this method may be
237          * automatically called regularly for you.
238          * 
239          * This method is only available with the `std` feature. See
240          * [`NetworkGraph::remove_stale_channels_with_time`] for `no-std` use.
241          */
242         public void remove_stale_channels() {
243                 bindings.NetworkGraph_remove_stale_channels(this.ptr);
244                 Reference.reachabilityFence(this);
245         }
246
247         /**
248          * Removes information about channels that we haven't heard any updates about in some time.
249          * This can be used regularly to prune the network graph of channels that likely no longer
250          * exist.
251          * 
252          * While there is no formal requirement that nodes regularly re-broadcast their channel
253          * updates every two weeks, the non-normative section of BOLT 7 currently suggests that
254          * pruning occur for updates which are at least two weeks old, which we implement here.
255          * 
256          * This function takes the current unix time as an argument. For users with the `std` feature
257          * enabled, [`NetworkGraph::remove_stale_channels`] may be preferable.
258          */
259         public void remove_stale_channels_with_time(long current_time_unix) {
260                 bindings.NetworkGraph_remove_stale_channels_with_time(this.ptr, current_time_unix);
261                 Reference.reachabilityFence(this);
262                 Reference.reachabilityFence(current_time_unix);
263         }
264
265         /**
266          * For an already known (from announcement) channel, update info about one of the directions
267          * of the channel.
268          * 
269          * You probably don't want to call this directly, instead relying on a P2PGossipSync's
270          * RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
271          * routing messages from a source using a protocol other than the lightning P2P protocol.
272          * 
273          * If built with `no-std`, any updates with a timestamp more than two weeks in the past or
274          * materially in the future will be rejected.
275          */
276         public Result_NoneLightningErrorZ update_channel(ChannelUpdate msg) {
277                 long ret = bindings.NetworkGraph_update_channel(this.ptr, msg == null ? 0 : msg.ptr & ~1);
278                 Reference.reachabilityFence(this);
279                 Reference.reachabilityFence(msg);
280                 if (ret >= 0 && ret <= 4096) { return null; }
281                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
282                 this.ptrs_to.add(msg);
283                 return ret_hu_conv;
284         }
285
286         /**
287          * For an already known (from announcement) channel, update info about one of the directions
288          * of the channel without verifying the associated signatures. Because we aren't given the
289          * associated signatures here we cannot relay the channel update to any of our peers.
290          * 
291          * If built with `no-std`, any updates with a timestamp more than two weeks in the past or
292          * materially in the future will be rejected.
293          */
294         public Result_NoneLightningErrorZ update_channel_unsigned(UnsignedChannelUpdate msg) {
295                 long ret = bindings.NetworkGraph_update_channel_unsigned(this.ptr, msg == null ? 0 : msg.ptr & ~1);
296                 Reference.reachabilityFence(this);
297                 Reference.reachabilityFence(msg);
298                 if (ret >= 0 && ret <= 4096) { return null; }
299                 Result_NoneLightningErrorZ ret_hu_conv = Result_NoneLightningErrorZ.constr_from_ptr(ret);
300                 this.ptrs_to.add(msg);
301                 return ret_hu_conv;
302         }
303
304 }