Class Block

java.lang.Object
com.exonum.binding.core.blockchain.Block

public abstract class Block
extends java.lang.Object
Exonum block header data structure.

A block is essentially a list of transactions, which is a result of the consensus algorithm (thus authenticated by the supermajority of validators) and is applied atomically to the blockchain state.

This structure only contains the amount of transactions and the transactions root hash as well as other information, but not the transactions themselves.

See Also:
Blockchain
  • Nested Class Summary

    Nested Classes 
    Modifier and Type Class Description
    static class  Block.Builder  
  • Constructor Summary

    Constructors 
    Constructor Description
    Block()  
  • Method Summary

    Modifier and Type Method Description
    static Block.Builder builder()
    Creates a new block builder.
    static Block fromMessage​(Blockchain.Block blockMessage)
    Creates a block from the block message.
    abstract com.google.common.collect.ImmutableMap<java.lang.String,​com.google.protobuf.ByteString> getAdditionalHeaders()
    Contains additional block headers of the block.
    abstract HashCode getBlockHash()
    Returns the SHA-256 hash of this block.
    abstract HashCode getErrorHash()
    Root hash of exceptions occurred in the block.
    abstract long getHeight()
    Returns the height of this block which is a distance between the last block and the "genesis" block.
    abstract int getNumTransactions()
    Number of transactions in this block.
    abstract HashCode getPreviousBlockHash()
    Hash link to the previous block in the blockchain.
    abstract int getProposerId()
    Identifier of the leader node which has proposed the block.
    abstract HashCode getStateHash()
    Hash of the blockchain state after applying transactions in the block.
    abstract HashCode getTxRootHash()
    Root hash of the Merkle tree of transactions in this block.
    int hashCode()  
    boolean isEmpty()
    Returns true if this block is empty: contains no transactions.
    static Block parseFrom​(byte[] serializedBlock)
    Creates a block from the serialized block message.
    static com.google.gson.TypeAdapter<Block> typeAdapter​(com.google.gson.Gson gson)
    Provides a Gson type adapter for this class.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • getBlockHash

      public abstract HashCode getBlockHash()
      Returns the SHA-256 hash of this block.
    • getProposerId

      public abstract int getProposerId()
      Identifier of the leader node which has proposed the block.
    • getHeight

      public abstract long getHeight()
      Returns the height of this block which is a distance between the last block and the "genesis" block. Genesis block has 0 height. Therefore, the blockchain height is equal to the number of blocks plus one.

      The height also identifies each block in the blockchain.

    • isEmpty

      public final boolean isEmpty()
      Returns true if this block is empty: contains no transactions.
    • getNumTransactions

      public abstract int getNumTransactions()
      Number of transactions in this block.
    • getPreviousBlockHash

      public abstract HashCode getPreviousBlockHash()
      Hash link to the previous block in the blockchain.
    • getTxRootHash

      public abstract HashCode getTxRootHash()
      Root hash of the Merkle tree of transactions in this block. These transactions can be accessed with Blockchain.getBlockTransactions(Block).
    • getStateHash

      public abstract HashCode getStateHash()
      Hash of the blockchain state after applying transactions in the block.
      See Also:
      Schema
    • getErrorHash

      public abstract HashCode getErrorHash()
      Root hash of exceptions occurred in the block.
      See Also:
      Blockchain.getCallRecords(long)
    • getAdditionalHeaders

      public abstract com.google.common.collect.ImmutableMap<java.lang.String,​com.google.protobuf.ByteString> getAdditionalHeaders()
      Contains additional block headers of the block. The key is a block header; and the value is a header bytes value.
    • hashCode

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

      public static com.google.gson.TypeAdapter<Block> typeAdapter​(com.google.gson.Gson gson)
      Provides a Gson type adapter for this class.
      See Also:
      CoreTypeAdapterFactory
    • fromMessage

      public static Block fromMessage​(Blockchain.Block blockMessage)
      Creates a block from the block message.
      Parameters:
      blockMessage - a block
    • parseFrom

      public static Block parseFrom​(byte[] serializedBlock)
      Creates a block from the serialized block message.
      Parameters:
      serializedBlock - a serialized block message
      Throws:
      java.lang.IllegalArgumentException - if the block bytes are not a serialized Blockchain.Block
    • builder

      public static Block.Builder builder()
      Creates a new block builder.