Interface Node

All Superinterfaces:
java.lang.AutoCloseable
All Known Implementing Classes:
NodeFake

public interface Node
extends java.lang.AutoCloseable
An Exonum node context. Allows to add transactions to Exonum network and get a snapshot of the database state.

Once the node is closed, it can no longer be used. Methods of a closed Node will throw an IllegalStateException if invoked.

All method arguments are non-null by default.

  • Method Summary

    Modifier and Type Method Description
    void close()
    Closes this node.
    PublicKey getPublicKey()
    Returns the service public key of this node.
    HashCode submitTransaction​(RawTransaction rawTransaction)
    Creates a transaction from the given parameters, signs it with the node service key, and then submits it into Exonum network.
    <ResultT> ResultT withBlockchainData​(java.util.function.Function<BlockchainData,​ResultT> snapshotFunction)
    Performs the given function with a snapshot of the current database state.
    default <ResultT> ResultT withServiceData​(java.util.function.Function<? super Prefixed,​ResultT> snapshotFunction)
    Performs the given function with a snapshot of the current database state.
  • Method Details

    • submitTransaction

      HashCode submitTransaction​(RawTransaction rawTransaction)
      Creates a transaction from the given parameters, signs it with the node service key, and then submits it into Exonum network. This node does not execute the transaction immediately, but broadcasts it to all the nodes in the network. Then each node verifies the transaction and, if it is correct, adds it to the pool of unconfirmed transactions. The transaction is executed later asynchronously.

      Incorrect transactions (e.g., the payload of which cannot be deserialized by the target service, or which have unknown message id) are rejected by the network.

      Be aware that each node has its own service key pair, therefore invocations of this method on different nodes will produce different transactions.

      Parameters:
      rawTransaction - transaction parameters to include in transaction message
      Returns:
      hash of the transaction message created by the framework
      Throws:
      TransactionSubmissionException - if the transaction belongs to an unknown service, or cannot be submitted
      See Also:
      Blockchain.getTxMessages()
    • withServiceData

      default <ResultT> ResultT withServiceData​(java.util.function.Function<? super Prefixed,​ResultT> snapshotFunction)
      Performs the given function with a snapshot of the current database state. Only the executing service data is accessible through the provided snapshot.

      A shortcut for BlockchainData.getExecutingServiceData().

      Type Parameters:
      ResultT - a type the function returns
      Parameters:
      snapshotFunction - a function to execute
      Returns:
      the result of applying the given function to the database state
      See Also:
      withBlockchainData(Function)
    • withBlockchainData

      <ResultT> ResultT withBlockchainData​(java.util.function.Function<BlockchainData,​ResultT> snapshotFunction)
      Performs the given function with a snapshot of the current database state.
      Type Parameters:
      ResultT - a type the function returns
      Parameters:
      snapshotFunction - a function to execute
      Returns:
      the result of applying the given function to the database state
      See Also:
      withServiceData(Function)
    • getPublicKey

      PublicKey getPublicKey()
      Returns the service public key of this node. The corresponding private key is used for signing transactions in submitTransaction(RawTransaction).

      This key is stored under "service_public_key" key in the node configuration file.

    • close

      void close()
      Closes this node. A closed node must no longer be used.
      Specified by:
      close in interface java.lang.AutoCloseable