1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Either [`P2PGossipSync`] or [`RapidGossipSync`].
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class GossipSync extends CommonBase {
16 private GossipSync(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.GossipSync_free(ptr); }
22 static GossipSync constr_from_ptr(long ptr) {
23 bindings.LDKGossipSync raw_val = bindings.LDKGossipSync_ref_from_ptr(ptr);
24 if (raw_val.getClass() == bindings.LDKGossipSync.P2P.class) {
25 return new P2P(ptr, (bindings.LDKGossipSync.P2P)raw_val);
27 if (raw_val.getClass() == bindings.LDKGossipSync.Rapid.class) {
28 return new Rapid(ptr, (bindings.LDKGossipSync.Rapid)raw_val);
30 if (raw_val.getClass() == bindings.LDKGossipSync.None.class) {
31 return new None(ptr, (bindings.LDKGossipSync.None)raw_val);
33 assert false; return null; // Unreachable without extending the (internal) bindings interface
37 * Gossip sync via the lightning peer-to-peer network as defined by BOLT 7.
39 public final static class P2P extends GossipSync {
40 public final org.ldk.structs.P2PGossipSync p2p;
41 private P2P(long ptr, bindings.LDKGossipSync.P2P obj) {
44 org.ldk.structs.P2PGossipSync p2p_hu_conv = null; if (p2p < 0 || p2p > 4096) { p2p_hu_conv = new org.ldk.structs.P2PGossipSync(null, p2p); }
45 p2p_hu_conv.ptrs_to.add(this);
46 this.p2p = p2p_hu_conv;
50 * Rapid gossip sync from a trusted server.
52 public final static class Rapid extends GossipSync {
53 public final org.ldk.structs.RapidGossipSync rapid;
54 private Rapid(long ptr, bindings.LDKGossipSync.Rapid obj) {
56 long rapid = obj.rapid;
57 org.ldk.structs.RapidGossipSync rapid_hu_conv = null; if (rapid < 0 || rapid > 4096) { rapid_hu_conv = new org.ldk.structs.RapidGossipSync(null, rapid); }
58 rapid_hu_conv.ptrs_to.add(this);
59 this.rapid = rapid_hu_conv;
65 public final static class None extends GossipSync {
66 private None(long ptr, bindings.LDKGossipSync.None obj) {
71 * Utility method to constructs a new P2P-variant GossipSync
73 public static GossipSync p2_p(P2PGossipSync a) {
74 long ret = bindings.GossipSync_p2_p(a == null ? 0 : a.ptr & ~1);
75 Reference.reachabilityFence(a);
76 if (ret >= 0 && ret <= 4096) { return null; }
77 org.ldk.structs.GossipSync ret_hu_conv = org.ldk.structs.GossipSync.constr_from_ptr(ret);
78 ret_hu_conv.ptrs_to.add(ret_hu_conv);
79 ret_hu_conv.ptrs_to.add(a);
84 * Utility method to constructs a new Rapid-variant GossipSync
86 public static GossipSync rapid(RapidGossipSync a) {
87 long ret = bindings.GossipSync_rapid(a == null ? 0 : a.ptr & ~1);
88 Reference.reachabilityFence(a);
89 if (ret >= 0 && ret <= 4096) { return null; }
90 org.ldk.structs.GossipSync ret_hu_conv = org.ldk.structs.GossipSync.constr_from_ptr(ret);
91 ret_hu_conv.ptrs_to.add(ret_hu_conv);
92 ret_hu_conv.ptrs_to.add(a);
97 * Utility method to constructs a new None-variant GossipSync
99 public static GossipSync none() {
100 long ret = bindings.GossipSync_none();
101 if (ret >= 0 && ret <= 4096) { return null; }
102 org.ldk.structs.GossipSync ret_hu_conv = org.ldk.structs.GossipSync.constr_from_ptr(ret);
103 ret_hu_conv.ptrs_to.add(ret_hu_conv);