X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FPositiveTimestamp.java;h=cb2de852cbdd16e5d66b54e35f26fbe53c79fef2;hb=3c60e0fd0da579be9932801c1be2b32014c944a5;hp=dd04d046844dc1bb094a00c089905cbb9c4c2c70;hpb=d2925e24ac4643ec22eb73495f0424e27def2545;p=ldk-java diff --git a/src/main/java/org/ldk/structs/PositiveTimestamp.java b/src/main/java/org/ldk/structs/PositiveTimestamp.java index dd04d046..cb2de852 100644 --- a/src/main/java/org/ldk/structs/PositiveTimestamp.java +++ b/src/main/java/org/ldk/structs/PositiveTimestamp.java @@ -9,12 +9,12 @@ import javax.annotation.Nullable; /** - * A timestamp that refers to a date after 1 January 1970 which means its representation as UNIX - * timestamp is positive. + * A timestamp that refers to a date after 1 January 1970. * * # Invariants - * The UNIX timestamp representing the stored time has to be positive and small enough so that - * a `EpiryTime` can be added to it without an overflow. + * + * The Unix timestamp representing the stored time has to be positive and no greater than + * [`MAX_TIMESTAMP`]. */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class PositiveTimestamp extends CommonBase { @@ -31,10 +31,10 @@ public class PositiveTimestamp extends CommonBase { * Two objects with NULL inner values will be considered "equal" here. */ public boolean eq(PositiveTimestamp b) { - boolean ret = bindings.PositiveTimestamp_eq(this.ptr, b == null ? 0 : b.ptr & ~1); + boolean ret = bindings.PositiveTimestamp_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,15 +55,15 @@ public class PositiveTimestamp extends CommonBase { long ret = bindings.PositiveTimestamp_clone(this.ptr); Reference.reachabilityFence(this); if (ret >= 0 && ret <= 4096) { return null; } - PositiveTimestamp ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new PositiveTimestamp(null, ret); } - ret_hu_conv.ptrs_to.add(this); + org.ldk.structs.PositiveTimestamp ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PositiveTimestamp(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } /** - * Create a new `PositiveTimestamp` from a unix timestamp in the Range - * `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a - * `CreationError::TimestampOutOfBounds`. + * Creates a `PositiveTimestamp` from a Unix timestamp in the range `0..=MAX_TIMESTAMP`. + * + * Otherwise, returns a [`CreationError::TimestampOutOfBounds`]. */ public static Result_PositiveTimestampCreationErrorZ from_unix_timestamp(long unix_seconds) { long ret = bindings.PositiveTimestamp_from_unix_timestamp(unix_seconds); @@ -74,9 +74,10 @@ public class PositiveTimestamp extends CommonBase { } /** - * Create a new `PositiveTimestamp` from a `SystemTime` with a corresponding unix timestamp in - * the Range `0...SYSTEM_TIME_MAX_UNIX_TIMESTAMP - MAX_EXPIRY_TIME`, otherwise return a - * `CreationError::TimestampOutOfBounds`. + * Creates a `PositiveTimestamp` from a [`SystemTime`] with a corresponding Unix timestamp in + * the range `0..=MAX_TIMESTAMP`. + * + * Otherwise, returns a [`CreationError::TimestampOutOfBounds`]. */ public static Result_PositiveTimestampCreationErrorZ from_system_time(long time) { long ret = bindings.PositiveTimestamp_from_system_time(time); @@ -87,7 +88,21 @@ public class PositiveTimestamp extends CommonBase { } /** - * Returns the UNIX timestamp representing the stored time + * Creates a `PositiveTimestamp` from a [`Duration`] since the Unix epoch in the range + * `0..=MAX_TIMESTAMP`. + * + * Otherwise, returns a [`CreationError::TimestampOutOfBounds`]. + */ + public static Result_PositiveTimestampCreationErrorZ from_duration_since_epoch(long duration) { + long ret = bindings.PositiveTimestamp_from_duration_since_epoch(duration); + Reference.reachabilityFence(duration); + if (ret >= 0 && ret <= 4096) { return null; } + Result_PositiveTimestampCreationErrorZ ret_hu_conv = Result_PositiveTimestampCreationErrorZ.constr_from_ptr(ret); + return ret_hu_conv; + } + + /** + * Returns the Unix timestamp representing the stored time */ public long as_unix_timestamp() { long ret = bindings.PositiveTimestamp_as_unix_timestamp(this.ptr); @@ -96,7 +111,16 @@ public class PositiveTimestamp extends CommonBase { } /** - * Returns a reference to the internal `SystemTime` time representation + * Returns the duration of the stored time since the Unix epoch + */ + public long as_duration_since_epoch() { + long ret = bindings.PositiveTimestamp_as_duration_since_epoch(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + /** + * Returns the [`SystemTime`] representing the stored time */ public long as_time() { long ret = bindings.PositiveTimestamp_as_time(this.ptr);