X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FInvoice.java;h=cbcad6bd78db4d6cc3e28ba52a0f45418214a5a1;hb=4a36fa97d4eee96099c4a176ea845c52db27e64c;hp=3f209e3d22781115fedbec401245f0db754c84d5;hpb=ff3dacec3be60f870d81f6df11bd9fff92aa6047;p=ldk-java diff --git a/src/main/java/org/ldk/structs/Invoice.java b/src/main/java/org/ldk/structs/Invoice.java index 3f209e3d..cbcad6bd 100644 --- a/src/main/java/org/ldk/structs/Invoice.java +++ b/src/main/java/org/ldk/structs/Invoice.java @@ -12,9 +12,11 @@ import javax.annotation.Nullable; * Represents a syntactically and semantically correct lightning BOLT11 invoice. * * There are three ways to construct an `Invoice`: - * 1. using `InvoiceBuilder` - * 2. using `Invoice::from_signed(SignedRawInvoice)` - * 3. using `str::parse::(&str)` + * 1. using [`InvoiceBuilder`] + * 2. using [`Invoice::from_signed`] + * 3. using `str::parse::(&str)` (see [`Invoice::from_str`]) + * + * [`Invoice::from_str`]: crate::Invoice#impl-FromStr */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class Invoice extends CommonBase { @@ -30,11 +32,11 @@ public class Invoice extends CommonBase { * This ignores pointers and is_owned flags and looks at the values in fields. * Two objects with NULL inner values will be considered "equal" here. */ - public boolean eq(Invoice b) { - boolean ret = bindings.Invoice_eq(this.ptr, b == null ? 0 : b.ptr & ~1); + public boolean eq(org.ldk.structs.Invoice b) { + boolean ret = bindings.Invoice_eq(this.ptr, b == null ? 0 : b.ptr); Reference.reachabilityFence(this); Reference.reachabilityFence(b); - this.ptrs_to.add(b); + if (this != null) { this.ptrs_to.add(b); }; return ret; } @@ -55,11 +57,32 @@ public class Invoice extends CommonBase { long ret = bindings.Invoice_clone(this.ptr); Reference.reachabilityFence(this); if (ret >= 0 && ret <= 4096) { return null; } - Invoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new Invoice(null, ret); } - ret_hu_conv.ptrs_to.add(this); + org.ldk.structs.Invoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Invoice(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } + /** + * Generates a non-cryptographic 64-bit hash of the Invoice. + */ + public long hash() { + long ret = bindings.Invoice_hash(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + @Override public int hashCode() { + return (int)this.hash(); + } + /** + * The hash of the [`RawInvoice`] that was signed. + */ + public byte[] signable_hash() { + byte[] ret = bindings.Invoice_signable_hash(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + /** * Transform the `Invoice` into it's unchecked version */ @@ -67,9 +90,9 @@ public class Invoice extends CommonBase { long ret = bindings.Invoice_into_signed_raw(this.ptr); Reference.reachabilityFence(this); if (ret >= 0 && ret <= 4096) { return null; } - SignedRawInvoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new SignedRawInvoice(null, ret); } - ret_hu_conv.ptrs_to.add(this); - ; + org.ldk.structs.SignedRawInvoice ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.SignedRawInvoice(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; + if (this != null) { this.ptrs_to.add(this); }; return ret_hu_conv; } @@ -85,7 +108,7 @@ public class Invoice extends CommonBase { } /** - * Constructs an `Invoice` from a `SignedRawInvoice` by checking all its invariants. + * Constructs an `Invoice` from a [`SignedRawInvoice`] by checking all its invariants. * ``` * use lightning_invoice::*; * @@ -106,11 +129,12 @@ public class Invoice extends CommonBase { * assert!(Invoice::from_signed(signed).is_ok()); * ``` */ - public static Result_InvoiceSemanticErrorZ from_signed(SignedRawInvoice signed_invoice) { - long ret = bindings.Invoice_from_signed(signed_invoice == null ? 0 : signed_invoice.ptr & ~1); + public static Result_InvoiceSemanticErrorZ from_signed(org.ldk.structs.SignedRawInvoice signed_invoice) { + long ret = bindings.Invoice_from_signed(signed_invoice == null ? 0 : signed_invoice.ptr); Reference.reachabilityFence(signed_invoice); if (ret >= 0 && ret <= 4096) { return null; } Result_InvoiceSemanticErrorZ ret_hu_conv = Result_InvoiceSemanticErrorZ.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(signed_invoice); }; return ret_hu_conv; } @@ -162,6 +186,18 @@ public class Invoice extends CommonBase { return ret; } + /** + * Get the payment metadata blob if one was included in the invoice + */ + public Option_CVec_u8ZZ payment_metadata() { + long ret = bindings.Invoice_payment_metadata(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; + return ret_hu_conv; + } + /** * Get the invoice features if they were included in the invoice * @@ -172,8 +208,8 @@ public class Invoice extends CommonBase { long ret = bindings.Invoice_features(this.ptr); Reference.reachabilityFence(this); if (ret >= 0 && ret <= 4096) { return null; } - InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new InvoiceFeatures(null, ret); } - ret_hu_conv.ptrs_to.add(this); + org.ldk.structs.InvoiceFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InvoiceFeatures(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } @@ -186,6 +222,19 @@ public class Invoice extends CommonBase { return ret; } + /** + * Returns the Duration since the Unix epoch at which the invoice expires. + * Returning None if overflow occurred. + */ + public Option_DurationZ expires_at() { + long ret = bindings.Invoice_expires_at(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.Option_DurationZ ret_hu_conv = org.ldk.structs.Option_DurationZ.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; + return ret_hu_conv; + } + /** * Returns the invoice's expiry time, if present, otherwise [`DEFAULT_EXPIRY_TIME`]. */ @@ -204,6 +253,26 @@ public class Invoice extends CommonBase { return ret; } + /** + * Returns the Duration remaining until the invoice expires. + */ + public long duration_until_expiry() { + long ret = bindings.Invoice_duration_until_expiry(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + /** + * Returns the Duration remaining until the invoice expires given the current time. + * `time` is the timestamp as a duration since the Unix epoch. + */ + public long expiration_remaining_from_epoch(long time) { + long ret = bindings.Invoice_expiration_remaining_from_epoch(this.ptr, time); + Reference.reachabilityFence(this); + Reference.reachabilityFence(time); + return ret; + } + /** * Returns whether the expiry time would pass at the given point in time. * `at_time` is the timestamp as a duration since the Unix epoch. @@ -216,11 +285,20 @@ public class Invoice extends CommonBase { } /** - * Returns the invoice's `min_final_cltv_expiry` time, if present, otherwise - * [`DEFAULT_MIN_FINAL_CLTV_EXPIRY`]. + * Returns the invoice's `min_final_cltv_expiry_delta` time, if present, otherwise + * [`DEFAULT_MIN_FINAL_CLTV_EXPIRY_DELTA`]. + */ + public long min_final_cltv_expiry_delta() { + long ret = bindings.Invoice_min_final_cltv_expiry_delta(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + /** + * Returns a list of all fallback addresses as [`Address`]es */ - public long min_final_cltv_expiry() { - long ret = bindings.Invoice_min_final_cltv_expiry(this.ptr); + public String[] fallback_addresses() { + String[] ret = bindings.Invoice_fallback_addresses(this.ptr); Reference.reachabilityFence(this); return ret; } @@ -235,8 +313,8 @@ public class Invoice extends CommonBase { PrivateRoute[] ret_conv_14_arr = new PrivateRoute[ret_conv_14_len]; for (int o = 0; o < ret_conv_14_len; o++) { long ret_conv_14 = ret[o]; - PrivateRoute ret_conv_14_hu_conv = null; if (ret_conv_14 < 0 || ret_conv_14 > 4096) { ret_conv_14_hu_conv = new PrivateRoute(null, ret_conv_14); } - ret_conv_14_hu_conv.ptrs_to.add(this); + 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); } + if (ret_conv_14_hu_conv != null) { ret_conv_14_hu_conv.ptrs_to.add(this); }; ret_conv_14_arr[o] = ret_conv_14_hu_conv; } return ret_conv_14_arr; @@ -252,8 +330,8 @@ public class Invoice extends CommonBase { RouteHint[] ret_conv_11_arr = new RouteHint[ret_conv_11_len]; for (int l = 0; l < ret_conv_11_len; l++) { long ret_conv_11 = ret[l]; - RouteHint ret_conv_11_hu_conv = null; if (ret_conv_11 < 0 || ret_conv_11 > 4096) { ret_conv_11_hu_conv = new RouteHint(null, ret_conv_11); } - ret_conv_11_hu_conv.ptrs_to.add(this); + 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); } + if (ret_conv_11_hu_conv != null) { ret_conv_11_hu_conv.ptrs_to.add(this); }; ret_conv_11_arr[l] = ret_conv_11_hu_conv; } return ret_conv_11_arr; @@ -276,7 +354,7 @@ public class Invoice extends CommonBase { Reference.reachabilityFence(this); if (ret >= 0 && ret <= 4096) { return null; } org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(this); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; }