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