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 Payee extends CommonBase {
16 Payee(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.Payee_free(ptr); }
24 * The node id of the payee.
26 public byte[] get_pubkey() {
27 byte[] ret = bindings.Payee_get_pubkey(this.ptr);
28 Reference.reachabilityFence(this);
33 * The node id of the payee.
35 public void set_pubkey(byte[] val) {
36 bindings.Payee_set_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.Payee_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.Payee_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.Payee_get_route_hints(this.ptr);
82 Reference.reachabilityFence(this);
83 RouteHint[] ret_conv_11_arr = new RouteHint[ret.length];
84 for (int l = 0; l < ret.length; l++) {
85 long ret_conv_11 = ret[l];
86 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); }
87 ret_conv_11_hu_conv.ptrs_to.add(this);
88 ret_conv_11_arr[l] = ret_conv_11_hu_conv;
90 return ret_conv_11_arr;
94 * Hints for routing to the payee, containing channels connecting the payee to public nodes.
96 public void set_route_hints(RouteHint[] val) {
97 bindings.Payee_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);
98 Reference.reachabilityFence(this);
99 Reference.reachabilityFence(val);
103 * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
105 public Option_u64Z get_expiry_time() {
106 long ret = bindings.Payee_get_expiry_time(this.ptr);
107 Reference.reachabilityFence(this);
108 if (ret >= 0 && ret <= 4096) { return null; }
109 Option_u64Z ret_hu_conv = Option_u64Z.constr_from_ptr(ret);
110 ret_hu_conv.ptrs_to.add(this);
115 * Expiration of a payment to the payee, in seconds relative to the UNIX epoch.
117 public void set_expiry_time(Option_u64Z val) {
118 bindings.Payee_set_expiry_time(this.ptr, val.ptr);
119 Reference.reachabilityFence(this);
120 Reference.reachabilityFence(val);
124 * Constructs a new Payee given each field
126 public static Payee of(byte[] pubkey_arg, InvoiceFeatures features_arg, RouteHint[] route_hints_arg, Option_u64Z expiry_time_arg) {
127 long ret = bindings.Payee_new(InternalUtils.check_arr_len(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);
128 Reference.reachabilityFence(pubkey_arg);
129 Reference.reachabilityFence(features_arg);
130 Reference.reachabilityFence(route_hints_arg);
131 Reference.reachabilityFence(expiry_time_arg);
132 if (ret >= 0 && ret <= 4096) { return null; }
133 Payee ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Payee(null, ret); }
134 ret_hu_conv.ptrs_to.add(ret_hu_conv);
139 long ret = bindings.Payee_clone_ptr(this.ptr);
140 Reference.reachabilityFence(this);
145 * Creates a copy of the Payee
147 public Payee clone() {
148 long ret = bindings.Payee_clone(this.ptr);
149 Reference.reachabilityFence(this);
150 if (ret >= 0 && ret <= 4096) { return null; }
151 Payee ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Payee(null, ret); }
152 ret_hu_conv.ptrs_to.add(this);
157 * Checks if two Payees contain equal inner contents.
160 long ret = bindings.Payee_hash(this.ptr);
161 Reference.reachabilityFence(this);
165 @Override public int hashCode() {
166 return (int)this.hash();
169 * Checks if two Payees contain equal inner contents.
170 * This ignores pointers and is_owned flags and looks at the values in fields.
171 * Two objects with NULL inner values will be considered "equal" here.
173 public boolean eq(Payee b) {
174 boolean ret = bindings.Payee_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
175 Reference.reachabilityFence(this);
176 Reference.reachabilityFence(b);
181 @Override public boolean equals(Object o) {
182 if (!(o instanceof Payee)) return false;
183 return this.eq((Payee)o);
186 * Serialize the Payee object into a byte array which can be read by Payee_read
188 public byte[] write() {
189 byte[] ret = bindings.Payee_write(this.ptr);
190 Reference.reachabilityFence(this);
195 * Read a Payee from a byte array, created by Payee_write
197 public static Result_PayeeDecodeErrorZ read(byte[] ser) {
198 long ret = bindings.Payee_read(ser);
199 Reference.reachabilityFence(ser);
200 if (ret >= 0 && ret <= 4096) { return null; }
201 Result_PayeeDecodeErrorZ ret_hu_conv = Result_PayeeDecodeErrorZ.constr_from_ptr(ret);
206 * Creates a payee with the node id of the given `pubkey`.
208 public static Payee from_node_id(byte[] pubkey) {
209 long ret = bindings.Payee_from_node_id(InternalUtils.check_arr_len(pubkey, 33));
210 Reference.reachabilityFence(pubkey);
211 if (ret >= 0 && ret <= 4096) { return null; }
212 Payee ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Payee(null, ret); }
213 ret_hu_conv.ptrs_to.add(ret_hu_conv);
218 * Creates a payee with the node id of the given `pubkey` to use for keysend payments.
220 public static Payee for_keysend(byte[] pubkey) {
221 long ret = bindings.Payee_for_keysend(InternalUtils.check_arr_len(pubkey, 33));
222 Reference.reachabilityFence(pubkey);
223 if (ret >= 0 && ret <= 4096) { return null; }
224 Payee ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Payee(null, ret); }
225 ret_hu_conv.ptrs_to.add(ret_hu_conv);