[Java] Update auto-generated Java bindings to LDK 0.0.121
[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  * Information used to route 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          * Information about the payee, such as their features and route hints for their channels.
25          */
26         public Payee get_payee() {
27                 long ret = bindings.PaymentParameters_get_payee(this.ptr);
28                 Reference.reachabilityFence(this);
29                 if (ret >= 0 && ret <= 4096) { return null; }
30                 org.ldk.structs.Payee ret_hu_conv = org.ldk.structs.Payee.constr_from_ptr(ret);
31                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
32                 return ret_hu_conv;
33         }
34
35         /**
36          * Information about the payee, such as their features and route hints for their channels.
37          */
38         public void set_payee(org.ldk.structs.Payee val) {
39                 bindings.PaymentParameters_set_payee(this.ptr, val.ptr);
40                 Reference.reachabilityFence(this);
41                 Reference.reachabilityFence(val);
42                 if (this != null) { this.ptrs_to.add(val); };
43         }
44
45         /**
46          * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
47          */
48         public Option_u64Z get_expiry_time() {
49                 long ret = bindings.PaymentParameters_get_expiry_time(this.ptr);
50                 Reference.reachabilityFence(this);
51                 if (ret >= 0 && ret <= 4096) { return null; }
52                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
53                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
54                 return ret_hu_conv;
55         }
56
57         /**
58          * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
59          */
60         public void set_expiry_time(org.ldk.structs.Option_u64Z val) {
61                 bindings.PaymentParameters_set_expiry_time(this.ptr, val.ptr);
62                 Reference.reachabilityFence(this);
63                 Reference.reachabilityFence(val);
64                 if (this != null) { this.ptrs_to.add(val); };
65         }
66
67         /**
68          * The maximum total CLTV delta we accept for the route.
69          * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
70          */
71         public int get_max_total_cltv_expiry_delta() {
72                 int ret = bindings.PaymentParameters_get_max_total_cltv_expiry_delta(this.ptr);
73                 Reference.reachabilityFence(this);
74                 return ret;
75         }
76
77         /**
78          * The maximum total CLTV delta we accept for the route.
79          * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
80          */
81         public void set_max_total_cltv_expiry_delta(int val) {
82                 bindings.PaymentParameters_set_max_total_cltv_expiry_delta(this.ptr, val);
83                 Reference.reachabilityFence(this);
84                 Reference.reachabilityFence(val);
85         }
86
87         /**
88          * The maximum number of paths that may be used by (MPP) payments.
89          * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
90          */
91         public byte get_max_path_count() {
92                 byte ret = bindings.PaymentParameters_get_max_path_count(this.ptr);
93                 Reference.reachabilityFence(this);
94                 return ret;
95         }
96
97         /**
98          * The maximum number of paths that may be used by (MPP) payments.
99          * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
100          */
101         public void set_max_path_count(byte val) {
102                 bindings.PaymentParameters_set_max_path_count(this.ptr, val);
103                 Reference.reachabilityFence(this);
104                 Reference.reachabilityFence(val);
105         }
106
107         /**
108          * Selects the maximum share of a channel's total capacity which will be sent over a channel,
109          * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
110          * a lower value prefers to send larger MPP parts, potentially saturating channels and
111          * increasing failure probability for those paths.
112          * 
113          * Note that this restriction will be relaxed during pathfinding after paths which meet this
114          * restriction have been found. While paths which meet this criteria will be searched for, it
115          * is ultimately up to the scorer to select them over other paths.
116          * 
117          * A value of 0 will allow payments up to and including a channel's total announced usable
118          * capacity, a value of one will only use up to half its capacity, two 1/4, etc.
119          * 
120          * Default value: 2
121          */
122         public byte get_max_channel_saturation_power_of_half() {
123                 byte ret = bindings.PaymentParameters_get_max_channel_saturation_power_of_half(this.ptr);
124                 Reference.reachabilityFence(this);
125                 return ret;
126         }
127
128         /**
129          * Selects the maximum share of a channel's total capacity which will be sent over a channel,
130          * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
131          * a lower value prefers to send larger MPP parts, potentially saturating channels and
132          * increasing failure probability for those paths.
133          * 
134          * Note that this restriction will be relaxed during pathfinding after paths which meet this
135          * restriction have been found. While paths which meet this criteria will be searched for, it
136          * is ultimately up to the scorer to select them over other paths.
137          * 
138          * A value of 0 will allow payments up to and including a channel's total announced usable
139          * capacity, a value of one will only use up to half its capacity, two 1/4, etc.
140          * 
141          * Default value: 2
142          */
143         public void set_max_channel_saturation_power_of_half(byte val) {
144                 bindings.PaymentParameters_set_max_channel_saturation_power_of_half(this.ptr, val);
145                 Reference.reachabilityFence(this);
146                 Reference.reachabilityFence(val);
147         }
148
149         /**
150          * A list of SCIDs which this payment was previously attempted over and which caused the
151          * payment to fail. Future attempts for the same payment shouldn't be relayed through any of
152          * these SCIDs.
153          * 
154          * Returns a copy of the field.
155          */
156         public long[] get_previously_failed_channels() {
157                 long[] ret = bindings.PaymentParameters_get_previously_failed_channels(this.ptr);
158                 Reference.reachabilityFence(this);
159                 return ret;
160         }
161
162         /**
163          * A list of SCIDs which this payment was previously attempted over and which caused the
164          * payment to fail. Future attempts for the same payment shouldn't be relayed through any of
165          * these SCIDs.
166          */
167         public void set_previously_failed_channels(long[] val) {
168                 bindings.PaymentParameters_set_previously_failed_channels(this.ptr, val);
169                 Reference.reachabilityFence(this);
170                 Reference.reachabilityFence(val);
171         }
172
173         /**
174          * A list of indices corresponding to blinded paths in [`Payee::Blinded::route_hints`] which this
175          * payment was previously attempted over and which caused the payment to fail. Future attempts
176          * for the same payment shouldn't be relayed through any of these blinded paths.
177          * 
178          * Returns a copy of the field.
179          */
180         public long[] get_previously_failed_blinded_path_idxs() {
181                 long[] ret = bindings.PaymentParameters_get_previously_failed_blinded_path_idxs(this.ptr);
182                 Reference.reachabilityFence(this);
183                 return ret;
184         }
185
186         /**
187          * A list of indices corresponding to blinded paths in [`Payee::Blinded::route_hints`] which this
188          * payment was previously attempted over and which caused the payment to fail. Future attempts
189          * for the same payment shouldn't be relayed through any of these blinded paths.
190          */
191         public void set_previously_failed_blinded_path_idxs(long[] val) {
192                 bindings.PaymentParameters_set_previously_failed_blinded_path_idxs(this.ptr, val);
193                 Reference.reachabilityFence(this);
194                 Reference.reachabilityFence(val);
195         }
196
197         /**
198          * Constructs a new PaymentParameters given each field
199          */
200         public static PaymentParameters of(org.ldk.structs.Payee payee_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, long[] previously_failed_blinded_path_idxs_arg) {
201                 long ret = bindings.PaymentParameters_new(payee_arg.ptr, 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, previously_failed_blinded_path_idxs_arg);
202                 Reference.reachabilityFence(payee_arg);
203                 Reference.reachabilityFence(expiry_time_arg);
204                 Reference.reachabilityFence(max_total_cltv_expiry_delta_arg);
205                 Reference.reachabilityFence(max_path_count_arg);
206                 Reference.reachabilityFence(max_channel_saturation_power_of_half_arg);
207                 Reference.reachabilityFence(previously_failed_channels_arg);
208                 Reference.reachabilityFence(previously_failed_blinded_path_idxs_arg);
209                 if (ret >= 0 && ret <= 4096) { return null; }
210                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
211                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
212                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payee_arg); };
213                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(expiry_time_arg); };
214                 return ret_hu_conv;
215         }
216
217         long clone_ptr() {
218                 long ret = bindings.PaymentParameters_clone_ptr(this.ptr);
219                 Reference.reachabilityFence(this);
220                 return ret;
221         }
222
223         /**
224          * Creates a copy of the PaymentParameters
225          */
226         public PaymentParameters clone() {
227                 long ret = bindings.PaymentParameters_clone(this.ptr);
228                 Reference.reachabilityFence(this);
229                 if (ret >= 0 && ret <= 4096) { return null; }
230                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
231                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
232                 return ret_hu_conv;
233         }
234
235         /**
236          * Generates a non-cryptographic 64-bit hash of the PaymentParameters.
237          */
238         public long hash() {
239                 long ret = bindings.PaymentParameters_hash(this.ptr);
240                 Reference.reachabilityFence(this);
241                 return ret;
242         }
243
244         @Override public int hashCode() {
245                 return (int)this.hash();
246         }
247         /**
248          * Checks if two PaymentParameterss contain equal inner contents.
249          * This ignores pointers and is_owned flags and looks at the values in fields.
250          * Two objects with NULL inner values will be considered "equal" here.
251          */
252         public boolean eq(org.ldk.structs.PaymentParameters b) {
253                 boolean ret = bindings.PaymentParameters_eq(this.ptr, b == null ? 0 : b.ptr);
254                 Reference.reachabilityFence(this);
255                 Reference.reachabilityFence(b);
256                 if (this != null) { this.ptrs_to.add(b); };
257                 return ret;
258         }
259
260         @Override public boolean equals(Object o) {
261                 if (!(o instanceof PaymentParameters)) return false;
262                 return this.eq((PaymentParameters)o);
263         }
264         /**
265          * Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
266          */
267         public byte[] write() {
268                 byte[] ret = bindings.PaymentParameters_write(this.ptr);
269                 Reference.reachabilityFence(this);
270                 return ret;
271         }
272
273         /**
274          * Read a PaymentParameters from a byte array, created by PaymentParameters_write
275          */
276         public static Result_PaymentParametersDecodeErrorZ read(byte[] ser, int arg) {
277                 long ret = bindings.PaymentParameters_read(ser, arg);
278                 Reference.reachabilityFence(ser);
279                 Reference.reachabilityFence(arg);
280                 if (ret >= 0 && ret <= 4096) { return null; }
281                 Result_PaymentParametersDecodeErrorZ ret_hu_conv = Result_PaymentParametersDecodeErrorZ.constr_from_ptr(ret);
282                 return ret_hu_conv;
283         }
284
285         /**
286          * Creates a payee with the node id of the given `pubkey`.
287          * 
288          * The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
289          * provided.
290          */
291         public static PaymentParameters from_node_id(byte[] payee_pubkey, int final_cltv_expiry_delta) {
292                 long ret = bindings.PaymentParameters_from_node_id(InternalUtils.check_arr_len(payee_pubkey, 33), final_cltv_expiry_delta);
293                 Reference.reachabilityFence(payee_pubkey);
294                 Reference.reachabilityFence(final_cltv_expiry_delta);
295                 if (ret >= 0 && ret <= 4096) { return null; }
296                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
297                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
298                 return ret_hu_conv;
299         }
300
301         /**
302          * Creates a payee with the node id of the given `pubkey` to use for keysend payments.
303          * 
304          * The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
305          * provided.
306          * 
307          * Note that MPP keysend is not widely supported yet. The `allow_mpp` lets you choose
308          * whether your router will be allowed to find a multi-part route for this payment. If you
309          * set `allow_mpp` to true, you should ensure a payment secret is set on send, likely via
310          * [`RecipientOnionFields::secret_only`].
311          * 
312          * [`RecipientOnionFields::secret_only`]: crate::ln::channelmanager::RecipientOnionFields::secret_only
313          */
314         public static PaymentParameters for_keysend(byte[] payee_pubkey, int final_cltv_expiry_delta, boolean allow_mpp) {
315                 long ret = bindings.PaymentParameters_for_keysend(InternalUtils.check_arr_len(payee_pubkey, 33), final_cltv_expiry_delta, allow_mpp);
316                 Reference.reachabilityFence(payee_pubkey);
317                 Reference.reachabilityFence(final_cltv_expiry_delta);
318                 Reference.reachabilityFence(allow_mpp);
319                 if (ret >= 0 && ret <= 4096) { return null; }
320                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
321                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
322                 return ret_hu_conv;
323         }
324
325         /**
326          * Creates parameters for paying to a blinded payee from the provided invoice. Sets
327          * [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and
328          * [`PaymentParameters::expiry_time`].
329          */
330         public static PaymentParameters from_bolt12_invoice(org.ldk.structs.Bolt12Invoice invoice) {
331                 long ret = bindings.PaymentParameters_from_bolt12_invoice(invoice == null ? 0 : invoice.ptr);
332                 Reference.reachabilityFence(invoice);
333                 if (ret >= 0 && ret <= 4096) { return null; }
334                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
335                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
336                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(invoice); };
337                 return ret_hu_conv;
338         }
339
340         /**
341          * Creates parameters for paying to a blinded payee from the provided blinded route hints.
342          */
343         public static PaymentParameters blinded(TwoTuple_BlindedPayInfoBlindedPathZ[] blinded_route_hints) {
344                 long ret = bindings.PaymentParameters_blinded(blinded_route_hints != null ? Arrays.stream(blinded_route_hints).mapToLong(blinded_route_hints_conv_37 -> blinded_route_hints_conv_37 != null ? blinded_route_hints_conv_37.ptr : 0).toArray() : null);
345                 Reference.reachabilityFence(blinded_route_hints);
346                 if (ret >= 0 && ret <= 4096) { return null; }
347                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
348                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
349                 return ret_hu_conv;
350         }
351
352 }