Class LockTime

  • Direct Known Subclasses:
    LockTime.HeightLock, LockTime.TimeLock

    public abstract class LockTime
    extends java.lang.Object
    Wrapper for transaction lock time, specified either as a block height LockTime.HeightLock or as a timestamp LockTime.TimeLock (in seconds since epoch). Both are encoded into the same long "raw value", as used in the Bitcoin protocol. The lock time is said to be "not set" if its raw value is zero (and the zero value will be represented by a LockTime.HeightLock with value zero.)

    Instances of this class are immutable and should be treated as Java value-based.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  LockTime.HeightLock
      A LockTime instance that contains a block height.
      static class  LockTime.TimeLock
      A LockTime instance that contains a timestamp.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static long THRESHOLD
      Raw values below this threshold specify a block height, otherwise a timestamp in seconds since epoch.
      protected long value  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      boolean isSet()
      The lock time is considered to be set only if its raw value is greater than zero.
      static LockTime of​(long rawValue)
      Wrap a raw value (as used in the Bitcoin protocol) into a lock time.
      static LockTime.HeightLock ofBlockHeight​(int blockHeight)
      Wrap a block height into a lock time.
      static LockTime.TimeLock ofTimestamp​(java.time.Instant time)
      Wrap a timestamp into a lock time.
      long rawValue()
      Gets the raw value as used in the Bitcoin protocol
      java.lang.String toString()  
      static LockTime unset()
      Construct an unset lock time.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • THRESHOLD

        public static final long THRESHOLD
        Raw values below this threshold specify a block height, otherwise a timestamp in seconds since epoch. Consider using lockTime instance of HeightLock or lockTime instance of TimeLock before using this constant.
        See Also:
        Constant Field Values
      • value

        protected final long value
    • Method Detail

      • of

        public static LockTime of​(long rawValue)
        Wrap a raw value (as used in the Bitcoin protocol) into a lock time.
        Parameters:
        rawValue - raw value to be wrapped
        Returns:
        wrapped value
      • ofBlockHeight

        public static LockTime.HeightLock ofBlockHeight​(int blockHeight)
        Wrap a block height into a lock time.
        Parameters:
        blockHeight - block height to be wrapped
        Returns:
        wrapped block height
      • ofTimestamp

        public static LockTime.TimeLock ofTimestamp​(java.time.Instant time)
        Wrap a timestamp into a lock time.
        Parameters:
        time - timestamp to be wrapped
        Returns:
        wrapped timestamp
      • unset

        public static LockTime unset()
        Construct an unset lock time.
        Returns:
        unset lock time
      • rawValue

        public long rawValue()
        Gets the raw value as used in the Bitcoin protocol
        Returns:
        raw value
      • isSet

        public boolean isSet()
        The lock time is considered to be set only if its raw value is greater than zero. In other words, it is set if it is either a non-zero block height or a timestamp.
        Returns:
        true if lock time is set
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object