d9b85257633f46a0e62bd6c12f033c8e8851b7da
[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 == null ? 0 : 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          * Update network graph from binary data.
44          * Returns the last sync timestamp to be used the next time rapid sync data is queried.
45          * 
46          * `update_data`: `&[u8]` binary stream that comprises the update data
47          * `current_time_unix`: `Option<u64>` optional current timestamp to verify data age
48          */
49         public Result_u32GraphSyncErrorZ update_network_graph_no_std(byte[] update_data, org.ldk.structs.Option_u64Z current_time_unix) {
50                 long ret = bindings.RapidGossipSync_update_network_graph_no_std(this.ptr, update_data, current_time_unix.ptr);
51                 Reference.reachabilityFence(this);
52                 Reference.reachabilityFence(update_data);
53                 Reference.reachabilityFence(current_time_unix);
54                 if (ret >= 0 && ret <= 4096) { return null; }
55                 Result_u32GraphSyncErrorZ ret_hu_conv = Result_u32GraphSyncErrorZ.constr_from_ptr(ret);
56                 if (this != null) { this.ptrs_to.add(current_time_unix); };
57                 return ret_hu_conv;
58         }
59
60         /**
61          * Returns whether a rapid gossip sync has completed at least once.
62          */
63         public boolean is_initial_sync_complete() {
64                 boolean ret = bindings.RapidGossipSync_is_initial_sync_complete(this.ptr);
65                 Reference.reachabilityFence(this);
66                 return ret;
67         }
68
69 }