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