6 namespace org { namespace ldk { namespace structs {
10 * Represents a syntactically and semantically correct lightning BOLT11 invoice.
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)`
17 public class Invoice : CommonBase {
18 internal Invoice(object _dummy, long ptr) : base(ptr) { }
20 if (ptr != 0) { bindings.Invoice_free(ptr); }
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.
28 public bool eq(org.ldk.structs.Invoice b) {
29 bool ret = bindings.Invoice_eq(this.ptr, b == null ? 0 : b.ptr);
32 if (this != null) { this.ptrs_to.AddLast(b); };
36 public override bool Equals(object o) {
37 if (!(o is Invoice)) return false;
38 return this.eq((Invoice)o);
40 internal long clone_ptr() {
41 long ret = bindings.Invoice_clone_ptr(this.ptr);
47 * Creates a copy of the Invoice
49 public Invoice clone() {
50 long ret = bindings.Invoice_clone(this.ptr);
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); };
59 * Checks if two Invoices contain equal inner contents.
62 long ret = bindings.Invoice_hash(this.ptr);
67 public override int GetHashCode() {
68 return (int)this.hash();
71 * Transform the `Invoice` into it's unchecked version
73 public SignedRawInvoice into_signed_raw() {
74 long ret = bindings.Invoice_into_signed_raw(this.ptr);
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); };
84 * Check that the invoice is signed correctly and that key recovery works
86 public Result_NoneSemanticErrorZ check_signature() {
87 long ret = bindings.Invoice_check_signature(this.ptr);
89 if (ret >= 0 && ret <= 4096) { return null; }
90 Result_NoneSemanticErrorZ ret_hu_conv = Result_NoneSemanticErrorZ.constr_from_ptr(ret);
95 * Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants.
97 * use lightning_invoice::*;
99 * let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
100 * h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
101 * 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
102 * h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
103 * j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
104 * ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
105 * guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
106 * ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
107 * p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
108 * 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
109 * j5r6drg6k6zcqj0fcwg\";
111 * let signed = invoice.parse::<SignedRawInvoice>().unwrap();
113 * assert!(Invoice::from_signed(signed).is_ok());
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); };
126 * Returns the `Invoice`'s timestamp (should equal its creation time)
128 public long timestamp() {
129 long ret = bindings.Invoice_timestamp(this.ptr);
135 * Returns the `Invoice`'s timestamp as a duration since the Unix epoch
137 public long duration_since_epoch() {
138 long ret = bindings.Invoice_duration_since_epoch(this.ptr);
144 * Returns the hash to which we will receive the preimage on completion of the payment
146 public byte[] payment_hash() {
147 byte[] ret = bindings.Invoice_payment_hash(this.ptr);
153 * Get the payee's public key if one was included in the invoice
155 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
157 public byte[] payee_pub_key() {
158 byte[] ret = bindings.Invoice_payee_pub_key(this.ptr);
164 * Get the payment secret if one was included in the invoice
166 public byte[] payment_secret() {
167 byte[] ret = bindings.Invoice_payment_secret(this.ptr);
173 * Get the invoice features if they were included in the invoice
175 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
177 public InvoiceFeatures features() {
178 long ret = bindings.Invoice_features(this.ptr);
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); };
187 * Recover the payee's public key (only to be used if none was included in the invoice)
189 public byte[] recover_payee_pub_key() {
190 byte[] ret = bindings.Invoice_recover_payee_pub_key(this.ptr);
196 * Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
198 public long expiry_time() {
199 long ret = bindings.Invoice_expiry_time(this.ptr);
205 * Returns whether the invoice has expired.
207 public bool is_expired() {
208 bool ret = bindings.Invoice_is_expired(this.ptr);
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.
217 public bool would_expire(long at_time) {
218 bool ret = bindings.Invoice_would_expire(this.ptr, at_time);
220 GC.KeepAlive(at_time);
225 * Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise
226 * [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`].
228 public long min_final_cltv_expiry() {
229 long ret = bindings.Invoice_min_final_cltv_expiry(this.ptr);
235 * Returns a list of all routes included in the invoice
237 public PrivateRoute[] private_routes() {
238 long[] ret = bindings.Invoice_private_routes(this.ptr);
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;
248 return ret_conv_14_arr;
252 * Returns a list of all routes included in the invoice as the underlying hints
254 public RouteHint[] route_hints() {
255 long[] ret = bindings.Invoice_route_hints(this.ptr);
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;
265 return ret_conv_11_arr;
269 * Returns the currency for which the invoice was issued
271 public Currency currency() {
272 Currency ret = bindings.Invoice_currency(this.ptr);
278 * Returns the amount if specified in the invoice as millisatoshis.
280 public Option_u64Z amount_milli_satoshis() {
281 long ret = bindings.Invoice_amount_milli_satoshis(this.ptr);
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); };
290 * Read a Invoice object from a string
292 public static Result_InvoiceParseOrSemanticErrorZ from_str(string s) {
293 long ret = bindings.Invoice_from_str(s);
295 if (ret >= 0 && ret <= 4096) { return null; }
296 Result_InvoiceParseOrSemanticErrorZ ret_hu_conv = Result_InvoiceParseOrSemanticErrorZ.constr_from_ptr(ret);
301 * Get the string representation of a Invoice object
303 public string to_str() {
304 string ret = bindings.Invoice_to_str(this.ptr);