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()
    • Method Detail

      • start

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

        public void start​(boolean blocking)
      • stop

        public void stop()
        Specified by:
        stop in interface org.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 address
        fromBlock - search starting from this block number
        toBlock - search until this block number
        Returns:
        a Set of 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 - 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 adres to determine its next nonce
        blockParameterName - DefaultBlockParameterName value
        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:
        getStatisticParameters in interface org.exoplatform.wallet.statistic.ExoWalletStatisticService
      • renewBlockSubscription

        public void renewBlockSubscription​(long lastWatchedBlockNumber)
                                    throws IOException
        Throws:
        IOException
      • setPoolingInterval

        public void setPoolingInterval​(long poolingInterval)
      • getPoolingInterval

        public long getPoolingInterval()