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 to [`find_route`].
57 * This is used by `ChannelManager` to track information which may be required for retries,
58 * provided back to you via [`Event::PaymentPathFailed`].
60 * [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
62 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
65 public PaymentParameters get_payment_params() {
66 long ret = bindings.Route_get_payment_params(this.ptr);
67 Reference.reachabilityFence(this);
68 if (ret >= 0 && ret <= 4096) { return null; }
69 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
70 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
75 * The `payment_params` parameter passed to [`find_route`].
76 * This is used by `ChannelManager` to track information which may be required for retries,
77 * provided back to you via [`Event::PaymentPathFailed`].
79 * [`Event::PaymentPathFailed`]: crate::events::Event::PaymentPathFailed
81 * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
83 public void set_payment_params(@Nullable org.ldk.structs.PaymentParameters val) {
84 bindings.Route_set_payment_params(this.ptr, val == null ? 0 : val.ptr);
85 Reference.reachabilityFence(this);
86 Reference.reachabilityFence(val);
87 if (this != null) { this.ptrs_to.add(val); };
91 * Constructs a new Route given each field
93 public static Route of(Path[] paths_arg, org.ldk.structs.PaymentParameters payment_params_arg) {
94 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);
95 Reference.reachabilityFence(paths_arg);
96 Reference.reachabilityFence(payment_params_arg);
97 if (ret >= 0 && ret <= 4096) { return null; }
98 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
99 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
100 for (Path paths_arg_conv_6: paths_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(paths_arg_conv_6); }; };
101 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_params_arg); };
106 long ret = bindings.Route_clone_ptr(this.ptr);
107 Reference.reachabilityFence(this);
112 * Creates a copy of the Route
114 public Route clone() {
115 long ret = bindings.Route_clone(this.ptr);
116 Reference.reachabilityFence(this);
117 if (ret >= 0 && ret <= 4096) { return null; }
118 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
119 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
124 * Generates a non-cryptographic 64-bit hash of the Route.
127 long ret = bindings.Route_hash(this.ptr);
128 Reference.reachabilityFence(this);
132 @Override public int hashCode() {
133 return (int)this.hash();
136 * Checks if two Routes contain equal inner contents.
137 * This ignores pointers and is_owned flags and looks at the values in fields.
138 * Two objects with NULL inner values will be considered "equal" here.
140 public boolean eq(org.ldk.structs.Route b) {
141 boolean ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr);
142 Reference.reachabilityFence(this);
143 Reference.reachabilityFence(b);
144 if (this != null) { this.ptrs_to.add(b); };
148 @Override public boolean equals(Object o) {
149 if (!(o instanceof Route)) return false;
150 return this.eq((Route)o);
153 * Returns the total amount of fees paid on this [`Route`].
155 * This doesn't include any extra payment made to the recipient, which can happen in excess of
156 * the amount passed to [`find_route`]'s `params.final_value_msat`.
158 public long get_total_fees() {
159 long ret = bindings.Route_get_total_fees(this.ptr);
160 Reference.reachabilityFence(this);
165 * Returns the total amount paid on this [`Route`], excluding the fees. Might be more than
166 * requested if we had to reach htlc_minimum_msat.
168 public long get_total_amount() {
169 long ret = bindings.Route_get_total_amount(this.ptr);
170 Reference.reachabilityFence(this);
175 * Serialize the Route object into a byte array which can be read by Route_read
177 public byte[] write() {
178 byte[] ret = bindings.Route_write(this.ptr);
179 Reference.reachabilityFence(this);
184 * Read a Route from a byte array, created by Route_write
186 public static Result_RouteDecodeErrorZ read(byte[] ser) {
187 long ret = bindings.Route_read(ser);
188 Reference.reachabilityFence(ser);
189 if (ret >= 0 && ret <= 4096) { return null; }
190 Result_RouteDecodeErrorZ ret_hu_conv = Result_RouteDecodeErrorZ.constr_from_ptr(ret);