X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FInvoice.java;h=6faacbd0cc475cb4495ef2100744ecc41e71df2d;hb=3c60e0fd0da579be9932801c1be2b32014c944a5;hp=e162d340d5d467490b3e9a402c805286c0a56ac2;hpb=a7653cf8717b1f9df4d3f4c4bd0b1f50f3bbc230;p=ldk-java diff --git a/src/main/java/org/ldk/structs/Invoice.java b/src/main/java/org/ldk/structs/Invoice.java index e162d340..6faacbd0 100644 --- a/src/main/java/org/ldk/structs/Invoice.java +++ b/src/main/java/org/ldk/structs/Invoice.java @@ -4,6 +4,7 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import java.lang.ref.Reference; import javax.annotation.Nullable; @@ -30,8 +31,20 @@ public class Invoice extends CommonBase { * 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); - this.ptrs_to.add(b); + boolean ret = bindings.Invoice_eq(this.ptr, b == null ? 0 : b.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(b); + if (this != null) { this.ptrs_to.add(b); }; + return ret; + } + + @Override public boolean equals(Object o) { + if (!(o instanceof Invoice)) return false; + return this.eq((Invoice)o); + } + long clone_ptr() { + long ret = bindings.Invoice_clone_ptr(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -40,9 +53,10 @@ public class Invoice extends CommonBase { */ public Invoice clone() { long ret = bindings.Invoice_clone(this.ptr); - if (ret < 1024) { return null; } - Invoice ret_hu_conv = new Invoice(null, ret); - ret_hu_conv.ptrs_to.add(this); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + 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; } @@ -51,10 +65,11 @@ public class Invoice extends CommonBase { */ public SignedRawInvoice into_signed_raw() { long ret = bindings.Invoice_into_signed_raw(this.ptr); - if (ret < 1024) { return null; } - SignedRawInvoice ret_hu_conv = new SignedRawInvoice(null, ret); - ret_hu_conv.ptrs_to.add(this); - this.ptrs_to.add(this); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + 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; } @@ -63,7 +78,8 @@ public class Invoice extends CommonBase { */ public Result_NoneSemanticErrorZ check_signature() { long ret = bindings.Invoice_check_signature(this.ptr); - if (ret < 1024) { return null; } + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } Result_NoneSemanticErrorZ ret_hu_conv = Result_NoneSemanticErrorZ.constr_from_ptr(ret); return ret_hu_conv; } @@ -91,18 +107,29 @@ public class Invoice extends CommonBase { * ``` */ public static Result_InvoiceSemanticErrorZ from_signed(SignedRawInvoice signed_invoice) { - long ret = bindings.Invoice_from_signed(signed_invoice == null ? 0 : signed_invoice.ptr & ~1); - if (ret < 1024) { return null; } + 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); - ret_hu_conv.ptrs_to.add(signed_invoice); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(signed_invoice); }; return ret_hu_conv; } /** - * Returns the `Invoice`'s timestamp (should equal it's creation time) + * Returns the `Invoice`'s timestamp (should equal its creation time) */ public long timestamp() { long ret = bindings.Invoice_timestamp(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + /** + * Returns the `Invoice`'s timestamp as a duration since the Unix epoch + */ + public long duration_since_epoch() { + long ret = bindings.Invoice_duration_since_epoch(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -111,6 +138,7 @@ public class Invoice extends CommonBase { */ public byte[] payment_hash() { byte[] ret = bindings.Invoice_payment_hash(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -122,6 +150,7 @@ public class Invoice extends CommonBase { @Nullable public byte[] payee_pub_key() { byte[] ret = bindings.Invoice_payee_pub_key(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -130,6 +159,7 @@ public class Invoice extends CommonBase { */ public byte[] payment_secret() { byte[] ret = bindings.Invoice_payment_secret(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -141,9 +171,10 @@ public class Invoice extends CommonBase { @Nullable public InvoiceFeatures features() { long ret = bindings.Invoice_features(this.ptr); - if (ret < 1024) { return null; } - InvoiceFeatures ret_hu_conv = new InvoiceFeatures(null, ret); - ret_hu_conv.ptrs_to.add(this); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + 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; } @@ -152,6 +183,7 @@ public class Invoice extends CommonBase { */ public byte[] recover_payee_pub_key() { byte[] ret = bindings.Invoice_recover_payee_pub_key(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -160,6 +192,27 @@ public class Invoice extends CommonBase { */ public long expiry_time() { long ret = bindings.Invoice_expiry_time(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + /** + * Returns whether the invoice has expired. + */ + public boolean is_expired() { + boolean ret = bindings.Invoice_is_expired(this.ptr); + Reference.reachabilityFence(this); + 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. + */ + public boolean would_expire(long at_time) { + boolean ret = bindings.Invoice_would_expire(this.ptr, at_time); + Reference.reachabilityFence(this); + Reference.reachabilityFence(at_time); return ret; } @@ -169,6 +222,7 @@ public class Invoice extends CommonBase { */ public long min_final_cltv_expiry() { long ret = bindings.Invoice_min_final_cltv_expiry(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -177,11 +231,13 @@ public class Invoice extends CommonBase { */ public PrivateRoute[] private_routes() { long[] ret = bindings.Invoice_private_routes(this.ptr); - PrivateRoute[] ret_conv_14_arr = new PrivateRoute[ret.length]; - for (int o = 0; o < ret.length; o++) { + Reference.reachabilityFence(this); + int ret_conv_14_len = ret.length; + 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 = 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; @@ -192,11 +248,13 @@ public class Invoice extends CommonBase { */ public RouteHint[] route_hints() { long[] ret = bindings.Invoice_route_hints(this.ptr); - RouteHint[] ret_conv_11_arr = new RouteHint[ret.length]; - for (int l = 0; l < ret.length; l++) { + Reference.reachabilityFence(this); + int ret_conv_11_len = ret.length; + 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 = 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; @@ -207,27 +265,30 @@ public class Invoice extends CommonBase { */ public Currency currency() { Currency ret = bindings.Invoice_currency(this.ptr); + Reference.reachabilityFence(this); return ret; } /** - * Returns the amount if specified in the invoice as pico . + * Returns the amount if specified in the invoice as millisatoshis. */ - public Option_u64Z amount_pico_btc() { - long ret = bindings.Invoice_amount_pico_btc(this.ptr); - if (ret < 1024) { return null; } - Option_u64Z ret_hu_conv = Option_u64Z.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(this); + public Option_u64Z amount_milli_satoshis() { + long ret = bindings.Invoice_amount_milli_satoshis(this.ptr); + 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); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } /** * Read a Invoice object from a string */ - public static Result_InvoiceNoneZ from_str(java.lang.String s) { + public static Result_InvoiceParseOrSemanticErrorZ from_str(java.lang.String s) { long ret = bindings.Invoice_from_str(s); - if (ret < 1024) { return null; } - Result_InvoiceNoneZ ret_hu_conv = Result_InvoiceNoneZ.constr_from_ptr(ret); + Reference.reachabilityFence(s); + if (ret >= 0 && ret <= 4096) { return null; } + Result_InvoiceParseOrSemanticErrorZ ret_hu_conv = Result_InvoiceParseOrSemanticErrorZ.constr_from_ptr(ret); return ret_hu_conv; } @@ -236,6 +297,7 @@ public class Invoice extends CommonBase { */ public String to_str() { String ret = bindings.Invoice_to_str(this.ptr); + Reference.reachabilityFence(this); return ret; }