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 route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
13 * it can take multiple paths. Each path is composed of one or more hops through the network.
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class Route extends CommonBase {
17 Route(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.Route_free(ptr); }
25 * The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
26 * [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
29 public Path[] get_paths() {
30 long[] ret = bindings.Route_get_paths(this.ptr);
31 Reference.reachabilityFence(this);
32 int ret_conv_6_len = ret.length;
33 Path[] ret_conv_6_arr = new Path[ret_conv_6_len];
34 for (int g = 0; g < ret_conv_6_len; g++) {
35 long ret_conv_6 = ret[g];
36 org.ldk.structs.Path ret_conv_6_hu_conv = null; if (ret_conv_6 < 0 || ret_conv_6 > 4096) { ret_conv_6_hu_conv = new org.ldk.structs.Path(null, ret_conv_6); }
37 if (ret_conv_6_hu_conv != null) { ret_conv_6_hu_conv.ptrs_to.add(this); };
38 ret_conv_6_arr[g] = ret_conv_6_hu_conv;
40 return ret_conv_6_arr;
44 * The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
45 * [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
48 public void set_paths(Path[] val) {
49 bindings.Route_set_paths(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_6 -> val_conv_6 == null ? 0 : val_conv_6.ptr).toArray() : null);
50 Reference.reachabilityFence(this);
51 Reference.reachabilityFence(val);
52 for (Path val_conv_6: val) { if (this != null) { this.ptrs_to.add(val_conv_6); }; };
56 * The `payment_params` parameter passed via [`RouteParameters`] to [`find_route`].
58 * This is used by `ChannelManager` to track information which may be required for retries.
60 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
63 public PaymentParameters get_payment_params() {
64 long ret = bindings.Route_get_payment_params(this.ptr);
65 Reference.reachabilityFence(this);
66 if (ret >= 0 && ret <= 4096) { return null; }
67 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
68 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
73 * The `payment_params` parameter passed via [`RouteParameters`] to [`find_route`].
75 * This is used by `ChannelManager` to track information which may be required for retries.
77 * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
79 public void set_payment_params(@Nullable org.ldk.structs.PaymentParameters val) {
80 bindings.Route_set_payment_params(this.ptr, val == null ? 0 : val.ptr);
81 Reference.reachabilityFence(this);
82 Reference.reachabilityFence(val);
83 if (this != null) { this.ptrs_to.add(val); };
87 * Constructs a new Route given each field
89 public static Route of(Path[] paths_arg, org.ldk.structs.PaymentParameters payment_params_arg) {
90 long ret = bindings.Route_new(paths_arg != null ? Arrays.stream(paths_arg).mapToLong(paths_arg_conv_6 -> paths_arg_conv_6 == null ? 0 : paths_arg_conv_6.ptr).toArray() : null, payment_params_arg == null ? 0 : payment_params_arg.ptr);
91 Reference.reachabilityFence(paths_arg);
92 Reference.reachabilityFence(payment_params_arg);
93 if (ret >= 0 && ret <= 4096) { return null; }
94 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
95 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
96 for (Path paths_arg_conv_6: paths_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(paths_arg_conv_6); }; };
97 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_params_arg); };
102 long ret = bindings.Route_clone_ptr(this.ptr);
103 Reference.reachabilityFence(this);
108 * Creates a copy of the Route
110 public Route clone() {
111 long ret = bindings.Route_clone(this.ptr);
112 Reference.reachabilityFence(this);
113 if (ret >= 0 && ret <= 4096) { return null; }
114 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
115 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
120 * Generates a non-cryptographic 64-bit hash of the Route.
123 long ret = bindings.Route_hash(this.ptr);
124 Reference.reachabilityFence(this);
128 @Override public int hashCode() {
129 return (int)this.hash();
132 * Checks if two Routes contain equal inner contents.
133 * This ignores pointers and is_owned flags and looks at the values in fields.
134 * Two objects with NULL inner values will be considered "equal" here.
136 public boolean eq(org.ldk.structs.Route b) {
137 boolean ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr);
138 Reference.reachabilityFence(this);
139 Reference.reachabilityFence(b);
140 if (this != null) { this.ptrs_to.add(b); };
144 @Override public boolean equals(Object o) {
145 if (!(o instanceof Route)) return false;
146 return this.eq((Route)o);
149 * Returns the total amount of fees paid on this [`Route`].
151 * This doesn't include any extra payment made to the recipient, which can happen in excess of
152 * the amount passed to [`find_route`]'s `route_params.final_value_msat`.
154 public long get_total_fees() {
155 long ret = bindings.Route_get_total_fees(this.ptr);
156 Reference.reachabilityFence(this);
161 * Returns the total amount paid on this [`Route`], excluding the fees. Might be more than
162 * requested if we had to reach htlc_minimum_msat.
164 public long get_total_amount() {
165 long ret = bindings.Route_get_total_amount(this.ptr);
166 Reference.reachabilityFence(this);
171 * Serialize the Route object into a byte array which can be read by Route_read
173 public byte[] write() {
174 byte[] ret = bindings.Route_write(this.ptr);
175 Reference.reachabilityFence(this);
180 * Read a Route from a byte array, created by Route_write
182 public static Result_RouteDecodeErrorZ read(byte[] ser) {
183 long ret = bindings.Route_read(ser);
184 Reference.reachabilityFence(ser);
185 if (ret >= 0 && ret <= 4096) { return null; }
186 Result_RouteDecodeErrorZ ret_hu_conv = Result_RouteDecodeErrorZ.constr_from_ptr(ret);