Update auto-updated Java files
[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 java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
13  * it can take multiple paths. Each path is composed of one or more hops through the network.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class Route extends CommonBase {
17         Route(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.Route_free(ptr); }
22         }
23
24         /**
25          * The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
26          * last RouteHop in each path must be the same.
27          * Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the
28          * destination. Thus, this must always be at least length one. While the maximum length of any
29          * given path is variable, keeping the length of any path to less than 20 should currently
30          * ensure it is viable.
31          */
32         public RouteHop[][] get_paths() {
33                 long[][] ret = bindings.Route_get_paths(this.ptr);
34                 Reference.reachabilityFence(this);
35                 RouteHop[][] ret_conv_12_arr = new RouteHop[ret.length][];
36                 for (int m = 0; m < ret.length; m++) {
37                         long[] ret_conv_12 = ret[m];
38                         RouteHop[] ret_conv_12_conv_10_arr = new RouteHop[ret_conv_12.length];
39                         for (int k = 0; k < ret_conv_12.length; k++) {
40                                 long ret_conv_12_conv_10 = ret_conv_12[k];
41                                 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); }
42                                 ret_conv_12_conv_10_hu_conv.ptrs_to.add(this);
43                                 ret_conv_12_conv_10_arr[k] = ret_conv_12_conv_10_hu_conv;
44                         }
45                         ret_conv_12_arr[m] = ret_conv_12_conv_10_arr;
46                 }
47                 return ret_conv_12_arr;
48         }
49
50         /**
51          * The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
52          * last RouteHop in each path must be the same.
53          * Each entry represents a list of hops, NOT INCLUDING our own, where the last hop is the
54          * destination. Thus, this must always be at least length one. While the maximum length of any
55          * given path is variable, keeping the length of any path to less than 20 should currently
56          * ensure it is viable.
57          */
58         public void set_paths(RouteHop[][] val) {
59                 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);
60                 Reference.reachabilityFence(this);
61                 Reference.reachabilityFence(val);
62         }
63
64         /**
65          * The `payee` parameter passed to [`find_route`].
66          * This is used by `ChannelManager` to track information which may be required for retries,
67          * provided back to you via [`Event::PaymentPathFailed`].
68          * 
69          * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
70          * 
71          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
72          */
73         @Nullable
74         public Payee get_payee() {
75                 long ret = bindings.Route_get_payee(this.ptr);
76                 Reference.reachabilityFence(this);
77                 if (ret >= 0 && ret <= 4096) { return null; }
78                 Payee ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Payee(null, ret); }
79                 ret_hu_conv.ptrs_to.add(this);
80                 return ret_hu_conv;
81         }
82
83         /**
84          * The `payee` parameter passed to [`find_route`].
85          * This is used by `ChannelManager` to track information which may be required for retries,
86          * provided back to you via [`Event::PaymentPathFailed`].
87          * 
88          * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
89          * 
90          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
91          */
92         public void set_payee(@Nullable Payee val) {
93                 bindings.Route_set_payee(this.ptr, val == null ? 0 : val.ptr & ~1);
94                 Reference.reachabilityFence(this);
95                 Reference.reachabilityFence(val);
96         }
97
98         /**
99          * Constructs a new Route given each field
100          */
101         public static Route of(RouteHop[][] paths_arg, Payee payee_arg) {
102                 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);
103                 Reference.reachabilityFence(paths_arg);
104                 Reference.reachabilityFence(payee_arg);
105                 if (ret >= 0 && ret <= 4096) { return null; }
106                 Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Route(null, ret); }
107                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
108                 return ret_hu_conv;
109         }
110
111         long clone_ptr() {
112                 long ret = bindings.Route_clone_ptr(this.ptr);
113                 Reference.reachabilityFence(this);
114                 return ret;
115         }
116
117         /**
118          * Creates a copy of the Route
119          */
120         public Route clone() {
121                 long ret = bindings.Route_clone(this.ptr);
122                 Reference.reachabilityFence(this);
123                 if (ret >= 0 && ret <= 4096) { return null; }
124                 Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Route(null, ret); }
125                 ret_hu_conv.ptrs_to.add(this);
126                 return ret_hu_conv;
127         }
128
129         /**
130          * Checks if two Routes contain equal inner contents.
131          */
132         public long hash() {
133                 long ret = bindings.Route_hash(this.ptr);
134                 Reference.reachabilityFence(this);
135                 return ret;
136         }
137
138         @Override public int hashCode() {
139                 return (int)this.hash();
140         }
141         /**
142          * Checks if two Routes contain equal inner contents.
143          * This ignores pointers and is_owned flags and looks at the values in fields.
144          * Two objects with NULL inner values will be considered "equal" here.
145          */
146         public boolean eq(Route b) {
147                 boolean ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
148                 Reference.reachabilityFence(this);
149                 Reference.reachabilityFence(b);
150                 this.ptrs_to.add(b);
151                 return ret;
152         }
153
154         @Override public boolean equals(Object o) {
155                 if (!(o instanceof Route)) return false;
156                 return this.eq((Route)o);
157         }
158         /**
159          * Returns the total amount of fees paid on this [`Route`].
160          * 
161          * This doesn't include any extra payment made to the recipient, which can happen in excess of
162          * the amount passed to [`find_route`]'s `params.final_value_msat`.
163          */
164         public long get_total_fees() {
165                 long ret = bindings.Route_get_total_fees(this.ptr);
166                 Reference.reachabilityFence(this);
167                 return ret;
168         }
169
170         /**
171          * Returns the total amount paid on this [`Route`], excluding the fees.
172          */
173         public long get_total_amount() {
174                 long ret = bindings.Route_get_total_amount(this.ptr);
175                 Reference.reachabilityFence(this);
176                 return ret;
177         }
178
179         /**
180          * Serialize the Route object into a byte array which can be read by Route_read
181          */
182         public byte[] write() {
183                 byte[] ret = bindings.Route_write(this.ptr);
184                 Reference.reachabilityFence(this);
185                 return ret;
186         }
187
188         /**
189          * Read a Route from a byte array, created by Route_write
190          */
191         public static Result_RouteDecodeErrorZ read(byte[] ser) {
192                 long ret = bindings.Route_read(ser);
193                 Reference.reachabilityFence(ser);
194                 if (ret >= 0 && ret <= 4096) { return null; }
195                 Result_RouteDecodeErrorZ ret_hu_conv = Result_RouteDecodeErrorZ.constr_from_ptr(ret);
196                 return ret_hu_conv;
197         }
198
199 }