use of org.ethereum.rpc.dto.TransactionReceiptDTO in project rskj by rsksmart.
the class Web3ImplLogsTest method getLogsFromBlockchainWithEventInContractCreation.
@Test
public void getLogsFromBlockchainWithEventInContractCreation() throws Exception {
Web3Impl web3 = getWeb3WithEventInContractCreation();
Web3.FilterRequest fr = new Web3.FilterRequest();
fr.fromBlock = "earliest";
Object[] logs = web3.eth_getLogs(fr);
Assert.assertNotNull(logs);
Assert.assertEquals(1, logs.length);
String txhash = ((LogFilterElement) logs[0]).transactionHash;
TransactionReceiptDTO txdto = web3.eth_getTransactionReceipt(txhash);
Assert.assertEquals(txdto.contractAddress, ((LogFilterElement) logs[0]).address);
}
use of org.ethereum.rpc.dto.TransactionReceiptDTO in project rskj by rsksmart.
the class Web3ImplLogsTest method getLogsFromBlockchainWithInvokeContract.
@Test
public void getLogsFromBlockchainWithInvokeContract() throws Exception {
Web3Impl web3 = getWeb3WithContractInvoke();
Web3.FilterRequest fr = new Web3.FilterRequest();
fr.fromBlock = "earliest";
Object[] logs = web3.eth_getLogs(fr);
Assert.assertNotNull(logs);
Assert.assertEquals(2, logs.length);
String txhash = ((LogFilterElement) logs[0]).transactionHash;
TransactionReceiptDTO txdto = web3.eth_getTransactionReceipt(txhash);
Assert.assertEquals(txdto.contractAddress, ((LogFilterElement) logs[0]).address);
Assert.assertEquals(txdto.contractAddress, ((LogFilterElement) logs[1]).address);
}
use of org.ethereum.rpc.dto.TransactionReceiptDTO in project rskj by rsksmart.
the class Web3ImplTest method getTransactionReceipt.
@Test
public void getTransactionReceipt() throws Exception {
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
Web3Impl web3 = createWeb3(world, receiptStore);
Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(2000000)).build();
Account acc2 = new AccountBuilder().name("acc2").build();
Transaction tx = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(1000000)).build();
List<Transaction> txs = new ArrayList<>();
txs.add(tx);
Block genesis = world.getBlockChain().getBestBlock();
Block block1 = new BlockBuilder(world).parent(genesis).transactions(txs).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
String hashString = tx.getHash().toHexString();
TransactionReceiptDTO tr = web3.eth_getTransactionReceipt(hashString);
org.junit.Assert.assertNotNull(tr);
org.junit.Assert.assertEquals("0x" + hashString, tr.transactionHash);
String trxFrom = TypeConverter.toJsonHex(tx.getSender().getBytes());
org.junit.Assert.assertEquals(trxFrom, tr.from);
String trxTo = TypeConverter.toJsonHex(tx.getReceiveAddress().getBytes());
org.junit.Assert.assertEquals(trxTo, tr.to);
String blockHashString = "0x" + block1.getHash();
org.junit.Assert.assertEquals(blockHashString, tr.blockHash);
String blockNumberAsHex = "0x" + Long.toHexString(block1.getNumber());
org.junit.Assert.assertEquals(blockNumberAsHex, tr.blockNumber);
}
use of org.ethereum.rpc.dto.TransactionReceiptDTO 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.rpc.dto.TransactionReceiptDTO in project rskj by rsksmart.
the class Web3ImplTest method getTransactionReceiptNotInMainBlockchain.
@Test
public void getTransactionReceiptNotInMainBlockchain() throws Exception {
ReceiptStore receiptStore = new ReceiptStoreImpl(new HashMapDB());
World world = new World(receiptStore);
Web3Impl web3 = createWeb3(world, receiptStore);
Account acc1 = new AccountBuilder(world).name("acc1").balance(Coin.valueOf(2000000)).build();
Account acc2 = new AccountBuilder().name("acc2").build();
Transaction tx = new TransactionBuilder().sender(acc1).receiver(acc2).value(BigInteger.valueOf(1000000)).build();
List<Transaction> txs = new ArrayList<>();
txs.add(tx);
Block genesis = world.getBlockChain().getBestBlock();
Block block1 = new BlockBuilder(world).parent(genesis).difficulty(3l).transactions(txs).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
Block block1b = new BlockBuilder(world).parent(genesis).difficulty(block1.getDifficulty().asBigInteger().longValue() - 1).build();
Block block2b = new BlockBuilder(world).difficulty(2).parent(block1b).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_NOT_BEST, world.getBlockChain().tryToConnect(block1b));
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block2b));
String hashString = tx.getHash().toHexString();
TransactionReceiptDTO tr = web3.eth_getTransactionReceipt(hashString);
Assert.assertNull(tr);
}
Aggregations