[C#] Run tests against release library in determinism CI run
[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 [`Path`]s taken for a single (potentially-)multi-part payment. If no
26          * [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
27          * the same.
28          */
29         public Path[] get_paths() {
30                 long[] ret = bindings.Route_get_paths(this.ptr);
31                 Reference.reachabilityFence(this);
32                 int ret_conv_6_len = ret.length;
33                 Path[] ret_conv_6_arr = new Path[ret_conv_6_len];
34                 for (int g = 0; g < ret_conv_6_len; g++) {
35                         long ret_conv_6 = ret[g];
36                         org.ldk.structs.Path ret_conv_6_hu_conv = null; if (ret_conv_6 < 0 || ret_conv_6 > 4096) { ret_conv_6_hu_conv = new org.ldk.structs.Path(null, ret_conv_6); }
37                         if (ret_conv_6_hu_conv != null) { ret_conv_6_hu_conv.ptrs_to.add(this); };
38                         ret_conv_6_arr[g] = ret_conv_6_hu_conv;
39                 }
40                 return ret_conv_6_arr;
41         }
42
43         /**
44          * The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
45          * [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
46          * the same.
47          */
48         public void set_paths(Path[] val) {
49                 bindings.Route_set_paths(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_6 -> val_conv_6.ptr).toArray() : null);
50                 Reference.reachabilityFence(this);
51                 Reference.reachabilityFence(val);
52                 for (Path val_conv_6: val) { if (this != null) { this.ptrs_to.add(val_conv_6); }; };
53         }
54
55         /**
56          * The `route_params` parameter passed to [`find_route`].
57          * 
58          * This is used by `ChannelManager` to track information which may be required for retries.
59          * 
60          * Will be `None` for objects serialized with LDK versions prior to 0.0.117.
61          * 
62          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
63          */
64         @Nullable
65         public RouteParameters get_route_params() {
66                 long ret = bindings.Route_get_route_params(this.ptr);
67                 Reference.reachabilityFence(this);
68                 if (ret >= 0 && ret <= 4096) { return null; }
69                 org.ldk.structs.RouteParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RouteParameters(null, ret); }
70                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
71                 return ret_hu_conv;
72         }
73
74         /**
75          * The `route_params` parameter passed to [`find_route`].
76          * 
77          * This is used by `ChannelManager` to track information which may be required for retries.
78          * 
79          * Will be `None` for objects serialized with LDK versions prior to 0.0.117.
80          * 
81          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
82          */
83         public void set_route_params(@Nullable org.ldk.structs.RouteParameters val) {
84                 bindings.Route_set_route_params(this.ptr, val == null ? 0 : val.ptr);
85                 Reference.reachabilityFence(this);
86                 Reference.reachabilityFence(val);
87                 if (this != null) { this.ptrs_to.add(val); };
88         }
89
90         /**
91          * Constructs a new Route given each field
92          * 
93          * Note that route_params_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
94          */
95         public static Route of(Path[] paths_arg, @Nullable org.ldk.structs.RouteParameters route_params_arg) {
96                 long ret = bindings.Route_new(paths_arg != null ? Arrays.stream(paths_arg).mapToLong(paths_arg_conv_6 -> paths_arg_conv_6.ptr).toArray() : null, route_params_arg == null ? 0 : route_params_arg.ptr);
97                 Reference.reachabilityFence(paths_arg);
98                 Reference.reachabilityFence(route_params_arg);
99                 if (ret >= 0 && ret <= 4096) { return null; }
100                 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
101                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
102                 for (Path paths_arg_conv_6: paths_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(paths_arg_conv_6); }; };
103                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(route_params_arg); };
104                 return ret_hu_conv;
105         }
106
107         long clone_ptr() {
108                 long ret = bindings.Route_clone_ptr(this.ptr);
109                 Reference.reachabilityFence(this);
110                 return ret;
111         }
112
113         /**
114          * Creates a copy of the Route
115          */
116         public Route clone() {
117                 long ret = bindings.Route_clone(this.ptr);
118                 Reference.reachabilityFence(this);
119                 if (ret >= 0 && ret <= 4096) { return null; }
120                 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
121                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
122                 return ret_hu_conv;
123         }
124
125         /**
126          * Generates a non-cryptographic 64-bit hash of the Route.
127          */
128         public long hash() {
129                 long ret = bindings.Route_hash(this.ptr);
130                 Reference.reachabilityFence(this);
131                 return ret;
132         }
133
134         @Override public int hashCode() {
135                 return (int)this.hash();
136         }
137         /**
138          * Checks if two Routes contain equal inner contents.
139          * This ignores pointers and is_owned flags and looks at the values in fields.
140          * Two objects with NULL inner values will be considered "equal" here.
141          */
142         public boolean eq(org.ldk.structs.Route b) {
143                 boolean ret = bindings.Route_eq(this.ptr, b.ptr);
144                 Reference.reachabilityFence(this);
145                 Reference.reachabilityFence(b);
146                 if (this != null) { this.ptrs_to.add(b); };
147                 return ret;
148         }
149
150         @Override public boolean equals(Object o) {
151                 if (!(o instanceof Route)) return false;
152                 return this.eq((Route)o);
153         }
154         /**
155          * Returns the total amount of fees paid on this [`Route`].
156          * 
157          * For objects serialized with LDK 0.0.117 and after, this includes any extra payment made to
158          * the recipient, which can happen in excess of the amount passed to [`find_route`] via
159          * [`RouteParameters::final_value_msat`], if we had to reach the [`htlc_minimum_msat`] limits.
160          * 
161          * [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
162          */
163         public long get_total_fees() {
164                 long ret = bindings.Route_get_total_fees(this.ptr);
165                 Reference.reachabilityFence(this);
166                 return ret;
167         }
168
169         /**
170          * Returns the total amount paid on this [`Route`], excluding the fees.
171          * 
172          * Might be more than requested as part of the given [`RouteParameters::final_value_msat`] if
173          * we had to reach the [`htlc_minimum_msat`] limits.
174          * 
175          * [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
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 }