Search in sources :

Example 1 with SimpleRskTransaction

use of co.rsk.peg.simples.SimpleRskTransaction in project rskj by rsksmart.

the class BlockGenerator method getBlockChain.

public List<Block> getBlockChain(Block parent, int size, int ntxs, boolean withUncles, boolean withMining, Long difficulty) {
    List<Block> chain = new ArrayList<Block>();
    List<BlockHeader> uncles = new ArrayList<>();
    int chainSize = 0;
    while (chainSize < size) {
        List<Transaction> txs = new ArrayList<>();
        for (int ntx = 0; ntx < ntxs; ntx++) {
            txs.add(new SimpleRskTransaction(null));
        }
        if (difficulty == null) {
            difficulty = 0l;
        }
        Block newblock = createChildBlock(parent, txs, uncles, difficulty, null);
        if (withMining) {
            newblock = BlockMiner.mineBlock(newblock);
        }
        chain.add(newblock);
        if (withUncles) {
            uncles = new ArrayList<>();
            Block newuncle = createChildBlock(parent, ntxs);
            chain.add(newuncle);
            uncles.add(newuncle.getHeader());
            newuncle = createChildBlock(parent, ntxs);
            chain.add(newuncle);
            uncles.add(newuncle.getHeader());
        }
        parent = newblock;
        chainSize++;
    }
    return chain;
}
Also used : SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) ArrayList(java.util.ArrayList) SimpleBlock(co.rsk.peg.simples.SimpleBlock)

Example 2 with SimpleRskTransaction

use of co.rsk.peg.simples.SimpleRskTransaction in project rskj by rsksmart.

the class BlockGenerator method createSimpleChildBlock.

public Block createSimpleChildBlock(Block parent, int ntxs) {
    Bloom logBloom = new Bloom();
    List<Transaction> txs = new ArrayList<>();
    for (int ntx = 0; ntx < ntxs; ntx++) {
        txs.add(new SimpleRskTransaction(PegTestUtils.createHash3().getBytes()));
    }
    return new SimpleBlock(// parent hash
    parent.getHash().getBytes(), // uncle hash
    EMPTY_LIST_HASH, // coinbase
    parent.getCoinbase().getBytes(), // logs bloom
    logBloom.getData(), // difficulty
    parent.getDifficulty().getBytes(), parent.getNumber() + 1, parent.getGasLimit(), parent.getGasUsed(), parent.getTimestamp() + ++count, // extraData
    EMPTY_BYTE_ARRAY, // mixHash
    EMPTY_BYTE_ARRAY, // provisory nonce
    BigInteger.ZERO.toByteArray(), // receipts root
    EMPTY_TRIE_HASH, // transaction receipts
    EMPTY_TRIE_HASH, // state root
    EMPTY_TRIE_HASH, // transaction list
    txs, // uncle list
    null);
}
Also used : SimpleBlock(co.rsk.peg.simples.SimpleBlock) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) ArrayList(java.util.ArrayList)

Example 3 with SimpleRskTransaction

use of co.rsk.peg.simples.SimpleRskTransaction in project rskj by rsksmart.

the class BlockGenerator method createBlock.

public Block createBlock(int number, int ntxs) {
    Bloom logBloom = new Bloom();
    Block parent = getGenesisBlock();
    List<Transaction> txs = new ArrayList<>();
    for (int ntx = 0; ntx < ntxs; ntx++) {
        txs.add(new SimpleRskTransaction(null));
    }
    Coin previousMGP = parent.getMinimumGasPrice() != null ? parent.getMinimumGasPrice() : Coin.valueOf(10L);
    Coin minimumGasPrice = new MinimumGasPriceCalculator().calculate(previousMGP, Coin.valueOf(100L));
    return new Block(// parent hash
    parent.getHash().getBytes(), // uncle hash
    EMPTY_LIST_HASH, // coinbase
    parent.getCoinbase().getBytes(), // logs bloom
    logBloom.getData(), // difficulty
    parent.getDifficulty().getBytes(), number, parent.getGasLimit(), parent.getGasUsed(), parent.getTimestamp() + ++count, // extraData
    EMPTY_BYTE_ARRAY, // mixHash
    EMPTY_BYTE_ARRAY, // provisory nonce
    BigInteger.ZERO.toByteArray(), // receipts root
    EMPTY_TRIE_HASH, // transaction receipts
    EMPTY_TRIE_HASH, // state root
    EMPTY_TRIE_HASH, // transaction list
    txs, // uncle list
    null, minimumGasPrice.getBytes(), Coin.ZERO);
}
Also used : Coin(co.rsk.core.Coin) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) MinimumGasPriceCalculator(co.rsk.mine.MinimumGasPriceCalculator) ArrayList(java.util.ArrayList) SimpleBlock(co.rsk.peg.simples.SimpleBlock)

Example 4 with SimpleRskTransaction

use of co.rsk.peg.simples.SimpleRskTransaction in project rskj by rsksmart.

the class BlockGenerator method createChildBlock.

public Block createChildBlock(Block parent, int ntxs, long difficulty) {
    List<Transaction> txs = new ArrayList<>();
    for (int ntx = 0; ntx < ntxs; ntx++) {
        txs.add(new SimpleRskTransaction(null));
    }
    List<BlockHeader> uncles = new ArrayList<>();
    return createChildBlock(parent, txs, uncles, difficulty, null);
}
Also used : SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) SimpleRskTransaction(co.rsk.peg.simples.SimpleRskTransaction) ArrayList(java.util.ArrayList)

Aggregations

SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)4 ArrayList (java.util.ArrayList)4 SimpleBlock (co.rsk.peg.simples.SimpleBlock)3 Coin (co.rsk.core.Coin)1 MinimumGasPriceCalculator (co.rsk.mine.MinimumGasPriceCalculator)1