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 public Option_AmountZ amount() {
107 long ret = bindings.Bolt12Invoice_amount(this.ptr);
108 Reference.reachabilityFence(this);
109 if (ret >= 0 && ret <= 4096) { return null; }
110 org.ldk.structs.Option_AmountZ ret_hu_conv = org.ldk.structs.Option_AmountZ.constr_from_ptr(ret);
111 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
116 * Features pertaining to the originating [`Offer`].
118 * From [`Offer::offer_features`]; `None` if the invoice was created in response to a
121 * [`Offer`]: crate::offers::offer::Offer
122 * [`Offer::offer_features`]: crate::offers::offer::Offer::offer_features
124 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
127 public OfferFeatures offer_features() {
128 long ret = bindings.Bolt12Invoice_offer_features(this.ptr);
129 Reference.reachabilityFence(this);
130 if (ret >= 0 && ret <= 4096) { return null; }
131 org.ldk.structs.OfferFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OfferFeatures(null, ret); }
132 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
137 * A complete description of the purpose of the originating offer or refund.
139 * From [`Offer::description`] or [`Refund::description`].
141 * [`Offer::description`]: crate::offers::offer::Offer::description
143 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
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 public Option_QuantityZ supported_quantity() {
220 long ret = bindings.Bolt12Invoice_supported_quantity(this.ptr);
221 Reference.reachabilityFence(this);
222 if (ret >= 0 && ret <= 4096) { return null; }
223 org.ldk.structs.Option_QuantityZ ret_hu_conv = org.ldk.structs.Option_QuantityZ.constr_from_ptr(ret);
224 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
229 * An unpredictable series of bytes from the payer.
231 * From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
233 public byte[] payer_metadata() {
234 byte[] ret = bindings.Bolt12Invoice_payer_metadata(this.ptr);
235 Reference.reachabilityFence(this);
240 * Features pertaining to requesting an invoice.
242 * From [`InvoiceRequest::invoice_request_features`] or [`Refund::features`].
244 public InvoiceRequestFeatures invoice_request_features() {
245 long ret = bindings.Bolt12Invoice_invoice_request_features(this.ptr);
246 Reference.reachabilityFence(this);
247 if (ret >= 0 && ret <= 4096) { return null; }
248 org.ldk.structs.InvoiceRequestFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InvoiceRequestFeatures(null, ret); }
249 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
254 * The quantity of items requested or refunded for.
256 * From [`InvoiceRequest::quantity`] or [`Refund::quantity`].
258 public Option_u64Z quantity() {
259 long ret = bindings.Bolt12Invoice_quantity(this.ptr);
260 Reference.reachabilityFence(this);
261 if (ret >= 0 && ret <= 4096) { return null; }
262 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
263 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
268 * A possibly transient pubkey used to sign the invoice request or to send an invoice for a
269 * refund in case there are no [`message_paths`].
271 * [`message_paths`]: Self::message_paths
273 public byte[] payer_id() {
274 byte[] ret = bindings.Bolt12Invoice_payer_id(this.ptr);
275 Reference.reachabilityFence(this);
280 * A payer-provided note reflected back in the invoice.
282 * From [`InvoiceRequest::payer_note`] or [`Refund::payer_note`].
284 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
287 public PrintableString payer_note() {
288 long ret = bindings.Bolt12Invoice_payer_note(this.ptr);
289 Reference.reachabilityFence(this);
290 if (ret >= 0 && ret <= 4096) { return null; }
291 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
292 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
297 * Duration since the Unix epoch when the invoice was created.
299 public long created_at() {
300 long ret = bindings.Bolt12Invoice_created_at(this.ptr);
301 Reference.reachabilityFence(this);
306 * Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
307 * should no longer be paid.
309 public long relative_expiry() {
310 long ret = bindings.Bolt12Invoice_relative_expiry(this.ptr);
311 Reference.reachabilityFence(this);
316 * Whether the invoice has expired.
318 public boolean is_expired() {
319 boolean ret = bindings.Bolt12Invoice_is_expired(this.ptr);
320 Reference.reachabilityFence(this);
325 * SHA256 hash of the payment preimage that will be given in return for paying the invoice.
327 public byte[] payment_hash() {
328 byte[] ret = bindings.Bolt12Invoice_payment_hash(this.ptr);
329 Reference.reachabilityFence(this);
334 * The minimum amount required for a successful payment of the invoice.
336 public long amount_msats() {
337 long ret = bindings.Bolt12Invoice_amount_msats(this.ptr);
338 Reference.reachabilityFence(this);
343 * Features pertaining to paying an invoice.
345 public Bolt12InvoiceFeatures invoice_features() {
346 long ret = bindings.Bolt12Invoice_invoice_features(this.ptr);
347 Reference.reachabilityFence(this);
348 if (ret >= 0 && ret <= 4096) { return null; }
349 org.ldk.structs.Bolt12InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Bolt12InvoiceFeatures(null, ret); }
350 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
355 * The public key corresponding to the key used to sign the invoice.
357 public byte[] signing_pubkey() {
358 byte[] ret = bindings.Bolt12Invoice_signing_pubkey(this.ptr);
359 Reference.reachabilityFence(this);
364 * Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
366 public byte[] signature() {
367 byte[] ret = bindings.Bolt12Invoice_signature(this.ptr);
368 Reference.reachabilityFence(this);
373 * Hash that was used for signing the invoice.
375 public byte[] signable_hash() {
376 byte[] ret = bindings.Bolt12Invoice_signable_hash(this.ptr);
377 Reference.reachabilityFence(this);
382 * Verifies that the invoice was for a request or refund created using the given key. Returns
383 * the associated [`PaymentId`] to use when sending the payment.
385 public Result_ThirtyTwoBytesNoneZ verify(org.ldk.structs.ExpandedKey key) {
386 long ret = bindings.Bolt12Invoice_verify(this.ptr, key.ptr);
387 Reference.reachabilityFence(this);
388 Reference.reachabilityFence(key);
389 if (ret >= 0 && ret <= 4096) { return null; }
390 Result_ThirtyTwoBytesNoneZ ret_hu_conv = Result_ThirtyTwoBytesNoneZ.constr_from_ptr(ret);
391 if (this != null) { this.ptrs_to.add(key); };
396 * Generates a non-cryptographic 64-bit hash of the Bolt12Invoice.
399 long ret = bindings.Bolt12Invoice_hash(this.ptr);
400 Reference.reachabilityFence(this);
404 @Override public int hashCode() {
405 return (int)this.hash();
408 * Serialize the Bolt12Invoice object into a byte array which can be read by Bolt12Invoice_read
410 public byte[] write() {
411 byte[] ret = bindings.Bolt12Invoice_write(this.ptr);
412 Reference.reachabilityFence(this);