8e3efc9d013f4eb22a92d400c393894a2ad5da8d
[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                 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 InvoiceFeatures val) {
72                 bindings.PaymentParameters_set_features(this.ptr, val == null ? 0 : val.ptr & ~1);
73                 Reference.reachabilityFence(this);
74                 Reference.reachabilityFence(val);
75         }
76
77         /**
78          * Hints for routing to the payee, containing channels connecting the payee to public nodes.
79          */
80         public RouteHint[] get_route_hints() {
81                 long[] ret = bindings.PaymentParameters_get_route_hints(this.ptr);
82                 Reference.reachabilityFence(this);
83                 int ret_conv_11_len = ret.length;
84                 RouteHint[] ret_conv_11_arr = new RouteHint[ret_conv_11_len];
85                 for (int l = 0; l < ret_conv_11_len; l++) {
86                         long ret_conv_11 = ret[l];
87                         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); }
88                         ret_conv_11_hu_conv.ptrs_to.add(this);
89                         ret_conv_11_arr[l] = ret_conv_11_hu_conv;
90                 }
91                 return ret_conv_11_arr;
92         }
93
94         /**
95          * Hints for routing to the payee, containing channels connecting the payee to public nodes.
96          */
97         public void set_route_hints(RouteHint[] val) {
98                 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 & ~1).toArray() : null);
99                 Reference.reachabilityFence(this);
100                 Reference.reachabilityFence(val);
101         }
102
103         /**
104          * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
105          */
106         public Option_u64Z get_expiry_time() {
107                 long ret = bindings.PaymentParameters_get_expiry_time(this.ptr);
108                 Reference.reachabilityFence(this);
109                 if (ret >= 0 && ret <= 4096) { return null; }
110                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
111                 ret_hu_conv.ptrs_to.add(this);
112                 return ret_hu_conv;
113         }
114
115         /**
116          * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
117          */
118         public void set_expiry_time(Option_u64Z val) {
119                 bindings.PaymentParameters_set_expiry_time(this.ptr, val.ptr);
120                 Reference.reachabilityFence(this);
121                 Reference.reachabilityFence(val);
122         }
123
124         /**
125          * The maximum total CLTV delta we accept for the route.
126          * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
127          */
128         public int get_max_total_cltv_expiry_delta() {
129                 int ret = bindings.PaymentParameters_get_max_total_cltv_expiry_delta(this.ptr);
130                 Reference.reachabilityFence(this);
131                 return ret;
132         }
133
134         /**
135          * The maximum total CLTV delta we accept for the route.
136          * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
137          */
138         public void set_max_total_cltv_expiry_delta(int val) {
139                 bindings.PaymentParameters_set_max_total_cltv_expiry_delta(this.ptr, val);
140                 Reference.reachabilityFence(this);
141                 Reference.reachabilityFence(val);
142         }
143
144         /**
145          * The maximum number of paths that may be used by (MPP) payments.
146          * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
147          */
148         public byte get_max_path_count() {
149                 byte ret = bindings.PaymentParameters_get_max_path_count(this.ptr);
150                 Reference.reachabilityFence(this);
151                 return ret;
152         }
153
154         /**
155          * The maximum number of paths that may be used by (MPP) payments.
156          * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
157          */
158         public void set_max_path_count(byte val) {
159                 bindings.PaymentParameters_set_max_path_count(this.ptr, val);
160                 Reference.reachabilityFence(this);
161                 Reference.reachabilityFence(val);
162         }
163
164         /**
165          * Selects the maximum share of a channel's total capacity which will be sent over a channel,
166          * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
167          * a lower value prefers to send larger MPP parts, potentially saturating channels and
168          * increasing failure probability for those paths.
169          * 
170          * Note that this restriction will be relaxed during pathfinding after paths which meet this
171          * restriction have been found. While paths which meet this criteria will be searched for, it
172          * is ultimately up to the scorer to select them over other paths.
173          * 
174          * A value of 0 will allow payments up to and including a channel's total announced usable
175          * capacity, a value of one will only use up to half its capacity, two 1/4, etc.
176          * 
177          * Default value: 2
178          */
179         public byte get_max_channel_saturation_power_of_half() {
180                 byte ret = bindings.PaymentParameters_get_max_channel_saturation_power_of_half(this.ptr);
181                 Reference.reachabilityFence(this);
182                 return ret;
183         }
184
185         /**
186          * Selects the maximum share of a channel's total capacity which will be sent over a channel,
187          * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
188          * a lower value prefers to send larger MPP parts, potentially saturating channels and
189          * increasing failure probability for those paths.
190          * 
191          * Note that this restriction will be relaxed during pathfinding after paths which meet this
192          * restriction have been found. While paths which meet this criteria will be searched for, it
193          * is ultimately up to the scorer to select them over other paths.
194          * 
195          * A value of 0 will allow payments up to and including a channel's total announced usable
196          * capacity, a value of one will only use up to half its capacity, two 1/4, etc.
197          * 
198          * Default value: 2
199          */
200         public void set_max_channel_saturation_power_of_half(byte val) {
201                 bindings.PaymentParameters_set_max_channel_saturation_power_of_half(this.ptr, val);
202                 Reference.reachabilityFence(this);
203                 Reference.reachabilityFence(val);
204         }
205
206         /**
207          * A list of SCIDs which this payment was previously attempted over and which caused the
208          * payment to fail. Future attempts for the same payment shouldn't be relayed through any of
209          * these SCIDs.
210          */
211         public void set_previously_failed_channels(long[] val) {
212                 bindings.PaymentParameters_set_previously_failed_channels(this.ptr, val);
213                 Reference.reachabilityFence(this);
214                 Reference.reachabilityFence(val);
215         }
216
217         /**
218          * Constructs a new PaymentParameters given each field
219          */
220         public static PaymentParameters of(byte[] payee_pubkey_arg, InvoiceFeatures features_arg, RouteHint[] route_hints_arg, 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) {
221                 long ret = bindings.PaymentParameters_new(InternalUtils.check_arr_len(payee_pubkey_arg, 33), features_arg == null ? 0 : features_arg.ptr & ~1, 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 & ~1).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);
222                 Reference.reachabilityFence(payee_pubkey_arg);
223                 Reference.reachabilityFence(features_arg);
224                 Reference.reachabilityFence(route_hints_arg);
225                 Reference.reachabilityFence(expiry_time_arg);
226                 Reference.reachabilityFence(max_total_cltv_expiry_delta_arg);
227                 Reference.reachabilityFence(max_path_count_arg);
228                 Reference.reachabilityFence(max_channel_saturation_power_of_half_arg);
229                 Reference.reachabilityFence(previously_failed_channels_arg);
230                 if (ret >= 0 && ret <= 4096) { return null; }
231                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
232                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
233                 return ret_hu_conv;
234         }
235
236         long clone_ptr() {
237                 long ret = bindings.PaymentParameters_clone_ptr(this.ptr);
238                 Reference.reachabilityFence(this);
239                 return ret;
240         }
241
242         /**
243          * Creates a copy of the PaymentParameters
244          */
245         public PaymentParameters clone() {
246                 long ret = bindings.PaymentParameters_clone(this.ptr);
247                 Reference.reachabilityFence(this);
248                 if (ret >= 0 && ret <= 4096) { return null; }
249                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
250                 ret_hu_conv.ptrs_to.add(this);
251                 return ret_hu_conv;
252         }
253
254         /**
255          * Checks if two PaymentParameterss contain equal inner contents.
256          */
257         public long hash() {
258                 long ret = bindings.PaymentParameters_hash(this.ptr);
259                 Reference.reachabilityFence(this);
260                 return ret;
261         }
262
263         @Override public int hashCode() {
264                 return (int)this.hash();
265         }
266         /**
267          * Checks if two PaymentParameterss contain equal inner contents.
268          * This ignores pointers and is_owned flags and looks at the values in fields.
269          * Two objects with NULL inner values will be considered "equal" here.
270          */
271         public boolean eq(PaymentParameters b) {
272                 boolean ret = bindings.PaymentParameters_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
273                 Reference.reachabilityFence(this);
274                 Reference.reachabilityFence(b);
275                 this.ptrs_to.add(b);
276                 return ret;
277         }
278
279         @Override public boolean equals(Object o) {
280                 if (!(o instanceof PaymentParameters)) return false;
281                 return this.eq((PaymentParameters)o);
282         }
283         /**
284          * Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
285          */
286         public byte[] write() {
287                 byte[] ret = bindings.PaymentParameters_write(this.ptr);
288                 Reference.reachabilityFence(this);
289                 return ret;
290         }
291
292         /**
293          * Read a PaymentParameters from a byte array, created by PaymentParameters_write
294          */
295         public static Result_PaymentParametersDecodeErrorZ read(byte[] ser) {
296                 long ret = bindings.PaymentParameters_read(ser);
297                 Reference.reachabilityFence(ser);
298                 if (ret >= 0 && ret <= 4096) { return null; }
299                 Result_PaymentParametersDecodeErrorZ ret_hu_conv = Result_PaymentParametersDecodeErrorZ.constr_from_ptr(ret);
300                 return ret_hu_conv;
301         }
302
303         /**
304          * Creates a payee with the node id of the given `pubkey`.
305          */
306         public static PaymentParameters from_node_id(byte[] payee_pubkey) {
307                 long ret = bindings.PaymentParameters_from_node_id(InternalUtils.check_arr_len(payee_pubkey, 33));
308                 Reference.reachabilityFence(payee_pubkey);
309                 if (ret >= 0 && ret <= 4096) { return null; }
310                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
311                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
312                 return ret_hu_conv;
313         }
314
315         /**
316          * Creates a payee with the node id of the given `pubkey` to use for keysend payments.
317          */
318         public static PaymentParameters for_keysend(byte[] payee_pubkey) {
319                 long ret = bindings.PaymentParameters_for_keysend(InternalUtils.check_arr_len(payee_pubkey, 33));
320                 Reference.reachabilityFence(payee_pubkey);
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                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
324                 return ret_hu_conv;
325         }
326
327 }