1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * The recipient of a payment.
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 {
20 if (ptr != 0) { bindings.PaymentParameters_free(ptr); }
24 * The node id of the payee.
26 public byte[] get_payee_pubkey() {
27 byte[] ret = bindings.PaymentParameters_get_payee_pubkey(this.ptr);
28 Reference.reachabilityFence(this);
33 * The node id of the payee.
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);
42 * Features supported by the payee.
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.
47 * [`for_keysend`]: Self::for_keysend
49 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
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); };
62 * Features supported by the payee.
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.
67 * [`for_keysend`]: Self::for_keysend
69 * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
71 public void set_features(@Nullable 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); };
79 * Hints for routing to the payee, containing channels connecting the payee to public nodes.
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;
92 return ret_conv_11_arr;
96 * Hints for routing to the payee, containing channels connecting the payee to public nodes.
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); }; };
106 * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
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); };
118 * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
120 public void set_expiry_time(Option_u64Z val) {
121 bindings.PaymentParameters_set_expiry_time(this.ptr, val.ptr);
122 Reference.reachabilityFence(this);
123 Reference.reachabilityFence(val);
127 * The maximum total CLTV delta we accept for the route.
128 * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
130 public int get_max_total_cltv_expiry_delta() {
131 int ret = bindings.PaymentParameters_get_max_total_cltv_expiry_delta(this.ptr);
132 Reference.reachabilityFence(this);
137 * The maximum total CLTV delta we accept for the route.
138 * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
140 public void set_max_total_cltv_expiry_delta(int val) {
141 bindings.PaymentParameters_set_max_total_cltv_expiry_delta(this.ptr, val);
142 Reference.reachabilityFence(this);
143 Reference.reachabilityFence(val);
147 * The maximum number of paths that may be used by (MPP) payments.
148 * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
150 public byte get_max_path_count() {
151 byte ret = bindings.PaymentParameters_get_max_path_count(this.ptr);
152 Reference.reachabilityFence(this);
157 * The maximum number of paths that may be used by (MPP) payments.
158 * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
160 public void set_max_path_count(byte val) {
161 bindings.PaymentParameters_set_max_path_count(this.ptr, val);
162 Reference.reachabilityFence(this);
163 Reference.reachabilityFence(val);
167 * Selects the maximum share of a channel's total capacity which will be sent over a channel,
168 * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
169 * a lower value prefers to send larger MPP parts, potentially saturating channels and
170 * increasing failure probability for those paths.
172 * Note that this restriction will be relaxed during pathfinding after paths which meet this
173 * restriction have been found. While paths which meet this criteria will be searched for, it
174 * is ultimately up to the scorer to select them over other paths.
176 * A value of 0 will allow payments up to and including a channel's total announced usable
177 * capacity, a value of one will only use up to half its capacity, two 1/4, etc.
181 public byte get_max_channel_saturation_power_of_half() {
182 byte ret = bindings.PaymentParameters_get_max_channel_saturation_power_of_half(this.ptr);
183 Reference.reachabilityFence(this);
188 * Selects the maximum share of a channel's total capacity which will be sent over a channel,
189 * as a power of 1/2. A higher value prefers to send the payment using more MPP parts whereas
190 * a lower value prefers to send larger MPP parts, potentially saturating channels and
191 * increasing failure probability for those paths.
193 * Note that this restriction will be relaxed during pathfinding after paths which meet this
194 * restriction have been found. While paths which meet this criteria will be searched for, it
195 * is ultimately up to the scorer to select them over other paths.
197 * A value of 0 will allow payments up to and including a channel's total announced usable
198 * capacity, a value of one will only use up to half its capacity, two 1/4, etc.
202 public void set_max_channel_saturation_power_of_half(byte val) {
203 bindings.PaymentParameters_set_max_channel_saturation_power_of_half(this.ptr, val);
204 Reference.reachabilityFence(this);
205 Reference.reachabilityFence(val);
209 * A list of SCIDs which this payment was previously attempted over and which caused the
210 * payment to fail. Future attempts for the same payment shouldn't be relayed through any of
213 * Returns a copy of the field.
215 public long[] get_previously_failed_channels() {
216 long[] ret = bindings.PaymentParameters_get_previously_failed_channels(this.ptr);
217 Reference.reachabilityFence(this);
222 * A list of SCIDs which this payment was previously attempted over and which caused the
223 * payment to fail. Future attempts for the same payment shouldn't be relayed through any of
226 public void set_previously_failed_channels(long[] val) {
227 bindings.PaymentParameters_set_previously_failed_channels(this.ptr, val);
228 Reference.reachabilityFence(this);
229 Reference.reachabilityFence(val);
233 * Constructs a new PaymentParameters given each field
235 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) {
236 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);
237 Reference.reachabilityFence(payee_pubkey_arg);
238 Reference.reachabilityFence(features_arg);
239 Reference.reachabilityFence(route_hints_arg);
240 Reference.reachabilityFence(expiry_time_arg);
241 Reference.reachabilityFence(max_total_cltv_expiry_delta_arg);
242 Reference.reachabilityFence(max_path_count_arg);
243 Reference.reachabilityFence(max_channel_saturation_power_of_half_arg);
244 Reference.reachabilityFence(previously_failed_channels_arg);
245 if (ret >= 0 && ret <= 4096) { return null; }
246 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
247 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
248 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(features_arg); };
249 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); }; };
254 long ret = bindings.PaymentParameters_clone_ptr(this.ptr);
255 Reference.reachabilityFence(this);
260 * Creates a copy of the PaymentParameters
262 public PaymentParameters clone() {
263 long ret = bindings.PaymentParameters_clone(this.ptr);
264 Reference.reachabilityFence(this);
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(this); };
272 * Checks if two PaymentParameterss contain equal inner contents.
275 long ret = bindings.PaymentParameters_hash(this.ptr);
276 Reference.reachabilityFence(this);
280 @Override public int hashCode() {
281 return (int)this.hash();
284 * Checks if two PaymentParameterss contain equal inner contents.
285 * This ignores pointers and is_owned flags and looks at the values in fields.
286 * Two objects with NULL inner values will be considered "equal" here.
288 public boolean eq(PaymentParameters b) {
289 boolean ret = bindings.PaymentParameters_eq(this.ptr, b == null ? 0 : b.ptr);
290 Reference.reachabilityFence(this);
291 Reference.reachabilityFence(b);
292 if (this != null) { this.ptrs_to.add(b); };
296 @Override public boolean equals(Object o) {
297 if (!(o instanceof PaymentParameters)) return false;
298 return this.eq((PaymentParameters)o);
301 * Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
303 public byte[] write() {
304 byte[] ret = bindings.PaymentParameters_write(this.ptr);
305 Reference.reachabilityFence(this);
310 * Read a PaymentParameters from a byte array, created by PaymentParameters_write
312 public static Result_PaymentParametersDecodeErrorZ read(byte[] ser) {
313 long ret = bindings.PaymentParameters_read(ser);
314 Reference.reachabilityFence(ser);
315 if (ret >= 0 && ret <= 4096) { return null; }
316 Result_PaymentParametersDecodeErrorZ ret_hu_conv = Result_PaymentParametersDecodeErrorZ.constr_from_ptr(ret);
321 * Creates a payee with the node id of the given `pubkey`.
323 public static PaymentParameters from_node_id(byte[] payee_pubkey) {
324 long ret = bindings.PaymentParameters_from_node_id(InternalUtils.check_arr_len(payee_pubkey, 33));
325 Reference.reachabilityFence(payee_pubkey);
326 if (ret >= 0 && ret <= 4096) { return null; }
327 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
328 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
333 * Creates a payee with the node id of the given `pubkey` to use for keysend payments.
335 public static PaymentParameters for_keysend(byte[] payee_pubkey) {
336 long ret = bindings.PaymentParameters_for_keysend(InternalUtils.check_arr_len(payee_pubkey, 33));
337 Reference.reachabilityFence(payee_pubkey);
338 if (ret >= 0 && ret <= 4096) { return null; }
339 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
340 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };