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, differing based on whether they've hidden their identity with route
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class Payee extends CommonBase {
17 private Payee(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.Payee_free(ptr); }
23 static Payee constr_from_ptr(long ptr) {
24 bindings.LDKPayee raw_val = bindings.LDKPayee_ref_from_ptr(ptr);
25 if (raw_val.getClass() == bindings.LDKPayee.Blinded.class) {
26 return new Blinded(ptr, (bindings.LDKPayee.Blinded)raw_val);
28 if (raw_val.getClass() == bindings.LDKPayee.Clear.class) {
29 return new Clear(ptr, (bindings.LDKPayee.Clear)raw_val);
31 assert false; return null; // Unreachable without extending the (internal) bindings interface
35 * The recipient provided blinded paths and payinfo to reach them. The blinded paths themselves
36 * will be included in the final [`Route`].
38 public final static class Blinded extends Payee {
40 * Aggregated routing info and blinded paths, for routing to the payee without knowing their
43 public final TwoTuple_BlindedPayInfoBlindedPathZ[] route_hints;
45 * Features supported by the payee.
47 * May be set from the payee's invoice. May be `None` if the invoice does not contain any
50 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
52 @Nullable public final org.ldk.structs.Bolt12InvoiceFeatures features;
53 private Blinded(long ptr, bindings.LDKPayee.Blinded obj) {
55 long[] route_hints = obj.route_hints;
56 int route_hints_conv_37_len = route_hints.length;
57 TwoTuple_BlindedPayInfoBlindedPathZ[] route_hints_conv_37_arr = new TwoTuple_BlindedPayInfoBlindedPathZ[route_hints_conv_37_len];
58 for (int l = 0; l < route_hints_conv_37_len; l++) {
59 long route_hints_conv_37 = route_hints[l];
60 TwoTuple_BlindedPayInfoBlindedPathZ route_hints_conv_37_hu_conv = new TwoTuple_BlindedPayInfoBlindedPathZ(null, route_hints_conv_37);
61 if (route_hints_conv_37_hu_conv != null) { route_hints_conv_37_hu_conv.ptrs_to.add(this); };
62 route_hints_conv_37_arr[l] = route_hints_conv_37_hu_conv;
64 this.route_hints = route_hints_conv_37_arr;
65 long features = obj.features;
66 org.ldk.structs.Bolt12InvoiceFeatures features_hu_conv = null; if (features < 0 || features > 4096) { features_hu_conv = new org.ldk.structs.Bolt12InvoiceFeatures(null, features); }
67 if (features_hu_conv != null) { features_hu_conv.ptrs_to.add(this); };
68 this.features = features_hu_conv;
72 * The recipient included these route hints in their BOLT11 invoice.
74 public final static class Clear extends Payee {
76 * The node id of the payee.
78 public final byte[] node_id;
80 * Hints for routing to the payee, containing channels connecting the payee to public nodes.
82 public final RouteHint[] route_hints;
84 * Features supported by the payee.
86 * May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
87 * does not contain any features.
89 * [`for_keysend`]: PaymentParameters::for_keysend
91 * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
93 @Nullable public final org.ldk.structs.Bolt11InvoiceFeatures features;
95 * The minimum CLTV delta at the end of the route. This value must not be zero.
97 public final int final_cltv_expiry_delta;
98 private Clear(long ptr, bindings.LDKPayee.Clear obj) {
100 this.node_id = obj.node_id;
101 long[] route_hints = obj.route_hints;
102 int route_hints_conv_11_len = route_hints.length;
103 RouteHint[] route_hints_conv_11_arr = new RouteHint[route_hints_conv_11_len];
104 for (int l = 0; l < route_hints_conv_11_len; l++) {
105 long route_hints_conv_11 = route_hints[l];
106 org.ldk.structs.RouteHint route_hints_conv_11_hu_conv = null; if (route_hints_conv_11 < 0 || route_hints_conv_11 > 4096) { route_hints_conv_11_hu_conv = new org.ldk.structs.RouteHint(null, route_hints_conv_11); }
107 if (route_hints_conv_11_hu_conv != null) { route_hints_conv_11_hu_conv.ptrs_to.add(this); };
108 route_hints_conv_11_arr[l] = route_hints_conv_11_hu_conv;
110 this.route_hints = route_hints_conv_11_arr;
111 long features = obj.features;
112 org.ldk.structs.Bolt11InvoiceFeatures features_hu_conv = null; if (features < 0 || features > 4096) { features_hu_conv = new org.ldk.structs.Bolt11InvoiceFeatures(null, features); }
113 if (features_hu_conv != null) { features_hu_conv.ptrs_to.add(this); };
114 this.features = features_hu_conv;
115 this.final_cltv_expiry_delta = obj.final_cltv_expiry_delta;
119 long ret = bindings.Payee_clone_ptr(this.ptr);
120 Reference.reachabilityFence(this);
125 * Creates a copy of the Payee
127 public Payee clone() {
128 long ret = bindings.Payee_clone(this.ptr);
129 Reference.reachabilityFence(this);
130 if (ret >= 0 && ret <= 4096) { return null; }
131 org.ldk.structs.Payee ret_hu_conv = org.ldk.structs.Payee.constr_from_ptr(ret);
132 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
137 * Utility method to constructs a new Blinded-variant Payee
139 public static Payee blinded(TwoTuple_BlindedPayInfoBlindedPathZ[] route_hints, org.ldk.structs.Bolt12InvoiceFeatures features) {
140 long ret = bindings.Payee_blinded(route_hints != null ? Arrays.stream(route_hints).mapToLong(route_hints_conv_37 -> route_hints_conv_37 != null ? route_hints_conv_37.ptr : 0).toArray() : null, features == null ? 0 : features.ptr);
141 Reference.reachabilityFence(route_hints);
142 Reference.reachabilityFence(features);
143 if (ret >= 0 && ret <= 4096) { return null; }
144 org.ldk.structs.Payee ret_hu_conv = org.ldk.structs.Payee.constr_from_ptr(ret);
145 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
146 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(features); };
151 * Utility method to constructs a new Clear-variant Payee
153 public static Payee clear(byte[] node_id, RouteHint[] route_hints, org.ldk.structs.Bolt11InvoiceFeatures features, int final_cltv_expiry_delta) {
154 long ret = bindings.Payee_clear(InternalUtils.check_arr_len(node_id, 33), route_hints != null ? Arrays.stream(route_hints).mapToLong(route_hints_conv_11 -> route_hints_conv_11 == null ? 0 : route_hints_conv_11.ptr).toArray() : null, features == null ? 0 : features.ptr, final_cltv_expiry_delta);
155 Reference.reachabilityFence(node_id);
156 Reference.reachabilityFence(route_hints);
157 Reference.reachabilityFence(features);
158 Reference.reachabilityFence(final_cltv_expiry_delta);
159 if (ret >= 0 && ret <= 4096) { return null; }
160 org.ldk.structs.Payee ret_hu_conv = org.ldk.structs.Payee.constr_from_ptr(ret);
161 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
162 for (RouteHint route_hints_conv_11: route_hints) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(route_hints_conv_11); }; };
163 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(features); };
168 * Generates a non-cryptographic 64-bit hash of the Payee.
171 long ret = bindings.Payee_hash(this.ptr);
172 Reference.reachabilityFence(this);
176 @Override public int hashCode() {
177 return (int)this.hash();
180 * Checks if two Payees contain equal inner contents.
181 * This ignores pointers and is_owned flags and looks at the values in fields.
183 public boolean eq(org.ldk.structs.Payee b) {
184 boolean ret = bindings.Payee_eq(this.ptr, b == null ? 0 : b.ptr);
185 Reference.reachabilityFence(this);
186 Reference.reachabilityFence(b);
190 @Override public boolean equals(Object o) {
191 if (!(o instanceof Payee)) return false;
192 return this.eq((Payee)o);