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