Search in sources :

Example 11 with CreateAgentTransaction

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);
}
Also used : Agent(io.nuls.consensus.poc.protocol.entity.Agent) Deposit(io.nuls.consensus.poc.protocol.entity.Deposit) DepositTransaction(io.nuls.consensus.poc.protocol.tx.DepositTransaction) ChainContainer(io.nuls.consensus.poc.container.ChainContainer) ArrayList(java.util.ArrayList) NulsRuntimeException(io.nuls.kernel.exception.NulsRuntimeException) ECKey(io.nuls.core.tools.crypto.ECKey) IOException(java.io.IOException) CreateAgentTransaction(io.nuls.consensus.poc.protocol.tx.CreateAgentTransaction)

Aggregations

CreateAgentTransaction (io.nuls.consensus.poc.protocol.tx.CreateAgentTransaction)11 Agent (io.nuls.consensus.poc.protocol.entity.Agent)9 CoinDataResult (io.nuls.account.ledger.model.CoinDataResult)4 MultiSigAccount (io.nuls.account.model.MultiSigAccount)4 StopAgent (io.nuls.consensus.poc.protocol.entity.StopAgent)4 NulsRuntimeException (io.nuls.kernel.exception.NulsRuntimeException)4 Account (io.nuls.account.model.Account)3 Deposit (io.nuls.consensus.poc.protocol.entity.Deposit)3 DepositTransaction (io.nuls.consensus.poc.protocol.tx.DepositTransaction)3 ECKey (io.nuls.core.tools.crypto.ECKey)3 ValidateResult (io.nuls.kernel.validate.ValidateResult)3 RedPunishTransaction (io.nuls.consensus.poc.protocol.tx.RedPunishTransaction)2 Transaction (io.nuls.kernel.model.Transaction)2 HashSet (java.util.HashSet)2 BaseTest (io.nuls.consensus.poc.BaseTest)1 ChainContainer (io.nuls.consensus.poc.container.ChainContainer)1 RedPunishData (io.nuls.consensus.poc.protocol.entity.RedPunishData)1 StopAgentTransaction (io.nuls.consensus.poc.protocol.tx.StopAgentTransaction)1 AgentPo (io.nuls.consensus.poc.storage.po.AgentPo)1 CreateAgentTxValidator (io.nuls.consensus.poc.tx.validator.CreateAgentTxValidator)1