Update auto-generated bindings
[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
8
9 /**
10  * Represents a syntactically and semantically correct lightning BOLT11 invoice.
11  * 
12  * There are three ways to construct an `Invoice`:
13  * 1. using `InvoiceBuilder`
14  * 2. using `Invoice::from_signed(SignedRawInvoice)`
15  * 3. using `str::parse::<Invoice>(&str)`
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class Invoice extends CommonBase {
19         Invoice(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.Invoice_free(ptr); }
24         }
25
26         /**
27          * Checks if two Invoices contain equal inner contents.
28          * This ignores pointers and is_owned flags and looks at the values in fields.
29          * Two objects with NULL inner values will be considered "equal" here.
30          */
31         public boolean eq(Invoice b) {
32                 boolean ret = bindings.Invoice_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
33                 this.ptrs_to.add(b);
34                 return ret;
35         }
36
37         /**
38          * Creates a copy of the Invoice
39          */
40         public Invoice clone() {
41                 long ret = bindings.Invoice_clone(this.ptr);
42                 if (ret < 1024) { return null; }
43                 Invoice ret_hu_conv = new Invoice(null, ret);
44                 ret_hu_conv.ptrs_to.add(this);
45                 return ret_hu_conv;
46         }
47
48         /**
49          * Transform the `Invoice` into it's unchecked version
50          */
51         public SignedRawInvoice into_signed_raw() {
52                 long ret = bindings.Invoice_into_signed_raw(this.ptr);
53                 if (ret < 1024) { return null; }
54                 SignedRawInvoice ret_hu_conv = new SignedRawInvoice(null, ret);
55                 ret_hu_conv.ptrs_to.add(this);
56                 this.ptrs_to.add(this);
57                 return ret_hu_conv;
58         }
59
60         /**
61          * Check that the invoice is signed correctly and that key recovery works
62          */
63         public Result_NoneSemanticErrorZ check_signature() {
64                 long ret = bindings.Invoice_check_signature(this.ptr);
65                 if (ret < 1024) { return null; }
66                 Result_NoneSemanticErrorZ ret_hu_conv = Result_NoneSemanticErrorZ.constr_from_ptr(ret);
67                 return ret_hu_conv;
68         }
69
70         /**
71          * Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
72          * ```
73          * use lightning_invoice::*;
74          * 
75          * let invoice = \"lnbc1pvjluezpp5qqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqqqsyqcyq5rqwzqfqypqdp\\
76          * \tl2pkx2ctnv5sxxmmwwd5kgetjypeh2ursdae8g6twvus8g6rfwvs8qun0dfjkxaq8rkx3yf5tcsyz3d7\\
77          * \t3gafnh3cax9rn449d9p5uxz9ezhhypd0elx87sjle52x86fux2ypatgddc6k63n7erqz25le42c4u4ec\\
78          * \tky03ylcqca784w\";
79          * 
80          * let signed = invoice.parse::<SignedRawInvoice>().unwrap();
81          * 
82          * assert!(Invoice::from_signed(signed).is_ok());
83          * ```
84          */
85         public static Result_InvoiceSemanticErrorZ from_signed(SignedRawInvoice signed_invoice) {
86                 long ret = bindings.Invoice_from_signed(signed_invoice == null ? 0 : signed_invoice.ptr & ~1);
87                 if (ret < 1024) { return null; }
88                 Result_InvoiceSemanticErrorZ ret_hu_conv = Result_InvoiceSemanticErrorZ.constr_from_ptr(ret);
89                 ret_hu_conv.ptrs_to.add(signed_invoice);
90                 return ret_hu_conv;
91         }
92
93         /**
94          * Returns the `Invoice`'s timestamp (should equal it's creation time)
95          */
96         public long timestamp() {
97                 long ret = bindings.Invoice_timestamp(this.ptr);
98                 return ret;
99         }
100
101         /**
102          * Returns the hash to which we will receive the preimage on completion of the payment
103          */
104         public byte[] payment_hash() {
105                 byte[] ret = bindings.Invoice_payment_hash(this.ptr);
106                 return ret;
107         }
108
109         /**
110          * Get the payee's public key if one was included in the invoice
111          * 
112          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
113          */
114         @Nullable
115         public byte[] payee_pub_key() {
116                 byte[] ret = bindings.Invoice_payee_pub_key(this.ptr);
117                 return ret;
118         }
119
120         /**
121          * Get the payment secret if one was included in the invoice
122          * 
123          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
124          */
125         @Nullable
126         public byte[] payment_secret() {
127                 byte[] ret = bindings.Invoice_payment_secret(this.ptr);
128                 return ret;
129         }
130
131         /**
132          * Get the invoice features if they were included in the invoice
133          * 
134          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
135          */
136         @Nullable
137         public InvoiceFeatures features() {
138                 long ret = bindings.Invoice_features(this.ptr);
139                 if (ret < 1024) { return null; }
140                 InvoiceFeatures ret_hu_conv = new InvoiceFeatures(null, ret);
141                 ret_hu_conv.ptrs_to.add(this);
142                 return ret_hu_conv;
143         }
144
145         /**
146          * Recover the payee's public key (only to be used if none was included in the invoice)
147          */
148         public byte[] recover_payee_pub_key() {
149                 byte[] ret = bindings.Invoice_recover_payee_pub_key(this.ptr);
150                 return ret;
151         }
152
153         /**
154          * Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
155          */
156         public long expiry_time() {
157                 long ret = bindings.Invoice_expiry_time(this.ptr);
158                 return ret;
159         }
160
161         /**
162          * Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
163          * [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
164          */
165         public long min_final_cltv_expiry() {
166                 long ret = bindings.Invoice_min_final_cltv_expiry(this.ptr);
167                 return ret;
168         }
169
170         /**
171          * Returns a list of all routes included in the invoice
172          */
173         public PrivateRoute[] private_routes() {
174                 long[] ret = bindings.Invoice_private_routes(this.ptr);
175                 PrivateRoute[] ret_conv_14_arr = new PrivateRoute[ret.length];
176                 for (int o = 0; o < ret.length; o++) {
177                         long ret_conv_14 = ret[o];
178                         PrivateRoute ret_conv_14_hu_conv = new PrivateRoute(null, ret_conv_14);
179                         ret_conv_14_hu_conv.ptrs_to.add(this);
180                         ret_conv_14_arr[o] = ret_conv_14_hu_conv;
181                 }
182                 return ret_conv_14_arr;
183         }
184
185         /**
186          * Returns a list of all routes included in the invoice as the underlying hints
187          */
188         public RouteHint[] route_hints() {
189                 long[] ret = bindings.Invoice_route_hints(this.ptr);
190                 RouteHint[] ret_conv_11_arr = new RouteHint[ret.length];
191                 for (int l = 0; l < ret.length; l++) {
192                         long ret_conv_11 = ret[l];
193                         RouteHint ret_conv_11_hu_conv = new RouteHint(null, ret_conv_11);
194                         ret_conv_11_hu_conv.ptrs_to.add(this);
195                         ret_conv_11_arr[l] = ret_conv_11_hu_conv;
196                 }
197                 return ret_conv_11_arr;
198         }
199
200         /**
201          * Returns the currency for which the invoice was issued
202          */
203         public Currency currency() {
204                 Currency ret = bindings.Invoice_currency(this.ptr);
205                 return ret;
206         }
207
208         /**
209          * Returns the amount if specified in the invoice as pico <currency>.
210          */
211         public Option_u64Z amount_pico_btc() {
212                 long ret = bindings.Invoice_amount_pico_btc(this.ptr);
213                 if (ret < 1024) { return null; }
214                 Option_u64Z ret_hu_conv = Option_u64Z.constr_from_ptr(ret);
215                 ret_hu_conv.ptrs_to.add(this);
216                 return ret_hu_conv;
217         }
218
219         /**
220          * Read a Invoice object from a string
221          */
222         public static Result_InvoiceNoneZ from_str(String s) {
223                 long ret = bindings.Invoice_from_str(s);
224                 if (ret < 1024) { return null; }
225                 Result_InvoiceNoneZ ret_hu_conv = Result_InvoiceNoneZ.constr_from_ptr(ret);
226                 return ret_hu_conv;
227         }
228
229         /**
230          * Get the string representation of a Invoice object
231          */
232         public String to_str() {
233                 String ret = bindings.Invoice_to_str(this.ptr);
234                 return ret;
235         }
236
237 }