use of io.nuls.consensus.poc.protocol.tx.CreateAgentTransaction in project nuls by nuls-io.
the class BaseChainTest method initChain.
protected void initChain() {
chain = new Chain();
// new a block header
BlockHeader blockHeader = new BlockHeader();
blockHeader.setHeight(0);
blockHeader.setPreHash(NulsDigestData.calcDigestData("00000000000".getBytes()));
blockHeader.setTime(1L);
blockHeader.setTxCount(0);
// 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);
// chain.setEndBlockHeader(blockHeader);
// // add the block into chain
// chain.getBlockList().add(block);
// chain.setStartBlockHeader(blockHeader);
// chain.setEndBlockHeader(blockHeader);
chain.addBlock(block);
// init some agent
List<Agent> agentList = new ArrayList<>();
Transaction<Agent> agentTx = new CreateAgentTransaction();
Agent agent = new Agent();
agent.setPackingAddress(AddressTool.getAddress(ecKey.getPubKey()));
agent.setAgentAddress(AddressTool.getAddress(new ECKey().getPubKey()));
agent.setRewardAddress(AddressTool.getAddress(ecKey.getPubKey()));
agent.setTime(System.currentTimeMillis());
agent.setDeposit(Na.NA.multiply(20000));
agent.setCommissionRate(0.3d);
agent.setBlockHeight(blockHeader.getHeight());
agentTx.setTxData(agent);
agentTx.setTime(agent.getTime());
agentTx.setBlockHeight(blockHeader.getHeight());
NulsSignData signData = signDigest(agentTx.getHash().getDigestBytes(), ecKey);
agentTx.setTransactionSignature(signData.getSignBytes());
agentTx.getTxData().setTxHash(agentTx.getHash());
// add the agent tx into agent list
agentList.add(agentTx.getTxData());
// set the agent list into chain
chain.setAgentList(agentList);
// new a deposit
Deposit deposit = new Deposit();
deposit.setAddress(AddressTool.getAddress(ecKey.getPubKey()));
deposit.setAgentHash(agentTx.getHash());
deposit.setTime(System.currentTimeMillis());
deposit.setDeposit(Na.NA.multiply(200000));
deposit.setBlockHeight(blockHeader.getHeight());
DepositTransaction depositTx = new DepositTransaction();
depositTx.setTime(deposit.getTime());
depositTx.setTxData(deposit);
depositTx.setBlockHeight(blockHeader.getHeight());
List<Deposit> depositList = new ArrayList<>();
depositList.add(depositTx.getTxData());
chain.setDepositList(depositList);
chain.setYellowPunishList(new ArrayList<>());
chain.setRedPunishList(new ArrayList<>());
chainContainer = new ChainContainer(chain);
}
Aggregations