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 * A `Bolt12Invoice` is a payment request, typically corresponding to an [`Offer`] or a [`Refund`].
14 * An invoice may be sent in response to an [`InvoiceRequest`] in the case of an offer or sent
15 * directly after scanning a refund. It includes all the information needed to pay a recipient.
17 * [`Offer`]: crate::offers::offer::Offer
18 * [`Refund`]: crate::offers::refund::Refund
19 * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
21 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
22 public class Bolt12Invoice extends CommonBase {
23 Bolt12Invoice(Object _dummy, long ptr) { super(ptr); }
24 @Override @SuppressWarnings("deprecation")
25 protected void finalize() throws Throwable {
27 if (ptr != 0) { bindings.Bolt12Invoice_free(ptr); }
31 long ret = bindings.Bolt12Invoice_clone_ptr(this.ptr);
32 Reference.reachabilityFence(this);
37 * Creates a copy of the Bolt12Invoice
39 public Bolt12Invoice clone() {
40 long ret = bindings.Bolt12Invoice_clone(this.ptr);
41 Reference.reachabilityFence(this);
42 if (ret >= 0 && ret <= 4096) { return null; }
43 org.ldk.structs.Bolt12Invoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Bolt12Invoice(null, ret); }
44 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
49 * The chains that may be used when paying a requested invoice.
51 * From [`Offer::chains`]; `None` if the invoice was created in response to a [`Refund`].
53 * [`Offer::chains`]: crate::offers::offer::Offer::chains
55 public Option_CVec_ThirtyTwoBytesZZ offer_chains() {
56 long ret = bindings.Bolt12Invoice_offer_chains(this.ptr);
57 Reference.reachabilityFence(this);
58 if (ret >= 0 && ret <= 4096) { return null; }
59 org.ldk.structs.Option_CVec_ThirtyTwoBytesZZ ret_hu_conv = org.ldk.structs.Option_CVec_ThirtyTwoBytesZZ.constr_from_ptr(ret);
60 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
65 * The chain that must be used when paying the invoice; selected from [`offer_chains`] if the
66 * invoice originated from an offer.
68 * From [`InvoiceRequest::chain`] or [`Refund::chain`].
70 * [`offer_chains`]: Self::offer_chains
71 * [`InvoiceRequest::chain`]: crate::offers::invoice_request::InvoiceRequest::chain
73 public byte[] chain() {
74 byte[] ret = bindings.Bolt12Invoice_chain(this.ptr);
75 Reference.reachabilityFence(this);
80 * Opaque bytes set by the originating [`Offer`].
82 * From [`Offer::metadata`]; `None` if the invoice was created in response to a [`Refund`] or
83 * if the [`Offer`] did not set it.
85 * [`Offer`]: crate::offers::offer::Offer
86 * [`Offer::metadata`]: crate::offers::offer::Offer::metadata
88 public Option_CVec_u8ZZ metadata() {
89 long ret = bindings.Bolt12Invoice_metadata(this.ptr);
90 Reference.reachabilityFence(this);
91 if (ret >= 0 && ret <= 4096) { return null; }
92 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
93 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
98 * The minimum amount required for a successful payment of a single item.
100 * From [`Offer::amount`]; `None` if the invoice was created in response to a [`Refund`] or if
101 * the [`Offer`] did not set it.
103 * [`Offer`]: crate::offers::offer::Offer
104 * [`Offer::amount`]: crate::offers::offer::Offer::amount
106 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
109 public Amount amount() {
110 long ret = bindings.Bolt12Invoice_amount(this.ptr);
111 Reference.reachabilityFence(this);
112 if (ret >= 0 && ret <= 4096) { return null; }
113 org.ldk.structs.Amount ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Amount(null, ret); }
114 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
119 * Features pertaining to the originating [`Offer`].
121 * From [`Offer::offer_features`]; `None` if the invoice was created in response to a
124 * [`Offer`]: crate::offers::offer::Offer
125 * [`Offer::offer_features`]: crate::offers::offer::Offer::offer_features
127 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
130 public OfferFeatures offer_features() {
131 long ret = bindings.Bolt12Invoice_offer_features(this.ptr);
132 Reference.reachabilityFence(this);
133 if (ret >= 0 && ret <= 4096) { return null; }
134 org.ldk.structs.OfferFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OfferFeatures(null, ret); }
135 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
140 * A complete description of the purpose of the originating offer or refund.
142 * From [`Offer::description`] or [`Refund::description`].
144 * [`Offer::description`]: crate::offers::offer::Offer::description
146 public PrintableString description() {
147 long ret = bindings.Bolt12Invoice_description(this.ptr);
148 Reference.reachabilityFence(this);
149 if (ret >= 0 && ret <= 4096) { return null; }
150 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
151 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
156 * Duration since the Unix epoch when an invoice should no longer be requested.
158 * From [`Offer::absolute_expiry`] or [`Refund::absolute_expiry`].
160 * [`Offer::absolute_expiry`]: crate::offers::offer::Offer::absolute_expiry
162 public Option_u64Z absolute_expiry() {
163 long ret = bindings.Bolt12Invoice_absolute_expiry(this.ptr);
164 Reference.reachabilityFence(this);
165 if (ret >= 0 && ret <= 4096) { return null; }
166 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
167 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
172 * The issuer of the offer or refund.
174 * From [`Offer::issuer`] or [`Refund::issuer`].
176 * [`Offer::issuer`]: crate::offers::offer::Offer::issuer
178 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
181 public PrintableString issuer() {
182 long ret = bindings.Bolt12Invoice_issuer(this.ptr);
183 Reference.reachabilityFence(this);
184 if (ret >= 0 && ret <= 4096) { return null; }
185 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
186 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
191 * Paths to the recipient originating from publicly reachable nodes.
193 * From [`Offer::paths`] or [`Refund::paths`].
195 * [`Offer::paths`]: crate::offers::offer::Offer::paths
197 public BlindedPath[] message_paths() {
198 long[] ret = bindings.Bolt12Invoice_message_paths(this.ptr);
199 Reference.reachabilityFence(this);
200 int ret_conv_13_len = ret.length;
201 BlindedPath[] ret_conv_13_arr = new BlindedPath[ret_conv_13_len];
202 for (int n = 0; n < ret_conv_13_len; n++) {
203 long ret_conv_13 = ret[n];
204 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); }
205 if (ret_conv_13_hu_conv != null) { ret_conv_13_hu_conv.ptrs_to.add(this); };
206 ret_conv_13_arr[n] = ret_conv_13_hu_conv;
208 return ret_conv_13_arr;
212 * The quantity of items supported.
214 * From [`Offer::supported_quantity`]; `None` if the invoice was created in response to a
217 * [`Offer::supported_quantity`]: crate::offers::offer::Offer::supported_quantity
219 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
222 public Quantity supported_quantity() {
223 long ret = bindings.Bolt12Invoice_supported_quantity(this.ptr);
224 Reference.reachabilityFence(this);
225 if (ret >= 0 && ret <= 4096) { return null; }
226 org.ldk.structs.Quantity ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Quantity(null, ret); }
227 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
232 * An unpredictable series of bytes from the payer.
234 * From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
236 public byte[] payer_metadata() {
237 byte[] ret = bindings.Bolt12Invoice_payer_metadata(this.ptr);
238 Reference.reachabilityFence(this);
243 * Features pertaining to requesting an invoice.
245 * From [`InvoiceRequest::invoice_request_features`] or [`Refund::features`].
247 public InvoiceRequestFeatures invoice_request_features() {
248 long ret = bindings.Bolt12Invoice_invoice_request_features(this.ptr);
249 Reference.reachabilityFence(this);
250 if (ret >= 0 && ret <= 4096) { return null; }
251 org.ldk.structs.InvoiceRequestFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InvoiceRequestFeatures(null, ret); }
252 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
257 * The quantity of items requested or refunded for.
259 * From [`InvoiceRequest::quantity`] or [`Refund::quantity`].
261 public Option_u64Z quantity() {
262 long ret = bindings.Bolt12Invoice_quantity(this.ptr);
263 Reference.reachabilityFence(this);
264 if (ret >= 0 && ret <= 4096) { return null; }
265 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
266 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
271 * A possibly transient pubkey used to sign the invoice request or to send an invoice for a
272 * refund in case there are no [`message_paths`].
274 * [`message_paths`]: Self::message_paths
276 public byte[] payer_id() {
277 byte[] ret = bindings.Bolt12Invoice_payer_id(this.ptr);
278 Reference.reachabilityFence(this);
283 * A payer-provided note reflected back in the invoice.
285 * From [`InvoiceRequest::payer_note`] or [`Refund::payer_note`].
287 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
290 public PrintableString payer_note() {
291 long ret = bindings.Bolt12Invoice_payer_note(this.ptr);
292 Reference.reachabilityFence(this);
293 if (ret >= 0 && ret <= 4096) { return null; }
294 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
295 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
300 * Duration since the Unix epoch when the invoice was created.
302 public long created_at() {
303 long ret = bindings.Bolt12Invoice_created_at(this.ptr);
304 Reference.reachabilityFence(this);
309 * Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
310 * should no longer be paid.
312 public long relative_expiry() {
313 long ret = bindings.Bolt12Invoice_relative_expiry(this.ptr);
314 Reference.reachabilityFence(this);
319 * Whether the invoice has expired.
321 public boolean is_expired() {
322 boolean ret = bindings.Bolt12Invoice_is_expired(this.ptr);
323 Reference.reachabilityFence(this);
328 * SHA256 hash of the payment preimage that will be given in return for paying the invoice.
330 public byte[] payment_hash() {
331 byte[] ret = bindings.Bolt12Invoice_payment_hash(this.ptr);
332 Reference.reachabilityFence(this);
337 * The minimum amount required for a successful payment of the invoice.
339 public long amount_msats() {
340 long ret = bindings.Bolt12Invoice_amount_msats(this.ptr);
341 Reference.reachabilityFence(this);
346 * Features pertaining to paying an invoice.
348 public Bolt12InvoiceFeatures invoice_features() {
349 long ret = bindings.Bolt12Invoice_invoice_features(this.ptr);
350 Reference.reachabilityFence(this);
351 if (ret >= 0 && ret <= 4096) { return null; }
352 org.ldk.structs.Bolt12InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Bolt12InvoiceFeatures(null, ret); }
353 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
358 * The public key corresponding to the key used to sign the invoice.
360 public byte[] signing_pubkey() {
361 byte[] ret = bindings.Bolt12Invoice_signing_pubkey(this.ptr);
362 Reference.reachabilityFence(this);
367 * Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
369 public byte[] signature() {
370 byte[] ret = bindings.Bolt12Invoice_signature(this.ptr);
371 Reference.reachabilityFence(this);
376 * Hash that was used for signing the invoice.
378 public byte[] signable_hash() {
379 byte[] ret = bindings.Bolt12Invoice_signable_hash(this.ptr);
380 Reference.reachabilityFence(this);
385 * Verifies that the invoice was for a request or refund created using the given key. Returns
386 * the associated [`PaymentId`] to use when sending the payment.
388 public Result_ThirtyTwoBytesNoneZ verify(org.ldk.structs.ExpandedKey key) {
389 long ret = bindings.Bolt12Invoice_verify(this.ptr, key == null ? 0 : key.ptr);
390 Reference.reachabilityFence(this);
391 Reference.reachabilityFence(key);
392 if (ret >= 0 && ret <= 4096) { return null; }
393 Result_ThirtyTwoBytesNoneZ ret_hu_conv = Result_ThirtyTwoBytesNoneZ.constr_from_ptr(ret);
394 if (this != null) { this.ptrs_to.add(key); };
399 * Serialize the Bolt12Invoice object into a byte array which can be read by Bolt12Invoice_read
401 public byte[] write() {
402 byte[] ret = bindings.Bolt12Invoice_write(this.ptr);
403 Reference.reachabilityFence(this);