]> git.bitcoin.ninja Git - ldk-java/blob - src/main/java/org/ldk/structs/Route.java
[Java] Don't use `wait` as a method name as its reserved
[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. Each entry represents a list of hops, NOT
27          * INCLUDING our own, where the last hop is the destination. Thus, this must always be at
28          * least length one. While the maximum length of any given path is variable, keeping the length
29          * of any path less or equal to 19 should currently ensure it is viable.
30          */
31         public RouteHop[][] get_paths() {
32                 long[][] ret = bindings.Route_get_paths(this.ptr);
33                 Reference.reachabilityFence(this);
34                 int ret_conv_12_len = ret.length;
35                 RouteHop[][] ret_conv_12_arr = new RouteHop[ret_conv_12_len][];
36                 for (int m = 0; m < ret_conv_12_len; m++) {
37                         long[] ret_conv_12 = ret[m];
38                         int ret_conv_12_conv_10_len = ret_conv_12.length;
39                         RouteHop[] ret_conv_12_conv_10_arr = new RouteHop[ret_conv_12_conv_10_len];
40                         for (int k = 0; k < ret_conv_12_conv_10_len; k++) {
41                                 long ret_conv_12_conv_10 = ret_conv_12[k];
42                                 org.ldk.structs.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 org.ldk.structs.RouteHop(null, ret_conv_12_conv_10); }
43                                 if (ret_conv_12_conv_10_hu_conv != null) { ret_conv_12_conv_10_hu_conv.ptrs_to.add(this); };
44                                 ret_conv_12_conv_10_arr[k] = ret_conv_12_conv_10_hu_conv;
45                         }
46                         ret_conv_12_arr[m] = ret_conv_12_conv_10_arr;
47                 }
48                 return ret_conv_12_arr;
49         }
50
51         /**
52          * The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
53          * last RouteHop in each path must be the same. Each entry represents a list of hops, NOT
54          * INCLUDING our own, where the last hop is the destination. Thus, this must always be at
55          * least length one. While the maximum length of any given path is variable, keeping the length
56          * of any path less or equal to 19 should currently 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).toArray() : null).toArray(long[][]::new) : null);
60                 Reference.reachabilityFence(this);
61                 Reference.reachabilityFence(val);
62                 for (RouteHop[] val_conv_12: val) { for (RouteHop val_conv_12_conv_10: val_conv_12) { if (this != null) { this.ptrs_to.add(val_conv_12_conv_10); }; }; };
63         }
64
65         /**
66          * The `payment_params` parameter passed to [`find_route`].
67          * This is used by `ChannelManager` to track information which may be required for retries,
68          * provided back to you via [`Event::PaymentPathFailed`].
69          * 
70          * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
71          * 
72          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
73          */
74         @Nullable
75         public PaymentParameters get_payment_params() {
76                 long ret = bindings.Route_get_payment_params(this.ptr);
77                 Reference.reachabilityFence(this);
78                 if (ret >= 0 && ret <= 4096) { return null; }
79                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
80                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
81                 return ret_hu_conv;
82         }
83
84         /**
85          * The `payment_params` parameter passed to [`find_route`].
86          * This is used by `ChannelManager` to track information which may be required for retries,
87          * provided back to you via [`Event::PaymentPathFailed`].
88          * 
89          * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
90          * 
91          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
92          */
93         public void set_payment_params(@Nullable org.ldk.structs.PaymentParameters val) {
94                 bindings.Route_set_payment_params(this.ptr, val == null ? 0 : val.ptr);
95                 Reference.reachabilityFence(this);
96                 Reference.reachabilityFence(val);
97                 if (this != null) { this.ptrs_to.add(val); };
98         }
99
100         /**
101          * Constructs a new Route given each field
102          */
103         public static Route of(RouteHop[][] paths_arg, org.ldk.structs.PaymentParameters payment_params_arg) {
104                 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).toArray() : null).toArray(long[][]::new) : null, payment_params_arg == null ? 0 : payment_params_arg.ptr);
105                 Reference.reachabilityFence(paths_arg);
106                 Reference.reachabilityFence(payment_params_arg);
107                 if (ret >= 0 && ret <= 4096) { return null; }
108                 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
109                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
110                 for (RouteHop[] paths_arg_conv_12: paths_arg) { for (RouteHop paths_arg_conv_12_conv_10: paths_arg_conv_12) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(paths_arg_conv_12_conv_10); }; }; };
111                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_params_arg); };
112                 return ret_hu_conv;
113         }
114
115         long clone_ptr() {
116                 long ret = bindings.Route_clone_ptr(this.ptr);
117                 Reference.reachabilityFence(this);
118                 return ret;
119         }
120
121         /**
122          * Creates a copy of the Route
123          */
124         public Route clone() {
125                 long ret = bindings.Route_clone(this.ptr);
126                 Reference.reachabilityFence(this);
127                 if (ret >= 0 && ret <= 4096) { return null; }
128                 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
129                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
130                 return ret_hu_conv;
131         }
132
133         /**
134          * Checks if two Routes contain equal inner contents.
135          */
136         public long hash() {
137                 long ret = bindings.Route_hash(this.ptr);
138                 Reference.reachabilityFence(this);
139                 return ret;
140         }
141
142         @Override public int hashCode() {
143                 return (int)this.hash();
144         }
145         /**
146          * Checks if two Routes contain equal inner contents.
147          * This ignores pointers and is_owned flags and looks at the values in fields.
148          * Two objects with NULL inner values will be considered "equal" here.
149          */
150         public boolean eq(org.ldk.structs.Route b) {
151                 boolean ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr);
152                 Reference.reachabilityFence(this);
153                 Reference.reachabilityFence(b);
154                 if (this != null) { this.ptrs_to.add(b); };
155                 return ret;
156         }
157
158         @Override public boolean equals(Object o) {
159                 if (!(o instanceof Route)) return false;
160                 return this.eq((Route)o);
161         }
162         /**
163          * Returns the total amount of fees paid on this [`Route`].
164          * 
165          * This doesn't include any extra payment made to the recipient, which can happen in excess of
166          * the amount passed to [`find_route`]'s `params.final_value_msat`.
167          */
168         public long get_total_fees() {
169                 long ret = bindings.Route_get_total_fees(this.ptr);
170                 Reference.reachabilityFence(this);
171                 return ret;
172         }
173
174         /**
175          * Returns the total amount paid on this [`Route`], excluding the fees.
176          */
177         public long get_total_amount() {
178                 long ret = bindings.Route_get_total_amount(this.ptr);
179                 Reference.reachabilityFence(this);
180                 return ret;
181         }
182
183         /**
184          * Serialize the Route object into a byte array which can be read by Route_read
185          */
186         public byte[] write() {
187                 byte[] ret = bindings.Route_write(this.ptr);
188                 Reference.reachabilityFence(this);
189                 return ret;
190         }
191
192         /**
193          * Read a Route from a byte array, created by Route_write
194          */
195         public static Result_RouteDecodeErrorZ read(byte[] ser) {
196                 long ret = bindings.Route_read(ser);
197                 Reference.reachabilityFence(ser);
198                 if (ret >= 0 && ret <= 4096) { return null; }
199                 Result_RouteDecodeErrorZ ret_hu_conv = Result_RouteDecodeErrorZ.constr_from_ptr(ret);
200                 return ret_hu_conv;
201         }
202
203 }