1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Represents a syntactically and semantically correct lightning BOLT11 invoice.
14 * There are three ways to construct a `Bolt11Invoice`:
15 * 1. using [`InvoiceBuilder`]
16 * 2. using [`Bolt11Invoice::from_signed`]
17 * 3. using `str::parse::<Bolt11Invoice>(&str)` (see [`Bolt11Invoice::from_str`])
19 * [`Bolt11Invoice::from_str`]: crate::Bolt11Invoice#impl-FromStr
21 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
22 public class Bolt11Invoice extends CommonBase {
23 Bolt11Invoice(Object _dummy, long ptr) { super(ptr); }
24 @Override @SuppressWarnings("deprecation")
25 protected void finalize() throws Throwable {
27 if (ptr != 0) { bindings.Bolt11Invoice_free(ptr); }
31 * Checks if two Bolt11Invoices contain equal inner contents.
32 * This ignores pointers and is_owned flags and looks at the values in fields.
33 * Two objects with NULL inner values will be considered "equal" here.
35 public boolean eq(org.ldk.structs.Bolt11Invoice b) {
36 boolean ret = bindings.Bolt11Invoice_eq(this.ptr, b == null ? 0 : b.ptr);
37 Reference.reachabilityFence(this);
38 Reference.reachabilityFence(b);
39 if (this != null) { this.ptrs_to.add(b); };
43 @Override public boolean equals(Object o) {
44 if (!(o instanceof Bolt11Invoice)) return false;
45 return this.eq((Bolt11Invoice)o);
48 long ret = bindings.Bolt11Invoice_clone_ptr(this.ptr);
49 Reference.reachabilityFence(this);
54 * Creates a copy of the Bolt11Invoice
56 public Bolt11Invoice clone() {
57 long ret = bindings.Bolt11Invoice_clone(this.ptr);
58 Reference.reachabilityFence(this);
59 if (ret >= 0 && ret <= 4096) { return null; }
60 org.ldk.structs.Bolt11Invoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Bolt11Invoice(null, ret); }
61 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
66 * Generates a non-cryptographic 64-bit hash of the Bolt11Invoice.
69 long ret = bindings.Bolt11Invoice_hash(this.ptr);
70 Reference.reachabilityFence(this);
74 @Override public int hashCode() {
75 return (int)this.hash();
78 * The hash of the [`RawBolt11Invoice`] that was signed.
80 public byte[] signable_hash() {
81 byte[] ret = bindings.Bolt11Invoice_signable_hash(this.ptr);
82 Reference.reachabilityFence(this);
87 * Transform the `Bolt11Invoice` into its unchecked version.
89 public SignedRawBolt11Invoice into_signed_raw() {
90 long ret = bindings.Bolt11Invoice_into_signed_raw(this.ptr);
91 Reference.reachabilityFence(this);
92 if (ret >= 0 && ret <= 4096) { return null; }
93 org.ldk.structs.SignedRawBolt11Invoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.SignedRawBolt11Invoice(null, ret); }
94 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
95 if (this != null) { this.ptrs_to.add(this); };
100 * Check that the invoice is signed correctly and that key recovery works
102 public Result_NoneBolt11SemanticErrorZ check_signature() {
103 long ret = bindings.Bolt11Invoice_check_signature(this.ptr);
104 Reference.reachabilityFence(this);
105 if (ret >= 0 && ret <= 4096) { return null; }
106 Result_NoneBolt11SemanticErrorZ ret_hu_conv = Result_NoneBolt11SemanticErrorZ.constr_from_ptr(ret);
111 * Constructs a `Bolt11Invoice` from a [`SignedRawBolt11Invoice`] by checking all its invariants.
113 * use lightning_invoice::*;
115 * let invoice = \"lnbc100p1psj9jhxdqud3jxktt5w46x7unfv9kz6mn0v3jsnp4q0d3p2sfluzdx45tqcs\\
116 * h2pu5qc7lgq0xs578ngs6s0s68ua4h7cvspp5q6rmq35js88zp5dvwrv9m459tnk2zunwj5jalqtyxqulh0l\\
117 * 5gflssp5nf55ny5gcrfl30xuhzj3nphgj27rstekmr9fw3ny5989s300gyus9qyysgqcqpcrzjqw2sxwe993\\
118 * h5pcm4dxzpvttgza8zhkqxpgffcrf5v25nwpr3cmfg7z54kuqq8rgqqqqqqqq2qqqqq9qq9qrzjqd0ylaqcl\\
119 * j9424x9m8h2vcukcgnm6s56xfgu3j78zyqzhgs4hlpzvznlugqq9vsqqqqqqqlgqqqqqeqq9qrzjqwldmj9d\\
120 * ha74df76zhx6l9we0vjdquygcdt3kssupehe64g6yyp5yz5rhuqqwccqqyqqqqlgqqqqjcqq9qrzjqf9e58a\\
121 * guqr0rcun0ajlvmzq3ek63cw2w282gv3z5uupmuwvgjtq2z55qsqqg6qqqyqqqrtnqqqzq3cqygrzjqvphms\\
122 * ywntrrhqjcraumvc4y6r8v4z5v593trte429v4hredj7ms5z52usqq9ngqqqqqqqlgqqqqqqgq9qrzjq2v0v\\
123 * p62g49p7569ev48cmulecsxe59lvaw3wlxm7r982zxa9zzj7z5l0cqqxusqqyqqqqlgqqqqqzsqygarl9fh3\\
124 * 8s0gyuxjjgux34w75dnc6xp2l35j7es3jd4ugt3lu0xzre26yg5m7ke54n2d5sym4xcmxtl8238xxvw5h5h5\\
125 * j5r6drg6k6zcqj0fcwg\";
127 * let signed = invoice.parse::<SignedRawBolt11Invoice>().unwrap();
129 * assert!(Bolt11Invoice::from_signed(signed).is_ok());
132 public static Result_Bolt11InvoiceBolt11SemanticErrorZ from_signed(org.ldk.structs.SignedRawBolt11Invoice signed_invoice) {
133 long ret = bindings.Bolt11Invoice_from_signed(signed_invoice == null ? 0 : signed_invoice.ptr);
134 Reference.reachabilityFence(signed_invoice);
135 if (ret >= 0 && ret <= 4096) { return null; }
136 Result_Bolt11InvoiceBolt11SemanticErrorZ ret_hu_conv = Result_Bolt11InvoiceBolt11SemanticErrorZ.constr_from_ptr(ret);
137 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(signed_invoice); };
142 * Returns the `Bolt11Invoice`'s timestamp (should equal its creation time)
144 public long timestamp() {
145 long ret = bindings.Bolt11Invoice_timestamp(this.ptr);
146 Reference.reachabilityFence(this);
151 * Returns the `Bolt11Invoice`'s timestamp as a duration since the Unix epoch
153 public long duration_since_epoch() {
154 long ret = bindings.Bolt11Invoice_duration_since_epoch(this.ptr);
155 Reference.reachabilityFence(this);
160 * Returns the hash to which we will receive the preimage on completion of the payment
162 public byte[] payment_hash() {
163 byte[] ret = bindings.Bolt11Invoice_payment_hash(this.ptr);
164 Reference.reachabilityFence(this);
169 * Get the payee's public key if one was included in the invoice
171 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
174 public byte[] payee_pub_key() {
175 byte[] ret = bindings.Bolt11Invoice_payee_pub_key(this.ptr);
176 Reference.reachabilityFence(this);
181 * Get the payment secret if one was included in the invoice
183 public byte[] payment_secret() {
184 byte[] ret = bindings.Bolt11Invoice_payment_secret(this.ptr);
185 Reference.reachabilityFence(this);
190 * Get the payment metadata blob if one was included in the invoice
192 public Option_CVec_u8ZZ payment_metadata() {
193 long ret = bindings.Bolt11Invoice_payment_metadata(this.ptr);
194 Reference.reachabilityFence(this);
195 if (ret >= 0 && ret <= 4096) { return null; }
196 org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret);
197 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
202 * Get the invoice features if they were included in the invoice
204 * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
207 public Bolt11InvoiceFeatures features() {
208 long ret = bindings.Bolt11Invoice_features(this.ptr);
209 Reference.reachabilityFence(this);
210 if (ret >= 0 && ret <= 4096) { return null; }
211 org.ldk.structs.Bolt11InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Bolt11InvoiceFeatures(null, ret); }
212 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
217 * Recover the payee's public key (only to be used if none was included in the invoice)
219 public byte[] recover_payee_pub_key() {
220 byte[] ret = bindings.Bolt11Invoice_recover_payee_pub_key(this.ptr);
221 Reference.reachabilityFence(this);
226 * Returns the Duration since the Unix epoch at which the invoice expires.
227 * Returning None if overflow occurred.
229 public Option_u64Z expires_at() {
230 long ret = bindings.Bolt11Invoice_expires_at(this.ptr);
231 Reference.reachabilityFence(this);
232 if (ret >= 0 && ret <= 4096) { return null; }
233 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
234 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
239 * Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`].
241 public long expiry_time() {
242 long ret = bindings.Bolt11Invoice_expiry_time(this.ptr);
243 Reference.reachabilityFence(this);
248 * Returns whether the invoice has expired.
250 public boolean is_expired() {
251 boolean ret = bindings.Bolt11Invoice_is_expired(this.ptr);
252 Reference.reachabilityFence(this);
257 * Returns the Duration remaining until the invoice expires.
259 public long duration_until_expiry() {
260 long ret = bindings.Bolt11Invoice_duration_until_expiry(this.ptr);
261 Reference.reachabilityFence(this);
266 * Returns the Duration remaining until the invoice expires given the current time.
267 * `time` is the timestamp as a duration since the Unix epoch.
269 public long expiration_remaining_from_epoch(long time) {
270 long ret = bindings.Bolt11Invoice_expiration_remaining_from_epoch(this.ptr, time);
271 Reference.reachabilityFence(this);
272 Reference.reachabilityFence(time);
277 * Returns whether the expiry time would pass at the given point in time.
278 * `at_time` is the timestamp as a duration since the Unix epoch.
280 public boolean would_expire(long at_time) {
281 boolean ret = bindings.Bolt11Invoice_would_expire(this.ptr, at_time);
282 Reference.reachabilityFence(this);
283 Reference.reachabilityFence(at_time);
288 * Returns the invoice's `min_final_cltv_expiry_delta` time, if present, otherwise
289 * [`DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA`].
291 public long min_final_cltv_expiry_delta() {
292 long ret = bindings.Bolt11Invoice_min_final_cltv_expiry_delta(this.ptr);
293 Reference.reachabilityFence(this);
298 * Returns a list of all fallback addresses as [`Address`]es
300 public String[] fallback_addresses() {
301 String[] ret = bindings.Bolt11Invoice_fallback_addresses(this.ptr);
302 Reference.reachabilityFence(this);
307 * Returns a list of all routes included in the invoice
309 public PrivateRoute[] private_routes() {
310 long[] ret = bindings.Bolt11Invoice_private_routes(this.ptr);
311 Reference.reachabilityFence(this);
312 int ret_conv_14_len = ret.length;
313 PrivateRoute[] ret_conv_14_arr = new PrivateRoute[ret_conv_14_len];
314 for (int o = 0; o < ret_conv_14_len; o++) {
315 long ret_conv_14 = ret[o];
316 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); }
317 if (ret_conv_14_hu_conv != null) { ret_conv_14_hu_conv.ptrs_to.add(this); };
318 ret_conv_14_arr[o] = ret_conv_14_hu_conv;
320 return ret_conv_14_arr;
324 * Returns a list of all routes included in the invoice as the underlying hints
326 public RouteHint[] route_hints() {
327 long[] ret = bindings.Bolt11Invoice_route_hints(this.ptr);
328 Reference.reachabilityFence(this);
329 int ret_conv_11_len = ret.length;
330 RouteHint[] ret_conv_11_arr = new RouteHint[ret_conv_11_len];
331 for (int l = 0; l < ret_conv_11_len; l++) {
332 long ret_conv_11 = ret[l];
333 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); }
334 if (ret_conv_11_hu_conv != null) { ret_conv_11_hu_conv.ptrs_to.add(this); };
335 ret_conv_11_arr[l] = ret_conv_11_hu_conv;
337 return ret_conv_11_arr;
341 * Returns the currency for which the invoice was issued
343 public Currency currency() {
344 Currency ret = bindings.Bolt11Invoice_currency(this.ptr);
345 Reference.reachabilityFence(this);
350 * Returns the amount if specified in the invoice as millisatoshis.
352 public Option_u64Z amount_milli_satoshis() {
353 long ret = bindings.Bolt11Invoice_amount_milli_satoshis(this.ptr);
354 Reference.reachabilityFence(this);
355 if (ret >= 0 && ret <= 4096) { return null; }
356 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
357 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
362 * Read a Bolt11Invoice object from a string
364 public static Result_Bolt11InvoiceParseOrSemanticErrorZ from_str(java.lang.String s) {
365 long ret = bindings.Bolt11Invoice_from_str(s);
366 Reference.reachabilityFence(s);
367 if (ret >= 0 && ret <= 4096) { return null; }
368 Result_Bolt11InvoiceParseOrSemanticErrorZ ret_hu_conv = Result_Bolt11InvoiceParseOrSemanticErrorZ.constr_from_ptr(ret);
373 * Get the string representation of a Bolt11Invoice object
375 public String to_str() {
376 String ret = bindings.Bolt11Invoice_to_str(this.ptr);
377 Reference.reachabilityFence(this);