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