[Java] Update auto-generated Java bindings for 0.0.116
[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 == 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); }; };
53         }
54
55         /**
56          * The `payment_params` parameter passed via [`RouteParameters`] to [`find_route`].
57          * 
58          * This is used by `ChannelManager` to track information which may be required for retries.
59          * 
60          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
61          */
62         @Nullable
63         public PaymentParameters get_payment_params() {
64                 long ret = bindings.Route_get_payment_params(this.ptr);
65                 Reference.reachabilityFence(this);
66                 if (ret >= 0 && ret <= 4096) { return null; }
67                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
68                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
69                 return ret_hu_conv;
70         }
71
72         /**
73          * The `payment_params` parameter passed via [`RouteParameters`] to [`find_route`].
74          * 
75          * This is used by `ChannelManager` to track information which may be required for retries.
76          * 
77          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
78          */
79         public void set_payment_params(@Nullable org.ldk.structs.PaymentParameters val) {
80                 bindings.Route_set_payment_params(this.ptr, val == null ? 0 : val.ptr);
81                 Reference.reachabilityFence(this);
82                 Reference.reachabilityFence(val);
83                 if (this != null) { this.ptrs_to.add(val); };
84         }
85
86         /**
87          * Constructs a new Route given each field
88          */
89         public static Route of(Path[] paths_arg, org.ldk.structs.PaymentParameters payment_params_arg) {
90                 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, payment_params_arg == null ? 0 : payment_params_arg.ptr);
91                 Reference.reachabilityFence(paths_arg);
92                 Reference.reachabilityFence(payment_params_arg);
93                 if (ret >= 0 && ret <= 4096) { return null; }
94                 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
95                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
96                 for (Path paths_arg_conv_6: paths_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(paths_arg_conv_6); }; };
97                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payment_params_arg); };
98                 return ret_hu_conv;
99         }
100
101         long clone_ptr() {
102                 long ret = bindings.Route_clone_ptr(this.ptr);
103                 Reference.reachabilityFence(this);
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                 Reference.reachabilityFence(this);
113                 if (ret >= 0 && ret <= 4096) { return null; }
114                 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
115                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
116                 return ret_hu_conv;
117         }
118
119         /**
120          * Generates a non-cryptographic 64-bit hash of the Route.
121          */
122         public long hash() {
123                 long ret = bindings.Route_hash(this.ptr);
124                 Reference.reachabilityFence(this);
125                 return ret;
126         }
127
128         @Override public int hashCode() {
129                 return (int)this.hash();
130         }
131         /**
132          * Checks if two Routes contain equal inner contents.
133          * This ignores pointers and is_owned flags and looks at the values in fields.
134          * Two objects with NULL inner values will be considered "equal" here.
135          */
136         public boolean eq(org.ldk.structs.Route b) {
137                 boolean ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr);
138                 Reference.reachabilityFence(this);
139                 Reference.reachabilityFence(b);
140                 if (this != null) { this.ptrs_to.add(b); };
141                 return ret;
142         }
143
144         @Override public boolean equals(Object o) {
145                 if (!(o instanceof Route)) return false;
146                 return this.eq((Route)o);
147         }
148         /**
149          * Returns the total amount of fees paid on this [`Route`].
150          * 
151          * This doesn't include any extra payment made to the recipient, which can happen in excess of
152          * the amount passed to [`find_route`]'s `route_params.final_value_msat`.
153          */
154         public long get_total_fees() {
155                 long ret = bindings.Route_get_total_fees(this.ptr);
156                 Reference.reachabilityFence(this);
157                 return ret;
158         }
159
160         /**
161          * Returns the total amount paid on this [`Route`], excluding the fees. Might be more than
162          * requested if we had to reach htlc_minimum_msat.
163          */
164         public long get_total_amount() {
165                 long ret = bindings.Route_get_total_amount(this.ptr);
166                 Reference.reachabilityFence(this);
167                 return ret;
168         }
169
170         /**
171          * Serialize the Route object into a byte array which can be read by Route_read
172          */
173         public byte[] write() {
174                 byte[] ret = bindings.Route_write(this.ptr);
175                 Reference.reachabilityFence(this);
176                 return ret;
177         }
178
179         /**
180          * Read a Route from a byte array, created by Route_write
181          */
182         public static Result_RouteDecodeErrorZ read(byte[] ser) {
183                 long ret = bindings.Route_read(ser);
184                 Reference.reachabilityFence(ser);
185                 if (ret >= 0 && ret <= 4096) { return null; }
186                 Result_RouteDecodeErrorZ ret_hu_conv = Result_RouteDecodeErrorZ.constr_from_ptr(ret);
187                 return ret_hu_conv;
188         }
189
190 }