1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
12 * it can take multiple paths. Each path is composed of one or more hops through the network.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Route extends CommonBase {
16 Route(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.Route_free(ptr); }
24 * The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
25 * last RouteHop in each path must be the same.
26 * Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the
27 * destination. Thus, this must always be at least length one. While the maximum length of any
28 * given path is variable, keeping the length of any path to less than 20 should currently
29 * ensure it is viable.
31 public RouteHop[][] get_paths() {
32 long[][] ret = bindings.Route_get_paths(this.ptr);
33 RouteHop[][] ret_conv_12_arr = new RouteHop[ret.length][];
34 for (int m = 0; m < ret.length; m++) {
35 long[] ret_conv_12 = ret[m];
36 RouteHop[] ret_conv_12_conv_10_arr = new RouteHop[ret_conv_12.length];
37 for (int k = 0; k < ret_conv_12.length; k++) {
38 long ret_conv_12_conv_10 = ret_conv_12[k];
39 RouteHop ret_conv_12_conv_10_hu_conv = null; if (ret_conv_12_conv_10 < 0 || ret_conv_12_conv_10 > 4096) { ret_conv_12_conv_10_hu_conv = new RouteHop(null, ret_conv_12_conv_10); }
40 ret_conv_12_conv_10_hu_conv.ptrs_to.add(this);
41 ret_conv_12_conv_10_arr[k] = ret_conv_12_conv_10_hu_conv;
43 ret_conv_12_arr[m] = ret_conv_12_conv_10_arr;
45 return ret_conv_12_arr;
49 * The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
50 * last RouteHop in each path must be the same.
51 * Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the
52 * destination. Thus, this must always be at least length one. While the maximum length of any
53 * given path is variable, keeping the length of any path to less than 20 should currently
54 * ensure it is viable.
56 public void set_paths(RouteHop[][] val) {
57 bindings.Route_set_paths(this.ptr, val != null ? Arrays.stream(val).map(val_conv_12 -> val_conv_12 != null ? Arrays.stream(val_conv_12).mapToLong(val_conv_12_conv_10 -> val_conv_12_conv_10 == null ? 0 : val_conv_12_conv_10.ptr & ~1).toArray() : null).toArray(long[][]::new) : null);
61 * The `payee` parameter passed to [`find_route`].
62 * This is used by `ChannelManager` to track information which may be required for retries,
63 * provided back to you via [`Event::PaymentPathFailed`].
65 * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
67 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
70 public Payee get_payee() {
71 long ret = bindings.Route_get_payee(this.ptr);
72 if (ret >= 0 && ret <= 4096) { return null; }
73 Payee ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Payee(null, ret); }
74 ret_hu_conv.ptrs_to.add(this);
79 * The `payee` parameter passed to [`find_route`].
80 * This is used by `ChannelManager` to track information which may be required for retries,
81 * provided back to you via [`Event::PaymentPathFailed`].
83 * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
85 * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
87 public void set_payee(@Nullable Payee val) {
88 bindings.Route_set_payee(this.ptr, val == null ? 0 : val.ptr & ~1);
92 * Constructs a new Route given each field
94 public static Route of(RouteHop[][] paths_arg, Payee payee_arg) {
95 long ret = bindings.Route_new(paths_arg != null ? Arrays.stream(paths_arg).map(paths_arg_conv_12 -> paths_arg_conv_12 != null ? Arrays.stream(paths_arg_conv_12).mapToLong(paths_arg_conv_12_conv_10 -> paths_arg_conv_12_conv_10 == null ? 0 : paths_arg_conv_12_conv_10.ptr & ~1).toArray() : null).toArray(long[][]::new) : null, payee_arg == null ? 0 : payee_arg.ptr & ~1);
96 if (ret >= 0 && ret <= 4096) { return null; }
97 Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Route(null, ret); }
98 ret_hu_conv.ptrs_to.add(ret_hu_conv);
103 * Creates a copy of the Route
105 public Route clone() {
106 long ret = bindings.Route_clone(this.ptr);
107 if (ret >= 0 && ret <= 4096) { return null; }
108 Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Route(null, ret); }
109 ret_hu_conv.ptrs_to.add(this);
114 * Checks if two Routes contain equal inner contents.
117 long ret = bindings.Route_hash(this.ptr);
122 * Checks if two Routes contain equal inner contents.
123 * This ignores pointers and is_owned flags and looks at the values in fields.
124 * Two objects with NULL inner values will be considered "equal" here.
126 public boolean eq(Route b) {
127 boolean ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
133 * Returns the total amount of fees paid on this [`Route`].
135 * This doesn't include any extra payment made to the recipient, which can happen in excess of
136 * the amount passed to [`find_route`]'s `params.final_value_msat`.
138 public long get_total_fees() {
139 long ret = bindings.Route_get_total_fees(this.ptr);
144 * Returns the total amount paid on this [`Route`], excluding the fees.
146 public long get_total_amount() {
147 long ret = bindings.Route_get_total_amount(this.ptr);
152 * Serialize the Route object into a byte array which can be read by Route_read
154 public byte[] write() {
155 byte[] ret = bindings.Route_write(this.ptr);
160 * Read a Route from a byte array, created by Route_write
162 public static Result_RouteDecodeErrorZ read(byte[] ser) {
163 long ret = bindings.Route_read(ser);
164 if (ret >= 0 && ret <= 4096) { return null; }
165 Result_RouteDecodeErrorZ ret_hu_conv = Result_RouteDecodeErrorZ.constr_from_ptr(ret);