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 * An `Offer` is a potentially long-lived proposal for payment of a good or service.
14 * An offer is a precursor to an [`InvoiceRequest`]. A merchant publishes an offer from which a
15 * customer may request an [`Bolt12Invoice`] for a specific quantity and using an amount sufficient
16 * to cover that quantity (i.e., at least `quantity * amount`). See [`Offer::amount`].
18 * Offers may be denominated in currency other than bitcoin but are ultimately paid using the
21 * Through the use of [`BlindedPath`]s, offers provide recipient privacy.
23 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
24 * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
26 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
27 public class Offer extends CommonBase {
28 Offer(Object _dummy, long ptr) { super(ptr); }
29 @Override @SuppressWarnings("deprecation")
30 protected void finalize() throws Throwable {
32 if (ptr != 0) { bindings.Offer_free(ptr); }
36 long ret = bindings.Offer_clone_ptr(this.ptr);
37 Reference.reachabilityFence(this);
42 * Creates a copy of the Offer
44 public Offer clone() {
45 long ret = bindings.Offer_clone(this.ptr);
46 Reference.reachabilityFence(this);
47 if (ret >= 0 && ret <= 4096) { return null; }
48 org.ldk.structs.Offer ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Offer(null, ret); }
49 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
54 * The chains that may be used when paying a requested invoice (e.g., bitcoin mainnet).
55 * Payments must be denominated in units of the minimal lightning-payable unit (e.g., msats)
56 * for the selected chain.
58 public byte[][] chains() {
59 byte[][] ret = bindings.Offer_chains(this.ptr);
60 Reference.reachabilityFence(this);
65 * Opaque bytes set by the originator. Useful for authentication and validating fields since it
66 * is reflected in `invoice_request` messages along with all the other fields from the `offer`.
68 public Option_CVec_u8ZZ metadata() {
69 long ret = bindings.Offer_metadata(this.ptr);
70 Reference.reachabilityFence(this);
71 if (ret >= 0 && ret <= 4096) { return null; }
72 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
73 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
78 * The minimum amount required for a successful payment of a single item.
80 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
83 public Amount amount() {
84 long ret = bindings.Offer_amount(this.ptr);
85 Reference.reachabilityFence(this);
86 if (ret >= 0 && ret <= 4096) { return null; }
87 org.ldk.structs.Amount ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Amount(null, ret); }
88 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
93 * A complete description of the purpose of the payment. Intended to be displayed to the user
94 * but with the caveat that it has not been verified in any way.
96 public PrintableString description() {
97 long ret = bindings.Offer_description(this.ptr);
98 Reference.reachabilityFence(this);
99 if (ret >= 0 && ret <= 4096) { return null; }
100 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
101 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
106 * Features pertaining to the offer.
108 public OfferFeatures offer_features() {
109 long ret = bindings.Offer_offer_features(this.ptr);
110 Reference.reachabilityFence(this);
111 if (ret >= 0 && ret <= 4096) { return null; }
112 org.ldk.structs.OfferFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OfferFeatures(null, ret); }
113 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
118 * Duration since the Unix epoch when an invoice should no longer be requested.
120 * If `None`, the offer does not expire.
122 public Option_u64Z absolute_expiry() {
123 long ret = bindings.Offer_absolute_expiry(this.ptr);
124 Reference.reachabilityFence(this);
125 if (ret >= 0 && ret <= 4096) { return null; }
126 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
127 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
132 * The issuer of the offer, possibly beginning with `user@domain` or `domain`. Intended to be
133 * displayed to the user but with the caveat that it has not been verified in any way.
135 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
138 public PrintableString issuer() {
139 long ret = bindings.Offer_issuer(this.ptr);
140 Reference.reachabilityFence(this);
141 if (ret >= 0 && ret <= 4096) { return null; }
142 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
143 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
148 * Paths to the recipient originating from publicly reachable nodes. Blinded paths provide
149 * recipient privacy by obfuscating its node id.
151 public BlindedPath[] paths() {
152 long[] ret = bindings.Offer_paths(this.ptr);
153 Reference.reachabilityFence(this);
154 int ret_conv_13_len = ret.length;
155 BlindedPath[] ret_conv_13_arr = new BlindedPath[ret_conv_13_len];
156 for (int n = 0; n < ret_conv_13_len; n++) {
157 long ret_conv_13 = ret[n];
158 org.ldk.structs.BlindedPath ret_conv_13_hu_conv = null; if (ret_conv_13 < 0 || ret_conv_13 > 4096) { ret_conv_13_hu_conv = new org.ldk.structs.BlindedPath(null, ret_conv_13); }
159 if (ret_conv_13_hu_conv != null) { ret_conv_13_hu_conv.ptrs_to.add(this); };
160 ret_conv_13_arr[n] = ret_conv_13_hu_conv;
162 return ret_conv_13_arr;
166 * The quantity of items supported.
168 public Quantity supported_quantity() {
169 long ret = bindings.Offer_supported_quantity(this.ptr);
170 Reference.reachabilityFence(this);
171 if (ret >= 0 && ret <= 4096) { return null; }
172 org.ldk.structs.Quantity ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Quantity(null, ret); }
173 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
178 * The public key used by the recipient to sign invoices.
180 public byte[] signing_pubkey() {
181 byte[] ret = bindings.Offer_signing_pubkey(this.ptr);
182 Reference.reachabilityFence(this);
187 * Returns whether the given chain is supported by the offer.
189 public boolean supports_chain(byte[] chain) {
190 boolean ret = bindings.Offer_supports_chain(this.ptr, InternalUtils.check_arr_len(chain, 32));
191 Reference.reachabilityFence(this);
192 Reference.reachabilityFence(chain);
197 * Whether the offer has expired.
199 public boolean is_expired() {
200 boolean ret = bindings.Offer_is_expired(this.ptr);
201 Reference.reachabilityFence(this);
206 * Whether the offer has expired given the duration since the Unix epoch.
208 public boolean is_expired_no_std(long duration_since_epoch) {
209 boolean ret = bindings.Offer_is_expired_no_std(this.ptr, duration_since_epoch);
210 Reference.reachabilityFence(this);
211 Reference.reachabilityFence(duration_since_epoch);
216 * Returns whether the given quantity is valid for the offer.
218 public boolean is_valid_quantity(long quantity) {
219 boolean ret = bindings.Offer_is_valid_quantity(this.ptr, quantity);
220 Reference.reachabilityFence(this);
221 Reference.reachabilityFence(quantity);
226 * Returns whether a quantity is expected in an [`InvoiceRequest`] for the offer.
228 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
230 public boolean expects_quantity() {
231 boolean ret = bindings.Offer_expects_quantity(this.ptr);
232 Reference.reachabilityFence(this);
237 * Serialize the Offer object into a byte array which can be read by Offer_read
239 public byte[] write() {
240 byte[] ret = bindings.Offer_write(this.ptr);
241 Reference.reachabilityFence(this);
246 * Read a Offer object from a string
248 public static Result_OfferBolt12ParseErrorZ from_str(java.lang.String s) {
249 long ret = bindings.Offer_from_str(s);
250 Reference.reachabilityFence(s);
251 if (ret >= 0 && ret <= 4096) { return null; }
252 Result_OfferBolt12ParseErrorZ ret_hu_conv = Result_OfferBolt12ParseErrorZ.constr_from_ptr(ret);