[Java] Update auto-generated Java bindings
[ldk-java] / src / main / java / org / ldk / structs / PaymentParameters.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  * The recipient of a payment.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class PaymentParameters extends CommonBase {
16         PaymentParameters(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.PaymentParameters_free(ptr); }
21         }
22
23         /**
24          * The node id of the payee.
25          */
26         public byte[] get_payee_pubkey() {
27                 byte[] ret = bindings.PaymentParameters_get_payee_pubkey(this.ptr);
28                 Reference.reachabilityFence(this);
29                 return ret;
30         }
31
32         /**
33          * The node id of the payee.
34          */
35         public void set_payee_pubkey(byte[] val) {
36                 bindings.PaymentParameters_set_payee_pubkey(this.ptr, InternalUtils.check_arr_len(val, 33));
37                 Reference.reachabilityFence(this);
38                 Reference.reachabilityFence(val);
39         }
40
41         /**
42          * Features supported by the payee.
43          * 
44          * May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
45          * does not contain any features.
46          * 
47          * [`for_keysend`]: Self::for_keysend
48          * 
49          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
50          */
51         @Nullable
52         public InvoiceFeatures get_features() {
53                 long ret = bindings.PaymentParameters_get_features(this.ptr);
54                 Reference.reachabilityFence(this);
55                 if (ret >= 0 && ret <= 4096) { return null; }
56                 org.ldk.structs.InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InvoiceFeatures(null, ret); }
57                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
58                 return ret_hu_conv;
59         }
60
61         /**
62          * Features supported by the payee.
63          * 
64          * May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
65          * does not contain any features.
66          * 
67          * [`for_keysend`]: Self::for_keysend
68          * 
69          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
70          */
71         public void set_features(@Nullable org.ldk.structs.InvoiceFeatures val) {
72                 bindings.PaymentParameters_set_features(this.ptr, val == null ? 0 : val.ptr);
73                 Reference.reachabilityFence(this);
74                 Reference.reachabilityFence(val);
75                 if (this != null) { this.ptrs_to.add(val); };
76         }
77
78         /**
79          * Hints for routing to the payee, containing channels connecting the payee to public nodes.
80          */
81         public RouteHint[] get_route_hints() {
82                 long[] ret = bindings.PaymentParameters_get_route_hints(this.ptr);
83                 Reference.reachabilityFence(this);
84                 int ret_conv_11_len = ret.length;
85                 RouteHint[] ret_conv_11_arr = new RouteHint[ret_conv_11_len];
86                 for (int l = 0; l < ret_conv_11_len; l++) {
87                         long ret_conv_11 = ret[l];
88                         org.ldk.structs.RouteHint ret_conv_11_hu_conv = null; if (ret_conv_11 < 0 || ret_conv_11 > 4096) { ret_conv_11_hu_conv = new org.ldk.structs.RouteHint(null, ret_conv_11); }
89                         if (ret_conv_11_hu_conv != null) { ret_conv_11_hu_conv.ptrs_to.add(this); };
90                         ret_conv_11_arr[l] = ret_conv_11_hu_conv;
91                 }
92                 return ret_conv_11_arr;
93         }
94
95         /**
96          * Hints for routing to the payee, containing channels connecting the payee to public nodes.
97          */
98         public void set_route_hints(RouteHint[] val) {
99                 bindings.PaymentParameters_set_route_hints(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_11 -> val_conv_11 == null ? 0 : val_conv_11.ptr).toArray() : null);
100                 Reference.reachabilityFence(this);
101                 Reference.reachabilityFence(val);
102                 for (RouteHint val_conv_11: val) { if (this != null) { this.ptrs_to.add(val_conv_11); }; };
103         }
104
105         /**
106          * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
107          */
108         public Option_u64Z get_expiry_time() {
109                 long ret = bindings.PaymentParameters_get_expiry_time(this.ptr);
110                 Reference.reachabilityFence(this);
111                 if (ret >= 0 && ret <= 4096) { return null; }
112                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
113                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
114                 return ret_hu_conv;
115         }
116
117         /**
118          * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
119          */
120         public void set_expiry_time(org.ldk.structs.Option_u64Z val) {
121                 bindings.PaymentParameters_set_expiry_time(this.ptr, val.ptr);
122                 Reference.reachabilityFence(this);
123                 Reference.reachabilityFence(val);
124                 if (this != null) { this.ptrs_to.add(val); };
125         }
126
127         /**
128          * The maximum total CLTV delta we accept for the route.
129          * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
130          */
131         public int get_max_total_cltv_expiry_delta() {
132                 int ret = bindings.PaymentParameters_get_max_total_cltv_expiry_delta(this.ptr);
133                 Reference.reachabilityFence(this);
134                 return ret;
135         }
136
137         /**
138          * The maximum total CLTV delta we accept for the route.
139          * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
140          */
141         public void set_max_total_cltv_expiry_delta(int val) {
142                 bindings.PaymentParameters_set_max_total_cltv_expiry_delta(this.ptr, val);
143                 Reference.reachabilityFence(this);
144                 Reference.reachabilityFence(val);
145         }
146
147         /**
148          * The maximum number of paths that may be used by (MPP) payments.
149          * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
150          */
151         public byte get_max_path_count() {
152                 byte ret = bindings.PaymentParameters_get_max_path_count(this.ptr);
153                 Reference.reachabilityFence(this);
154                 return ret;
155         }
156
157         /**
158          * The maximum number of paths that may be used by (MPP) payments.
159          * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
160          */
161         public void set_max_path_count(byte val) {
162                 bindings.PaymentParameters_set_max_path_count(this.ptr, val);
163                 Reference.reachabilityFence(this);
164                 Reference.reachabilityFence(val);
165         }
166
167         /**
168          * Selects the maximum share of a channel's total capacity which will be sent over a channel,
169          * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
170          * a lower value prefers to send larger MPP parts, potentially saturating channels and
171          * increasing failure probability for those paths.
172          * 
173          * Note that this restriction will be relaxed during pathfinding after paths which meet this
174          * restriction have been found. While paths which meet this criteria will be searched for, it
175          * is ultimately up to the scorer to select them over other paths.
176          * 
177          * A value of 0 will allow payments up to and including a channel's total announced usable
178          * capacity, a value of one will only use up to half its capacity, two 1/4, etc.
179          * 
180          * Default value: 2
181          */
182         public byte get_max_channel_saturation_power_of_half() {
183                 byte ret = bindings.PaymentParameters_get_max_channel_saturation_power_of_half(this.ptr);
184                 Reference.reachabilityFence(this);
185                 return ret;
186         }
187
188         /**
189          * Selects the maximum share of a channel's total capacity which will be sent over a channel,
190          * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
191          * a lower value prefers to send larger MPP parts, potentially saturating channels and
192          * increasing failure probability for those paths.
193          * 
194          * Note that this restriction will be relaxed during pathfinding after paths which meet this
195          * restriction have been found. While paths which meet this criteria will be searched for, it
196          * is ultimately up to the scorer to select them over other paths.
197          * 
198          * A value of 0 will allow payments up to and including a channel's total announced usable
199          * capacity, a value of one will only use up to half its capacity, two 1/4, etc.
200          * 
201          * Default value: 2
202          */
203         public void set_max_channel_saturation_power_of_half(byte val) {
204                 bindings.PaymentParameters_set_max_channel_saturation_power_of_half(this.ptr, val);
205                 Reference.reachabilityFence(this);
206                 Reference.reachabilityFence(val);
207         }
208
209         /**
210          * A list of SCIDs which this payment was previously attempted over and which caused the
211          * payment to fail. Future attempts for the same payment shouldn't be relayed through any of
212          * these SCIDs.
213          * 
214          * Returns a copy of the field.
215          */
216         public long[] get_previously_failed_channels() {
217                 long[] ret = bindings.PaymentParameters_get_previously_failed_channels(this.ptr);
218                 Reference.reachabilityFence(this);
219                 return ret;
220         }
221
222         /**
223          * A list of SCIDs which this payment was previously attempted over and which caused the
224          * payment to fail. Future attempts for the same payment shouldn't be relayed through any of
225          * these SCIDs.
226          */
227         public void set_previously_failed_channels(long[] val) {
228                 bindings.PaymentParameters_set_previously_failed_channels(this.ptr, val);
229                 Reference.reachabilityFence(this);
230                 Reference.reachabilityFence(val);
231         }
232
233         /**
234          * The minimum CLTV delta at the end of the route. This value must not be zero.
235          */
236         public int get_final_cltv_expiry_delta() {
237                 int ret = bindings.PaymentParameters_get_final_cltv_expiry_delta(this.ptr);
238                 Reference.reachabilityFence(this);
239                 return ret;
240         }
241
242         /**
243          * The minimum CLTV delta at the end of the route. This value must not be zero.
244          */
245         public void set_final_cltv_expiry_delta(int val) {
246                 bindings.PaymentParameters_set_final_cltv_expiry_delta(this.ptr, val);
247                 Reference.reachabilityFence(this);
248                 Reference.reachabilityFence(val);
249         }
250
251         /**
252          * Constructs a new PaymentParameters given each field
253          */
254         public static PaymentParameters of(byte[] payee_pubkey_arg, org.ldk.structs.InvoiceFeatures features_arg, RouteHint[] route_hints_arg, org.ldk.structs.Option_u64Z expiry_time_arg, int max_total_cltv_expiry_delta_arg, byte max_path_count_arg, byte max_channel_saturation_power_of_half_arg, long[] previously_failed_channels_arg, int final_cltv_expiry_delta_arg) {
255                 long ret = bindings.PaymentParameters_new(InternalUtils.check_arr_len(payee_pubkey_arg, 33), features_arg == null ? 0 : features_arg.ptr, route_hints_arg != null ? Arrays.stream(route_hints_arg).mapToLong(route_hints_arg_conv_11 -> route_hints_arg_conv_11 == null ? 0 : route_hints_arg_conv_11.ptr).toArray() : null, expiry_time_arg.ptr, max_total_cltv_expiry_delta_arg, max_path_count_arg, max_channel_saturation_power_of_half_arg, previously_failed_channels_arg, final_cltv_expiry_delta_arg);
256                 Reference.reachabilityFence(payee_pubkey_arg);
257                 Reference.reachabilityFence(features_arg);
258                 Reference.reachabilityFence(route_hints_arg);
259                 Reference.reachabilityFence(expiry_time_arg);
260                 Reference.reachabilityFence(max_total_cltv_expiry_delta_arg);
261                 Reference.reachabilityFence(max_path_count_arg);
262                 Reference.reachabilityFence(max_channel_saturation_power_of_half_arg);
263                 Reference.reachabilityFence(previously_failed_channels_arg);
264                 Reference.reachabilityFence(final_cltv_expiry_delta_arg);
265                 if (ret >= 0 && ret <= 4096) { return null; }
266                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
267                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
268                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(features_arg); };
269                 for (RouteHint route_hints_arg_conv_11: route_hints_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(route_hints_arg_conv_11); }; };
270                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(expiry_time_arg); };
271                 return ret_hu_conv;
272         }
273
274         long clone_ptr() {
275                 long ret = bindings.PaymentParameters_clone_ptr(this.ptr);
276                 Reference.reachabilityFence(this);
277                 return ret;
278         }
279
280         /**
281          * Creates a copy of the PaymentParameters
282          */
283         public PaymentParameters clone() {
284                 long ret = bindings.PaymentParameters_clone(this.ptr);
285                 Reference.reachabilityFence(this);
286                 if (ret >= 0 && ret <= 4096) { return null; }
287                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
288                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
289                 return ret_hu_conv;
290         }
291
292         /**
293          * Checks if two PaymentParameterss contain equal inner contents.
294          */
295         public long hash() {
296                 long ret = bindings.PaymentParameters_hash(this.ptr);
297                 Reference.reachabilityFence(this);
298                 return ret;
299         }
300
301         @Override public int hashCode() {
302                 return (int)this.hash();
303         }
304         /**
305          * Checks if two PaymentParameterss contain equal inner contents.
306          * This ignores pointers and is_owned flags and looks at the values in fields.
307          * Two objects with NULL inner values will be considered "equal" here.
308          */
309         public boolean eq(org.ldk.structs.PaymentParameters b) {
310                 boolean ret = bindings.PaymentParameters_eq(this.ptr, b == null ? 0 : b.ptr);
311                 Reference.reachabilityFence(this);
312                 Reference.reachabilityFence(b);
313                 if (this != null) { this.ptrs_to.add(b); };
314                 return ret;
315         }
316
317         @Override public boolean equals(Object o) {
318                 if (!(o instanceof PaymentParameters)) return false;
319                 return this.eq((PaymentParameters)o);
320         }
321         /**
322          * Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
323          */
324         public byte[] write() {
325                 byte[] ret = bindings.PaymentParameters_write(this.ptr);
326                 Reference.reachabilityFence(this);
327                 return ret;
328         }
329
330         /**
331          * Read a PaymentParameters from a byte array, created by PaymentParameters_write
332          */
333         public static Result_PaymentParametersDecodeErrorZ read(byte[] ser, int arg) {
334                 long ret = bindings.PaymentParameters_read(ser, arg);
335                 Reference.reachabilityFence(ser);
336                 Reference.reachabilityFence(arg);
337                 if (ret >= 0 && ret <= 4096) { return null; }
338                 Result_PaymentParametersDecodeErrorZ ret_hu_conv = Result_PaymentParametersDecodeErrorZ.constr_from_ptr(ret);
339                 return ret_hu_conv;
340         }
341
342         /**
343          * Creates a payee with the node id of the given `pubkey`.
344          * 
345          * The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
346          * provided.
347          */
348         public static PaymentParameters from_node_id(byte[] payee_pubkey, int final_cltv_expiry_delta) {
349                 long ret = bindings.PaymentParameters_from_node_id(InternalUtils.check_arr_len(payee_pubkey, 33), final_cltv_expiry_delta);
350                 Reference.reachabilityFence(payee_pubkey);
351                 Reference.reachabilityFence(final_cltv_expiry_delta);
352                 if (ret >= 0 && ret <= 4096) { return null; }
353                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
354                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
355                 return ret_hu_conv;
356         }
357
358         /**
359          * Creates a payee with the node id of the given `pubkey` to use for keysend payments.
360          * 
361          * The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
362          * provided.
363          */
364         public static PaymentParameters for_keysend(byte[] payee_pubkey, int final_cltv_expiry_delta) {
365                 long ret = bindings.PaymentParameters_for_keysend(InternalUtils.check_arr_len(payee_pubkey, 33), final_cltv_expiry_delta);
366                 Reference.reachabilityFence(payee_pubkey);
367                 Reference.reachabilityFence(final_cltv_expiry_delta);
368                 if (ret >= 0 && ret <= 4096) { return null; }
369                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
370                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
371                 return ret_hu_conv;
372         }
373
374 }