Search in sources :

Example 1 with BlockRoundData

use of io.nuls.consensus.poc.model.BlockRoundData in project nuls by nuls-io.

the class BaseTest method createBlock.

protected Block createBlock() {
    // new a block header
    BlockHeader blockHeader = new BlockHeader();
    blockHeader.setHeight(0);
    blockHeader.setPreHash(NulsDigestData.calcDigestData("00000000000".getBytes()));
    blockHeader.setTime(1L);
    blockHeader.setTxCount(1);
    blockHeader.setMerkleHash(NulsDigestData.calcDigestData(new byte[20]));
    // add a round data
    BlockRoundData roundData = new BlockRoundData();
    roundData.setConsensusMemberCount(1);
    roundData.setPackingIndexOfRound(1);
    roundData.setRoundIndex(1);
    roundData.setRoundStartTime(1L);
    try {
        blockHeader.setExtend(roundData.serialize());
    } catch (IOException e) {
        throw new NulsRuntimeException(e);
    }
    // new a block of height 0
    Block block = new Block();
    block.setHeader(blockHeader);
    List<Transaction> txs = new ArrayList<>();
    block.setTxs(txs);
    Transaction tx = new TestTransaction();
    txs.add(tx);
    List<NulsDigestData> txHashList = block.getTxHashList();
    blockHeader.setMerkleHash(NulsDigestData.calcMerkleDigestData(txHashList));
    NulsSignData signData = signDigest(blockHeader.getHash().getDigestBytes(), ecKey);
    BlockSignature sig = new BlockSignature();
    sig.setSignData(signData);
    sig.setPublicKey(ecKey.getPubKey());
    blockHeader.setBlockSignature(sig);
    return block;
}
Also used : BlockSignature(io.nuls.kernel.script.BlockSignature) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) IOException(java.io.IOException) BlockRoundData(io.nuls.consensus.poc.model.BlockRoundData)

Aggregations

BlockRoundData (io.nuls.consensus.poc.model.BlockRoundData)1 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)1 BlockSignature (io.nuls.kernel.script.BlockSignature)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1