[Java] Update auto-generated bindings to 0.0.117
[ldk-java] / src / main / java / org / ldk / structs / Bolt11Invoice.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 a `Bolt11Invoice`:
15  * 1. using [`InvoiceBuilder`]
16  * 2. using [`Bolt11Invoice::from_signed`]
17  * 3. using `str::parse::<Bolt11Invoice>(&str)` (see [`Bolt11Invoice::from_str`])
18  * 
19  * [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
20  */
21 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
22 public class Bolt11Invoice extends CommonBase {
23         Bolt11Invoice(Object _dummy, long ptr) { super(ptr); }
24         @Override @SuppressWarnings("deprecation")
25         protected void finalize() throws Throwable {
26                 super.finalize();
27                 if (ptr != 0) { bindings.Bolt11Invoice_free(ptr); }
28         }
29
30         /**
31          * Checks if two Bolt11Invoices contain equal inner contents.
32          * This ignores pointers and is_owned flags and looks at the values in fields.
33          * Two objects with NULL inner values will be considered "equal" here.
34          */
35         public boolean eq(org.ldk.structs.Bolt11Invoice b) {
36                 boolean ret = bindings.Bolt11Invoice_eq(this.ptr, b == null ? 0 : b.ptr);
37                 Reference.reachabilityFence(this);
38                 Reference.reachabilityFence(b);
39                 if (this != null) { this.ptrs_to.add(b); };
40                 return ret;
41         }
42
43         @Override public boolean equals(Object o) {
44                 if (!(o instanceof Bolt11Invoice)) return false;
45                 return this.eq((Bolt11Invoice)o);
46         }
47         long clone_ptr() {
48                 long ret = bindings.Bolt11Invoice_clone_ptr(this.ptr);
49                 Reference.reachabilityFence(this);
50                 return ret;
51         }
52
53         /**
54          * Creates a copy of the Bolt11Invoice
55          */
56         public Bolt11Invoice clone() {
57                 long ret = bindings.Bolt11Invoice_clone(this.ptr);
58                 Reference.reachabilityFence(this);
59                 if (ret >= 0 && ret <= 4096) { return null; }
60                 org.ldk.structs.Bolt11Invoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Bolt11Invoice(null, ret); }
61                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
62                 return ret_hu_conv;
63         }
64
65         /**
66          * Generates a non-cryptographic 64-bit hash of the Bolt11Invoice.
67          */
68         public long hash() {
69                 long ret = bindings.Bolt11Invoice_hash(this.ptr);
70                 Reference.reachabilityFence(this);
71                 return ret;
72         }
73
74         @Override public int hashCode() {
75                 return (int)this.hash();
76         }
77         /**
78          * The hash of the [`RawBolt11Invoice`] that was signed.
79          */
80         public byte[] signable_hash() {
81                 byte[] ret = bindings.Bolt11Invoice_signable_hash(this.ptr);
82                 Reference.reachabilityFence(this);
83                 return ret;
84         }
85
86         /**
87          * Transform the `Bolt11Invoice` into its unchecked version.
88          */
89         public SignedRawBolt11Invoice into_signed_raw() {
90                 long ret = bindings.Bolt11Invoice_into_signed_raw(this.ptr);
91                 Reference.reachabilityFence(this);
92                 if (ret >= 0 && ret <= 4096) { return null; }
93                 org.ldk.structs.SignedRawBolt11Invoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.SignedRawBolt11Invoice(null, ret); }
94                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
95                 if (this != null) { this.ptrs_to.add(this); };
96                 return ret_hu_conv;
97         }
98
99         /**
100          * Check that the invoice is signed correctly and that key recovery works
101          */
102         public Result_NoneBolt11SemanticErrorZ check_signature() {
103                 long ret = bindings.Bolt11Invoice_check_signature(this.ptr);
104                 Reference.reachabilityFence(this);
105                 if (ret >= 0 && ret <= 4096) { return null; }
106                 Result_NoneBolt11SemanticErrorZ ret_hu_conv = Result_NoneBolt11SemanticErrorZ.constr_from_ptr(ret);
107                 return ret_hu_conv;
108         }
109
110         /**
111          * Constructs a `Bolt11Invoice` from a [`SignedRawBolt11Invoice`] by checking all its invariants.
112          * ```
113          * use lightning_invoice::*;
114          * 
115          * let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
116          * h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
117          * 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
118          * h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
119          * j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
120          * ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
121          * guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
122          * ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
123          * p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
124          * 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
125          * j5r6drg6k6zcqj0fcwg\";
126          * 
127          * let signed = invoice.parse::<SignedRawBolt11Invoice>().unwrap();
128          * 
129          * assert!(Bolt11Invoice::from_signed(signed).is_ok());
130          * ```
131          */
132         public static Result_Bolt11InvoiceBolt11SemanticErrorZ from_signed(org.ldk.structs.SignedRawBolt11Invoice signed_invoice) {
133                 long ret = bindings.Bolt11Invoice_from_signed(signed_invoice == null ? 0 : signed_invoice.ptr);
134                 Reference.reachabilityFence(signed_invoice);
135                 if (ret >= 0 && ret <= 4096) { return null; }
136                 Result_Bolt11InvoiceBolt11SemanticErrorZ ret_hu_conv = Result_Bolt11InvoiceBolt11SemanticErrorZ.constr_from_ptr(ret);
137                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(signed_invoice); };
138                 return ret_hu_conv;
139         }
140
141         /**
142          * Returns the `Bolt11Invoice`'s timestamp (should equal its creation time)
143          */
144         public long timestamp() {
145                 long ret = bindings.Bolt11Invoice_timestamp(this.ptr);
146                 Reference.reachabilityFence(this);
147                 return ret;
148         }
149
150         /**
151          * Returns the `Bolt11Invoice`'s timestamp as a duration since the Unix epoch
152          */
153         public long duration_since_epoch() {
154                 long ret = bindings.Bolt11Invoice_duration_since_epoch(this.ptr);
155                 Reference.reachabilityFence(this);
156                 return ret;
157         }
158
159         /**
160          * Returns the hash to which we will receive the preimage on completion of the payment
161          */
162         public byte[] payment_hash() {
163                 byte[] ret = bindings.Bolt11Invoice_payment_hash(this.ptr);
164                 Reference.reachabilityFence(this);
165                 return ret;
166         }
167
168         /**
169          * Get the payee's public key if one was included in the invoice
170          * 
171          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
172          */
173         @Nullable
174         public byte[] payee_pub_key() {
175                 byte[] ret = bindings.Bolt11Invoice_payee_pub_key(this.ptr);
176                 Reference.reachabilityFence(this);
177                 return ret;
178         }
179
180         /**
181          * Get the payment secret if one was included in the invoice
182          */
183         public byte[] payment_secret() {
184                 byte[] ret = bindings.Bolt11Invoice_payment_secret(this.ptr);
185                 Reference.reachabilityFence(this);
186                 return ret;
187         }
188
189         /**
190          * Get the payment metadata blob if one was included in the invoice
191          */
192         public Option_CVec_u8ZZ payment_metadata() {
193                 long ret = bindings.Bolt11Invoice_payment_metadata(this.ptr);
194                 Reference.reachabilityFence(this);
195                 if (ret >= 0 && ret <= 4096) { return null; }
196                 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
197                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
198                 return ret_hu_conv;
199         }
200
201         /**
202          * Get the invoice features if they were included in the invoice
203          * 
204          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
205          */
206         @Nullable
207         public Bolt11InvoiceFeatures features() {
208                 long ret = bindings.Bolt11Invoice_features(this.ptr);
209                 Reference.reachabilityFence(this);
210                 if (ret >= 0 && ret <= 4096) { return null; }
211                 org.ldk.structs.Bolt11InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Bolt11InvoiceFeatures(null, ret); }
212                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
213                 return ret_hu_conv;
214         }
215
216         /**
217          * Recover the payee's public key (only to be used if none was included in the invoice)
218          */
219         public byte[] recover_payee_pub_key() {
220                 byte[] ret = bindings.Bolt11Invoice_recover_payee_pub_key(this.ptr);
221                 Reference.reachabilityFence(this);
222                 return ret;
223         }
224
225         /**
226          * Returns the Duration since the Unix epoch at which the invoice expires.
227          * Returning None if overflow occurred.
228          */
229         public Option_u64Z expires_at() {
230                 long ret = bindings.Bolt11Invoice_expires_at(this.ptr);
231                 Reference.reachabilityFence(this);
232                 if (ret >= 0 && ret <= 4096) { return null; }
233                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
234                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
235                 return ret_hu_conv;
236         }
237
238         /**
239          * Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
240          */
241         public long expiry_time() {
242                 long ret = bindings.Bolt11Invoice_expiry_time(this.ptr);
243                 Reference.reachabilityFence(this);
244                 return ret;
245         }
246
247         /**
248          * Returns whether the invoice has expired.
249          */
250         public boolean is_expired() {
251                 boolean ret = bindings.Bolt11Invoice_is_expired(this.ptr);
252                 Reference.reachabilityFence(this);
253                 return ret;
254         }
255
256         /**
257          * Returns the Duration remaining until the invoice expires.
258          */
259         public long duration_until_expiry() {
260                 long ret = bindings.Bolt11Invoice_duration_until_expiry(this.ptr);
261                 Reference.reachabilityFence(this);
262                 return ret;
263         }
264
265         /**
266          * Returns the Duration remaining until the invoice expires given the current time.
267          * `time` is the timestamp as a duration since the Unix epoch.
268          */
269         public long expiration_remaining_from_epoch(long time) {
270                 long ret = bindings.Bolt11Invoice_expiration_remaining_from_epoch(this.ptr, time);
271                 Reference.reachabilityFence(this);
272                 Reference.reachabilityFence(time);
273                 return ret;
274         }
275
276         /**
277          * Returns whether the expiry time would pass at the given point in time.
278          * `at_time` is the timestamp as a duration since the Unix epoch.
279          */
280         public boolean would_expire(long at_time) {
281                 boolean ret = bindings.Bolt11Invoice_would_expire(this.ptr, at_time);
282                 Reference.reachabilityFence(this);
283                 Reference.reachabilityFence(at_time);
284                 return ret;
285         }
286
287         /**
288          * Returns the invoice's `min_final_cltv_expiry_delta` time, if present, otherwise
289          * [`DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA`].
290          */
291         public long min_final_cltv_expiry_delta() {
292                 long ret = bindings.Bolt11Invoice_min_final_cltv_expiry_delta(this.ptr);
293                 Reference.reachabilityFence(this);
294                 return ret;
295         }
296
297         /**
298          * Returns a list of all fallback addresses as [`Address`]es
299          */
300         public String[] fallback_addresses() {
301                 String[] ret = bindings.Bolt11Invoice_fallback_addresses(this.ptr);
302                 Reference.reachabilityFence(this);
303                 return ret;
304         }
305
306         /**
307          * Returns a list of all routes included in the invoice
308          */
309         public PrivateRoute[] private_routes() {
310                 long[] ret = bindings.Bolt11Invoice_private_routes(this.ptr);
311                 Reference.reachabilityFence(this);
312                 int ret_conv_14_len = ret.length;
313                 PrivateRoute[] ret_conv_14_arr = new PrivateRoute[ret_conv_14_len];
314                 for (int o = 0; o < ret_conv_14_len; o++) {
315                         long ret_conv_14 = ret[o];
316                         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); }
317                         if (ret_conv_14_hu_conv != null) { ret_conv_14_hu_conv.ptrs_to.add(this); };
318                         ret_conv_14_arr[o] = ret_conv_14_hu_conv;
319                 }
320                 return ret_conv_14_arr;
321         }
322
323         /**
324          * Returns a list of all routes included in the invoice as the underlying hints
325          */
326         public RouteHint[] route_hints() {
327                 long[] ret = bindings.Bolt11Invoice_route_hints(this.ptr);
328                 Reference.reachabilityFence(this);
329                 int ret_conv_11_len = ret.length;
330                 RouteHint[] ret_conv_11_arr = new RouteHint[ret_conv_11_len];
331                 for (int l = 0; l < ret_conv_11_len; l++) {
332                         long ret_conv_11 = ret[l];
333                         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); }
334                         if (ret_conv_11_hu_conv != null) { ret_conv_11_hu_conv.ptrs_to.add(this); };
335                         ret_conv_11_arr[l] = ret_conv_11_hu_conv;
336                 }
337                 return ret_conv_11_arr;
338         }
339
340         /**
341          * Returns the currency for which the invoice was issued
342          */
343         public Currency currency() {
344                 Currency ret = bindings.Bolt11Invoice_currency(this.ptr);
345                 Reference.reachabilityFence(this);
346                 return ret;
347         }
348
349         /**
350          * Returns the amount if specified in the invoice as millisatoshis.
351          */
352         public Option_u64Z amount_milli_satoshis() {
353                 long ret = bindings.Bolt11Invoice_amount_milli_satoshis(this.ptr);
354                 Reference.reachabilityFence(this);
355                 if (ret >= 0 && ret <= 4096) { return null; }
356                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
357                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
358                 return ret_hu_conv;
359         }
360
361         /**
362          * Read a Bolt11Invoice object from a string
363          */
364         public static Result_Bolt11InvoiceParseOrSemanticErrorZ from_str(java.lang.String s) {
365                 long ret = bindings.Bolt11Invoice_from_str(s);
366                 Reference.reachabilityFence(s);
367                 if (ret >= 0 && ret <= 4096) { return null; }
368                 Result_Bolt11InvoiceParseOrSemanticErrorZ ret_hu_conv = Result_Bolt11InvoiceParseOrSemanticErrorZ.constr_from_ptr(ret);
369                 return ret_hu_conv;
370         }
371
372         /**
373          * Get the string representation of a Bolt11Invoice object
374          */
375         public String to_str() {
376                 String ret = bindings.Bolt11Invoice_to_str(this.ptr);
377                 Reference.reachabilityFence(this);
378                 return ret;
379         }
380
381 }