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 InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new InvoiceFeatures(null, ret); }
57 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 & ~1);
73 Reference.reachabilityFence(this);
74 Reference.reachabilityFence(val);
78 * Hints for routing to the payee, containing channels connecting the payee to public nodes.
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 RouteHint ret_conv_11_hu_conv = null; if (ret_conv_11 < 0 || ret_conv_11 > 4096) { ret_conv_11_hu_conv = new 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;
91 return ret_conv_11_arr;
95 * Hints for routing to the payee, containing channels connecting the payee to public nodes.
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);
104 * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
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);
116 * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
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);
125 * The maximum total CLTV delta we accept for the route.
127 public int get_max_total_cltv_expiry_delta() {
128 int ret = bindings.PaymentParameters_get_max_total_cltv_expiry_delta(this.ptr);
129 Reference.reachabilityFence(this);
134 * The maximum total CLTV delta we accept for the route.
136 public void set_max_total_cltv_expiry_delta(int val) {
137 bindings.PaymentParameters_set_max_total_cltv_expiry_delta(this.ptr, val);
138 Reference.reachabilityFence(this);
139 Reference.reachabilityFence(val);
143 * Constructs a new PaymentParameters given each field
145 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) {
146 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);
147 Reference.reachabilityFence(payee_pubkey_arg);
148 Reference.reachabilityFence(features_arg);
149 Reference.reachabilityFence(route_hints_arg);
150 Reference.reachabilityFence(expiry_time_arg);
151 Reference.reachabilityFence(max_total_cltv_expiry_delta_arg);
152 if (ret >= 0 && ret <= 4096) { return null; }
153 PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new PaymentParameters(null, ret); }
154 ret_hu_conv.ptrs_to.add(ret_hu_conv);
159 long ret = bindings.PaymentParameters_clone_ptr(this.ptr);
160 Reference.reachabilityFence(this);
165 * Creates a copy of the PaymentParameters
167 public PaymentParameters clone() {
168 long ret = bindings.PaymentParameters_clone(this.ptr);
169 Reference.reachabilityFence(this);
170 if (ret >= 0 && ret <= 4096) { return null; }
171 PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new PaymentParameters(null, ret); }
172 ret_hu_conv.ptrs_to.add(this);
177 * Checks if two PaymentParameterss contain equal inner contents.
180 long ret = bindings.PaymentParameters_hash(this.ptr);
181 Reference.reachabilityFence(this);
185 @Override public int hashCode() {
186 return (int)this.hash();
189 * Checks if two PaymentParameterss contain equal inner contents.
190 * This ignores pointers and is_owned flags and looks at the values in fields.
191 * Two objects with NULL inner values will be considered "equal" here.
193 public boolean eq(PaymentParameters b) {
194 boolean ret = bindings.PaymentParameters_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
195 Reference.reachabilityFence(this);
196 Reference.reachabilityFence(b);
201 @Override public boolean equals(Object o) {
202 if (!(o instanceof PaymentParameters)) return false;
203 return this.eq((PaymentParameters)o);
206 * Serialize the PaymentParameters object into a byte array which can be read by PaymentParameters_read
208 public byte[] write() {
209 byte[] ret = bindings.PaymentParameters_write(this.ptr);
210 Reference.reachabilityFence(this);
215 * Read a PaymentParameters from a byte array, created by PaymentParameters_write
217 public static Result_PaymentParametersDecodeErrorZ read(byte[] ser) {
218 long ret = bindings.PaymentParameters_read(ser);
219 Reference.reachabilityFence(ser);
220 if (ret >= 0 && ret <= 4096) { return null; }
221 Result_PaymentParametersDecodeErrorZ ret_hu_conv = Result_PaymentParametersDecodeErrorZ.constr_from_ptr(ret);
226 * Creates a payee with the node id of the given `pubkey`.
228 public static PaymentParameters from_node_id(byte[] payee_pubkey) {
229 long ret = bindings.PaymentParameters_from_node_id(InternalUtils.check_arr_len(payee_pubkey, 33));
230 Reference.reachabilityFence(payee_pubkey);
231 if (ret >= 0 && ret <= 4096) { return null; }
232 PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new PaymentParameters(null, ret); }
233 ret_hu_conv.ptrs_to.add(ret_hu_conv);
238 * Creates a payee with the node id of the given `pubkey` to use for keysend payments.
240 public static PaymentParameters for_keysend(byte[] payee_pubkey) {
241 long ret = bindings.PaymentParameters_for_keysend(InternalUtils.check_arr_len(payee_pubkey, 33));
242 Reference.reachabilityFence(payee_pubkey);
243 if (ret >= 0 && ret <= 4096) { return null; }
244 PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new PaymentParameters(null, ret); }
245 ret_hu_conv.ptrs_to.add(ret_hu_conv);