Search in sources :

Example 6 with TransactionInfo

use of org.ethereum.db.TransactionInfo in project rskj by rsksmart.

the class Web3Impl method eth_getTransactionByHash.

@Override
public TransactionResultDTO eth_getTransactionByHash(String transactionHash) throws Exception {
    TransactionResultDTO s = null;
    try {
        Keccak256 txHash = new Keccak256(stringHexToByteArray(transactionHash));
        Block block = null;
        TransactionInfo txInfo = blockchain.getTransactionInfo(txHash.getBytes());
        if (txInfo == null) {
            List<Transaction> txs = this.getTransactionsByJsonBlockId("pending");
            for (Transaction tx : txs) {
                if (tx.getHash().equals(txHash)) {
                    return s = new TransactionResultDTO(null, null, tx);
                }
            }
        } else {
            block = blockchain.getBlockByHash(txInfo.getBlockHash());
            // need to return txes only from main chain
            Block mainBlock = blockchain.getBlockByNumber(block.getNumber());
            if (!block.getHash().equals(mainBlock.getHash())) {
                return null;
            }
            txInfo.setTransaction(block.getTransactionsList().get(txInfo.getIndex()));
        }
        if (txInfo == null) {
            return null;
        }
        return s = new TransactionResultDTO(block, txInfo.getIndex(), txInfo.getReceipt().getTransaction());
    } finally {
        logger.debug("eth_getTransactionByHash({}): {}", transactionHash, s);
    }
}
Also used : TransactionInfo(org.ethereum.db.TransactionInfo) TransactionResultDTO(org.ethereum.rpc.dto.TransactionResultDTO) Keccak256(co.rsk.crypto.Keccak256)

Aggregations

TransactionInfo (org.ethereum.db.TransactionInfo)6 DslParser (co.rsk.test.dsl.DslParser)2 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)2 Test (org.junit.Test)2 BlockChainStatus (co.rsk.core.bc.BlockChainStatus)1 Keccak256 (co.rsk.crypto.Keccak256)1 BigInteger (java.math.BigInteger)1 Block (org.ethereum.core.Block)1 Transaction (org.ethereum.core.Transaction)1 TransactionReceiptDTO (org.ethereum.rpc.dto.TransactionReceiptDTO)1 TransactionResultDTO (org.ethereum.rpc.dto.TransactionResultDTO)1 DataWord (org.ethereum.vm.DataWord)1 LogInfo (org.ethereum.vm.LogInfo)1