Search in sources :

Example 56 with Transaction

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

the class TransactionsMessage method parse.

private void parse() {
    RLPList paramsList = (RLPList) RLP.decode2(encoded).get(0);
    transactions = new ArrayList<>();
    for (int i = 0; i < paramsList.size(); ++i) {
        RLPList rlpTxData = (RLPList) paramsList.get(i);
        Transaction tx = new ImmutableTransaction(rlpTxData.getRLPData());
        transactions.add(tx);
    }
    parsed = true;
}
Also used : ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction) ImmutableTransaction(org.ethereum.core.ImmutableTransaction) RLPList(org.ethereum.util.RLPList)

Example 57 with Transaction

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

the class BlockEncodingTest method testBadBlockEncoding1.

@Test(expected = ArithmeticException.class)
public void testBadBlockEncoding1() {
    List<Transaction> txs = new ArrayList<>();
    Transaction tx = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ONE.toByteArray(), BigInteger.valueOf(21000).toByteArray(), new ECKey().getAddress(), BigInteger.valueOf(1000).toByteArray(), null);
    txs.add(tx);
    byte[] bigBadByteArray = new byte[10000];
    Arrays.fill(bigBadByteArray, (byte) -1);
    FreeBlock fblock = new FreeBlock(// parent hash
    PegTestUtils.createHash3().getBytes(), // uncle hash
    EMPTY_LIST_HASH, // coinbase
    TestUtils.randomAddress().getBytes(), // logs bloom
    new Bloom().getData(), // difficulty
    BigInteger.ONE.toByteArray(), bigBadByteArray, // gasLimit
    bigBadByteArray, // gasUsed
    bigBadByteArray, // timestamp
    bigBadByteArray, // extraData
    new byte[0], // mixHash
    new byte[0], // provisory nonce
    new byte[] { 0 }, // receipts root
    HashUtil.EMPTY_TRIE_HASH, // transaction root
    BlockChainImpl.calcTxTrie(txs), // EMPTY_TRIE_HASH,   // state root
    HashUtil.EMPTY_TRIE_HASH, // transaction list
    txs, // uncle list
    null, BigInteger.TEN.toByteArray(), new byte[0]);
    // Now decode, and re-encode
    Block parsedBlock = new Block(fblock.getEncoded());
    // must throw java.lang.ArithmeticException
    // forced parse
    parsedBlock.getGasLimit();
}
Also used : Transaction(org.ethereum.core.Transaction) Bloom(org.ethereum.core.Bloom) ArrayList(java.util.ArrayList) Block(org.ethereum.core.Block) ECKey(org.ethereum.crypto.ECKey) Test(org.junit.Test)

Example 58 with Transaction

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

the class CodeReplaceTest method createTx.

protected Transaction createTx(BlockChainImpl blockchain, ECKey sender, byte[] receiveAddress, byte[] data, long value) throws InterruptedException {
    BigInteger nonce = blockchain.getRepository().getNonce(new RskAddress(sender.getAddress()));
    Transaction tx = new Transaction(ByteUtil.bigIntegerToBytes(nonce), ByteUtil.longToBytesNoLeadZeroes(1), ByteUtil.longToBytesNoLeadZeroes(3_000_000), receiveAddress, ByteUtil.longToBytesNoLeadZeroes(value), data, config.getBlockchainConfig().getCommonConstants().getChainId());
    tx.sign(sender.getPrivKeyBytes());
    return tx;
}
Also used : Transaction(org.ethereum.core.Transaction) BigInteger(java.math.BigInteger)

Example 59 with Transaction

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

the class FreeBlock method parseTxs.

private static List<Transaction> parseTxs(RLPList txTransactions) {
    List<Transaction> parsedTxs = new ArrayList<>();
    for (int i = 0; i < txTransactions.size(); i++) {
        RLPElement transactionRaw = txTransactions.get(i);
        Transaction tx = new ImmutableTransaction(transactionRaw.getRLPData());
        parsedTxs.add(tx);
    }
    return Collections.unmodifiableList(parsedTxs);
}
Also used : ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction) RLPElement(org.ethereum.util.RLPElement) ImmutableTransaction(org.ethereum.core.ImmutableTransaction) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Example 60 with Transaction

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

the class FreeBlock method getTxTrie.

public static Trie getTxTrie(List<Transaction> transactions) {
    if (transactions == null) {
        return new TrieImpl();
    }
    Trie txsState = new TrieImpl();
    for (int i = 0; i < transactions.size(); i++) {
        Transaction transaction = transactions.get(i);
        txsState = txsState.put(RLP.encodeInt(i), transaction.getEncoded());
    }
    return txsState;
}
Also used : TrieImpl(co.rsk.trie.TrieImpl) ImmutableTransaction(org.ethereum.core.ImmutableTransaction) Transaction(org.ethereum.core.Transaction) Trie(co.rsk.trie.Trie)

Aggregations

Transaction (org.ethereum.core.Transaction)131 Test (org.junit.Test)82 BigInteger (java.math.BigInteger)33 Coin (co.rsk.core.Coin)23 Account (org.ethereum.core.Account)20 ArrayList (java.util.ArrayList)17 Block (org.ethereum.core.Block)17 RskAddress (co.rsk.core.RskAddress)15 JsonNode (com.fasterxml.jackson.databind.JsonNode)15 Repository (org.ethereum.core.Repository)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 AccountState (org.ethereum.core.AccountState)10 RemascTransaction (co.rsk.remasc.RemascTransaction)9 TransactionBuilder (co.rsk.test.builders.TransactionBuilder)9 ImmutableTransaction (org.ethereum.core.ImmutableTransaction)8 ECKey (org.ethereum.crypto.ECKey)8 Keccak256 (co.rsk.crypto.Keccak256)7 AccountBuilder (co.rsk.test.builders.AccountBuilder)7 DslParser (co.rsk.test.dsl.DslParser)6 WorldDslProcessor (co.rsk.test.dsl.WorldDslProcessor)6