Class TransactionLog

java.lang.Object
dev.hloth.zgztransport.TransactionLog

public final class TransactionLog extends Object
The ring of six blocks a card keeps its last transactions in: block 5 holds the newest record, and the five before it live in the archive blocks, each in the slot its sequence byte picks.
  • Field Details

    • LIVE_BLOCK

      public static final int LIVE_BLOCK
      The block holding the newest record.
      See Also:
    • ARCHIVE_BLOCKS

      public static final List<Integer> ARCHIVE_BLOCKS
      The blocks holding the five records before the newest, indexed by sequence byte.
    • BLOCKS

      public static final List<Integer> BLOCKS
      The six slots, in the order decode(byte[][]) expects.
  • Method Details

    • archiveBlock

      public static OptionalInt archiveBlock(int sequence)
      The block a record moves to when a newer one replaces it.
      Parameters:
      sequence - the sequence byte of the record
      Returns:
      the block number, or empty when the byte is not one the ring uses
    • decode

      public static List<Transaction> decode(byte[][] slots)
      Decodes the six slots of the ring, oldest record first. Slots whose first byte is zero hold no record and are skipped; records that share a timestamp keep the order of the slots.
      Parameters:
      slots - the six blocks, in the order of BLOCKS
      Returns:
      the records the ring holds
      Throws:
      CardFormatException - if there are not six slots or an occupied one does not decode