Search in sources :

Example 1 with TransactionInfo

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

the class DslFilesTest method runCreate01Resource.

@Test
public void runCreate01Resource() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/create01.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    Transaction transaction = world.getTransactionByName("tx01");
    Assert.assertNotNull(transaction);
    TransactionInfo txinfo = world.getBlockChain().getTransactionInfo(transaction.getHash().getBytes());
    Assert.assertNotNull(txinfo);
    BigInteger gasUsed = BigIntegers.fromUnsignedByteArray(txinfo.getReceipt().getGasUsed());
    Assert.assertNotEquals(BigInteger.ZERO, gasUsed);
    // According to TestRPC and geth, the gas used is 0x010c2d
    Assert.assertEquals(BigIntegers.fromUnsignedByteArray(Hex.decode("010c2d")), gasUsed);
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) Transaction(org.ethereum.core.Transaction) DslParser(co.rsk.test.dsl.DslParser) TransactionInfo(org.ethereum.db.TransactionInfo) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 2 with TransactionInfo

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

the class DslFilesTest method runLogs01Resource.

@Test
public void runLogs01Resource() throws FileNotFoundException, DslProcessorException {
    DslParser parser = DslParser.fromResource("dsl/logs01.txt");
    World world = new World();
    WorldDslProcessor processor = new WorldDslProcessor(world);
    processor.processCommands(parser);
    // the transaction receipt should have three logs
    BlockChainStatus status = world.getBlockChain().getStatus();
    Assert.assertEquals(1, status.getBestBlockNumber());
    Block block = status.getBestBlock();
    Assert.assertEquals(1, block.getTransactionsList().size());
    byte[] txhash = block.getTransactionsList().get(0).getHash().getBytes();
    TransactionInfo txinfo = world.getBlockChain().getTransactionInfo(txhash);
    // only three events, raised by
    // Counter constructor
    // Counter getValue
    // Creator constructor
    Assert.assertEquals(3, txinfo.getReceipt().getLogInfoList().size());
    // only one topic in each event
    Assert.assertEquals(1, txinfo.getReceipt().getLogInfoList().get(0).getTopics().size());
    Assert.assertEquals(1, txinfo.getReceipt().getLogInfoList().get(1).getTopics().size());
    Assert.assertEquals(1, txinfo.getReceipt().getLogInfoList().get(2).getTopics().size());
    // the topics are different
    DataWord topic1 = txinfo.getReceipt().getLogInfoList().get(0).getTopics().get(0);
    DataWord topic2 = txinfo.getReceipt().getLogInfoList().get(1).getTopics().get(0);
    DataWord topic3 = txinfo.getReceipt().getLogInfoList().get(2).getTopics().get(0);
    Assert.assertNotEquals(topic1, topic2);
    Assert.assertNotEquals(topic1, topic3);
    Assert.assertNotEquals(topic2, topic3);
    // only the third log was directly produced by the created contract
    byte[] contractAddress = txinfo.getReceipt().getTransaction().getContractAddress().getBytes();
    Assert.assertFalse(Arrays.equals(contractAddress, txinfo.getReceipt().getLogInfoList().get(0).getAddress()));
    Assert.assertFalse(Arrays.equals(contractAddress, txinfo.getReceipt().getLogInfoList().get(1).getAddress()));
    Assert.assertTrue(Arrays.equals(contractAddress, txinfo.getReceipt().getLogInfoList().get(2).getAddress()));
}
Also used : WorldDslProcessor(co.rsk.test.dsl.WorldDslProcessor) DslParser(co.rsk.test.dsl.DslParser) Block(org.ethereum.core.Block) TransactionInfo(org.ethereum.db.TransactionInfo) BlockChainStatus(co.rsk.core.bc.BlockChainStatus) DataWord(org.ethereum.vm.DataWord) Test(org.junit.Test)

Example 3 with TransactionInfo

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

the class BlockChainImpl method getTransactionInfo.

/**
 * Returns transaction info by hash
 *
 * @param hash      the hash of the transaction
 * @return transaction info, null if the transaction does not exist
 */
@Override
public TransactionInfo getTransactionInfo(byte[] hash) {
    TransactionInfo txInfo = receiptStore.get(hash);
    if (txInfo == null) {
        return null;
    }
    Transaction tx = this.getBlockByHash(txInfo.getBlockHash()).getTransactionsList().get(txInfo.getIndex());
    txInfo.setTransaction(tx);
    return txInfo;
}
Also used : TransactionInfo(org.ethereum.db.TransactionInfo)

Example 4 with TransactionInfo

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

the class Web3Impl method eth_getTransactionReceipt.

@Override
public TransactionReceiptDTO eth_getTransactionReceipt(String transactionHash) throws Exception {
    logger.trace("eth_getTransactionReceipt(" + transactionHash + ")");
    byte[] hash = stringHexToByteArray(transactionHash);
    TransactionInfo txInfo = receiptStore.getInMainChain(hash, blockStore);
    if (txInfo == null) {
        logger.trace("No transaction info for " + transactionHash);
        return null;
    }
    Block block = blockStore.getBlockByHash(txInfo.getBlockHash());
    Transaction tx = block.getTransactionsList().get(txInfo.getIndex());
    txInfo.setTransaction(tx);
    return new TransactionReceiptDTO(block, txInfo);
}
Also used : TransactionReceiptDTO(org.ethereum.rpc.dto.TransactionReceiptDTO) TransactionInfo(org.ethereum.db.TransactionInfo)

Example 5 with TransactionInfo

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

the class LogFilter method onTransaction.

void onTransaction(Transaction tx, Block b, int txIndex) {
    TransactionInfo txInfo = blockchain.getTransactionInfo(tx.getHash().getBytes());
    TransactionReceipt receipt = txInfo.getReceipt();
    LogFilterElement[] logs = new LogFilterElement[receipt.getLogInfoList().size()];
    for (int i = 0; i < logs.length; i++) {
        LogInfo logInfo = receipt.getLogInfoList().get(i);
        if (addressesTopicsFilter.matchesExactly(logInfo)) {
            onLogMatch(logInfo, b, txIndex, receipt.getTransaction(), i);
        }
    }
}
Also used : LogInfo(org.ethereum.vm.LogInfo) TransactionInfo(org.ethereum.db.TransactionInfo)

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