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 void set_paths(RouteHop[][] val) {
32 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);
33 /* TODO 2 RouteHop[] */;
37 * Constructs a new Route given each field
39 public static Route of(RouteHop[][] paths_arg) {
40 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);
41 if (ret < 1024) { return null; }
42 Route ret_hu_conv = new Route(null, ret);
43 ret_hu_conv.ptrs_to.add(ret_hu_conv);
44 /* TODO 2 RouteHop[] */;
49 * Creates a copy of the Route
51 public Route clone() {
52 long ret = bindings.Route_clone(this.ptr);
53 if (ret < 1024) { return null; }
54 Route ret_hu_conv = new Route(null, ret);
55 ret_hu_conv.ptrs_to.add(this);
60 * Serialize the Route object into a byte array which can be read by Route_read
62 public byte[] write() {
63 byte[] ret = bindings.Route_write(this.ptr);
68 * Read a Route from a byte array, created by Route_write
70 public static Result_RouteDecodeErrorZ read(byte[] ser) {
71 long ret = bindings.Route_read(ser);
72 if (ret < 1024) { return null; }
73 Result_RouteDecodeErrorZ ret_hu_conv = Result_RouteDecodeErrorZ.constr_from_ptr(ret);