Search in sources :

Example 1 with StopConsensusNotice

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

the class ExitConsensusTxService method onRollback.

@Override
public void onRollback(PocExitConsensusTransaction tx) throws NulsException {
    Transaction joinTx = ledgerService.getTx(tx.getTxData());
    if (joinTx.getType() == TransactionConstant.TX_TYPE_REGISTER_AGENT) {
        RegisterAgentTransaction raTx = (RegisterAgentTransaction) joinTx;
        Consensus<Agent> ca = raTx.getTxData();
        ca.getExtend().setStatus(ConsensusStatusEnum.IN.getCode());
        manager.cacheAgent(ca);
        AgentPo agentPo = new AgentPo();
        agentPo.setId(raTx.getTxData().getHexHash());
        agentPo.setStatus(ConsensusStatusEnum.IN.getCode());
        this.agentDataService.updateSelective(agentPo);
        DepositPo dpo = new DepositPo();
        dpo.setId(raTx.getTxData().getHexHash());
        dpo.setStatus(ConsensusStatusEnum.IN.getCode());
        this.depositDataService.updateSelectiveByAgentHash(dpo);
        CancelConsensusNotice notice = new CancelConsensusNotice();
        notice.setEventBody(tx);
        NulsContext.getServiceBean(EventBroadcaster.class).publishToLocal(notice);
        // cache delegates
        Map<String, Object> params = new HashMap<>();
        params.put("agentHash", raTx.getTxData().getHexHash());
        List<DepositPo> polist = this.depositDataService.getList(params);
        if (null == polist || polist.isEmpty()) {
            return;
        }
        for (DepositPo po : polist) {
            Consensus<Deposit> cd = ConsensusTool.fromPojo(po);
            this.manager.cacheDeposit(cd);
        }
        this.ledgerService.unlockTxRollback(tx.getTxData().getDigestHex());
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("agentHash", ca.getHexHash());
        List<DepositPo> poList = depositDataService.getList(paramsMap);
        for (DepositPo po : poList) {
            this.ledgerService.unlockTxRollback(po.getTxHash());
        }
        return;
    }
    PocJoinConsensusTransaction pjcTx = (PocJoinConsensusTransaction) joinTx;
    Consensus<Deposit> cd = pjcTx.getTxData();
    cd.getExtend().setStatus(ConsensusStatusEnum.IN.getCode());
    manager.cacheDeposit(cd);
    DepositPo dPo = this.depositDataService.get(cd.getHexHash());
    if (dPo == null) {
        dPo = ConsensusTool.depositToPojo(cd, tx.getHash().getDigestHex());
        this.depositDataService.save(dPo);
    }
    StopConsensusNotice notice = new StopConsensusNotice();
    notice.setEventBody(tx);
    NulsContext.getServiceBean(EventBroadcaster.class).publishToLocal(notice);
    this.ledgerService.unlockTxRollback(tx.getTxData().getDigestHex());
}
Also used : EventBroadcaster(io.nuls.event.bus.service.intf.EventBroadcaster) Agent(io.nuls.consensus.entity.member.Agent) Deposit(io.nuls.consensus.entity.member.Deposit) RegisterAgentTransaction(io.nuls.consensus.entity.tx.RegisterAgentTransaction) HashMap(java.util.HashMap) StopConsensusNotice(io.nuls.consensus.event.notice.StopConsensusNotice) CancelConsensusNotice(io.nuls.consensus.event.notice.CancelConsensusNotice) DepositPo(io.nuls.db.entity.DepositPo) PocExitConsensusTransaction(io.nuls.consensus.entity.tx.PocExitConsensusTransaction) Transaction(io.nuls.core.chain.entity.Transaction) RegisterAgentTransaction(io.nuls.consensus.entity.tx.RegisterAgentTransaction) PocJoinConsensusTransaction(io.nuls.consensus.entity.tx.PocJoinConsensusTransaction) PocJoinConsensusTransaction(io.nuls.consensus.entity.tx.PocJoinConsensusTransaction) AgentPo(io.nuls.db.entity.AgentPo)

Aggregations

Agent (io.nuls.consensus.entity.member.Agent)1 Deposit (io.nuls.consensus.entity.member.Deposit)1 PocExitConsensusTransaction (io.nuls.consensus.entity.tx.PocExitConsensusTransaction)1 PocJoinConsensusTransaction (io.nuls.consensus.entity.tx.PocJoinConsensusTransaction)1 RegisterAgentTransaction (io.nuls.consensus.entity.tx.RegisterAgentTransaction)1 CancelConsensusNotice (io.nuls.consensus.event.notice.CancelConsensusNotice)1 StopConsensusNotice (io.nuls.consensus.event.notice.StopConsensusNotice)1 Transaction (io.nuls.core.chain.entity.Transaction)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