Update auto-generated bindings to 0.0.101
[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         /**
39          * Creates a copy of the Invoice
40          */
41         public Invoice clone() {
42                 long ret = bindings.Invoice_clone(this.ptr);
43                 if (ret < 1024) { return null; }
44                 Invoice ret_hu_conv = new Invoice(null, ret);
45                 ret_hu_conv.ptrs_to.add(this);
46                 return ret_hu_conv;
47         }
48
49         /**
50          * Transform the `Invoice` into it's unchecked version
51          */
52         public SignedRawInvoice into_signed_raw() {
53                 long ret = bindings.Invoice_into_signed_raw(this.ptr);
54                 if (ret < 1024) { return null; }
55                 SignedRawInvoice ret_hu_conv = new SignedRawInvoice(null, ret);
56                 ret_hu_conv.ptrs_to.add(this);
57                 this.ptrs_to.add(this);
58                 return ret_hu_conv;
59         }
60
61         /**
62          * Check that the invoice is signed correctly and that key recovery works
63          */
64         public Result_NoneSemanticErrorZ check_signature() {
65                 long ret = bindings.Invoice_check_signature(this.ptr);
66                 if (ret < 1024) { return null; }
67                 Result_NoneSemanticErrorZ ret_hu_conv = Result_NoneSemanticErrorZ.constr_from_ptr(ret);
68                 return ret_hu_conv;
69         }
70
71         /**
72          * Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
73          * ```
74          * use lightning_invoice::*;
75          * 
76          * let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
77          * h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
78          * 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
79          * h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
80          * j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
81          * ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
82          * guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
83          * ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
84          * p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
85          * 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
86          * j5r6drg6k6zcqj0fcwg\";
87          * 
88          * let signed = invoice.parse::<SignedRawInvoice>().unwrap();
89          * 
90          * assert!(Invoice::from_signed(signed).is_ok());
91          * ```
92          */
93         public static Result_InvoiceSemanticErrorZ from_signed(SignedRawInvoice signed_invoice) {
94                 long ret = bindings.Invoice_from_signed(signed_invoice == null ? 0 : signed_invoice.ptr & ~1);
95                 if (ret < 1024) { return null; }
96                 Result_InvoiceSemanticErrorZ ret_hu_conv = Result_InvoiceSemanticErrorZ.constr_from_ptr(ret);
97                 ret_hu_conv.ptrs_to.add(signed_invoice);
98                 return ret_hu_conv;
99         }
100
101         /**
102          * Returns the `Invoice`'s timestamp (should equal it's creation time)
103          */
104         public long timestamp() {
105                 long ret = bindings.Invoice_timestamp(this.ptr);
106                 return ret;
107         }
108
109         /**
110          * Returns the hash to which we will receive the preimage on completion of the payment
111          */
112         public byte[] payment_hash() {
113                 byte[] ret = bindings.Invoice_payment_hash(this.ptr);
114                 return ret;
115         }
116
117         /**
118          * Get the payee's public key if one was included in the invoice
119          * 
120          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
121          */
122         @Nullable
123         public byte[] payee_pub_key() {
124                 byte[] ret = bindings.Invoice_payee_pub_key(this.ptr);
125                 return ret;
126         }
127
128         /**
129          * Get the payment secret if one was included in the invoice
130          */
131         public byte[] payment_secret() {
132                 byte[] ret = bindings.Invoice_payment_secret(this.ptr);
133                 return ret;
134         }
135
136         /**
137          * Get the invoice features if they were included in the invoice
138          * 
139          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
140          */
141         @Nullable
142         public InvoiceFeatures features() {
143                 long ret = bindings.Invoice_features(this.ptr);
144                 if (ret < 1024) { return null; }
145                 InvoiceFeatures ret_hu_conv = new InvoiceFeatures(null, ret);
146                 ret_hu_conv.ptrs_to.add(this);
147                 return ret_hu_conv;
148         }
149
150         /**
151          * Recover the payee's public key (only to be used if none was included in the invoice)
152          */
153         public byte[] recover_payee_pub_key() {
154                 byte[] ret = bindings.Invoice_recover_payee_pub_key(this.ptr);
155                 return ret;
156         }
157
158         /**
159          * Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
160          */
161         public long expiry_time() {
162                 long ret = bindings.Invoice_expiry_time(this.ptr);
163                 return ret;
164         }
165
166         /**
167          * Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
168          * [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
169          */
170         public long min_final_cltv_expiry() {
171                 long ret = bindings.Invoice_min_final_cltv_expiry(this.ptr);
172                 return ret;
173         }
174
175         /**
176          * Returns a list of all routes included in the invoice
177          */
178         public PrivateRoute[] private_routes() {
179                 long[] ret = bindings.Invoice_private_routes(this.ptr);
180                 PrivateRoute[] ret_conv_14_arr = new PrivateRoute[ret.length];
181                 for (int o = 0; o < ret.length; o++) {
182                         long ret_conv_14 = ret[o];
183                         PrivateRoute ret_conv_14_hu_conv = new PrivateRoute(null, ret_conv_14);
184                         ret_conv_14_hu_conv.ptrs_to.add(this);
185                         ret_conv_14_arr[o] = ret_conv_14_hu_conv;
186                 }
187                 return ret_conv_14_arr;
188         }
189
190         /**
191          * Returns a list of all routes included in the invoice as the underlying hints
192          */
193         public RouteHint[] route_hints() {
194                 long[] ret = bindings.Invoice_route_hints(this.ptr);
195                 RouteHint[] ret_conv_11_arr = new RouteHint[ret.length];
196                 for (int l = 0; l < ret.length; l++) {
197                         long ret_conv_11 = ret[l];
198                         RouteHint ret_conv_11_hu_conv = new RouteHint(null, ret_conv_11);
199                         ret_conv_11_hu_conv.ptrs_to.add(this);
200                         ret_conv_11_arr[l] = ret_conv_11_hu_conv;
201                 }
202                 return ret_conv_11_arr;
203         }
204
205         /**
206          * Returns the currency for which the invoice was issued
207          */
208         public Currency currency() {
209                 Currency ret = bindings.Invoice_currency(this.ptr);
210                 return ret;
211         }
212
213         /**
214          * Returns the amount if specified in the invoice as pico <currency>.
215          */
216         public Option_u64Z amount_pico_btc() {
217                 long ret = bindings.Invoice_amount_pico_btc(this.ptr);
218                 if (ret < 1024) { return null; }
219                 Option_u64Z ret_hu_conv = Option_u64Z.constr_from_ptr(ret);
220                 ret_hu_conv.ptrs_to.add(this);
221                 return ret_hu_conv;
222         }
223
224         /**
225          * Read a Invoice object from a string
226          */
227         public static Result_InvoiceNoneZ from_str(java.lang.String s) {
228                 long ret = bindings.Invoice_from_str(s);
229                 if (ret < 1024) { return null; }
230                 Result_InvoiceNoneZ ret_hu_conv = Result_InvoiceNoneZ.constr_from_ptr(ret);
231                 return ret_hu_conv;
232         }
233
234         /**
235          * Get the string representation of a Invoice object
236          */
237         public String to_str() {
238                 String ret = bindings.Invoice_to_str(this.ptr);
239                 return ret;
240         }
241
242 }