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
Fields Modifier and Type Field Description static intDEFAULT_POLLING_TIMEstatic intMINIMUM_POLLING_TIME
-
Constructor Summary
Constructors Constructor Description EthereumClientConnector(org.exoplatform.services.cache.CacheService cacheService)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancelTransactionListeningToBlockchain()protected booleancheckConnection(boolean periodicCheck)protected voidcheckSubscription()protected voidcloseConnection()protected booleanconnect()protected booleanconnect(boolean periodicCheck)protected ScheduledFuture<?>getConnectionVerifierFuture()BigIntegergetEtherBalanceOf(String address)BigIntegergetGasPrice()longgetLastestBlockNumber()longgetLastWatchedBlockNumber()BigIntegergetNonce(String walletAddress)Retruns last mined transaction nonceBigIntegergetNonce(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 noncelonggetPollingInterval()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.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 booleanisConnected()booleanisListeningToBlockchain()booleanisPermanentlyScanBlockchain()protected voidrenewSubscriptionWhenDisposed()Future<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 voidstopListeningToBlockchain()protected Future<io.reactivex.disposables.Disposable>subscribeToBlockchain()protected io.reactivex.disposables.DisposablesubscribeToBlockchain(org.web3j.protocol.core.DefaultBlockParameterNumber lastWatchedBlock)protected voiduninstallFilter()protected voidwaitConnection(int tentatives)
-
-
-
Field Detail
-
MINIMUM_POLLING_TIME
public static final int MINIMUM_POLLING_TIME
- See Also:
- Constant Field Values
-
DEFAULT_POLLING_TIME
public static final int DEFAULT_POLLING_TIME
- See Also:
- Constant Field Values
-
-
Method Detail
-
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
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
-
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
public final BigInteger getEtherBalanceOf(String address) throws IOException
- 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
public BigInteger getNonce(String walletAddress) throws IOException
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
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(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()
-
checkConnection
protected boolean checkConnection(boolean periodicCheck)
-
closeConnection
protected void closeConnection()
-
setListenerService
protected void setListenerService(org.exoplatform.services.listener.ListenerService listenerService)
-
getConnectionVerifierFuture
protected ScheduledFuture<?> getConnectionVerifierFuture()
-
checkSubscription
protected void checkSubscription()
-
renewSubscriptionWhenDisposed
protected void renewSubscriptionWhenDisposed()
-
waitConnection
protected void waitConnection(int tentatives)
-
subscribeToBlockchain
protected Future<io.reactivex.disposables.Disposable> subscribeToBlockchain()
-
subscribeToBlockchain
protected io.reactivex.disposables.Disposable subscribeToBlockchain(org.web3j.protocol.core.DefaultBlockParameterNumber lastWatchedBlock)
-
stopListeningToBlockchain
protected void stopListeningToBlockchain()
-
uninstallFilter
protected void uninstallFilter()
-
-