Class EthereumClientConnector
- java.lang.Object
-
- org.exoplatform.wallet.blockchain.service.EthereumClientConnector
-
- All Implemented Interfaces:
org.exoplatform.wallet.statistic.ExoWalletStatisticService,org.picocontainer.Startable
public class EthereumClientConnector extends Object implements org.exoplatform.wallet.statistic.ExoWalletStatisticService, org.picocontainer.Startable
A Web3j connector class to interact with Ethereum Blockchain
-
-
Constructor Summary
Constructors Constructor Description EthereumClientConnector()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Set<String>getContractTransactions(String contractsAddress, long fromBlock, long toBlock)Retrieve from blockchain transaction hashes from contract starting from a block number to a block numberBigIntegergetGasPrice()longgetLastestBlockNumber()BigIntegergetNonce(String walletAddress, org.web3j.protocol.core.DefaultBlockParameterName blockParameterName)Retruns nonce corresponding for a given wallet address: * if usingDefaultBlockParameterName.LATEST, this will return last mined transaction nonce * if usingDefaultBlockParameterName.PENDING, this will return last pending transaction nonce that can be used to compute next pending transaction noncelonggetPoolingInterval()Map<String,Object>getStatisticParameters(String statisticType, Object result, Object... methodArgs)org.web3j.protocol.core.methods.response.TransactiongetTransaction(String transactionHash)Get transaction by hashorg.web3j.protocol.core.methods.response.TransactionReceiptgetTransactionReceipt(String transactionHash)Get transaction receipt by hashorg.web3j.protocol.Web3jgetWeb3j()booleanisListeningToBlockchain()booleanisPermanentlyScanBlockchain()voidrenewBlockSubscription(long lastWatchedBlockNumber)CompletableFuture<org.web3j.protocol.core.methods.response.EthSendTransaction>sendTransactionToBlockchain(org.exoplatform.wallet.model.transaction.TransactionDetail transactionDetail)Send raw transaction specified in Transaction detailvoidsetPoolingInterval(long poolingInterval)voidstart()voidstart(boolean blocking)voidstartListeningBlockchain()voidstop()voidstopListeningToBlockchain()
-
-
-
Method Detail
-
start
public void start()
- Specified by:
startin interfaceorg.picocontainer.Startable
-
start
public void start(boolean blocking)
-
stop
public void stop()
- Specified by:
stopin interfaceorg.picocontainer.Startable
-
startListeningBlockchain
public void startListeningBlockchain()
-
stopListeningToBlockchain
public void stopListeningToBlockchain()
-
isPermanentlyScanBlockchain
public boolean isPermanentlyScanBlockchain()
-
isListeningToBlockchain
public boolean isListeningToBlockchain()
-
getTransaction
public org.web3j.protocol.core.methods.response.Transaction getTransaction(String transactionHash)
Get transaction by hash- Parameters:
transactionHash- transaction hash to retrieve- Returns:
- Web3j Transaction object
-
getTransactionReceipt
public org.web3j.protocol.core.methods.response.TransactionReceipt getTransactionReceipt(String transactionHash)
Get transaction receipt by hash- Parameters:
transactionHash- transaction hash to retrieve- Returns:
- Web3j Transaction receipt object
-
getLastestBlockNumber
public long getLastestBlockNumber() throws IOException- Returns:
- last mined block number from blockchain
- Throws:
IOException- when error sending transaction on blockchain
-
getContractTransactions
public Set<String> getContractTransactions(String contractsAddress, long fromBlock, long toBlock) throws IOException
Retrieve from blockchain transaction hashes from contract starting from a block number to a block number- Parameters:
contractsAddress- blockchain contract addressfromBlock- search starting from this block numbertoBlock- search until this block number- Returns:
- a
Setof transaction hashes - Throws:
IOException- if an error happens while getting information from blockchain
-
sendTransactionToBlockchain
public CompletableFuture<org.web3j.protocol.core.methods.response.EthSendTransaction> sendTransactionToBlockchain(org.exoplatform.wallet.model.transaction.TransactionDetail transactionDetail) throws IOException
Send raw transaction specified in Transaction detail- Parameters:
transactionDetail-TransactionDetailhaving rawTransaction to send to blockchain- Returns:
CompletableFuturefor transaction sent asynchronously to blockchain- Throws:
IOException- if an error occurs while sending transaction to blockchain
-
getNonce
public BigInteger getNonce(String walletAddress, org.web3j.protocol.core.DefaultBlockParameterName blockParameterName) throws IOException
Retruns nonce corresponding for a given wallet address: * if usingDefaultBlockParameterName.LATEST, this will return last mined transaction nonce * if usingDefaultBlockParameterName.PENDING, this will return last pending transaction nonce that can be used to compute next pending transaction nonce- Parameters:
walletAddress- wallet adres to determine its next nonceblockParameterName-DefaultBlockParameterNamevalue- Returns:
- next transaction nonce
- Throws:
IOException- if an I/O problem happens when connecting to blockchain
-
getGasPrice
public BigInteger getGasPrice() throws IOException
- Returns:
- current
- Throws:
IOException- if an error occurs while sending transaction to blockchain
-
getWeb3j
public org.web3j.protocol.Web3j getWeb3j()
-
getStatisticParameters
public Map<String,Object> getStatisticParameters(String statisticType, Object result, Object... methodArgs)
- Specified by:
getStatisticParametersin interfaceorg.exoplatform.wallet.statistic.ExoWalletStatisticService
-
renewBlockSubscription
public void renewBlockSubscription(long lastWatchedBlockNumber) throws IOException- Throws:
IOException
-
setPoolingInterval
public void setPoolingInterval(long poolingInterval)
-
getPoolingInterval
public long getPoolingInterval()
-
-