1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
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.
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 {
21 if (ptr != 0) { bindings.Route_free(ptr); }
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
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;
40 return ret_conv_6_arr;
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
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 == null ? 0 : 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); }; };
56 * The `route_params` parameter passed to [`find_route`].
58 * This is used by `ChannelManager` to track information which may be required for retries.
60 * Will be `None` for objects serialized with LDK versions prior to 0.0.117.
62 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
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); };
75 * The `route_params` parameter passed to [`find_route`].
77 * This is used by `ChannelManager` to track information which may be required for retries.
79 * Will be `None` for objects serialized with LDK versions prior to 0.0.117.
81 * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
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); };
91 * Constructs a new Route given each field
93 * Note that route_params_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
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 == null ? 0 : 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); };
108 long ret = bindings.Route_clone_ptr(this.ptr);
109 Reference.reachabilityFence(this);
114 * Creates a copy of the Route
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); };
126 * Generates a non-cryptographic 64-bit hash of the Route.
129 long ret = bindings.Route_hash(this.ptr);
130 Reference.reachabilityFence(this);
134 @Override public int hashCode() {
135 return (int)this.hash();
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.
142 public boolean eq(org.ldk.structs.Route b) {
143 boolean ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr);
144 Reference.reachabilityFence(this);
145 Reference.reachabilityFence(b);
146 if (this != null) { this.ptrs_to.add(b); };
150 @Override public boolean equals(Object o) {
151 if (!(o instanceof Route)) return false;
152 return this.eq((Route)o);
155 * Returns the total amount of fees paid on this [`Route`].
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.
161 * [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
163 public long get_total_fees() {
164 long ret = bindings.Route_get_total_fees(this.ptr);
165 Reference.reachabilityFence(this);
170 * Returns the total amount paid on this [`Route`], excluding the fees.
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.
175 * [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
177 public long get_total_amount() {
178 long ret = bindings.Route_get_total_amount(this.ptr);
179 Reference.reachabilityFence(this);
184 * Serialize the Route object into a byte array which can be read by Route_read
186 public byte[] write() {
187 byte[] ret = bindings.Route_write(this.ptr);
188 Reference.reachabilityFence(this);
193 * Read a Route from a byte array, created by Route_write
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);