6d83caf99fc0dc7fd5654bacc4b958033086713b
[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          * Constructs a new PaymentParameters given each field
175          */
176         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) {
177                 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);
178                 Reference.reachabilityFence(payee_arg);
179                 Reference.reachabilityFence(expiry_time_arg);
180                 Reference.reachabilityFence(max_total_cltv_expiry_delta_arg);
181                 Reference.reachabilityFence(max_path_count_arg);
182                 Reference.reachabilityFence(max_channel_saturation_power_of_half_arg);
183                 Reference.reachabilityFence(previously_failed_channels_arg);
184                 if (ret >= 0 && ret <= 4096) { return null; }
185                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
186                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
187                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(payee_arg); };
188                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(expiry_time_arg); };
189                 return ret_hu_conv;
190         }
191
192         long clone_ptr() {
193                 long ret = bindings.PaymentParameters_clone_ptr(this.ptr);
194                 Reference.reachabilityFence(this);
195                 return ret;
196         }
197
198         /**
199          * Creates a copy of the PaymentParameters
200          */
201         public PaymentParameters clone() {
202                 long ret = bindings.PaymentParameters_clone(this.ptr);
203                 Reference.reachabilityFence(this);
204                 if (ret >= 0 && ret <= 4096) { return null; }
205                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
206                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
207                 return ret_hu_conv;
208         }
209
210         /**
211          * Generates a non-cryptographic 64-bit hash of the PaymentParameters.
212          */
213         public long hash() {
214                 long ret = bindings.PaymentParameters_hash(this.ptr);
215                 Reference.reachabilityFence(this);
216                 return ret;
217         }
218
219         @Override public int hashCode() {
220                 return (int)this.hash();
221         }
222         /**
223          * Checks if two PaymentParameterss contain equal inner contents.
224          * This ignores pointers and is_owned flags and looks at the values in fields.
225          * Two objects with NULL inner values will be considered "equal" here.
226          */
227         public boolean eq(org.ldk.structs.PaymentParameters b) {
228                 boolean ret = bindings.PaymentParameters_eq(this.ptr, b == null ? 0 : b.ptr);
229                 Reference.reachabilityFence(this);
230                 Reference.reachabilityFence(b);
231                 if (this != null) { this.ptrs_to.add(b); };
232                 return ret;
233         }
234
235         @Override public boolean equals(Object o) {
236                 if (!(o instanceof PaymentParameters)) return false;
237                 return this.eq((PaymentParameters)o);
238         }
239         /**
240          * Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
241          */
242         public byte[] write() {
243                 byte[] ret = bindings.PaymentParameters_write(this.ptr);
244                 Reference.reachabilityFence(this);
245                 return ret;
246         }
247
248         /**
249          * Read a PaymentParameters from a byte array, created by PaymentParameters_write
250          */
251         public static Result_PaymentParametersDecodeErrorZ read(byte[] ser, int arg) {
252                 long ret = bindings.PaymentParameters_read(ser, arg);
253                 Reference.reachabilityFence(ser);
254                 Reference.reachabilityFence(arg);
255                 if (ret >= 0 && ret <= 4096) { return null; }
256                 Result_PaymentParametersDecodeErrorZ ret_hu_conv = Result_PaymentParametersDecodeErrorZ.constr_from_ptr(ret);
257                 return ret_hu_conv;
258         }
259
260         /**
261          * Creates a payee with the node id of the given `pubkey`.
262          * 
263          * The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
264          * provided.
265          */
266         public static PaymentParameters from_node_id(byte[] payee_pubkey, int final_cltv_expiry_delta) {
267                 long ret = bindings.PaymentParameters_from_node_id(InternalUtils.check_arr_len(payee_pubkey, 33), final_cltv_expiry_delta);
268                 Reference.reachabilityFence(payee_pubkey);
269                 Reference.reachabilityFence(final_cltv_expiry_delta);
270                 if (ret >= 0 && ret <= 4096) { return null; }
271                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
272                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
273                 return ret_hu_conv;
274         }
275
276         /**
277          * Creates a payee with the node id of the given `pubkey` to use for keysend payments.
278          * 
279          * The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
280          * provided.
281          * 
282          * Note that MPP keysend is not widely supported yet. The `allow_mpp` lets you choose
283          * whether your router will be allowed to find a multi-part route for this payment. If you
284          * set `allow_mpp` to true, you should ensure a payment secret is set on send, likely via
285          * [`RecipientOnionFields::secret_only`].
286          * 
287          * [`RecipientOnionFields::secret_only`]: crate::ln::channelmanager::RecipientOnionFields::secret_only
288          */
289         public static PaymentParameters for_keysend(byte[] payee_pubkey, int final_cltv_expiry_delta, boolean allow_mpp) {
290                 long ret = bindings.PaymentParameters_for_keysend(InternalUtils.check_arr_len(payee_pubkey, 33), final_cltv_expiry_delta, allow_mpp);
291                 Reference.reachabilityFence(payee_pubkey);
292                 Reference.reachabilityFence(final_cltv_expiry_delta);
293                 Reference.reachabilityFence(allow_mpp);
294                 if (ret >= 0 && ret <= 4096) { return null; }
295                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
296                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
297                 return ret_hu_conv;
298         }
299
300         /**
301          * Creates parameters for paying to a blinded payee from the provided invoice. Sets
302          * [`Payee::Blinded::route_hints`], [`Payee::Blinded::features`], and
303          * [`PaymentParameters::expiry_time`].
304          */
305         public static PaymentParameters from_bolt12_invoice(org.ldk.structs.Bolt12Invoice invoice) {
306                 long ret = bindings.PaymentParameters_from_bolt12_invoice(invoice == null ? 0 : invoice.ptr);
307                 Reference.reachabilityFence(invoice);
308                 if (ret >= 0 && ret <= 4096) { return null; }
309                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
310                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
311                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(invoice); };
312                 return ret_hu_conv;
313         }
314
315         /**
316          * Creates parameters for paying to a blinded payee from the provided blinded route hints.
317          */
318         public static PaymentParameters blinded(TwoTuple_BlindedPayInfoBlindedPathZ[] blinded_route_hints) {
319                 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);
320                 Reference.reachabilityFence(blinded_route_hints);
321                 if (ret >= 0 && ret <= 4096) { return null; }
322                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
323                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
324                 return ret_hu_conv;
325         }
326
327 }