Search in sources :

Example 1 with TransactionResultDTO

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);
}
Also used : TransactionResultDTO(org.ethereum.rpc.dto.TransactionResultDTO) World(co.rsk.test.World) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 2 with TransactionResultDTO

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);
}
Also used : TransactionBuilder(co.rsk.test.builders.TransactionBuilder) TransactionResultDTO(org.ethereum.rpc.dto.TransactionResultDTO) AccountBuilder(co.rsk.test.builders.AccountBuilder) World(co.rsk.test.World) BlockBuilder(co.rsk.test.builders.BlockBuilder) Test(org.junit.Test)

Example 3 with TransactionResultDTO

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);
        }
    }
}
Also used : TransactionResultDTO(org.ethereum.rpc.dto.TransactionResultDTO)

Example 4 with TransactionResultDTO

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;
}
Also used : Coin(co.rsk.core.Coin) TransactionResultDTO(org.ethereum.rpc.dto.TransactionResultDTO)

Example 5 with TransactionResultDTO

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);
        }
    }
}
Also used : TransactionResultDTO(org.ethereum.rpc.dto.TransactionResultDTO)

Aggregations

TransactionResultDTO (org.ethereum.rpc.dto.TransactionResultDTO)11 World (co.rsk.test.World)7 Test (org.junit.Test)7 BlockBuilder (co.rsk.test.builders.BlockBuilder)6 AccountBuilder (co.rsk.test.builders.AccountBuilder)5 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)5 Coin (co.rsk.core.Coin)1 BlockChainImpl (co.rsk.core.bc.BlockChainImpl)1 TransactionPoolImpl (co.rsk.core.bc.TransactionPoolImpl)1 Keccak256 (co.rsk.crypto.Keccak256)1 TransactionInfo (org.ethereum.db.TransactionInfo)1