[Java] Update auto-generated bindings to LDK 0.0.123
[ldk-java] / src / main / java / org / ldk / structs / Bolt12Invoice.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * A `Bolt12Invoice` is a payment request, typically corresponding to an [`Offer`] or a [`Refund`].
13  * 
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.
16  * 
17  * [`Offer`]: crate::offers::offer::Offer
18  * [`Refund`]: crate::offers::refund::Refund
19  * [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
20  */
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 {
26                 super.finalize();
27                 if (ptr != 0) { bindings.Bolt12Invoice_free(ptr); }
28         }
29
30         long clone_ptr() {
31                 long ret = bindings.Bolt12Invoice_clone_ptr(this.ptr);
32                 Reference.reachabilityFence(this);
33                 return ret;
34         }
35
36         /**
37          * Creates a copy of the Bolt12Invoice
38          */
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); };
45                 return ret_hu_conv;
46         }
47
48         /**
49          * The chains that may be used when paying a requested invoice.
50          * 
51          * From [`Offer::chains`]; `None` if the invoice was created in response to a [`Refund`].
52          * 
53          * [`Offer::chains`]: crate::offers::offer::Offer::chains
54          */
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); };
61                 return ret_hu_conv;
62         }
63
64         /**
65          * The chain that must be used when paying the invoice; selected from [`offer_chains`] if the
66          * invoice originated from an offer.
67          * 
68          * From [`InvoiceRequest::chain`] or [`Refund::chain`].
69          * 
70          * [`offer_chains`]: Self::offer_chains
71          * [`InvoiceRequest::chain`]: crate::offers::invoice_request::InvoiceRequest::chain
72          */
73         public byte[] chain() {
74                 byte[] ret = bindings.Bolt12Invoice_chain(this.ptr);
75                 Reference.reachabilityFence(this);
76                 return ret;
77         }
78
79         /**
80          * Opaque bytes set by the originating [`Offer`].
81          * 
82          * From [`Offer::metadata`]; `None` if the invoice was created in response to a [`Refund`] or
83          * if the [`Offer`] did not set it.
84          * 
85          * [`Offer`]: crate::offers::offer::Offer
86          * [`Offer::metadata`]: crate::offers::offer::Offer::metadata
87          */
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); };
94                 return ret_hu_conv;
95         }
96
97         /**
98          * The minimum amount required for a successful payment of a single item.
99          * 
100          * From [`Offer::amount`]; `None` if the invoice was created in response to a [`Refund`] or if
101          * the [`Offer`] did not set it.
102          * 
103          * [`Offer`]: crate::offers::offer::Offer
104          * [`Offer::amount`]: crate::offers::offer::Offer::amount
105          */
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); };
112                 return ret_hu_conv;
113         }
114
115         /**
116          * Features pertaining to the originating [`Offer`].
117          * 
118          * From [`Offer::offer_features`]; `None` if the invoice was created in response to a
119          * [`Refund`].
120          * 
121          * [`Offer`]: crate::offers::offer::Offer
122          * [`Offer::offer_features`]: crate::offers::offer::Offer::offer_features
123          * 
124          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
125          */
126         @Nullable
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); };
133                 return ret_hu_conv;
134         }
135
136         /**
137          * A complete description of the purpose of the originating offer or refund.
138          * 
139          * From [`Offer::description`] or [`Refund::description`].
140          * 
141          * [`Offer::description`]: crate::offers::offer::Offer::description
142          * 
143          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
144          */
145         @Nullable
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); };
152                 return ret_hu_conv;
153         }
154
155         /**
156          * Duration since the Unix epoch when an invoice should no longer be requested.
157          * 
158          * From [`Offer::absolute_expiry`] or [`Refund::absolute_expiry`].
159          * 
160          * [`Offer::absolute_expiry`]: crate::offers::offer::Offer::absolute_expiry
161          */
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); };
168                 return ret_hu_conv;
169         }
170
171         /**
172          * The issuer of the offer or refund.
173          * 
174          * From [`Offer::issuer`] or [`Refund::issuer`].
175          * 
176          * [`Offer::issuer`]: crate::offers::offer::Offer::issuer
177          * 
178          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
179          */
180         @Nullable
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); };
187                 return ret_hu_conv;
188         }
189
190         /**
191          * Paths to the recipient originating from publicly reachable nodes.
192          * 
193          * From [`Offer::paths`] or [`Refund::paths`].
194          * 
195          * [`Offer::paths`]: crate::offers::offer::Offer::paths
196          */
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;
207                 }
208                 return ret_conv_13_arr;
209         }
210
211         /**
212          * The quantity of items supported.
213          * 
214          * From [`Offer::supported_quantity`]; `None` if the invoice was created in response to a
215          * [`Refund`].
216          * 
217          * [`Offer::supported_quantity`]: crate::offers::offer::Offer::supported_quantity
218          */
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); };
225                 return ret_hu_conv;
226         }
227
228         /**
229          * An unpredictable series of bytes from the payer.
230          * 
231          * From [`InvoiceRequest::payer_metadata`] or [`Refund::payer_metadata`].
232          */
233         public byte[] payer_metadata() {
234                 byte[] ret = bindings.Bolt12Invoice_payer_metadata(this.ptr);
235                 Reference.reachabilityFence(this);
236                 return ret;
237         }
238
239         /**
240          * Features pertaining to requesting an invoice.
241          * 
242          * From [`InvoiceRequest::invoice_request_features`] or [`Refund::features`].
243          */
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); };
250                 return ret_hu_conv;
251         }
252
253         /**
254          * The quantity of items requested or refunded for.
255          * 
256          * From [`InvoiceRequest::quantity`] or [`Refund::quantity`].
257          */
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); };
264                 return ret_hu_conv;
265         }
266
267         /**
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`].
270          * 
271          * [`message_paths`]: Self::message_paths
272          */
273         public byte[] payer_id() {
274                 byte[] ret = bindings.Bolt12Invoice_payer_id(this.ptr);
275                 Reference.reachabilityFence(this);
276                 return ret;
277         }
278
279         /**
280          * A payer-provided note reflected back in the invoice.
281          * 
282          * From [`InvoiceRequest::payer_note`] or [`Refund::payer_note`].
283          * 
284          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
285          */
286         @Nullable
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); };
293                 return ret_hu_conv;
294         }
295
296         /**
297          * Duration since the Unix epoch when the invoice was created.
298          */
299         public long created_at() {
300                 long ret = bindings.Bolt12Invoice_created_at(this.ptr);
301                 Reference.reachabilityFence(this);
302                 return ret;
303         }
304
305         /**
306          * Duration since [`Bolt12Invoice::created_at`] when the invoice has expired and therefore
307          * should no longer be paid.
308          */
309         public long relative_expiry() {
310                 long ret = bindings.Bolt12Invoice_relative_expiry(this.ptr);
311                 Reference.reachabilityFence(this);
312                 return ret;
313         }
314
315         /**
316          * Whether the invoice has expired.
317          */
318         public boolean is_expired() {
319                 boolean ret = bindings.Bolt12Invoice_is_expired(this.ptr);
320                 Reference.reachabilityFence(this);
321                 return ret;
322         }
323
324         /**
325          * SHA256 hash of the payment preimage that will be given in return for paying the invoice.
326          */
327         public byte[] payment_hash() {
328                 byte[] ret = bindings.Bolt12Invoice_payment_hash(this.ptr);
329                 Reference.reachabilityFence(this);
330                 return ret;
331         }
332
333         /**
334          * The minimum amount required for a successful payment of the invoice.
335          */
336         public long amount_msats() {
337                 long ret = bindings.Bolt12Invoice_amount_msats(this.ptr);
338                 Reference.reachabilityFence(this);
339                 return ret;
340         }
341
342         /**
343          * Features pertaining to paying an invoice.
344          */
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); };
351                 return ret_hu_conv;
352         }
353
354         /**
355          * The public key corresponding to the key used to sign the invoice.
356          */
357         public byte[] signing_pubkey() {
358                 byte[] ret = bindings.Bolt12Invoice_signing_pubkey(this.ptr);
359                 Reference.reachabilityFence(this);
360                 return ret;
361         }
362
363         /**
364          * Signature of the invoice verified using [`Bolt12Invoice::signing_pubkey`].
365          */
366         public byte[] signature() {
367                 byte[] ret = bindings.Bolt12Invoice_signature(this.ptr);
368                 Reference.reachabilityFence(this);
369                 return ret;
370         }
371
372         /**
373          * Hash that was used for signing the invoice.
374          */
375         public byte[] signable_hash() {
376                 byte[] ret = bindings.Bolt12Invoice_signable_hash(this.ptr);
377                 Reference.reachabilityFence(this);
378                 return ret;
379         }
380
381         /**
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.
384          */
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); };
392                 return ret_hu_conv;
393         }
394
395         /**
396          * Generates a non-cryptographic 64-bit hash of the Bolt12Invoice.
397          */
398         public long hash() {
399                 long ret = bindings.Bolt12Invoice_hash(this.ptr);
400                 Reference.reachabilityFence(this);
401                 return ret;
402         }
403
404         @Override public int hashCode() {
405                 return (int)this.hash();
406         }
407         /**
408          * Serialize the Bolt12Invoice object into a byte array which can be read by Bolt12Invoice_read
409          */
410         public byte[] write() {
411                 byte[] ret = bindings.Bolt12Invoice_write(this.ptr);
412                 Reference.reachabilityFence(this);
413                 return ret;
414         }
415
416 }