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