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 [`Invoice`] for a specific quantity and using an amount sufficient to
16 * 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 * [`Invoice`]: crate::offers::invoice::Invoice
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 * Returns whether the given chain is supported by the offer.
67 public boolean supports_chain(byte[] chain) {
68 boolean ret = bindings.Offer_supports_chain(this.ptr, InternalUtils.check_arr_len(chain, 32));
69 Reference.reachabilityFence(this);
70 Reference.reachabilityFence(chain);
75 * Opaque bytes set by the originator. Useful for authentication and validating fields since it
76 * is reflected in `invoice_request` messages along with all the other fields from the `offer`.
78 public Option_CVec_u8ZZ metadata() {
79 long ret = bindings.Offer_metadata(this.ptr);
80 Reference.reachabilityFence(this);
81 if (ret >= 0 && ret <= 4096) { return null; }
82 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
83 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
88 * The minimum amount required for a successful payment of a single item.
90 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
93 public Amount amount() {
94 long ret = bindings.Offer_amount(this.ptr);
95 Reference.reachabilityFence(this);
96 if (ret >= 0 && ret <= 4096) { return null; }
97 org.ldk.structs.Amount ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Amount(null, ret); }
98 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
103 * A complete description of the purpose of the payment. Intended to be displayed to the user
104 * but with the caveat that it has not been verified in any way.
106 public PrintableString description() {
107 long ret = bindings.Offer_description(this.ptr);
108 Reference.reachabilityFence(this);
109 if (ret >= 0 && ret <= 4096) { return null; }
110 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
111 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
116 * Features pertaining to the offer.
118 public OfferFeatures features() {
119 long ret = bindings.Offer_features(this.ptr);
120 Reference.reachabilityFence(this);
121 if (ret >= 0 && ret <= 4096) { return null; }
122 org.ldk.structs.OfferFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OfferFeatures(null, ret); }
123 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
128 * Duration since the Unix epoch when an invoice should no longer be requested.
130 * If `None`, the offer does not expire.
132 public Option_DurationZ absolute_expiry() {
133 long ret = bindings.Offer_absolute_expiry(this.ptr);
134 Reference.reachabilityFence(this);
135 if (ret >= 0 && ret <= 4096) { return null; }
136 org.ldk.structs.Option_DurationZ ret_hu_conv = org.ldk.structs.Option_DurationZ.constr_from_ptr(ret);
137 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
142 * Whether the offer has expired.
144 public boolean is_expired() {
145 boolean ret = bindings.Offer_is_expired(this.ptr);
146 Reference.reachabilityFence(this);
151 * The issuer of the offer, possibly beginning with `user@domain` or `domain`. Intended to be
152 * displayed to the user but with the caveat that it has not been verified in any way.
154 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
157 public PrintableString issuer() {
158 long ret = bindings.Offer_issuer(this.ptr);
159 Reference.reachabilityFence(this);
160 if (ret >= 0 && ret <= 4096) { return null; }
161 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
162 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
167 * Paths to the recipient originating from publicly reachable nodes. Blinded paths provide
168 * recipient privacy by obfuscating its node id.
170 public BlindedPath[] paths() {
171 long[] ret = bindings.Offer_paths(this.ptr);
172 Reference.reachabilityFence(this);
173 int ret_conv_13_len = ret.length;
174 BlindedPath[] ret_conv_13_arr = new BlindedPath[ret_conv_13_len];
175 for (int n = 0; n < ret_conv_13_len; n++) {
176 long ret_conv_13 = ret[n];
177 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); }
178 if (ret_conv_13_hu_conv != null) { ret_conv_13_hu_conv.ptrs_to.add(this); };
179 ret_conv_13_arr[n] = ret_conv_13_hu_conv;
181 return ret_conv_13_arr;
185 * The quantity of items supported.
187 public Quantity supported_quantity() {
188 long ret = bindings.Offer_supported_quantity(this.ptr);
189 Reference.reachabilityFence(this);
190 if (ret >= 0 && ret <= 4096) { return null; }
191 org.ldk.structs.Quantity ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Quantity(null, ret); }
192 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
197 * Returns whether the given quantity is valid for the offer.
199 public boolean is_valid_quantity(long quantity) {
200 boolean ret = bindings.Offer_is_valid_quantity(this.ptr, quantity);
201 Reference.reachabilityFence(this);
202 Reference.reachabilityFence(quantity);
207 * Returns whether a quantity is expected in an [`InvoiceRequest`] for the offer.
209 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
211 public boolean expects_quantity() {
212 boolean ret = bindings.Offer_expects_quantity(this.ptr);
213 Reference.reachabilityFence(this);
218 * The public key used by the recipient to sign invoices.
220 public byte[] signing_pubkey() {
221 byte[] ret = bindings.Offer_signing_pubkey(this.ptr);
222 Reference.reachabilityFence(this);
227 * Serialize the Offer object into a byte array which can be read by Offer_read
229 public byte[] write() {
230 byte[] ret = bindings.Offer_write(this.ptr);
231 Reference.reachabilityFence(this);