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 = 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);
58 for (RouteHop[] val_conv_12: val) { for (RouteHop val_conv_12_conv_10: val_conv_12) { this.ptrs_to.add(val_conv_12_conv_10); }; };
62 * Constructs a new Route given each field
64 public static Route of(RouteHop[][] paths_arg) {
65 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);
66 if (ret < 1024) { return null; }
67 Route ret_hu_conv = new Route(null, ret);
68 ret_hu_conv.ptrs_to.add(ret_hu_conv);
69 for (RouteHop[] paths_arg_conv_12: paths_arg) { for (RouteHop paths_arg_conv_12_conv_10: paths_arg_conv_12) { ret_hu_conv.ptrs_to.add(paths_arg_conv_12_conv_10); }; };
74 * Creates a copy of the Route
76 public Route clone() {
77 long ret = bindings.Route_clone(this.ptr);
78 if (ret < 1024) { return null; }
79 Route ret_hu_conv = new Route(null, ret);
80 ret_hu_conv.ptrs_to.add(this);
85 * Checks if two Routes contain equal inner contents.
88 long ret = bindings.Route_hash(this.ptr);
93 * Checks if two Routes contain equal inner contents.
94 * This ignores pointers and is_owned flags and looks at the values in fields.
95 * Two objects with NULL inner values will be considered "equal" here.
97 public boolean eq(Route b) {
98 boolean ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
104 * Returns the total amount of fees paid on this [`Route`].
106 * This doesn't include any extra payment made to the recipient, which can happen in excess of
107 * the amount passed to [`get_route`]'s `final_value_msat`.
109 public long get_total_fees() {
110 long ret = bindings.Route_get_total_fees(this.ptr);
115 * Returns the total amount paid on this [`Route`], excluding the fees.
117 public long get_total_amount() {
118 long ret = bindings.Route_get_total_amount(this.ptr);
123 * Serialize the Route object into a byte array which can be read by Route_read
125 public byte[] write() {
126 byte[] ret = bindings.Route_write(this.ptr);
131 * Read a Route from a byte array, created by Route_write
133 public static Result_RouteDecodeErrorZ read(byte[] ser) {
134 long ret = bindings.Route_read(ser);
135 if (ret < 1024) { return null; }
136 Result_RouteDecodeErrorZ ret_hu_conv = Result_RouteDecodeErrorZ.constr_from_ptr(ret);