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 * Information used to route 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 * Information about the payee, such as their features and route hints for their channels.
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); };
36 * Information about the payee, such as their features and route hints for their channels.
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); };
46 * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
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); };
58 * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
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); };
68 * The maximum total CLTV delta we accept for the route.
69 * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
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);
78 * The maximum total CLTV delta we accept for the route.
79 * Defaults to [`DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA`].
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);
88 * The maximum number of paths that may be used by (MPP) payments.
89 * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
91 public byte get_max_path_count() {
92 byte ret = bindings.PaymentParameters_get_max_path_count(this.ptr);
93 Reference.reachabilityFence(this);
98 * The maximum number of paths that may be used by (MPP) payments.
99 * Defaults to [`DEFAULT_MAX_PATH_COUNT`].
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);
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.
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.
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.
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);
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.
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.
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.
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);
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
154 * Returns a copy of the field.
156 public long[] get_previously_failed_channels() {
157 long[] ret = bindings.PaymentParameters_get_previously_failed_channels(this.ptr);
158 Reference.reachabilityFence(this);
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
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);
174 * Constructs a new PaymentParameters given each field
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); };
193 long ret = bindings.PaymentParameters_clone_ptr(this.ptr);
194 Reference.reachabilityFence(this);
199 * Creates a copy of the PaymentParameters
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); };
211 * Generates a non-cryptographic 64-bit hash of the PaymentParameters.
214 long ret = bindings.PaymentParameters_hash(this.ptr);
215 Reference.reachabilityFence(this);
219 @Override public int hashCode() {
220 return (int)this.hash();
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.
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); };
235 @Override public boolean equals(Object o) {
236 if (!(o instanceof PaymentParameters)) return false;
237 return this.eq((PaymentParameters)o);
240 * Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
242 public byte[] write() {
243 byte[] ret = bindings.PaymentParameters_write(this.ptr);
244 Reference.reachabilityFence(this);
249 * Read a PaymentParameters from a byte array, created by PaymentParameters_write
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);
261 * Creates a payee with the node id of the given `pubkey`.
263 * The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
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); };
277 * Creates a payee with the node id of the given `pubkey` to use for keysend payments.
279 * The `final_cltv_expiry_delta` should match the expected final CLTV delta the recipient has
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`].
287 * [`RecipientOnionFields::secret_only`]: crate::ln::channelmanager::RecipientOnionFields::secret_only
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); };
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`].
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); };
316 * Creates parameters for paying to a blinded payee from the provided blinded route hints.
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); };