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 path in a [`Route`] to the payment recipient. Must always be at least length one.
13 * If no [`Path::blinded_tail`] is present, then [`Path::hops`] length may be up to 19.
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class Path extends CommonBase {
17 Path(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.Path_free(ptr); }
25 * The list of unblinded hops in this [`Path`]. Must be at least length one.
27 public RouteHop[] get_hops() {
28 long[] ret = bindings.Path_get_hops(this.ptr);
29 Reference.reachabilityFence(this);
30 int ret_conv_10_len = ret.length;
31 RouteHop[] ret_conv_10_arr = new RouteHop[ret_conv_10_len];
32 for (int k = 0; k < ret_conv_10_len; k++) {
33 long ret_conv_10 = ret[k];
34 org.ldk.structs.RouteHop ret_conv_10_hu_conv = null; if (ret_conv_10 < 0 || ret_conv_10 > 4096) { ret_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, ret_conv_10); }
35 if (ret_conv_10_hu_conv != null) { ret_conv_10_hu_conv.ptrs_to.add(this); };
36 ret_conv_10_arr[k] = ret_conv_10_hu_conv;
38 return ret_conv_10_arr;
42 * The list of unblinded hops in this [`Path`]. Must be at least length one.
44 public void set_hops(RouteHop[] val) {
45 bindings.Path_set_hops(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_10 -> val_conv_10 == null ? 0 : val_conv_10.ptr).toArray() : null);
46 Reference.reachabilityFence(this);
47 Reference.reachabilityFence(val);
48 for (RouteHop val_conv_10: val) { if (this != null) { this.ptrs_to.add(val_conv_10); }; };
52 * The blinded path at which this path terminates, if we're sending to one, and its metadata.
54 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
57 public BlindedTail get_blinded_tail() {
58 long ret = bindings.Path_get_blinded_tail(this.ptr);
59 Reference.reachabilityFence(this);
60 if (ret >= 0 && ret <= 4096) { return null; }
61 org.ldk.structs.BlindedTail ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedTail(null, ret); }
62 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
67 * The blinded path at which this path terminates, if we're sending to one, and its metadata.
69 * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
71 public void set_blinded_tail(@Nullable org.ldk.structs.BlindedTail val) {
72 bindings.Path_set_blinded_tail(this.ptr, val == null ? 0 : val.ptr);
73 Reference.reachabilityFence(this);
74 Reference.reachabilityFence(val);
75 if (this != null) { this.ptrs_to.add(val); };
79 * Constructs a new Path given each field
81 * Note that blinded_tail_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
83 public static Path of(RouteHop[] hops_arg, @Nullable org.ldk.structs.BlindedTail blinded_tail_arg) {
84 long ret = bindings.Path_new(hops_arg != null ? Arrays.stream(hops_arg).mapToLong(hops_arg_conv_10 -> hops_arg_conv_10 == null ? 0 : hops_arg_conv_10.ptr).toArray() : null, blinded_tail_arg == null ? 0 : blinded_tail_arg.ptr);
85 Reference.reachabilityFence(hops_arg);
86 Reference.reachabilityFence(blinded_tail_arg);
87 if (ret >= 0 && ret <= 4096) { return null; }
88 org.ldk.structs.Path ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Path(null, ret); }
89 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
90 for (RouteHop hops_arg_conv_10: hops_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(hops_arg_conv_10); }; };
91 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(blinded_tail_arg); };
96 long ret = bindings.Path_clone_ptr(this.ptr);
97 Reference.reachabilityFence(this);
102 * Creates a copy of the Path
104 public Path clone() {
105 long ret = bindings.Path_clone(this.ptr);
106 Reference.reachabilityFence(this);
107 if (ret >= 0 && ret <= 4096) { return null; }
108 org.ldk.structs.Path ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Path(null, ret); }
109 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
114 * Generates a non-cryptographic 64-bit hash of the Path.
117 long ret = bindings.Path_hash(this.ptr);
118 Reference.reachabilityFence(this);
122 @Override public int hashCode() {
123 return (int)this.hash();
126 * Checks if two Paths contain equal inner contents.
127 * This ignores pointers and is_owned flags and looks at the values in fields.
128 * Two objects with NULL inner values will be considered "equal" here.
130 public boolean eq(org.ldk.structs.Path b) {
131 boolean ret = bindings.Path_eq(this.ptr, b == null ? 0 : b.ptr);
132 Reference.reachabilityFence(this);
133 Reference.reachabilityFence(b);
134 if (this != null) { this.ptrs_to.add(b); };
138 @Override public boolean equals(Object o) {
139 if (!(o instanceof Path)) return false;
140 return this.eq((Path)o);
143 * Gets the fees for a given path, excluding any excess paid to the recipient.
145 public long fee_msat() {
146 long ret = bindings.Path_fee_msat(this.ptr);
147 Reference.reachabilityFence(this);
152 * Gets the total amount paid on this [`Path`], excluding the fees.
154 public long final_value_msat() {
155 long ret = bindings.Path_final_value_msat(this.ptr);
156 Reference.reachabilityFence(this);
161 * Gets the final hop's CLTV expiry delta.
163 public Option_u32Z final_cltv_expiry_delta() {
164 long ret = bindings.Path_final_cltv_expiry_delta(this.ptr);
165 Reference.reachabilityFence(this);
166 if (ret >= 0 && ret <= 4096) { return null; }
167 org.ldk.structs.Option_u32Z ret_hu_conv = org.ldk.structs.Option_u32Z.constr_from_ptr(ret);
168 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };