51d14b639f491c5aeb9bf8b9ee66fc799e03676b
[ldk-java] / src / main / java / org / ldk / structs / GossipSync.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  * Either [`P2PGossipSync`] or [`RapidGossipSync`].
13  */
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 {
19                 super.finalize();
20                 if (ptr != 0) { bindings.GossipSync_free(ptr); }
21         }
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);
26                 }
27                 if (raw_val.getClass() == bindings.LDKGossipSync.Rapid.class) {
28                         return new Rapid(ptr, (bindings.LDKGossipSync.Rapid)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKGossipSync.None.class) {
31                         return new None(ptr, (bindings.LDKGossipSync.None)raw_val);
32                 }
33                 assert false; return null; // Unreachable without extending the (internal) bindings interface
34         }
35
36         /**
37          * Gossip sync via the lightning peer-to-peer network as defined by BOLT 7.
38          */
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) {
42                         super(null, ptr);
43                         long p2p = obj.p2p;
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;
47                 }
48         }
49         /**
50          * Rapid gossip sync from a trusted server.
51          */
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) {
55                         super(null, ptr);
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;
60                 }
61         }
62         /**
63          * No gossip sync.
64          */
65         public final static class None extends GossipSync {
66                 private None(long ptr, bindings.LDKGossipSync.None obj) {
67                         super(null, ptr);
68                 }
69         }
70         /**
71          * Utility method to constructs a new P2P-variant GossipSync
72          */
73         public static GossipSync p2_p(P2PGossipSync a) {
74                 long ret = bindings.GossipSync_p2_p(a == null ? 0 : a.ptr);
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);
80                 return ret_hu_conv;
81         }
82
83         /**
84          * Utility method to constructs a new Rapid-variant GossipSync
85          */
86         public static GossipSync rapid(RapidGossipSync a) {
87                 long ret = bindings.GossipSync_rapid(a == null ? 0 : a.ptr);
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);
93                 return ret_hu_conv;
94         }
95
96         /**
97          * Utility method to constructs a new None-variant GossipSync
98          */
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);
104                 return ret_hu_conv;
105         }
106
107 }