Update auto-generated bindings
[ldk-java] / src / main / java / org / ldk / structs / Invoice.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 javax.annotation.Nullable;
8
9
10 /**
11  * Represents a syntactically and semantically correct lightning BOLT11 invoice.
12  * 
13  * There are three ways to construct an `Invoice`:
14  * 1. using `InvoiceBuilder`
15  * 2. using `Invoice::from_signed(SignedRawInvoice)`
16  * 3. using `str::parse::<Invoice>(&str)`
17  */
18 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
19 public class Invoice extends CommonBase {
20         Invoice(Object _dummy, long ptr) { super(ptr); }
21         @Override @SuppressWarnings("deprecation")
22         protected void finalize() throws Throwable {
23                 super.finalize();
24                 if (ptr != 0) { bindings.Invoice_free(ptr); }
25         }
26
27         /**
28          * Checks if two Invoices contain equal inner contents.
29          * This ignores pointers and is_owned flags and looks at the values in fields.
30          * Two objects with NULL inner values will be considered "equal" here.
31          */
32         public boolean eq(Invoice b) {
33                 boolean ret = bindings.Invoice_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
34                 this.ptrs_to.add(b);
35                 return ret;
36         }
37
38         long clone_ptr() {
39                 long ret = bindings.Invoice_clone_ptr(this.ptr);
40                 return ret;
41         }
42
43         /**
44          * Creates a copy of the Invoice
45          */
46         public Invoice clone() {
47                 long ret = bindings.Invoice_clone(this.ptr);
48                 if (ret >= 0 && ret <= 4096) { return null; }
49                 Invoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Invoice(null, ret); }
50                 ret_hu_conv.ptrs_to.add(this);
51                 return ret_hu_conv;
52         }
53
54         /**
55          * Transform the `Invoice` into it's unchecked version
56          */
57         public SignedRawInvoice into_signed_raw() {
58                 long ret = bindings.Invoice_into_signed_raw(this.ptr);
59                 if (ret >= 0 && ret <= 4096) { return null; }
60                 SignedRawInvoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new SignedRawInvoice(null, ret); }
61                 ret_hu_conv.ptrs_to.add(this);
62                 ;
63                 return ret_hu_conv;
64         }
65
66         /**
67          * Check that the invoice is signed correctly and that key recovery works
68          */
69         public Result_NoneSemanticErrorZ check_signature() {
70                 long ret = bindings.Invoice_check_signature(this.ptr);
71                 if (ret >= 0 && ret <= 4096) { return null; }
72                 Result_NoneSemanticErrorZ ret_hu_conv = Result_NoneSemanticErrorZ.constr_from_ptr(ret);
73                 return ret_hu_conv;
74         }
75
76         /**
77          * Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
78          * ```
79          * use lightning_invoice::*;
80          * 
81          * let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
82          * h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
83          * 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
84          * h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
85          * j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
86          * ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
87          * guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
88          * ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
89          * p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
90          * 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
91          * j5r6drg6k6zcqj0fcwg\";
92          * 
93          * let signed = invoice.parse::<SignedRawInvoice>().unwrap();
94          * 
95          * assert!(Invoice::from_signed(signed).is_ok());
96          * ```
97          */
98         public static Result_InvoiceSemanticErrorZ from_signed(SignedRawInvoice signed_invoice) {
99                 long ret = bindings.Invoice_from_signed(signed_invoice == null ? 0 : signed_invoice.ptr & ~1);
100                 if (ret >= 0 && ret <= 4096) { return null; }
101                 Result_InvoiceSemanticErrorZ ret_hu_conv = Result_InvoiceSemanticErrorZ.constr_from_ptr(ret);
102                 return ret_hu_conv;
103         }
104
105         /**
106          * Returns the `Invoice`'s timestamp (should equal it's creation time)
107          */
108         public long timestamp() {
109                 long ret = bindings.Invoice_timestamp(this.ptr);
110                 return ret;
111         }
112
113         /**
114          * Returns the hash to which we will receive the preimage on completion of the payment
115          */
116         public byte[] payment_hash() {
117                 byte[] ret = bindings.Invoice_payment_hash(this.ptr);
118                 return ret;
119         }
120
121         /**
122          * Get the payee's public key if one was included in the invoice
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 byte[] payee_pub_key() {
128                 byte[] ret = bindings.Invoice_payee_pub_key(this.ptr);
129                 return ret;
130         }
131
132         /**
133          * Get the payment secret if one was included in the invoice
134          */
135         public byte[] payment_secret() {
136                 byte[] ret = bindings.Invoice_payment_secret(this.ptr);
137                 return ret;
138         }
139
140         /**
141          * Get the invoice features if they were included in the invoice
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 InvoiceFeatures features() {
147                 long ret = bindings.Invoice_features(this.ptr);
148                 if (ret >= 0 && ret <= 4096) { return null; }
149                 InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new InvoiceFeatures(null, ret); }
150                 ret_hu_conv.ptrs_to.add(this);
151                 return ret_hu_conv;
152         }
153
154         /**
155          * Recover the payee's public key (only to be used if none was included in the invoice)
156          */
157         public byte[] recover_payee_pub_key() {
158                 byte[] ret = bindings.Invoice_recover_payee_pub_key(this.ptr);
159                 return ret;
160         }
161
162         /**
163          * Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
164          */
165         public long expiry_time() {
166                 long ret = bindings.Invoice_expiry_time(this.ptr);
167                 return ret;
168         }
169
170         /**
171          * Returns whether the invoice has expired.
172          */
173         public boolean is_expired() {
174                 boolean ret = bindings.Invoice_is_expired(this.ptr);
175                 return ret;
176         }
177
178         /**
179          * Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
180          * [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
181          */
182         public long min_final_cltv_expiry() {
183                 long ret = bindings.Invoice_min_final_cltv_expiry(this.ptr);
184                 return ret;
185         }
186
187         /**
188          * Returns a list of all routes included in the invoice
189          */
190         public PrivateRoute[] private_routes() {
191                 long[] ret = bindings.Invoice_private_routes(this.ptr);
192                 PrivateRoute[] ret_conv_14_arr = new PrivateRoute[ret.length];
193                 for (int o = 0; o < ret.length; o++) {
194                         long ret_conv_14 = ret[o];
195                         PrivateRoute ret_conv_14_hu_conv = null; if (ret_conv_14 < 0 || ret_conv_14 > 4096) { ret_conv_14_hu_conv = new PrivateRoute(null, ret_conv_14); }
196                         ret_conv_14_hu_conv.ptrs_to.add(this);
197                         ret_conv_14_arr[o] = ret_conv_14_hu_conv;
198                 }
199                 return ret_conv_14_arr;
200         }
201
202         /**
203          * Returns a list of all routes included in the invoice as the underlying hints
204          */
205         public RouteHint[] route_hints() {
206                 long[] ret = bindings.Invoice_route_hints(this.ptr);
207                 RouteHint[] ret_conv_11_arr = new RouteHint[ret.length];
208                 for (int l = 0; l < ret.length; l++) {
209                         long ret_conv_11 = ret[l];
210                         RouteHint ret_conv_11_hu_conv = null; if (ret_conv_11 < 0 || ret_conv_11 > 4096) { ret_conv_11_hu_conv = new RouteHint(null, ret_conv_11); }
211                         ret_conv_11_hu_conv.ptrs_to.add(this);
212                         ret_conv_11_arr[l] = ret_conv_11_hu_conv;
213                 }
214                 return ret_conv_11_arr;
215         }
216
217         /**
218          * Returns the currency for which the invoice was issued
219          */
220         public Currency currency() {
221                 Currency ret = bindings.Invoice_currency(this.ptr);
222                 return ret;
223         }
224
225         /**
226          * Returns the amount if specified in the invoice as millisatoshis.
227          */
228         public Option_u64Z amount_milli_satoshis() {
229                 long ret = bindings.Invoice_amount_milli_satoshis(this.ptr);
230                 if (ret >= 0 && ret <= 4096) { return null; }
231                 Option_u64Z ret_hu_conv = Option_u64Z.constr_from_ptr(ret);
232                 ret_hu_conv.ptrs_to.add(this);
233                 return ret_hu_conv;
234         }
235
236         /**
237          * Read a Invoice object from a string
238          */
239         public static Result_InvoiceNoneZ from_str(java.lang.String s) {
240                 long ret = bindings.Invoice_from_str(s);
241                 if (ret >= 0 && ret <= 4096) { return null; }
242                 Result_InvoiceNoneZ ret_hu_conv = Result_InvoiceNoneZ.constr_from_ptr(ret);
243                 return ret_hu_conv;
244         }
245
246         /**
247          * Get the string representation of a Invoice object
248          */
249         public String to_str() {
250                 String ret = bindings.Invoice_to_str(this.ptr);
251                 return ret;
252         }
253
254 }