Update auto-generated bindings
[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         long clone_ptr() {
103                 long ret = bindings.Route_clone_ptr(this.ptr);
104                 return ret;
105         }
106
107         /**
108          * Creates a copy of the Route
109          */
110         public Route clone() {
111                 long ret = bindings.Route_clone(this.ptr);
112                 if (ret >= 0 && ret <= 4096) { return null; }
113                 Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Route(null, ret); }
114                 ret_hu_conv.ptrs_to.add(this);
115                 return ret_hu_conv;
116         }
117
118         /**
119          * Checks if two Routes contain equal inner contents.
120          */
121         public long hash() {
122                 long ret = bindings.Route_hash(this.ptr);
123                 return ret;
124         }
125
126         /**
127          * Checks if two Routes contain equal inner contents.
128          * This ignores pointers and is_owned flags and looks at the values in fields.
129          * Two objects with NULL inner values will be considered "equal" here.
130          */
131         public boolean eq(Route b) {
132                 boolean ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
133                 this.ptrs_to.add(b);
134                 return ret;
135         }
136
137         /**
138          * Returns the total amount of fees paid on this [`Route`].
139          * 
140          * This doesn't include any extra payment made to the recipient, which can happen in excess of
141          * the amount passed to [`find_route`]'s `params.final_value_msat`.
142          */
143         public long get_total_fees() {
144                 long ret = bindings.Route_get_total_fees(this.ptr);
145                 return ret;
146         }
147
148         /**
149          * Returns the total amount paid on this [`Route`], excluding the fees.
150          */
151         public long get_total_amount() {
152                 long ret = bindings.Route_get_total_amount(this.ptr);
153                 return ret;
154         }
155
156         /**
157          * Serialize the Route object into a byte array which can be read by Route_read
158          */
159         public byte[] write() {
160                 byte[] ret = bindings.Route_write(this.ptr);
161                 return ret;
162         }
163
164         /**
165          * Read a Route from a byte array, created by Route_write
166          */
167         public static Result_RouteDecodeErrorZ read(byte[] ser) {
168                 long ret = bindings.Route_read(ser);
169                 if (ret >= 0 && ret <= 4096) { return null; }
170                 Result_RouteDecodeErrorZ ret_hu_conv = Result_RouteDecodeErrorZ.constr_from_ptr(ret);
171                 return ret_hu_conv;
172         }
173
174 }