Search in sources :

Example 16 with TransactionReceipt

use of org.ethereum.core.TransactionReceipt in project rskj by rsksmart.

the class BlockHashesHelper method calculateReceiptsTrieRootFor.

public static List<Trie> calculateReceiptsTrieRootFor(Block block, ReceiptStore receiptStore, Keccak256 txHash) throws BlockHashesHelperException {
    Keccak256 bhash = block.getHash();
    List<Transaction> transactions = block.getTransactionsList();
    List<TransactionReceipt> receipts = new ArrayList<>();
    int ntxs = transactions.size();
    int ntx = -1;
    for (int k = 0; k < ntxs; k++) {
        Transaction transaction = transactions.get(k);
        Keccak256 txh = transaction.getHash();
        Optional<TransactionInfo> txInfoOpt = receiptStore.get(txh.getBytes(), bhash.getBytes());
        if (!txInfoOpt.isPresent()) {
            throw new BlockHashesHelperException(String.format("Missing receipt for transaction %s in block %s", txh, bhash));
        }
        TransactionInfo txInfo = txInfoOpt.get();
        receipts.add(txInfo.getReceipt());
        if (txh.equals(txHash)) {
            ntx = k;
        }
    }
    if (ntx == -1) {
        return null;
    }
    Trie trie = calculateReceiptsTrieRootFor(receipts);
    List<Trie> nodes = trie.getNodes(RLP.encodeInt(ntx));
    return nodes;
}
Also used : Transaction(org.ethereum.core.Transaction) TransactionReceipt(org.ethereum.core.TransactionReceipt) ArrayList(java.util.ArrayList) TransactionInfo(org.ethereum.db.TransactionInfo) Keccak256(co.rsk.crypto.Keccak256) Trie(co.rsk.trie.Trie)

Example 17 with TransactionReceipt

use of org.ethereum.core.TransactionReceipt in project rskj by rsksmart.

the class TransactionReceiptDTOTest method testErrorStatusField.

@Test
public void testErrorStatusField() {
    RskAddress rskAddress = RskAddress.nullAddress();
    Keccak256 hash = Keccak256.ZERO_HASH;
    Bloom bloom = new Bloom();
    Block block = mock(Block.class);
    when(block.getHash()).thenReturn(hash);
    Transaction transaction = mock(Transaction.class);
    when(transaction.getHash()).thenReturn(hash);
    when(transaction.getSender()).thenReturn(rskAddress);
    when(transaction.getReceiveAddress()).thenReturn(rskAddress);
    TransactionReceipt txReceipt = mock(TransactionReceipt.class);
    when(txReceipt.getTransaction()).thenReturn(transaction);
    when(txReceipt.getLogInfoList()).thenReturn(Collections.emptyList());
    when(txReceipt.getBloomFilter()).thenReturn(bloom);
    when(txReceipt.getStatus()).thenReturn(new byte[] { 0x00 });
    TransactionInfo txInfo = new TransactionInfo(txReceipt, hash.getBytes(), 0);
    TransactionReceiptDTO transactionReceiptDTO = new TransactionReceiptDTO(block, txInfo);
    String actualStatus = transactionReceiptDTO.getStatus();
    assertNotNull(actualStatus);
    assertEquals("0x0", actualStatus);
}
Also used : Transaction(org.ethereum.core.Transaction) Bloom(org.ethereum.core.Bloom) RskAddress(co.rsk.core.RskAddress) TransactionReceipt(org.ethereum.core.TransactionReceipt) Block(org.ethereum.core.Block) TransactionInfo(org.ethereum.db.TransactionInfo) Keccak256(co.rsk.crypto.Keccak256) Test(org.junit.Test)

Example 18 with TransactionReceipt

use of org.ethereum.core.TransactionReceipt in project eth-propeller-ethj by adridadou.

the class EthJEventListener method toReceipt.

static org.adridadou.ethereum.propeller.values.TransactionReceipt toReceipt(TransactionReceipt transactionReceipt, EthHash blockHash) {
    Transaction tx = transactionReceipt.getTransaction();
    BigInteger txValue = tx.getValue().length > 0 ? new BigInteger(tx.getValue()) : BigInteger.ZERO;
    if (txValue.signum() == -1) {
        txValue = BigInteger.ZERO;
    }
    return new org.adridadou.ethereum.propeller.values.TransactionReceipt(EthHash.of(tx.getHash()), blockHash, EthAddress.of(tx.getSender()), EthAddress.of(tx.getReceiveAddress()), EthAddress.of(tx.getContractAddress()), EthData.of(tx.getData()), transactionReceipt.getError(), EthData.of(transactionReceipt.getExecutionResult()), transactionReceipt.isSuccessful() && transactionReceipt.isValid(), createEventInfoList(EthHash.of(tx.getHash()), transactionReceipt.getLogInfoList()), ethValueDecoder.decode(0, EthData.of(txValue), EthValue.class));
}
Also used : Transaction(org.ethereum.core.Transaction) TransactionReceipt(org.ethereum.core.TransactionReceipt) BigInteger(java.math.BigInteger)

Example 19 with TransactionReceipt

use of org.ethereum.core.TransactionReceipt in project eth-propeller-ethj by adridadou.

the class EthJEventListener method onBlock.

@Override
public void onBlock(Block block, List<TransactionReceipt> receipts) {
    EthHash blockHash = EthHash.of(block.getHash());
    eventHandler.onBlock(new BlockInfo(block.getNumber(), receipts.stream().map(receipt -> EthJEventListener.toReceipt(receipt, blockHash)).collect(Collectors.toList())));
    receipts.forEach(receipt -> eventHandler.onTransactionExecuted(new TransactionInfo(EthHash.of(receipt.getTransaction().getHash()), toReceipt(receipt, blockHash), TransactionStatus.Executed, EthHash.empty())));
}
Also used : LogInfo(org.ethereum.vm.LogInfo) EthValueDecoder(org.adridadou.ethereum.propeller.solidity.converters.decoders.EthValueDecoder) DataWord(org.ethereum.vm.DataWord) EthereumEventHandler(org.adridadou.ethereum.propeller.event.EthereumEventHandler) TransactionReceipt(org.ethereum.core.TransactionReceipt) EthereumListenerAdapter(org.ethereum.listener.EthereumListenerAdapter) Collectors(java.util.stream.Collectors) Block(org.ethereum.core.Block) BlockInfo(org.adridadou.ethereum.propeller.event.BlockInfo) List(java.util.List) BigInteger(java.math.BigInteger) org.adridadou.ethereum.propeller.values(org.adridadou.ethereum.propeller.values) Transaction(org.ethereum.core.Transaction) BlockInfo(org.adridadou.ethereum.propeller.event.BlockInfo)

Example 20 with TransactionReceipt

use of org.ethereum.core.TransactionReceipt in project rskj by rsksmart.

the class TransactionReceiptDTOTest method testErrorStatusFieldUsingNullByteArray.

@Test
public void testErrorStatusFieldUsingNullByteArray() {
    RskAddress rskAddress = RskAddress.nullAddress();
    Keccak256 hash = Keccak256.ZERO_HASH;
    Bloom bloom = new Bloom();
    Block block = mock(Block.class);
    when(block.getHash()).thenReturn(hash);
    Transaction transaction = mock(Transaction.class);
    when(transaction.getHash()).thenReturn(hash);
    when(transaction.getSender()).thenReturn(rskAddress);
    when(transaction.getReceiveAddress()).thenReturn(rskAddress);
    TransactionReceipt txReceipt = mock(TransactionReceipt.class);
    when(txReceipt.getTransaction()).thenReturn(transaction);
    when(txReceipt.getLogInfoList()).thenReturn(Collections.emptyList());
    when(txReceipt.getBloomFilter()).thenReturn(bloom);
    when(txReceipt.getStatus()).thenReturn(null);
    TransactionInfo txInfo = new TransactionInfo(txReceipt, hash.getBytes(), 0);
    TransactionReceiptDTO transactionReceiptDTO = new TransactionReceiptDTO(block, txInfo);
    String actualStatus = transactionReceiptDTO.getStatus();
    assertNotNull(actualStatus);
    assertEquals("0x0", actualStatus);
}
Also used : Transaction(org.ethereum.core.Transaction) Bloom(org.ethereum.core.Bloom) RskAddress(co.rsk.core.RskAddress) TransactionReceipt(org.ethereum.core.TransactionReceipt) Block(org.ethereum.core.Block) TransactionInfo(org.ethereum.db.TransactionInfo) Keccak256(co.rsk.crypto.Keccak256) Test(org.junit.Test)

Aggregations

TransactionReceipt (org.ethereum.core.TransactionReceipt)39 Test (org.junit.Test)30 Block (org.ethereum.core.Block)17 Transaction (org.ethereum.core.Transaction)15 Keccak256 (co.rsk.crypto.Keccak256)13 World (co.rsk.test.World)13 TransactionInfo (org.ethereum.db.TransactionInfo)10 RskAddress (co.rsk.core.RskAddress)8 CallArguments (org.ethereum.rpc.CallArguments)8 ArrayList (java.util.ArrayList)7 EthModuleTestUtils (org.ethereum.util.EthModuleTestUtils)7 LogInfo (org.ethereum.vm.LogInfo)7 BigInteger (java.math.BigInteger)6 Bloom (org.ethereum.core.Bloom)6 ProgramResult (org.ethereum.vm.program.ProgramResult)6 TestSystemProperties (co.rsk.config.TestSystemProperties)5 DslParser (co.rsk.test.dsl.DslParser)4 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)4 Trie (co.rsk.trie.Trie)4 List (java.util.List)4