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);
}
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()));
}
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;
}
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);
}
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);
}
}
}
Aggregations