Update auto-generated bindings to 0.0.103
[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 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;
42                         }
43                         ret_conv_12_arr[m] = ret_conv_12_conv_10_arr;
44                 }
45                 return ret_conv_12_arr;
46         }
47
48         /**
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.
55          */
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         }
59
60         /**
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`].
64          * 
65          * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
66          * 
67          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
68          */
69         @Nullable
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);
75                 return ret_hu_conv;
76         }
77
78         /**
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`].
82          * 
83          * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
84          * 
85          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
86          */
87         public void set_payee(@Nullable Payee val) {
88                 bindings.Route_set_payee(this.ptr, val == null ? 0 : val.ptr & ~1);
89         }
90
91         /**
92          * Constructs a new Route given each field
93          */
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);
99                 return ret_hu_conv;
100         }
101
102         /**
103          * Creates a copy of the Route
104          */
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);
110                 return ret_hu_conv;
111         }
112
113         /**
114          * Checks if two Routes contain equal inner contents.
115          */
116         public long hash() {
117                 long ret = bindings.Route_hash(this.ptr);
118                 return ret;
119         }
120
121         /**
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.
125          */
126         public boolean eq(Route b) {
127                 boolean ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
128                 this.ptrs_to.add(b);
129                 return ret;
130         }
131
132         /**
133          * Returns the total amount of fees paid on this [`Route`].
134          * 
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`.
137          */
138         public long get_total_fees() {
139                 long ret = bindings.Route_get_total_fees(this.ptr);
140                 return ret;
141         }
142
143         /**
144          * Returns the total amount paid on this [`Route`], excluding the fees.
145          */
146         public long get_total_amount() {
147                 long ret = bindings.Route_get_total_amount(this.ptr);
148                 return ret;
149         }
150
151         /**
152          * Serialize the Route object into a byte array which can be read by Route_read
153          */
154         public byte[] write() {
155                 byte[] ret = bindings.Route_write(this.ptr);
156                 return ret;
157         }
158
159         /**
160          * Read a Route from a byte array, created by Route_write
161          */
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);
166                 return ret_hu_conv;
167         }
168
169 }