46cd9b5b781865f9a420c0a1279db107564c2623
[ldk-java] / src / main / java / org / ldk / structs / RapidGossipSync.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  * The main Rapid Gossip Sync object.
13  * 
14  * See [crate-level documentation] for usage.
15  * 
16  * [crate-level documentation]: crate
17  */
18 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class RapidGossipSync extends CommonBase {
20         RapidGossipSync(Object _dummy, long ptr) { super(ptr); }
21         @Override @SuppressWarnings("deprecation")
22         protected void finalize() throws Throwable {
23                 super.finalize();
24                 if (ptr != 0) { bindings.RapidGossipSync_free(ptr); }
25         }
26
27         /**
28          * Instantiate a new [`RapidGossipSync`] instance.
29          */
30         public static RapidGossipSync of(org.ldk.structs.NetworkGraph network_graph, org.ldk.structs.Logger logger) {
31                 long ret = bindings.RapidGossipSync_new(network_graph == null ? 0 : network_graph.ptr, logger.ptr);
32                 Reference.reachabilityFence(network_graph);
33                 Reference.reachabilityFence(logger);
34                 if (ret >= 0 && ret <= 4096) { return null; }
35                 org.ldk.structs.RapidGossipSync ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RapidGossipSync(null, ret); }
36                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
37                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(network_graph); };
38                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(logger); };
39                 return ret_hu_conv;
40         }
41
42         /**
43          * Sync gossip data from a file.
44          * Returns the last sync timestamp to be used the next time rapid sync data is queried.
45          * 
46          * `network_graph`: The network graph to apply the updates to
47          * 
48          * `sync_path`: Path to the file where the gossip update data is located
49          */
50         public Result_u32GraphSyncErrorZ sync_network_graph_with_file_path(java.lang.String sync_path) {
51                 long ret = bindings.RapidGossipSync_sync_network_graph_with_file_path(this.ptr, sync_path);
52                 Reference.reachabilityFence(this);
53                 Reference.reachabilityFence(sync_path);
54                 if (ret >= 0 && ret <= 4096) { return null; }
55                 Result_u32GraphSyncErrorZ ret_hu_conv = Result_u32GraphSyncErrorZ.constr_from_ptr(ret);
56                 return ret_hu_conv;
57         }
58
59         /**
60          * Update network graph from binary data.
61          * Returns the last sync timestamp to be used the next time rapid sync data is queried.
62          * 
63          * `update_data`: `&[u8]` binary stream that comprises the update data
64          */
65         public Result_u32GraphSyncErrorZ update_network_graph(byte[] update_data) {
66                 long ret = bindings.RapidGossipSync_update_network_graph(this.ptr, update_data);
67                 Reference.reachabilityFence(this);
68                 Reference.reachabilityFence(update_data);
69                 if (ret >= 0 && ret <= 4096) { return null; }
70                 Result_u32GraphSyncErrorZ ret_hu_conv = Result_u32GraphSyncErrorZ.constr_from_ptr(ret);
71                 return ret_hu_conv;
72         }
73
74         /**
75          * Update network graph from binary data.
76          * Returns the last sync timestamp to be used the next time rapid sync data is queried.
77          * 
78          * `update_data`: `&[u8]` binary stream that comprises the update data
79          * `current_time_unix`: `Option<u64>` optional current timestamp to verify data age
80          */
81         public Result_u32GraphSyncErrorZ update_network_graph_no_std(byte[] update_data, org.ldk.structs.Option_u64Z current_time_unix) {
82                 long ret = bindings.RapidGossipSync_update_network_graph_no_std(this.ptr, update_data, current_time_unix.ptr);
83                 Reference.reachabilityFence(this);
84                 Reference.reachabilityFence(update_data);
85                 Reference.reachabilityFence(current_time_unix);
86                 if (ret >= 0 && ret <= 4096) { return null; }
87                 Result_u32GraphSyncErrorZ ret_hu_conv = Result_u32GraphSyncErrorZ.constr_from_ptr(ret);
88                 if (this != null) { this.ptrs_to.add(current_time_unix); };
89                 return ret_hu_conv;
90         }
91
92         /**
93          * Returns whether a rapid gossip sync has completed at least once.
94          */
95         public boolean is_initial_sync_complete() {
96                 boolean ret = bindings.RapidGossipSync_is_initial_sync_complete(this.ptr);
97                 Reference.reachabilityFence(this);
98                 return ret;
99         }
100
101 }