Interface BlockchainService

All Superinterfaces:
org.hyperledger.besu.plugin.services.BesuService

public interface BlockchainService extends org.hyperledger.besu.plugin.services.BesuService
A service for reading the blockchain: blocks, headers, receipts, transactions, the chain id and fork identity. It also stores blocks and sets the safe and finalized block.
  • Method Summary

    Modifier and Type
    Method
    Description
    org.hyperledger.besu.datatypes.Wei
    getBlobGasPrice(org.hyperledger.besu.plugin.data.BlockHeader blockHeader)
    Return the blob gas price for the specified block
    getBlockByHash(org.hyperledger.besu.datatypes.Hash hash)
    Gets block by hash
    getBlockByNumber(long number)
    Gets block by number
    Optional<org.hyperledger.besu.plugin.data.BlockHeader>
    getBlockHeaderByHash(org.hyperledger.besu.datatypes.Hash hash)
    Gets block header by hash
    org.hyperledger.besu.datatypes.Hash
    Get the hash of the chain head
    org.hyperledger.besu.plugin.data.BlockHeader
    Get the block header of the chain head
    Get the chain id
    Optional<org.hyperledger.besu.datatypes.Hash>
    Get the block hash of the finalized block
    org.hyperledger.besu.datatypes.HardforkId
    getHardforkId(long blockNumber)
    Get the hardfork identifier for the given block number
    org.hyperledger.besu.datatypes.HardforkId
    getHardforkId(org.hyperledger.besu.plugin.data.BlockHeader blockHeader)
    Get the hardfork identifier for the given block header
    Optional<org.hyperledger.besu.datatypes.Wei>
    Return the base fee for the next block
    org.hyperledger.besu.datatypes.HardforkId
    getNextBlockHardforkId(org.hyperledger.besu.plugin.data.BlockHeader parentBlockHeader, long timestampForNextBlock)
    Get the hardfork identifier for the next block based on the parent block and timestamp
    Optional<List<org.hyperledger.besu.plugin.data.TransactionReceipt>>
    getReceiptsByBlockHash(org.hyperledger.besu.datatypes.Hash blockHash)
    Get the receipts for a block by block hash
    Optional<org.hyperledger.besu.datatypes.Hash>
    Get the block hash of the safe block
    Optional<org.hyperledger.besu.datatypes.Transaction>
    getTransactionByHash(org.hyperledger.besu.datatypes.Hash transactionHash)
    Get a transaction by its hash
    void
    setFinalizedBlock(org.hyperledger.besu.datatypes.Hash blockHash)
    Set the finalized block for non-PoS networks
    void
    setSafeBlock(org.hyperledger.besu.datatypes.Hash blockHash)
    Set the safe block for non-PoS networks
    void
    storeBlock(org.hyperledger.besu.plugin.data.BlockHeader blockHeader, org.hyperledger.besu.plugin.data.BlockBody blockBody, List<? extends org.hyperledger.besu.plugin.data.TransactionReceipt> receipts)
    Store a block
  • Method Details

    • getBlockByNumber

      Optional<BlockContext> getBlockByNumber(long number)
      Gets block by number
      Parameters:
      number - the block number
      Returns:
      the BlockContext
    • getBlockByHash

      Optional<BlockContext> getBlockByHash(org.hyperledger.besu.datatypes.Hash hash)
      Gets block by hash
      Parameters:
      hash - the block hash
      Returns:
      the BlockContext
    • getBlockHeaderByHash

      Optional<org.hyperledger.besu.plugin.data.BlockHeader> getBlockHeaderByHash(org.hyperledger.besu.datatypes.Hash hash)
      Gets block header by hash
      Parameters:
      hash - the block hash
      Returns:
      the block header if block exists otherwise empty
    • getChainHeadHash

      org.hyperledger.besu.datatypes.Hash getChainHeadHash()
      Get the hash of the chain head
      Returns:
      chain head hash
    • getBlobGasPrice

      org.hyperledger.besu.datatypes.Wei getBlobGasPrice(org.hyperledger.besu.plugin.data.BlockHeader blockHeader)
      Return the blob gas price for the specified block
      Parameters:
      blockHeader - the block header
      Returns:
      the block gas price or Wei.ZERO if blobs are not yet supported for that block header
    • getTransactionByHash

      Optional<org.hyperledger.besu.datatypes.Transaction> getTransactionByHash(org.hyperledger.besu.datatypes.Hash transactionHash)
      Get a transaction by its hash
      Parameters:
      transactionHash - the transaction hash
      Returns:
      the transaction
    • getReceiptsByBlockHash

      Optional<List<org.hyperledger.besu.plugin.data.TransactionReceipt>> getReceiptsByBlockHash(org.hyperledger.besu.datatypes.Hash blockHash)
      Get the receipts for a block by block hash
      Parameters:
      blockHash - the block hash
      Returns:
      the transaction receipts
    • storeBlock

      void storeBlock(org.hyperledger.besu.plugin.data.BlockHeader blockHeader, org.hyperledger.besu.plugin.data.BlockBody blockBody, List<? extends org.hyperledger.besu.plugin.data.TransactionReceipt> receipts)
      Store a block
      Parameters:
      blockHeader - the block header
      blockBody - the block body
      receipts - the transaction receipts
    • getChainHeadHeader

      org.hyperledger.besu.plugin.data.BlockHeader getChainHeadHeader()
      Get the block header of the chain head
      Returns:
      chain head block header
    • getNextBlockBaseFee

      Optional<org.hyperledger.besu.datatypes.Wei> getNextBlockBaseFee()
      Return the base fee for the next block
      Returns:
      base fee of the next block or empty if the fee market does not support base fee
    • getSafeBlock

      Optional<org.hyperledger.besu.datatypes.Hash> getSafeBlock()
      Get the block hash of the safe block
      Returns:
      the block hash of the safe block
    • getFinalizedBlock

      Optional<org.hyperledger.besu.datatypes.Hash> getFinalizedBlock()
      Get the block hash of the finalized block
      Returns:
      the block hash of the finalized block
    • setFinalizedBlock

      void setFinalizedBlock(org.hyperledger.besu.datatypes.Hash blockHash) throws IllegalArgumentException, UnsupportedOperationException
      Set the finalized block for non-PoS networks
      Parameters:
      blockHash - Hash of the finalized block
      Throws:
      IllegalArgumentException - if the block hash is not on the chain
      UnsupportedOperationException - if the network is a PoS network
    • setSafeBlock

      void setSafeBlock(org.hyperledger.besu.datatypes.Hash blockHash) throws IllegalArgumentException, UnsupportedOperationException
      Set the safe block for non-PoS networks
      Parameters:
      blockHash - Hash of the safe block
      Throws:
      IllegalArgumentException - if the block hash is not on the chain
      UnsupportedOperationException - if the network is a PoS network
    • getChainId

      Optional<BigInteger> getChainId()
      Get the chain id
      Returns:
      the chain id
    • getHardforkId

      org.hyperledger.besu.datatypes.HardforkId getHardforkId(org.hyperledger.besu.plugin.data.BlockHeader blockHeader)
      Get the hardfork identifier for the given block header
      Parameters:
      blockHeader - the block header to determine the hardfork for
      Returns:
      the hardfork identifier applicable to the given block
    • getHardforkId

      org.hyperledger.besu.datatypes.HardforkId getHardforkId(long blockNumber)
      Get the hardfork identifier for the given block number
      Parameters:
      blockNumber - the block number to determine the hardfork for
      Returns:
      the hardfork identifier applicable to the given block number
      Throws:
      IllegalArgumentException - if no block with that number exists
    • getNextBlockHardforkId

      org.hyperledger.besu.datatypes.HardforkId getNextBlockHardforkId(org.hyperledger.besu.plugin.data.BlockHeader parentBlockHeader, long timestampForNextBlock)
      Get the hardfork identifier for the next block based on the parent block and timestamp
      Parameters:
      parentBlockHeader - the parent block header
      timestampForNextBlock - the timestamp for the next block
      Returns:
      the hardfork identifier that will be applicable to the next block