Package convex.core

Class Block

All Implemented Interfaces:
IValidated, IWriteable, Map<Keyword,​ACell>

public final class Block extends ARecord
A Block contains an ordered collection of signed transactions that may be applied collectively as part of a state update. Blocks represent the units of novelty in the consensus system: a future state is 100% deterministic given the previous state and the Block to be applied. "Man, the living creature, the creating individual, is always more important than any established style or system." - Bruce Lee
  • Method Details

    • get

      public ACell get(ACell k)
      Description copied from class: ARecord
      Gets the record field content for a given key, or null if not found.
      Specified by:
      get in class ARecord
      Parameters:
      k - Key to look up in this record
      Returns:
      Field value for the given key
    • updateAll

      protected Block updateAll(ACell[] newVals)
      Description copied from class: ARecord
      Updates all values in this record, in declared field order. Returns this if all values are identical.
      Specified by:
      updateAll in class ARecord
      Parameters:
      newVals - New values to replace current
      Returns:
      Updated Record
    • getTimeStamp

      public long getTimeStamp()
      Gets the timestamp of this block
      Returns:
      Timestamp, as a long value
    • create

      public static Block create(long timestamp, List<SignedData<ATransaction>> transactions)
      Creates a block with the given timestamp and transactions
      Parameters:
      timestamp - Timestamp for the newly created Block.
      transactions - A java.util.List instance containing the required transactions
      peerKey - Peer Key of Peer producing Block
      Returns:
      A new Block containing the specified signed transactions
    • create

      public static Block create(long timestamp, AVector<SignedData<ATransaction>> transactions)
      Creates a block with the given transactions.
      Parameters:
      timestamp - Timestamp of block creation, according to Peer
      peerKey - Public key of Peer producing Block
      transactions - Vector of transactions to include in Block
      Returns:
      A new Block containing the specified signed transactions
    • of

      @SafeVarargs public static Block of(long timestamp, SignedData<ATransaction>... transactions)
      Creates a block with the given transactions.
      Parameters:
      timestamp - Timestamp of block creation, according to Peer
      peerKey - Public key of Peer producing Block
      transactions - Array of transactions to include in Block
      Returns:
      New Block
    • length

      public int length()
      Gets the length of this block in number of transactions
      Returns:
      Number of transactions on this block
    • encode

      public int encode(byte[] bs, int pos)
      Description copied from class: ACell
      Writes this Cell's encoding to a byte array, including a tag byte which will be written first. Cell must be canonical, or else an error may occur.
      Specified by:
      encode in interface IWriteable
      Specified by:
      encode in class ACell
      Parameters:
      bs - A byte array to which to write the encoding
      pos - The offset into the byte array
      Returns:
      New position after writing
    • encodeRaw

      public int encodeRaw(byte[] bs, int pos)
      Description copied from class: ARecord
      Writes the raw fields of this record in declared order
      Overrides:
      encodeRaw in class ARecord
      Parameters:
      bs - Array to write to
      pos - The offset into the byte array
      Returns:
      New position after writing
    • estimatedEncodingSize

      public int estimatedEncodingSize()
      Description copied from interface: IWriteable
      Estimate the encoded data size for this Cell. Used for quickly sizing buffers. Implementations should try to return a size that is likely to contain the entire object when represented in binary format, including the tag byte.
      Specified by:
      estimatedEncodingSize in interface IWriteable
      Overrides:
      estimatedEncodingSize in class ARecord
      Returns:
      The estimated size for the binary representation of this object.
    • read

      public static Block read(ByteBuffer bb) throws BadFormatException
      Reads a Block from the given bytebuffer, assuming tag is already read
      Parameters:
      bb - ByteBuffer containing Block representation
      Returns:
      A Block
      Throws:
      BadFormatException - if a Block could noy be read.
    • getTransactions

      public AVector<SignedData<ATransaction>> getTransactions()
      Get the vector of transactions in this Block
      Returns:
      Vector of transactions
    • isCanonical

      public boolean isCanonical()
      Description copied from class: ACell
      Returns true if this Cell is in a canonical representation for message writing. Non-canonical objects may be used on a temporary internal basis, they must always be converted to canonical representations for external use (e.g. Encoding).
      Overrides:
      isCanonical in class ARecord
      Returns:
      true if the object is in canonical format, false otherwise
    • getTag

      public byte getTag()
      Description copied from class: ARecord
      Gets the tag byte for this record type. The Tag is the byte used to identify the record in the binary encoding.
      Specified by:
      getTag in class ARecord
      Returns:
      Record tag byte
    • validateCell

      public void validateCell() throws InvalidDataException
      Description copied from class: ACell
      Validates the local structure and invariants of this cell. Called by validate() super implementation. Should validate directly contained data, but should not validate all other structure of this cell. In particular, should not traverse potentially missing child Refs.
      Specified by:
      validateCell in class ACell
      Throws:
      InvalidDataException - If the Cell is invalid
    • equals

      public boolean equals(AMap<Keyword,​ACell> a)
      Description copied from class: AMap
      Checks this map for equality with another map. In general, maps should be considered equal if they have the same canonical representation, i.e. the same hash value. Subclasses may override this this they have a more efficient equals implementation or a more specific definition of equality.
      Specified by:
      equals in class AMap<Keyword,​ACell>
      Parameters:
      a - Map to compare with
      Returns:
      true if maps are equal, false otherwise.
    • equals

      public boolean equals(Block a)
      Tests if this Block is equal to another
      Parameters:
      a - PeerStatus to compare with
      Returns:
      true if equal, false otherwise