use of org.ethereum.rpc.dto.TransactionResultDTO in project rskj by rsksmart.
the class Web3ImplTest method getUnknownTransactionByBlockNumberAndIndex.
@Test
public void getUnknownTransactionByBlockNumberAndIndex() throws Exception {
World world = new World();
Web3Impl web3 = createWeb3(world);
Block genesis = world.getBlockChain().getBestBlock();
Block block1 = new BlockBuilder(world).parent(genesis).build();
org.junit.Assert.assertEquals(ImportResult.IMPORTED_BEST, world.getBlockChain().tryToConnect(block1));
TransactionResultDTO tr = web3.eth_getTransactionByBlockNumberAndIndex("0x1", "0x0");
Assert.assertNull(tr);
}
use of org.ethereum.rpc.dto.TransactionResultDTO in project rskj by rsksmart.
the class Web3ImplTest method getTransactionByHash.
@Test
public void getTransactionByHash() throws Exception {
World world = new World();
Web3Impl web3 = createWeb3(world);
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();
TransactionResultDTO tr = web3.eth_getTransactionByHash(hashString);
Assert.assertNotNull(tr);
org.junit.Assert.assertEquals("0x" + hashString, tr.hash);
String blockHashString = "0x" + block1.getHash();
org.junit.Assert.assertEquals(blockHashString, tr.blockHash);
org.junit.Assert.assertEquals("0x00", tr.input);
org.junit.Assert.assertEquals("0x" + Hex.toHexString(tx.getReceiveAddress().getBytes()), tr.to);
}
use of org.ethereum.rpc.dto.TransactionResultDTO in project rskj by rsksmart.
the class Web3Impl method eth_getTransactionByBlockNumberAndIndex.
@Override
public TransactionResultDTO eth_getTransactionByBlockNumberAndIndex(String bnOrId, String index) throws Exception {
TransactionResultDTO s = null;
try {
Block b = getByJsonBlockId(bnOrId);
List<Transaction> txs = getTransactionsByJsonBlockId(bnOrId);
if (txs == null) {
return null;
}
int idx = JSonHexToInt(index);
if (idx >= txs.size()) {
return null;
}
Transaction tx = txs.get(idx);
return s = new TransactionResultDTO(b, idx, tx);
} finally {
if (logger.isDebugEnabled()) {
logger.debug("eth_getTransactionByBlockNumberAndIndex(" + bnOrId + ", " + index + "): " + s);
}
}
}
use of org.ethereum.rpc.dto.TransactionResultDTO in project rskj by rsksmart.
the class Web3Impl method getBlockResult.
public BlockResult getBlockResult(Block b, boolean fullTx) {
if (b == null) {
return null;
}
byte[] mergeHeader = b.getBitcoinMergedMiningHeader();
boolean isPending = (mergeHeader == null || mergeHeader.length == 0) && !b.isGenesis();
BlockResult br = new BlockResult();
br.number = isPending ? null : TypeConverter.toJsonHex(b.getNumber());
br.hash = isPending ? null : b.getHashJsonString();
br.parentHash = b.getParentHashJsonString();
br.sha3Uncles = TypeConverter.toJsonHex(b.getUnclesHash());
br.logsBloom = isPending ? null : TypeConverter.toJsonHex(b.getLogBloom());
br.transactionsRoot = TypeConverter.toJsonHex(b.getTxTrieRoot());
br.stateRoot = TypeConverter.toJsonHex(b.getStateRoot());
br.receiptsRoot = TypeConverter.toJsonHex(b.getReceiptsRoot());
br.miner = isPending ? null : TypeConverter.toJsonHex(b.getCoinbase().getBytes());
br.difficulty = TypeConverter.toJsonHex(b.getDifficulty().getBytes());
br.totalDifficulty = TypeConverter.toJsonHex(this.blockchain.getBlockStore().getTotalDifficultyForHash(b.getHash().getBytes()).asBigInteger());
br.extraData = TypeConverter.toJsonHex(b.getExtraData());
br.size = TypeConverter.toJsonHex(b.getEncoded().length);
br.gasLimit = TypeConverter.toJsonHex(b.getGasLimit());
Coin mgp = b.getMinimumGasPrice();
br.minimumGasPrice = mgp != null ? mgp.asBigInteger().toString() : "";
br.gasUsed = TypeConverter.toJsonHex(b.getGasUsed());
br.timestamp = TypeConverter.toJsonHex(b.getTimestamp());
List<Object> txes = new ArrayList<>();
if (fullTx) {
for (int i = 0; i < b.getTransactionsList().size(); i++) {
txes.add(new TransactionResultDTO(b, i, b.getTransactionsList().get(i)));
}
} else {
for (Transaction tx : b.getTransactionsList()) {
txes.add(tx.getHash().toJsonString());
}
}
br.transactions = txes.toArray();
List<String> ul = new ArrayList<>();
for (BlockHeader header : b.getUncleList()) {
ul.add(toJsonHex(header.getHash().getBytes()));
}
br.uncles = ul.toArray(new String[ul.size()]);
return br;
}
use of org.ethereum.rpc.dto.TransactionResultDTO in project rskj by rsksmart.
the class Web3Impl method eth_getTransactionByBlockHashAndIndex.
@Override
public TransactionResultDTO eth_getTransactionByBlockHashAndIndex(String blockHash, String index) throws Exception {
TransactionResultDTO s = null;
try {
Block b = getBlockByJSonHash(blockHash);
if (b == null) {
return null;
}
int idx = JSonHexToInt(index);
if (idx >= b.getTransactionsList().size()) {
return null;
}
Transaction tx = b.getTransactionsList().get(idx);
return s = new TransactionResultDTO(b, idx, tx);
} finally {
if (logger.isDebugEnabled()) {
logger.debug("eth_getTransactionByBlockHashAndIndex(" + blockHash + ", " + index + "): " + s);
}
}
}
Aggregations