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 `InvoiceRequest` is a request for a [`Bolt12Invoice`] formulated from an [`Offer`].
14 * An offer may provide choices such as quantity, amount, chain, features, etc. An invoice request
15 * specifies these such that its recipient can send an invoice for payment.
17 * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
18 * [`Offer`]: crate::offers::offer::Offer
20 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
21 public class InvoiceRequest extends CommonBase {
22 InvoiceRequest(Object _dummy, long ptr) { super(ptr); }
23 @Override @SuppressWarnings("deprecation")
24 protected void finalize() throws Throwable {
26 if (ptr != 0) { bindings.InvoiceRequest_free(ptr); }
30 long ret = bindings.InvoiceRequest_clone_ptr(this.ptr);
31 Reference.reachabilityFence(this);
36 * Creates a copy of the InvoiceRequest
38 public InvoiceRequest clone() {
39 long ret = bindings.InvoiceRequest_clone(this.ptr);
40 Reference.reachabilityFence(this);
41 if (ret >= 0 && ret <= 4096) { return null; }
42 org.ldk.structs.InvoiceRequest ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InvoiceRequest(null, ret); }
43 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
48 * The chains that may be used when paying a requested invoice (e.g., bitcoin mainnet).
49 * Payments must be denominated in units of the minimal lightning-payable unit (e.g., msats)
50 * for the selected chain.
52 public byte[][] chains() {
53 byte[][] ret = bindings.InvoiceRequest_chains(this.ptr);
54 Reference.reachabilityFence(this);
59 * Opaque bytes set by the originator. Useful for authentication and validating fields since it
60 * is reflected in `invoice_request` messages along with all the other fields from the `offer`.
62 public Option_CVec_u8ZZ metadata() {
63 long ret = bindings.InvoiceRequest_metadata(this.ptr);
64 Reference.reachabilityFence(this);
65 if (ret >= 0 && ret <= 4096) { return null; }
66 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
67 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
72 * The minimum amount required for a successful payment of a single item.
74 public Option_AmountZ amount() {
75 long ret = bindings.InvoiceRequest_amount(this.ptr);
76 Reference.reachabilityFence(this);
77 if (ret >= 0 && ret <= 4096) { return null; }
78 org.ldk.structs.Option_AmountZ ret_hu_conv = org.ldk.structs.Option_AmountZ.constr_from_ptr(ret);
79 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
84 * A complete description of the purpose of the payment. Intended to be displayed to the user
85 * but with the caveat that it has not been verified in any way.
87 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
90 public PrintableString description() {
91 long ret = bindings.InvoiceRequest_description(this.ptr);
92 Reference.reachabilityFence(this);
93 if (ret >= 0 && ret <= 4096) { return null; }
94 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
95 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
100 * Features pertaining to the offer.
102 public OfferFeatures offer_features() {
103 long ret = bindings.InvoiceRequest_offer_features(this.ptr);
104 Reference.reachabilityFence(this);
105 if (ret >= 0 && ret <= 4096) { return null; }
106 org.ldk.structs.OfferFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OfferFeatures(null, ret); }
107 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
112 * Duration since the Unix epoch when an invoice should no longer be requested.
114 * If `None`, the offer does not expire.
116 public Option_u64Z absolute_expiry() {
117 long ret = bindings.InvoiceRequest_absolute_expiry(this.ptr);
118 Reference.reachabilityFence(this);
119 if (ret >= 0 && ret <= 4096) { return null; }
120 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
121 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
126 * The issuer of the offer, possibly beginning with `user@domain` or `domain`. Intended to be
127 * displayed to the user but with the caveat that it has not been verified in any way.
129 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
132 public PrintableString issuer() {
133 long ret = bindings.InvoiceRequest_issuer(this.ptr);
134 Reference.reachabilityFence(this);
135 if (ret >= 0 && ret <= 4096) { return null; }
136 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
137 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
142 * Paths to the recipient originating from publicly reachable nodes. Blinded paths provide
143 * recipient privacy by obfuscating its node id.
145 public BlindedPath[] paths() {
146 long[] ret = bindings.InvoiceRequest_paths(this.ptr);
147 Reference.reachabilityFence(this);
148 int ret_conv_13_len = ret.length;
149 BlindedPath[] ret_conv_13_arr = new BlindedPath[ret_conv_13_len];
150 for (int n = 0; n < ret_conv_13_len; n++) {
151 long ret_conv_13 = ret[n];
152 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); }
153 if (ret_conv_13_hu_conv != null) { ret_conv_13_hu_conv.ptrs_to.add(this); };
154 ret_conv_13_arr[n] = ret_conv_13_hu_conv;
156 return ret_conv_13_arr;
160 * The quantity of items supported.
162 public Quantity supported_quantity() {
163 long ret = bindings.InvoiceRequest_supported_quantity(this.ptr);
164 Reference.reachabilityFence(this);
165 if (ret >= 0 && ret <= 4096) { return null; }
166 org.ldk.structs.Quantity ret_hu_conv = org.ldk.structs.Quantity.constr_from_ptr(ret);
167 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
172 * The public key used by the recipient to sign invoices.
174 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
177 public byte[] signing_pubkey() {
178 byte[] ret = bindings.InvoiceRequest_signing_pubkey(this.ptr);
179 Reference.reachabilityFence(this);
184 * An unpredictable series of bytes, typically containing information about the derivation of
187 * [`payer_id`]: Self::payer_id
189 public byte[] payer_metadata() {
190 byte[] ret = bindings.InvoiceRequest_payer_metadata(this.ptr);
191 Reference.reachabilityFence(this);
196 * A chain from [`Offer::chains`] that the offer is valid for.
198 public byte[] chain() {
199 byte[] ret = bindings.InvoiceRequest_chain(this.ptr);
200 Reference.reachabilityFence(this);
205 * The amount to pay in msats (i.e., the minimum lightning-payable unit for [`chain`]), which
206 * must be greater than or equal to [`Offer::amount`], converted if necessary.
208 * [`chain`]: Self::chain
210 public Option_u64Z amount_msats() {
211 long ret = bindings.InvoiceRequest_amount_msats(this.ptr);
212 Reference.reachabilityFence(this);
213 if (ret >= 0 && ret <= 4096) { return null; }
214 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
215 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
220 * Features pertaining to requesting an invoice.
222 public InvoiceRequestFeatures invoice_request_features() {
223 long ret = bindings.InvoiceRequest_invoice_request_features(this.ptr);
224 Reference.reachabilityFence(this);
225 if (ret >= 0 && ret <= 4096) { return null; }
226 org.ldk.structs.InvoiceRequestFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InvoiceRequestFeatures(null, ret); }
227 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
232 * The quantity of the offer's item conforming to [`Offer::is_valid_quantity`].
234 public Option_u64Z quantity() {
235 long ret = bindings.InvoiceRequest_quantity(this.ptr);
236 Reference.reachabilityFence(this);
237 if (ret >= 0 && ret <= 4096) { return null; }
238 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
239 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
244 * A possibly transient pubkey used to sign the invoice request.
246 public byte[] payer_id() {
247 byte[] ret = bindings.InvoiceRequest_payer_id(this.ptr);
248 Reference.reachabilityFence(this);
253 * A payer-provided note which will be seen by the recipient and reflected back in the invoice
256 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
259 public PrintableString payer_note() {
260 long ret = bindings.InvoiceRequest_payer_note(this.ptr);
261 Reference.reachabilityFence(this);
262 if (ret >= 0 && ret <= 4096) { return null; }
263 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
264 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
269 * Creates an [`InvoiceBuilder`] for the request with the given required fields and using the
270 * [`Duration`] since [`std::time::SystemTime::UNIX_EPOCH`] as the creation time.
272 * See [`InvoiceRequest::respond_with_no_std`] for further details where the aforementioned
273 * creation time is used for the `created_at` parameter.
275 * [`Duration`]: core::time::Duration
277 public Result_InvoiceWithExplicitSigningPubkeyBuilderBolt12SemanticErrorZ respond_with(TwoTuple_BlindedPayInfoBlindedPathZ[] payment_paths, byte[] payment_hash) {
278 long ret = bindings.InvoiceRequest_respond_with(this.ptr, payment_paths != null ? Arrays.stream(payment_paths).mapToLong(payment_paths_conv_37 -> payment_paths_conv_37.ptr).toArray() : null, InternalUtils.check_arr_len(payment_hash, 32));
279 Reference.reachabilityFence(this);
280 Reference.reachabilityFence(payment_paths);
281 Reference.reachabilityFence(payment_hash);
282 if (ret >= 0 && ret <= 4096) { return null; }
283 Result_InvoiceWithExplicitSigningPubkeyBuilderBolt12SemanticErrorZ ret_hu_conv = Result_InvoiceWithExplicitSigningPubkeyBuilderBolt12SemanticErrorZ.constr_from_ptr(ret);
288 * Creates an [`InvoiceBuilder`] for the request with the given required fields.
290 * Unless [`InvoiceBuilder::relative_expiry`] is set, the invoice will expire two hours after
291 * `created_at`, which is used to set [`Bolt12Invoice::created_at`]. Useful for `no-std` builds
292 * where [`std::time::SystemTime`] is not available.
294 * The caller is expected to remember the preimage of `payment_hash` in order to claim a payment
297 * The `payment_paths` parameter is useful for maintaining the payment recipient's privacy. It
298 * must contain one or more elements ordered from most-preferred to least-preferred, if there's
299 * a preference. Note, however, that any privacy is lost if a public node id was used for
300 * [`Offer::signing_pubkey`].
302 * Errors if the request contains unknown required features.
306 * If the originating [`Offer`] was created using [`OfferBuilder::deriving_signing_pubkey`],
307 * then use [`InvoiceRequest::verify`] and [`VerifiedInvoiceRequest`] methods instead.
309 * [`Bolt12Invoice::created_at`]: crate::offers::invoice::Bolt12Invoice::created_at
310 * [`OfferBuilder::deriving_signing_pubkey`]: crate::offers::offer::OfferBuilder::deriving_signing_pubkey
312 public Result_InvoiceWithExplicitSigningPubkeyBuilderBolt12SemanticErrorZ respond_with_no_std(TwoTuple_BlindedPayInfoBlindedPathZ[] payment_paths, byte[] payment_hash, long created_at) {
313 long ret = bindings.InvoiceRequest_respond_with_no_std(this.ptr, payment_paths != null ? Arrays.stream(payment_paths).mapToLong(payment_paths_conv_37 -> payment_paths_conv_37.ptr).toArray() : null, InternalUtils.check_arr_len(payment_hash, 32), created_at);
314 Reference.reachabilityFence(this);
315 Reference.reachabilityFence(payment_paths);
316 Reference.reachabilityFence(payment_hash);
317 Reference.reachabilityFence(created_at);
318 if (ret >= 0 && ret <= 4096) { return null; }
319 Result_InvoiceWithExplicitSigningPubkeyBuilderBolt12SemanticErrorZ ret_hu_conv = Result_InvoiceWithExplicitSigningPubkeyBuilderBolt12SemanticErrorZ.constr_from_ptr(ret);
324 * Verifies that the request was for an offer created using the given key. Returns the verified
325 * request which contains the derived keys needed to sign a [`Bolt12Invoice`] for the request
326 * if they could be extracted from the metadata.
328 * [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
330 public Result_VerifiedInvoiceRequestNoneZ verify(org.ldk.structs.ExpandedKey key) {
331 long ret = bindings.InvoiceRequest_verify(this.ptr, key.ptr);
332 Reference.reachabilityFence(this);
333 Reference.reachabilityFence(key);
334 if (ret >= 0 && ret <= 4096) { return null; }
335 Result_VerifiedInvoiceRequestNoneZ ret_hu_conv = Result_VerifiedInvoiceRequestNoneZ.constr_from_ptr(ret);
336 if (this != null) { this.ptrs_to.add(key); };
337 if (this != null) { this.ptrs_to.add(this); };
342 * Signature of the invoice request using [`payer_id`].
344 * [`payer_id`]: Self::payer_id
346 public byte[] signature() {
347 byte[] ret = bindings.InvoiceRequest_signature(this.ptr);
348 Reference.reachabilityFence(this);
353 * Serialize the InvoiceRequest object into a byte array which can be read by InvoiceRequest_read
355 public byte[] write() {
356 byte[] ret = bindings.InvoiceRequest_write(this.ptr);
357 Reference.reachabilityFence(this);