[Java] Update auto-generated Java bindings to LDK 0.0.121
[ldk-java] / src / main / java / org / ldk / structs / CandidateRouteHop.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  * A wrapper around the various hop representations.
13  * 
14  * Can be used to examine the properties of a hop,
15  * potentially to decide whether to include it in a route.
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class CandidateRouteHop extends CommonBase {
19         private CandidateRouteHop(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.CandidateRouteHop_free(ptr); }
24         }
25         static CandidateRouteHop constr_from_ptr(long ptr) {
26                 bindings.LDKCandidateRouteHop raw_val = bindings.LDKCandidateRouteHop_ref_from_ptr(ptr);
27                 if (raw_val.getClass() == bindings.LDKCandidateRouteHop.FirstHop.class) {
28                         return new FirstHop(ptr, (bindings.LDKCandidateRouteHop.FirstHop)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKCandidateRouteHop.PublicHop.class) {
31                         return new PublicHop(ptr, (bindings.LDKCandidateRouteHop.PublicHop)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKCandidateRouteHop.PrivateHop.class) {
34                         return new PrivateHop(ptr, (bindings.LDKCandidateRouteHop.PrivateHop)raw_val);
35                 }
36                 if (raw_val.getClass() == bindings.LDKCandidateRouteHop.Blinded.class) {
37                         return new Blinded(ptr, (bindings.LDKCandidateRouteHop.Blinded)raw_val);
38                 }
39                 if (raw_val.getClass() == bindings.LDKCandidateRouteHop.OneHopBlinded.class) {
40                         return new OneHopBlinded(ptr, (bindings.LDKCandidateRouteHop.OneHopBlinded)raw_val);
41                 }
42                 assert false; return null; // Unreachable without extending the (internal) bindings interface
43         }
44
45         /**
46          * A hop from the payer, where the outbound liquidity is known.
47          */
48         public final static class FirstHop extends CandidateRouteHop {
49                 public final org.ldk.structs.FirstHopCandidate first_hop;
50                 private FirstHop(long ptr, bindings.LDKCandidateRouteHop.FirstHop obj) {
51                         super(null, ptr);
52                         long first_hop = obj.first_hop;
53                         org.ldk.structs.FirstHopCandidate first_hop_hu_conv = null; if (first_hop < 0 || first_hop > 4096) { first_hop_hu_conv = new org.ldk.structs.FirstHopCandidate(null, first_hop); }
54                         if (first_hop_hu_conv != null) { first_hop_hu_conv.ptrs_to.add(this); };
55                         this.first_hop = first_hop_hu_conv;
56                 }
57         }
58         /**
59          * A hop found in the [`ReadOnlyNetworkGraph`].
60          */
61         public final static class PublicHop extends CandidateRouteHop {
62                 public final org.ldk.structs.PublicHopCandidate public_hop;
63                 private PublicHop(long ptr, bindings.LDKCandidateRouteHop.PublicHop obj) {
64                         super(null, ptr);
65                         long public_hop = obj.public_hop;
66                         org.ldk.structs.PublicHopCandidate public_hop_hu_conv = null; if (public_hop < 0 || public_hop > 4096) { public_hop_hu_conv = new org.ldk.structs.PublicHopCandidate(null, public_hop); }
67                         if (public_hop_hu_conv != null) { public_hop_hu_conv.ptrs_to.add(this); };
68                         this.public_hop = public_hop_hu_conv;
69                 }
70         }
71         /**
72          * A private hop communicated by the payee, generally via a BOLT 11 invoice.
73          * 
74          * Because BOLT 11 route hints can take multiple hops to get to the destination, this may not
75          * terminate at the payee.
76          */
77         public final static class PrivateHop extends CandidateRouteHop {
78                 public final org.ldk.structs.PrivateHopCandidate private_hop;
79                 private PrivateHop(long ptr, bindings.LDKCandidateRouteHop.PrivateHop obj) {
80                         super(null, ptr);
81                         long private_hop = obj.private_hop;
82                         org.ldk.structs.PrivateHopCandidate private_hop_hu_conv = null; if (private_hop < 0 || private_hop > 4096) { private_hop_hu_conv = new org.ldk.structs.PrivateHopCandidate(null, private_hop); }
83                         if (private_hop_hu_conv != null) { private_hop_hu_conv.ptrs_to.add(this); };
84                         this.private_hop = private_hop_hu_conv;
85                 }
86         }
87         /**
88          * A blinded path which starts with an introduction point and ultimately terminates with the
89          * payee.
90          * 
91          * Because we don't know the payee's identity, [`CandidateRouteHop::target`] will return
92          * `None` in this state.
93          * 
94          * Because blinded paths are \"all or nothing\", and we cannot use just one part of a blinded
95          * path, the full path is treated as a single [`CandidateRouteHop`].
96          */
97         public final static class Blinded extends CandidateRouteHop {
98                 public final org.ldk.structs.BlindedPathCandidate blinded;
99                 private Blinded(long ptr, bindings.LDKCandidateRouteHop.Blinded obj) {
100                         super(null, ptr);
101                         long blinded = obj.blinded;
102                         org.ldk.structs.BlindedPathCandidate blinded_hu_conv = null; if (blinded < 0 || blinded > 4096) { blinded_hu_conv = new org.ldk.structs.BlindedPathCandidate(null, blinded); }
103                         if (blinded_hu_conv != null) { blinded_hu_conv.ptrs_to.add(this); };
104                         this.blinded = blinded_hu_conv;
105                 }
106         }
107         /**
108          * Similar to [`Self::Blinded`], but the path here only has one hop.
109          * 
110          * While we treat this similarly to [`CandidateRouteHop::Blinded`] in many respects (e.g.
111          * returning `None` from [`CandidateRouteHop::target`]), in this case we do actually know the
112          * payee's identity - it's the introduction point!
113          * 
114          * [`BlindedPayInfo`] provided for 1-hop blinded paths is ignored because it is meant to apply
115          * to the hops *between* the introduction node and the destination.
116          * 
117          * This primarily exists to track that we need to included a blinded path at the end of our
118          * [`Route`], even though it doesn't actually add an additional hop in the payment.
119          */
120         public final static class OneHopBlinded extends CandidateRouteHop {
121                 public final org.ldk.structs.OneHopBlindedPathCandidate one_hop_blinded;
122                 private OneHopBlinded(long ptr, bindings.LDKCandidateRouteHop.OneHopBlinded obj) {
123                         super(null, ptr);
124                         long one_hop_blinded = obj.one_hop_blinded;
125                         org.ldk.structs.OneHopBlindedPathCandidate one_hop_blinded_hu_conv = null; if (one_hop_blinded < 0 || one_hop_blinded > 4096) { one_hop_blinded_hu_conv = new org.ldk.structs.OneHopBlindedPathCandidate(null, one_hop_blinded); }
126                         if (one_hop_blinded_hu_conv != null) { one_hop_blinded_hu_conv.ptrs_to.add(this); };
127                         this.one_hop_blinded = one_hop_blinded_hu_conv;
128                 }
129         }
130         long clone_ptr() {
131                 long ret = bindings.CandidateRouteHop_clone_ptr(this.ptr);
132                 Reference.reachabilityFence(this);
133                 return ret;
134         }
135
136         /**
137          * Creates a copy of the CandidateRouteHop
138          */
139         public CandidateRouteHop clone() {
140                 long ret = bindings.CandidateRouteHop_clone(this.ptr);
141                 Reference.reachabilityFence(this);
142                 if (ret >= 0 && ret <= 4096) { return null; }
143                 org.ldk.structs.CandidateRouteHop ret_hu_conv = org.ldk.structs.CandidateRouteHop.constr_from_ptr(ret);
144                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
145                 return ret_hu_conv;
146         }
147
148         /**
149          * Utility method to constructs a new FirstHop-variant CandidateRouteHop
150          */
151         public static CandidateRouteHop first_hop(org.ldk.structs.FirstHopCandidate a) {
152                 long ret = bindings.CandidateRouteHop_first_hop(a == null ? 0 : a.ptr);
153                 Reference.reachabilityFence(a);
154                 if (ret >= 0 && ret <= 4096) { return null; }
155                 org.ldk.structs.CandidateRouteHop ret_hu_conv = org.ldk.structs.CandidateRouteHop.constr_from_ptr(ret);
156                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
157                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
158                 return ret_hu_conv;
159         }
160
161         /**
162          * Utility method to constructs a new PublicHop-variant CandidateRouteHop
163          */
164         public static CandidateRouteHop public_hop(org.ldk.structs.PublicHopCandidate a) {
165                 long ret = bindings.CandidateRouteHop_public_hop(a == null ? 0 : a.ptr);
166                 Reference.reachabilityFence(a);
167                 if (ret >= 0 && ret <= 4096) { return null; }
168                 org.ldk.structs.CandidateRouteHop ret_hu_conv = org.ldk.structs.CandidateRouteHop.constr_from_ptr(ret);
169                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
170                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
171                 return ret_hu_conv;
172         }
173
174         /**
175          * Utility method to constructs a new PrivateHop-variant CandidateRouteHop
176          */
177         public static CandidateRouteHop private_hop(org.ldk.structs.PrivateHopCandidate a) {
178                 long ret = bindings.CandidateRouteHop_private_hop(a == null ? 0 : a.ptr);
179                 Reference.reachabilityFence(a);
180                 if (ret >= 0 && ret <= 4096) { return null; }
181                 org.ldk.structs.CandidateRouteHop ret_hu_conv = org.ldk.structs.CandidateRouteHop.constr_from_ptr(ret);
182                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
183                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
184                 return ret_hu_conv;
185         }
186
187         /**
188          * Utility method to constructs a new Blinded-variant CandidateRouteHop
189          */
190         public static CandidateRouteHop blinded(org.ldk.structs.BlindedPathCandidate a) {
191                 long ret = bindings.CandidateRouteHop_blinded(a == null ? 0 : a.ptr);
192                 Reference.reachabilityFence(a);
193                 if (ret >= 0 && ret <= 4096) { return null; }
194                 org.ldk.structs.CandidateRouteHop ret_hu_conv = org.ldk.structs.CandidateRouteHop.constr_from_ptr(ret);
195                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
196                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
197                 return ret_hu_conv;
198         }
199
200         /**
201          * Utility method to constructs a new OneHopBlinded-variant CandidateRouteHop
202          */
203         public static CandidateRouteHop one_hop_blinded(org.ldk.structs.OneHopBlindedPathCandidate a) {
204                 long ret = bindings.CandidateRouteHop_one_hop_blinded(a == null ? 0 : a.ptr);
205                 Reference.reachabilityFence(a);
206                 if (ret >= 0 && ret <= 4096) { return null; }
207                 org.ldk.structs.CandidateRouteHop ret_hu_conv = org.ldk.structs.CandidateRouteHop.constr_from_ptr(ret);
208                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
209                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
210                 return ret_hu_conv;
211         }
212
213         /**
214          * Returns the globally unique short channel ID for this hop, if one is known.
215          * 
216          * This only returns `Some` if the channel is public (either our own, or one we've learned
217          * from the public network graph), and thus the short channel ID we have for this channel is
218          * globally unique and identifies this channel in a global namespace.
219          */
220         public Option_u64Z globally_unique_short_channel_id() {
221                 long ret = bindings.CandidateRouteHop_globally_unique_short_channel_id(this.ptr);
222                 Reference.reachabilityFence(this);
223                 if (ret >= 0 && ret <= 4096) { return null; }
224                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
225                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
226                 return ret_hu_conv;
227         }
228
229         /**
230          * Returns the required difference in HTLC CLTV expiry between the [`Self::source`] and the
231          * next-hop for an HTLC taking this hop.
232          * 
233          * This is the time that the node(s) in this hop have to claim the HTLC on-chain if the
234          * next-hop goes on chain with a payment preimage.
235          */
236         public int cltv_expiry_delta() {
237                 int ret = bindings.CandidateRouteHop_cltv_expiry_delta(this.ptr);
238                 Reference.reachabilityFence(this);
239                 return ret;
240         }
241
242         /**
243          * Returns the minimum amount that can be sent over this hop, in millisatoshis.
244          */
245         public long htlc_minimum_msat() {
246                 long ret = bindings.CandidateRouteHop_htlc_minimum_msat(this.ptr);
247                 Reference.reachabilityFence(this);
248                 return ret;
249         }
250
251         /**
252          * Returns the fees that must be paid to route an HTLC over this channel.
253          */
254         public RoutingFees fees() {
255                 long ret = bindings.CandidateRouteHop_fees(this.ptr);
256                 Reference.reachabilityFence(this);
257                 if (ret >= 0 && ret <= 4096) { return null; }
258                 org.ldk.structs.RoutingFees ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RoutingFees(null, ret); }
259                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
260                 return ret_hu_conv;
261         }
262
263         /**
264          * Returns the source node id of current hop.
265          * 
266          * Source node id refers to the node forwarding the HTLC through this hop.
267          * 
268          * For [`Self::FirstHop`] we return payer's node id.
269          */
270         public NodeId source() {
271                 long ret = bindings.CandidateRouteHop_source(this.ptr);
272                 Reference.reachabilityFence(this);
273                 if (ret >= 0 && ret <= 4096) { return null; }
274                 org.ldk.structs.NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeId(null, ret); }
275                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
276                 return ret_hu_conv;
277         }
278
279         /**
280          * Returns the target node id of this hop, if known.
281          * 
282          * Target node id refers to the node receiving the HTLC after this hop.
283          * 
284          * For [`Self::Blinded`] we return `None` because the ultimate destination after the blinded
285          * path is unknown.
286          * 
287          * For [`Self::OneHopBlinded`] we return `None` because the target is the same as the source,
288          * and such a return value would be somewhat nonsensical.
289          * 
290          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
291          */
292         @Nullable
293         public NodeId target() {
294                 long ret = bindings.CandidateRouteHop_target(this.ptr);
295                 Reference.reachabilityFence(this);
296                 if (ret >= 0 && ret <= 4096) { return null; }
297                 org.ldk.structs.NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeId(null, ret); }
298                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
299                 return ret_hu_conv;
300         }
301
302 }