Search in sources :

Example 11 with Deposit

use of io.nuls.consensus.entity.member.Deposit 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)

Example 12 with Deposit

use of io.nuls.consensus.entity.member.Deposit in project nuls by nuls-io.

the class PocMeetingMember method calcDeposit.

public void calcDeposit() {
    Na totolEntrustDeposit = Na.ZERO;
    if (delegateList == null) {
        return;
    }
    for (Consensus<Deposit> dc : delegateList) {
        totolEntrustDeposit = totolEntrustDeposit.add(dc.getExtend().getDeposit());
    }
    this.totolEntrustDeposit = totolEntrustDeposit;
}
Also used : Deposit(io.nuls.consensus.entity.member.Deposit) Na(io.nuls.core.chain.entity.Na)

Example 13 with Deposit

use of io.nuls.consensus.entity.member.Deposit in project nuls by nuls-io.

the class ConsensusCacheManager method init.

public void init() {
    Account self = accountService.getDefaultAccount();
    List<DepositPo> depositPoList = this.depositDao.getList();
    List<AgentPo> agentPoList = this.agentDao.getList();
    Consensus mine = null;
    for (AgentPo po : agentPoList) {
        Consensus<Agent> ca = ConsensusTool.fromPojo(po);
        this.cacheAgent(ca);
        if (null != self && ca.getAddress().equals(self.getAddress().toString())) {
            mine = ca;
        }
    }
    for (DepositPo dpo : depositPoList) {
        Consensus<Deposit> cd = ConsensusTool.fromPojo(dpo);
        this.cacheDeposit(cd);
        if (null != self && null == mine && cd.getAddress().equals(self.getAddress().toString())) {
            mine = cd;
        }
    }
    if (null == self) {
        return;
    }
    ConsensusStatusInfo info = new ConsensusStatusInfo();
    info.setAccount(self);
    if (null == mine) {
        info.setStatus(ConsensusStatusEnum.NOT_IN.getCode());
    } else if (mine.getExtend() instanceof Agent) {
        info.setSeed(((Agent) mine.getExtend()).getSeed());
        info.setStatus(((Agent) mine.getExtend()).getStatus());
    }
    this.updateConsensusStatusInfo(info);
}
Also used : Account(io.nuls.account.entity.Account) Agent(io.nuls.consensus.entity.member.Agent) Deposit(io.nuls.consensus.entity.member.Deposit) DepositPo(io.nuls.db.entity.DepositPo) Consensus(io.nuls.consensus.entity.Consensus) AgentPo(io.nuls.db.entity.AgentPo) ConsensusStatusInfo(io.nuls.consensus.entity.ConsensusStatusInfo)

Aggregations

Deposit (io.nuls.consensus.entity.member.Deposit)13 Agent (io.nuls.consensus.entity.member.Agent)6 Consensus (io.nuls.consensus.entity.Consensus)5 PocJoinConsensusTransaction (io.nuls.consensus.entity.tx.PocJoinConsensusTransaction)4 Transaction (io.nuls.core.chain.entity.Transaction)4 DepositPo (io.nuls.db.entity.DepositPo)4 PocExitConsensusTransaction (io.nuls.consensus.entity.tx.PocExitConsensusTransaction)3 RegisterAgentTransaction (io.nuls.consensus.entity.tx.RegisterAgentTransaction)3 Na (io.nuls.core.chain.entity.Na)3 AgentPo (io.nuls.db.entity.AgentPo)3 HashMap (java.util.HashMap)3 Account (io.nuls.account.entity.Account)2 ConsensusDepositImpl (io.nuls.consensus.entity.ConsensusDepositImpl)2 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)2 EventBroadcaster (io.nuls.event.bus.service.intf.EventBroadcaster)2 Balance (io.nuls.ledger.entity.Balance)2 ConsensusStatusInfo (io.nuls.consensus.entity.ConsensusStatusInfo)1 ConsensusReward (io.nuls.consensus.entity.meeting.ConsensusReward)1 PocMeetingMember (io.nuls.consensus.entity.meeting.PocMeetingMember)1 PocMeetingRound (io.nuls.consensus.entity.meeting.PocMeetingRound)1