Package org.saidone.service.notarization
Class EthereumService
java.lang.Object
org.saidone.component.BaseComponent
org.saidone.service.notarization.AbstractNotarizationService
org.saidone.service.notarization.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 Summary
ConstructorsConstructorDescriptionEthereumService(NodeService nodeService, ContentService contentService, EthereumConfig config) Creates the service with required dependencies. -
Method Summary
Modifier and TypeMethodDescriptionprotected StringFetches the hash data stored in the given Ethereum transaction.voidinit()Initializes the Web3j client and credentials after dependency injection.protected StringSends a zero-value transaction containing the given hash as data.voidstop()Shuts down the Web3j client before the bean is destroyed.Methods inherited from class org.saidone.service.notarization.AbstractNotarizationService
checkNotarization, notarizeNodeMethods inherited from class org.saidone.component.BaseComponent
setApplicationContext, shutDown
-
Constructor Details
-
EthereumService
public EthereumService(NodeService nodeService, ContentService contentService, EthereumConfig config) Creates the service with required dependencies.- Parameters:
nodeService- service used to interact with nodescontentService- service computing document hashesconfig- 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, correspondingCredentialsare loaded to allow signed transactions.- Overrides:
initin classBaseComponent
-
stop
@PreDestroy public void stop()Shuts down the Web3j client before the bean is destroyed.- Overrides:
stopin classBaseComponent
-
getHash
Fetches the hash data stored in the given Ethereum transaction.- Specified by:
getHashin classAbstractNotarizationService- Parameters:
txHash- the transaction identifier- Returns:
- the string stored in the transaction input data
-
putHash
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:
putHashin classAbstractNotarizationService- Parameters:
nodeId- the node identifierhash- the hash to store on the blockchain- Returns:
- the resulting Ethereum transaction hash
-