Class 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 Detail

      • EthereumClientConnector

        public EthereumClientConnector​(org.exoplatform.services.cache.CacheService cacheService)
    • Method Detail

      • start

        public void start()
        Specified by:
        start in interface org.picocontainer.Startable
      • stop

        public void stop()
        Specified by:
        stop in interface org.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
      • 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 - TransactionDetail having rawTransaction to send to blockchain
        Returns:
        CompletableFuture for 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 using DefaultBlockParameterName.LATEST, this will return last mined transaction nonce * if using DefaultBlockParameterName.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 nonce
        blockParameterName - DefaultBlockParameterName value
        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:
        getStatisticParameters in interface org.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

        protected boolean connect​(boolean periodicCheck)
                           throws Exception
        Throws:
        Exception
      • 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()