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 * A complete description of the purpose of the originating offer or refund. Intended to be
50 * displayed to the user but with the caveat that it has not been verified in any way.
52 public PrintableString description() {
53 long ret = bindings.Bolt12Invoice_description(this.ptr);
54 Reference.reachabilityFence(this);
55 if (ret >= 0 && ret <= 4096) { return null; }
56 org.ldk.structs.PrintableString ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PrintableString(null, ret); }
57 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
62 * Duration since the Unix epoch when the invoice was created.
64 public long created_at() {
65 long ret = bindings.Bolt12Invoice_created_at(this.ptr);
66 Reference.reachabilityFence(this);
71 * Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
72 * should no longer be paid.
74 public long relative_expiry() {
75 long ret = bindings.Bolt12Invoice_relative_expiry(this.ptr);
76 Reference.reachabilityFence(this);
81 * Whether the invoice has expired.
83 public boolean is_expired() {
84 boolean ret = bindings.Bolt12Invoice_is_expired(this.ptr);
85 Reference.reachabilityFence(this);
90 * SHA256 hash of the payment preimage that will be given in return for paying the invoice.
92 public byte[] payment_hash() {
93 byte[] ret = bindings.Bolt12Invoice_payment_hash(this.ptr);
94 Reference.reachabilityFence(this);
99 * The minimum amount required for a successful payment of the invoice.
101 public long amount_msats() {
102 long ret = bindings.Bolt12Invoice_amount_msats(this.ptr);
103 Reference.reachabilityFence(this);
108 * Features pertaining to paying an invoice.
110 public Bolt12InvoiceFeatures features() {
111 long ret = bindings.Bolt12Invoice_features(this.ptr);
112 Reference.reachabilityFence(this);
113 if (ret >= 0 && ret <= 4096) { return null; }
114 org.ldk.structs.Bolt12InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Bolt12InvoiceFeatures(null, ret); }
115 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
120 * The public key corresponding to the key used to sign the invoice.
122 public byte[] signing_pubkey() {
123 byte[] ret = bindings.Bolt12Invoice_signing_pubkey(this.ptr);
124 Reference.reachabilityFence(this);
129 * Hash that was used for signing the invoice.
131 public byte[] signable_hash() {
132 byte[] ret = bindings.Bolt12Invoice_signable_hash(this.ptr);
133 Reference.reachabilityFence(this);
138 * Verifies that the invoice was for a request or refund created using the given key.
140 public boolean verify(org.ldk.structs.ExpandedKey key) {
141 boolean ret = bindings.Bolt12Invoice_verify(this.ptr, key == null ? 0 : key.ptr);
142 Reference.reachabilityFence(this);
143 Reference.reachabilityFence(key);
144 if (this != null) { this.ptrs_to.add(key); };
149 * Serialize the Bolt12Invoice object into a byte array which can be read by Bolt12Invoice_read
151 public byte[] write() {
152 byte[] ret = bindings.Bolt12Invoice_write(this.ptr);
153 Reference.reachabilityFence(this);