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 * A wrapper around the various hop representations.
14 * Can be used to examine the properties of a hop,
15 * potentially to decide whether to include it in a route.
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 {
23 if (ptr != 0) { bindings.CandidateRouteHop_free(ptr); }
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);
30 if (raw_val.getClass() == bindings.LDKCandidateRouteHop.PublicHop.class) {
31 return new PublicHop(ptr, (bindings.LDKCandidateRouteHop.PublicHop)raw_val);
33 if (raw_val.getClass() == bindings.LDKCandidateRouteHop.PrivateHop.class) {
34 return new PrivateHop(ptr, (bindings.LDKCandidateRouteHop.PrivateHop)raw_val);
36 if (raw_val.getClass() == bindings.LDKCandidateRouteHop.Blinded.class) {
37 return new Blinded(ptr, (bindings.LDKCandidateRouteHop.Blinded)raw_val);
39 if (raw_val.getClass() == bindings.LDKCandidateRouteHop.OneHopBlinded.class) {
40 return new OneHopBlinded(ptr, (bindings.LDKCandidateRouteHop.OneHopBlinded)raw_val);
42 assert false; return null; // Unreachable without extending the (internal) bindings interface
46 * A hop from the payer, where the outbound liquidity is known.
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) {
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;
59 * A hop found in the [`ReadOnlyNetworkGraph`].
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) {
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;
72 * A private hop communicated by the payee, generally via a BOLT 11 invoice.
74 * Because BOLT 11 route hints can take multiple hops to get to the destination, this may not
75 * terminate at the payee.
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) {
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;
88 * A blinded path which starts with an introduction point and ultimately terminates with the
91 * Because we don't know the payee's identity, [`CandidateRouteHop::target`] will return
92 * `None` in this state.
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`].
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) {
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;
108 * Similar to [`Self::Blinded`], but the path here only has one hop.
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!
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.
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.
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) {
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;
131 long ret = bindings.CandidateRouteHop_clone_ptr(this.ptr);
132 Reference.reachabilityFence(this);
137 * Creates a copy of the CandidateRouteHop
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); };
149 * Utility method to constructs a new FirstHop-variant CandidateRouteHop
151 public static CandidateRouteHop first_hop(org.ldk.structs.FirstHopCandidate a) {
152 long ret = bindings.CandidateRouteHop_first_hop(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); };
162 * Utility method to constructs a new PublicHop-variant CandidateRouteHop
164 public static CandidateRouteHop public_hop(org.ldk.structs.PublicHopCandidate a) {
165 long ret = bindings.CandidateRouteHop_public_hop(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); };
175 * Utility method to constructs a new PrivateHop-variant CandidateRouteHop
177 public static CandidateRouteHop private_hop(org.ldk.structs.PrivateHopCandidate a) {
178 long ret = bindings.CandidateRouteHop_private_hop(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); };
188 * Utility method to constructs a new Blinded-variant CandidateRouteHop
190 public static CandidateRouteHop blinded(org.ldk.structs.BlindedPathCandidate a) {
191 long ret = bindings.CandidateRouteHop_blinded(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); };
201 * Utility method to constructs a new OneHopBlinded-variant CandidateRouteHop
203 public static CandidateRouteHop one_hop_blinded(org.ldk.structs.OneHopBlindedPathCandidate a) {
204 long ret = bindings.CandidateRouteHop_one_hop_blinded(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); };
214 * Returns the globally unique short channel ID for this hop, if one is known.
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.
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); };
230 * Returns the required difference in HTLC CLTV expiry between the [`Self::source`] and the
231 * next-hop for an HTLC taking this hop.
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.
236 public int cltv_expiry_delta() {
237 int ret = bindings.CandidateRouteHop_cltv_expiry_delta(this.ptr);
238 Reference.reachabilityFence(this);
243 * Returns the minimum amount that can be sent over this hop, in millisatoshis.
245 public long htlc_minimum_msat() {
246 long ret = bindings.CandidateRouteHop_htlc_minimum_msat(this.ptr);
247 Reference.reachabilityFence(this);
252 * Returns the fees that must be paid to route an HTLC over this channel.
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); };
264 * Returns the source node id of current hop.
266 * Source node id refers to the node forwarding the HTLC through this hop.
268 * For [`Self::FirstHop`] we return payer's node id.
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); };
280 * Returns the target node id of this hop, if known.
282 * Target node id refers to the node receiving the HTLC after this hop.
284 * For [`Self::Blinded`] we return `None` because the ultimate destination after the blinded
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.
290 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
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); };