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
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final int -
Constructor Summary
ConstructorsConstructorDescriptionEthereumClientConnector(org.exoplatform.services.cache.CacheService cacheService) -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected booleancheckConnection(boolean periodicCheck) protected voidprotected voidprotected booleanconnect()protected booleanconnect(boolean periodicCheck) protected ScheduledFuture<?>final BigIntegergetEtherBalanceOf(String address) longlongRetruns last mined transaction noncegetNonce(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 noncelonggetStatisticParameters(String statisticType, Object result, Object... methodArgs) org.web3j.protocol.core.methods.response.TransactiongetTransaction(String transactionHash) Get transaction by hashorg.web3j.protocol.core.methods.response.TransactiongetTransactionFromBlockchain(String transactionHash) Get transaction by hashorg.web3j.protocol.core.methods.response.TransactionReceiptgetTransactionReceipt(String transactionHash) Get transaction receipt by hashorg.web3j.protocol.core.methods.response.TransactionReceiptgetTransactionReceiptFromBlockchain(String transactionHash) Get transaction receipt by hashorg.web3j.protocol.Web3jgetWeb3j(boolean waitUntilConnected) protected booleanbooleanbooleanprotected voidFuture<io.reactivex.disposables.Disposable>renewTransactionListeningSubscription(long lastWatchedBlockNumber) CompletableFuture<org.web3j.protocol.core.methods.response.EthSendTransaction>sendTransactionToBlockchain(org.exoplatform.wallet.model.transaction.TransactionDetail transactionDetail) Send raw transaction specified in Transaction detailvoidsetLastWatchedBlockNumber(long blockNumber) protected voidsetListenerService(org.exoplatform.services.listener.ListenerService listenerService) voidsetPollingInterval(long pollingInterval) protected voidsetWeb3j(org.web3j.protocol.Web3j web3j) protected voidsetWeb3jService(org.web3j.protocol.websocket.WebSocketService web3jService) protected voidsetWebSocketClient(org.web3j.protocol.websocket.WebSocketClient webSocketClient) voidstart()voidstop()protected voidprotected Future<io.reactivex.disposables.Disposable>protected io.reactivex.disposables.DisposablesubscribeToBlockchain(org.web3j.protocol.core.DefaultBlockParameterNumber lastWatchedBlock) protected voidprotected voidwaitConnection(int tentatives)
-
Field Details
-
MINIMUM_POLLING_TIME
public static final int MINIMUM_POLLING_TIME- See Also:
-
DEFAULT_POLLING_TIME
public static final int DEFAULT_POLLING_TIME- See Also:
-
-
Constructor Details
-
EthereumClientConnector
public EthereumClientConnector(org.exoplatform.services.cache.CacheService cacheService)
-
-
Method Details
-
start
public void start()- Specified by:
startin interfaceorg.picocontainer.Startable
-
stop
public void stop()- Specified by:
stopin interfaceorg.picocontainer.Startable
-
isPermanentlyScanBlockchain
public boolean isPermanentlyScanBlockchain() -
isListeningToBlockchain
public boolean isListeningToBlockchain() -
getTransaction
Get transaction by hash- Parameters:
transactionHash- transaction hash to retrieve- Returns:
- Web3j Transaction object
-
getTransactionFromBlockchain
public org.web3j.protocol.core.methods.response.Transaction getTransactionFromBlockchain(String transactionHash) throws IOException Get transaction by hash- Parameters:
transactionHash- transaction hash to retrieve- Returns:
- Web3j Transaction object
- Throws:
IOException- when a network error happens
-
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
-
getEtherBalanceOf
- Throws:
IOException
-
getTransactionReceiptFromBlockchain
public org.web3j.protocol.core.methods.response.TransactionReceipt getTransactionReceiptFromBlockchain(String transactionHash) throws IOException Get transaction receipt by hash- Parameters:
transactionHash- transaction hash to retrieve- Returns:
- Web3j Transaction receipt object
- Throws:
IOException- when a network error happens
-
getLastestBlockNumber
public long getLastestBlockNumber()- Returns:
- last mined block number 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 address to determine its next nonceblockParameterName-DefaultBlockParameterNamevalue- Returns:
- next transaction nonce
- Throws:
IOException- if an I/O problem happens when connecting to blockchain
-
getNonce
Retruns last mined transaction nonce- Parameters:
walletAddress- wallet address to determine its next nonce- Returns:
- next transaction nonce
- Throws:
IOException- if an I/O problem happens when connecting to blockchain
-
getGasPrice
- Returns:
- current
- Throws:
IOException- if an error occurs while sending transaction to blockchain
-
getWeb3j
public org.web3j.protocol.Web3j getWeb3j(boolean waitUntilConnected) -
getStatisticParameters
public Map<String,Object> getStatisticParameters(String statisticType, Object result, Object... methodArgs) - Specified by:
getStatisticParametersin interfaceorg.exoplatform.wallet.statistic.ExoWalletStatisticService
-
renewTransactionListeningSubscription
public Future<io.reactivex.disposables.Disposable> renewTransactionListeningSubscription(long lastWatchedBlockNumber) -
cancelTransactionListeningToBlockchain
public void cancelTransactionListeningToBlockchain() -
setPollingInterval
public void setPollingInterval(long pollingInterval) -
getPollingInterval
public long getPollingInterval() -
setLastWatchedBlockNumber
public void setLastWatchedBlockNumber(long blockNumber) -
getLastWatchedBlockNumber
public long getLastWatchedBlockNumber() -
setWebSocketClient
protected void setWebSocketClient(org.web3j.protocol.websocket.WebSocketClient webSocketClient) -
setWeb3j
protected void setWeb3j(org.web3j.protocol.Web3j web3j) -
setWeb3jService
protected void setWeb3jService(org.web3j.protocol.websocket.WebSocketService web3jService) -
isConnected
protected boolean isConnected() -
connect
- Throws:
Exception
-
connect
- Throws:
Exception
-
checkConnection
protected boolean checkConnection(boolean periodicCheck) -
closeConnection
protected void closeConnection() -
setListenerService
protected void setListenerService(org.exoplatform.services.listener.ListenerService listenerService) -
getConnectionVerifierFuture
-
checkSubscription
protected void checkSubscription() -
renewSubscriptionWhenDisposed
protected void renewSubscriptionWhenDisposed() -
waitConnection
protected void waitConnection(int tentatives) -
subscribeToBlockchain
-
subscribeToBlockchain
protected io.reactivex.disposables.Disposable subscribeToBlockchain(org.web3j.protocol.core.DefaultBlockParameterNumber lastWatchedBlock) -
stopListeningToBlockchain
protected void stopListeningToBlockchain() -
uninstallFilter
protected void uninstallFilter()
-