[C#] Check in initial auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / Invoice.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 an `Invoice`:
13  * 1. using `InvoiceBuilder`
14  * 2. using `Invoice::from_signed(SignedRawInvoice)`
15  * 3. using `str::parse::<Invoice>(&str)`
16  */
17 public class Invoice : CommonBase {
18         internal Invoice(object _dummy, long ptr) : base(ptr) { }
19         ~Invoice() {
20                 if (ptr != 0) { bindings.Invoice_free(ptr); }
21         }
22
23         /**
24          * Checks if two Invoices contain equal inner contents.
25          * This ignores pointers and is_owned flags and looks at the values in fields.
26          * Two objects with NULL inner values will be considered "equal" here.
27          */
28         public bool eq(org.ldk.structs.Invoice b) {
29                 bool ret = bindings.Invoice_eq(this.ptr, b == null ? 0 : b.ptr);
30                 GC.KeepAlive(this);
31                 GC.KeepAlive(b);
32                 if (this != null) { this.ptrs_to.AddLast(b); };
33                 return ret;
34         }
35
36         public override bool Equals(object o) {
37                 if (!(o is Invoice)) return false;
38                 return this.eq((Invoice)o);
39         }
40         internal long clone_ptr() {
41                 long ret = bindings.Invoice_clone_ptr(this.ptr);
42                 GC.KeepAlive(this);
43                 return ret;
44         }
45
46         /**
47          * Creates a copy of the Invoice
48          */
49         public Invoice clone() {
50                 long ret = bindings.Invoice_clone(this.ptr);
51                 GC.KeepAlive(this);
52                 if (ret >= 0 && ret <= 4096) { return null; }
53                 org.ldk.structs.Invoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Invoice(null, ret); }
54                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
55                 return ret_hu_conv;
56         }
57
58         /**
59          * Checks if two Invoices contain equal inner contents.
60          */
61         public long hash() {
62                 long ret = bindings.Invoice_hash(this.ptr);
63                 GC.KeepAlive(this);
64                 return ret;
65         }
66
67         public override int GetHashCode() {
68                 return (int)this.hash();
69         }
70         /**
71          * Transform the `Invoice` into it's unchecked version
72          */
73         public SignedRawInvoice into_signed_raw() {
74                 long ret = bindings.Invoice_into_signed_raw(this.ptr);
75                 GC.KeepAlive(this);
76                 if (ret >= 0 && ret <= 4096) { return null; }
77                 org.ldk.structs.SignedRawInvoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.SignedRawInvoice(null, ret); }
78                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
79                 if (this != null) { this.ptrs_to.AddLast(this); };
80                 return ret_hu_conv;
81         }
82
83         /**
84          * Check that the invoice is signed correctly and that key recovery works
85          */
86         public Result_NoneSemanticErrorZ check_signature() {
87                 long ret = bindings.Invoice_check_signature(this.ptr);
88                 GC.KeepAlive(this);
89                 if (ret >= 0 && ret <= 4096) { return null; }
90                 Result_NoneSemanticErrorZ ret_hu_conv = Result_NoneSemanticErrorZ.constr_from_ptr(ret);
91                 return ret_hu_conv;
92         }
93
94         /**
95          * Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
96          * ```
97          * use lightning_invoice::*;
98          * 
99          * let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
100          * h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
101          * 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
102          * h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
103          * j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
104          * ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
105          * guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
106          * ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
107          * p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
108          * 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
109          * j5r6drg6k6zcqj0fcwg\";
110          * 
111          * let signed = invoice.parse::<SignedRawInvoice>().unwrap();
112          * 
113          * assert!(Invoice::from_signed(signed).is_ok());
114          * ```
115          */
116         public static Result_InvoiceSemanticErrorZ from_signed(org.ldk.structs.SignedRawInvoice signed_invoice) {
117                 long ret = bindings.Invoice_from_signed(signed_invoice == null ? 0 : signed_invoice.ptr);
118                 GC.KeepAlive(signed_invoice);
119                 if (ret >= 0 && ret <= 4096) { return null; }
120                 Result_InvoiceSemanticErrorZ ret_hu_conv = Result_InvoiceSemanticErrorZ.constr_from_ptr(ret);
121                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(signed_invoice); };
122                 return ret_hu_conv;
123         }
124
125         /**
126          * Returns the `Invoice`'s timestamp (should equal its creation time)
127          */
128         public long timestamp() {
129                 long ret = bindings.Invoice_timestamp(this.ptr);
130                 GC.KeepAlive(this);
131                 return ret;
132         }
133
134         /**
135          * Returns the `Invoice`'s timestamp as a duration since the Unix epoch
136          */
137         public long duration_since_epoch() {
138                 long ret = bindings.Invoice_duration_since_epoch(this.ptr);
139                 GC.KeepAlive(this);
140                 return ret;
141         }
142
143         /**
144          * Returns the hash to which we will receive the preimage on completion of the payment
145          */
146         public byte[] payment_hash() {
147                 byte[] ret = bindings.Invoice_payment_hash(this.ptr);
148                 GC.KeepAlive(this);
149                 return ret;
150         }
151
152         /**
153          * Get the payee's public key if one was included in the invoice
154          * 
155          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
156          */
157         public byte[] payee_pub_key() {
158                 byte[] ret = bindings.Invoice_payee_pub_key(this.ptr);
159                 GC.KeepAlive(this);
160                 return ret;
161         }
162
163         /**
164          * Get the payment secret if one was included in the invoice
165          */
166         public byte[] payment_secret() {
167                 byte[] ret = bindings.Invoice_payment_secret(this.ptr);
168                 GC.KeepAlive(this);
169                 return ret;
170         }
171
172         /**
173          * Get the invoice features if they were included in the invoice
174          * 
175          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
176          */
177         public InvoiceFeatures features() {
178                 long ret = bindings.Invoice_features(this.ptr);
179                 GC.KeepAlive(this);
180                 if (ret >= 0 && ret <= 4096) { return null; }
181                 org.ldk.structs.InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InvoiceFeatures(null, ret); }
182                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
183                 return ret_hu_conv;
184         }
185
186         /**
187          * Recover the payee's public key (only to be used if none was included in the invoice)
188          */
189         public byte[] recover_payee_pub_key() {
190                 byte[] ret = bindings.Invoice_recover_payee_pub_key(this.ptr);
191                 GC.KeepAlive(this);
192                 return ret;
193         }
194
195         /**
196          * Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
197          */
198         public long expiry_time() {
199                 long ret = bindings.Invoice_expiry_time(this.ptr);
200                 GC.KeepAlive(this);
201                 return ret;
202         }
203
204         /**
205          * Returns whether the invoice has expired.
206          */
207         public bool is_expired() {
208                 bool ret = bindings.Invoice_is_expired(this.ptr);
209                 GC.KeepAlive(this);
210                 return ret;
211         }
212
213         /**
214          * Returns whether the expiry time would pass at the given point in time.
215          * `at_time` is the timestamp as a duration since the Unix epoch.
216          */
217         public bool would_expire(long at_time) {
218                 bool ret = bindings.Invoice_would_expire(this.ptr, at_time);
219                 GC.KeepAlive(this);
220                 GC.KeepAlive(at_time);
221                 return ret;
222         }
223
224         /**
225          * Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
226          * [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
227          */
228         public long min_final_cltv_expiry() {
229                 long ret = bindings.Invoice_min_final_cltv_expiry(this.ptr);
230                 GC.KeepAlive(this);
231                 return ret;
232         }
233
234         /**
235          * Returns a list of all routes included in the invoice
236          */
237         public PrivateRoute[] private_routes() {
238                 long[] ret = bindings.Invoice_private_routes(this.ptr);
239                 GC.KeepAlive(this);
240                 int ret_conv_14_len = ret.Length;
241                 PrivateRoute[] ret_conv_14_arr = new PrivateRoute[ret_conv_14_len];
242                 for (int o = 0; o < ret_conv_14_len; o++) {
243                         long ret_conv_14 = ret[o];
244                         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); }
245                         if (ret_conv_14_hu_conv != null) { ret_conv_14_hu_conv.ptrs_to.AddLast(this); };
246                         ret_conv_14_arr[o] = ret_conv_14_hu_conv;
247                 }
248                 return ret_conv_14_arr;
249         }
250
251         /**
252          * Returns a list of all routes included in the invoice as the underlying hints
253          */
254         public RouteHint[] route_hints() {
255                 long[] ret = bindings.Invoice_route_hints(this.ptr);
256                 GC.KeepAlive(this);
257                 int ret_conv_11_len = ret.Length;
258                 RouteHint[] ret_conv_11_arr = new RouteHint[ret_conv_11_len];
259                 for (int l = 0; l < ret_conv_11_len; l++) {
260                         long ret_conv_11 = ret[l];
261                         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); }
262                         if (ret_conv_11_hu_conv != null) { ret_conv_11_hu_conv.ptrs_to.AddLast(this); };
263                         ret_conv_11_arr[l] = ret_conv_11_hu_conv;
264                 }
265                 return ret_conv_11_arr;
266         }
267
268         /**
269          * Returns the currency for which the invoice was issued
270          */
271         public Currency currency() {
272                 Currency ret = bindings.Invoice_currency(this.ptr);
273                 GC.KeepAlive(this);
274                 return ret;
275         }
276
277         /**
278          * Returns the amount if specified in the invoice as millisatoshis.
279          */
280         public Option_u64Z amount_milli_satoshis() {
281                 long ret = bindings.Invoice_amount_milli_satoshis(this.ptr);
282                 GC.KeepAlive(this);
283                 if (ret >= 0 && ret <= 4096) { return null; }
284                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
285                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
286                 return ret_hu_conv;
287         }
288
289         /**
290          * Read a Invoice object from a string
291          */
292         public static Result_InvoiceParseOrSemanticErrorZ from_str(string s) {
293                 long ret = bindings.Invoice_from_str(s);
294                 GC.KeepAlive(s);
295                 if (ret >= 0 && ret <= 4096) { return null; }
296                 Result_InvoiceParseOrSemanticErrorZ ret_hu_conv = Result_InvoiceParseOrSemanticErrorZ.constr_from_ptr(ret);
297                 return ret_hu_conv;
298         }
299
300         /**
301          * Get the string representation of a Invoice object
302          */
303         public string to_str() {
304                 string ret = bindings.Invoice_to_str(this.ptr);
305                 GC.KeepAlive(this);
306                 return ret;
307         }
308
309 }
310 } } }