Merge pull request #33 from TheBlueMatt/main
[ldk-java] / src / main / java / org / ldk / structs / Route.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
8
9
10 /**
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.
13  */
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 {
19                 super.finalize();
20                 if (ptr != 0) { bindings.Route_free(ptr); }
21         }
22
23         /**
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.
30          */
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[]  */;
34         }
35
36         /**
37          * Constructs a new Route given each field
38          */
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[]  */;
45                 return ret_hu_conv;
46         }
47
48         /**
49          * Creates a copy of the Route
50          */
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);
56                 return ret_hu_conv;
57         }
58
59         /**
60          * Serialize the Route object into a byte array which can be read by Route_read
61          */
62         public byte[] write() {
63                 byte[] ret = bindings.Route_write(this.ptr);
64                 return ret;
65         }
66
67         /**
68          * Read a Route from a byte array, created by Route_write
69          */
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);
74                 return ret_hu_conv;
75         }
76
77 }