Search in sources :

Example 1 with EntrustConsensusNotice

use of io.nuls.consensus.event.notice.EntrustConsensusNotice in project nuls by nuls-io.

the class JoinConsensusTxService method onCommit.

@Override
public void onCommit(PocJoinConsensusTransaction tx) throws NulsException {
    manager.changeDepositStatus(tx.getTxData().getHexHash(), ConsensusStatusEnum.WAITING);
    Consensus<Deposit> cd = tx.getTxData();
    cd.getExtend().setTxHash(tx.getHash().getDigestHex());
    cd.getExtend().setStatus(ConsensusStatusEnum.WAITING.getCode());
    DepositPo po = ConsensusTool.depositToPojo(cd, tx.getHash().getDigestHex());
    po.setBlockHeight(tx.getBlockHeight());
    po.setTime(tx.getTime());
    depositDataService.save(po);
    Map<String, Object> paramsMap = new HashMap<>();
    paramsMap.put("agentHash", cd.getExtend().getAgentHash());
    List<DepositPo> poList = depositDataService.getList(paramsMap);
    long sum = 0L;
    for (DepositPo depositPo : poList) {
        sum += depositPo.getDeposit();
    }
    if (sum >= PocConsensusConstant.SUM_OF_DEPOSIT_OF_AGENT_LOWER_LIMIT.getValue()) {
        manager.changeAgentStatusByHash(tx.getTxData().getExtend().getAgentHash(), ConsensusStatusEnum.IN);
        manager.changeDepositStatusByAgentHash(tx.getTxData().getExtend().getAgentHash(), ConsensusStatusEnum.IN);
        AgentPo daPo = this.accountDataService.get(cd.getExtend().getAgentHash());
        if (null == daPo) {
            throw new NulsRuntimeException(ErrorCode.DATA_ERROR, "the agent cannot find,agent hash:" + cd.getExtend().getAgentHash());
        }
        daPo.setStatus(ConsensusStatusEnum.IN.getCode());
        this.accountDataService.updateSelective(daPo);
    }
    EntrustConsensusNotice notice = new EntrustConsensusNotice();
    notice.setEventBody(tx);
    NulsContext.getServiceBean(EventBroadcaster.class).publishToLocal(notice);
}
Also used : EventBroadcaster(io.nuls.event.bus.service.intf.EventBroadcaster) Deposit(io.nuls.consensus.entity.member.Deposit) HashMap(java.util.HashMap) EntrustConsensusNotice(io.nuls.consensus.event.notice.EntrustConsensusNotice) NulsRuntimeException(io.nuls.core.exception.NulsRuntimeException) DepositPo(io.nuls.db.entity.DepositPo) AgentPo(io.nuls.db.entity.AgentPo)

Aggregations

Deposit (io.nuls.consensus.entity.member.Deposit)1 EntrustConsensusNotice (io.nuls.consensus.event.notice.EntrustConsensusNotice)1 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)1 AgentPo (io.nuls.db.entity.AgentPo)1 DepositPo (io.nuls.db.entity.DepositPo)1 EventBroadcaster (io.nuls.event.bus.service.intf.EventBroadcaster)1 HashMap (java.util.HashMap)1