Class EthereumService

All Implemented Interfaces:
NotarizationService, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware

@Service @ConditionalOnExpression("${application.service.vault.notarization.enabled}.equals(true) and \'${application.service.vault.notarization.impl}\'.equals(\'ethereum\')") public class EthereumService extends AbstractNotarizationService
Service responsible for interacting with an Ethereum node to store document hashes.

This component wraps the minimal Web3j interactions required by the application. It creates the Web3j client on startup and uses the provided Credentials to sign transactions that embed document hashes. The bean is instantiated only when the application is configured to use the ethereum implementation of the notarization service.

  • Constructor Details

    • EthereumService

      public EthereumService(NodeService nodeService, ContentService contentService, EthereumConfig config)
      Creates the service with required dependencies.
      Parameters:
      nodeService - service used to interact with nodes
      contentService - service computing document hashes
      config - Ethereum configuration properties
  • Method Details

    • init

      @PostConstruct public void init()
      Initializes the Web3j client and credentials after dependency injection.

      The client is built using the RPC URL from EthereumConfig. If a private key is configured, corresponding Credentials are loaded to allow signed transactions.

      Overrides:
      init in class BaseComponent
    • stop

      @PreDestroy public void stop()
      Shuts down the Web3j client before the bean is destroyed.
      Overrides:
      stop in class BaseComponent
    • getHash

      protected String getHash(String txHash)
      Fetches the hash data stored in the given Ethereum transaction.
      Specified by:
      getHash in class AbstractNotarizationService
      Parameters:
      txHash - the transaction identifier
      Returns:
      the string stored in the transaction input data
    • putHash

      protected String putHash(String nodeId, String hash)
      Sends a zero-value transaction containing the given hash as data.

      The transaction is signed with the configured credentials and addressed to the account defined in EthereumConfig.

      Specified by:
      putHash in class AbstractNotarizationService
      Parameters:
      nodeId - the node identifier
      hash - the hash to store on the blockchain
      Returns:
      the resulting Ethereum transaction hash