[Java] Update auto-generated bindings to LDK 0.0.123
[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.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.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          * Recover the payee's public key if one was included in the invoice, otherwise return the
227          * recovered public key from the signature
228          */
229         public byte[] get_payee_pub_key() {
230                 byte[] ret = bindings.Bolt11Invoice_get_payee_pub_key(this.ptr);
231                 Reference.reachabilityFence(this);
232                 return ret;
233         }
234
235         /**
236          * Returns the Duration since the Unix epoch at which the invoice expires.
237          * Returning None if overflow occurred.
238          */
239         public Option_u64Z expires_at() {
240                 long ret = bindings.Bolt11Invoice_expires_at(this.ptr);
241                 Reference.reachabilityFence(this);
242                 if (ret >= 0 && ret <= 4096) { return null; }
243                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
244                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
245                 return ret_hu_conv;
246         }
247
248         /**
249          * Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
250          */
251         public long expiry_time() {
252                 long ret = bindings.Bolt11Invoice_expiry_time(this.ptr);
253                 Reference.reachabilityFence(this);
254                 return ret;
255         }
256
257         /**
258          * Returns whether the invoice has expired.
259          */
260         public boolean is_expired() {
261                 boolean ret = bindings.Bolt11Invoice_is_expired(this.ptr);
262                 Reference.reachabilityFence(this);
263                 return ret;
264         }
265
266         /**
267          * Returns the Duration remaining until the invoice expires.
268          */
269         public long duration_until_expiry() {
270                 long ret = bindings.Bolt11Invoice_duration_until_expiry(this.ptr);
271                 Reference.reachabilityFence(this);
272                 return ret;
273         }
274
275         /**
276          * Returns the Duration remaining until the invoice expires given the current time.
277          * `time` is the timestamp as a duration since the Unix epoch.
278          */
279         public long expiration_remaining_from_epoch(long time) {
280                 long ret = bindings.Bolt11Invoice_expiration_remaining_from_epoch(this.ptr, time);
281                 Reference.reachabilityFence(this);
282                 Reference.reachabilityFence(time);
283                 return ret;
284         }
285
286         /**
287          * Returns whether the expiry time would pass at the given point in time.
288          * `at_time` is the timestamp as a duration since the Unix epoch.
289          */
290         public boolean would_expire(long at_time) {
291                 boolean ret = bindings.Bolt11Invoice_would_expire(this.ptr, at_time);
292                 Reference.reachabilityFence(this);
293                 Reference.reachabilityFence(at_time);
294                 return ret;
295         }
296
297         /**
298          * Returns the invoice's `min_final_cltv_expiry_delta` time, if present, otherwise
299          * [`DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA`].
300          */
301         public long min_final_cltv_expiry_delta() {
302                 long ret = bindings.Bolt11Invoice_min_final_cltv_expiry_delta(this.ptr);
303                 Reference.reachabilityFence(this);
304                 return ret;
305         }
306
307         /**
308          * Returns a list of all fallback addresses as [`Address`]es
309          */
310         public String[] fallback_addresses() {
311                 String[] ret = bindings.Bolt11Invoice_fallback_addresses(this.ptr);
312                 Reference.reachabilityFence(this);
313                 return ret;
314         }
315
316         /**
317          * Returns a list of all routes included in the invoice
318          */
319         public PrivateRoute[] private_routes() {
320                 long[] ret = bindings.Bolt11Invoice_private_routes(this.ptr);
321                 Reference.reachabilityFence(this);
322                 int ret_conv_14_len = ret.length;
323                 PrivateRoute[] ret_conv_14_arr = new PrivateRoute[ret_conv_14_len];
324                 for (int o = 0; o < ret_conv_14_len; o++) {
325                         long ret_conv_14 = ret[o];
326                         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); }
327                         if (ret_conv_14_hu_conv != null) { ret_conv_14_hu_conv.ptrs_to.add(this); };
328                         ret_conv_14_arr[o] = ret_conv_14_hu_conv;
329                 }
330                 return ret_conv_14_arr;
331         }
332
333         /**
334          * Returns a list of all routes included in the invoice as the underlying hints
335          */
336         public RouteHint[] route_hints() {
337                 long[] ret = bindings.Bolt11Invoice_route_hints(this.ptr);
338                 Reference.reachabilityFence(this);
339                 int ret_conv_11_len = ret.length;
340                 RouteHint[] ret_conv_11_arr = new RouteHint[ret_conv_11_len];
341                 for (int l = 0; l < ret_conv_11_len; l++) {
342                         long ret_conv_11 = ret[l];
343                         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); }
344                         if (ret_conv_11_hu_conv != null) { ret_conv_11_hu_conv.ptrs_to.add(this); };
345                         ret_conv_11_arr[l] = ret_conv_11_hu_conv;
346                 }
347                 return ret_conv_11_arr;
348         }
349
350         /**
351          * Returns the currency for which the invoice was issued
352          */
353         public Currency currency() {
354                 Currency ret = bindings.Bolt11Invoice_currency(this.ptr);
355                 Reference.reachabilityFence(this);
356                 return ret;
357         }
358
359         /**
360          * Returns the amount if specified in the invoice as millisatoshis.
361          */
362         public Option_u64Z amount_milli_satoshis() {
363                 long ret = bindings.Bolt11Invoice_amount_milli_satoshis(this.ptr);
364                 Reference.reachabilityFence(this);
365                 if (ret >= 0 && ret <= 4096) { return null; }
366                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
367                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
368                 return ret_hu_conv;
369         }
370
371         /**
372          * Read a Bolt11Invoice object from a string
373          */
374         public static Result_Bolt11InvoiceParseOrSemanticErrorZ from_str(java.lang.String s) {
375                 long ret = bindings.Bolt11Invoice_from_str(s);
376                 Reference.reachabilityFence(s);
377                 if (ret >= 0 && ret <= 4096) { return null; }
378                 Result_Bolt11InvoiceParseOrSemanticErrorZ ret_hu_conv = Result_Bolt11InvoiceParseOrSemanticErrorZ.constr_from_ptr(ret);
379                 return ret_hu_conv;
380         }
381
382         /**
383          * Get the string representation of a Bolt11Invoice object
384          */
385         public String to_str() {
386                 String ret = bindings.Bolt11Invoice_to_str(this.ptr);
387                 Reference.reachabilityFence(this);
388                 return ret;
389         }
390
391 }