Search in sources :

Example 1 with Agent

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

the class RegisterAgentTxService method onCommit.

@Override
public void onCommit(RegisterAgentTransaction tx) throws NulsException {
    manager.changeAgentStatusByHash(tx.getTxData().getHexHash(), ConsensusStatusEnum.WAITING);
    Consensus<Agent> ca = tx.getTxData();
    ca.getExtend().setStatus(ConsensusStatusEnum.WAITING.getCode());
    AgentPo po = ConsensusTool.agentToPojo(ca);
    delegateAccountService.save(po);
    RegisterAgentNotice notice = new RegisterAgentNotice();
    notice.setEventBody(tx);
    NulsContext.getServiceBean(EventBroadcaster.class).publishToLocal(notice);
}
Also used : EventBroadcaster(io.nuls.event.bus.service.intf.EventBroadcaster) Agent(io.nuls.consensus.entity.member.Agent) RegisterAgentNotice(io.nuls.consensus.event.notice.RegisterAgentNotice) AgentPo(io.nuls.db.entity.AgentPo)

Example 2 with Agent

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

the class ConsensusMeetingRunner method getDefaultSeedList.

private List<Consensus<Agent>> getDefaultSeedList() throws IOException {
    List<Consensus<Agent>> seedList = new ArrayList<>();
    if (consensusManager.getSeedNodeList() == null) {
        return seedList;
    }
    for (String address : consensusManager.getSeedNodeList()) {
        Consensus<Agent> member = new ConsensusAgentImpl();
        member.setAddress(address);
        Agent agent = new Agent();
        agent.setPackingAddress(address);
        agent.setStartTime(0);
        agent.setIntroduction("seed");
        agent.setCommissionRate(0);
        agent.setStatus(ConsensusStatusEnum.IN.getCode());
        agent.setSeed(true);
        agent.setDeposit(Na.ZERO);
        member.setExtend(agent);
        seedList.add(member);
    }
    return seedList;
}
Also used : Agent(io.nuls.consensus.entity.member.Agent) ConsensusAgentImpl(io.nuls.consensus.entity.ConsensusAgentImpl) Consensus(io.nuls.consensus.entity.Consensus)

Example 3 with Agent

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

the class ConsensusTool method fromPojo.

public static Consensus<Agent> fromPojo(AgentPo po) {
    if (null == po) {
        return null;
    }
    Agent agent = new Agent();
    agent.setStatus(ConsensusStatusEnum.WAITING.getCode());
    agent.setDeposit(Na.valueOf(po.getDeposit()));
    agent.setCommissionRate(po.getCommissionRate());
    agent.setPackingAddress(po.getPackingAddress());
    agent.setIntroduction(po.getRemark());
    agent.setStartTime(po.getStartTime());
    agent.setStatus(po.getStatus());
    agent.setAgentName(po.getAgentName());
    Consensus<Agent> ca = new ConsensusAgentImpl();
    ca.setAddress(po.getAgentAddress());
    ca.setHash(NulsDigestData.fromDigestHex(po.getId()));
    ca.setExtend(agent);
    return ca;
}
Also used : Agent(io.nuls.consensus.entity.member.Agent) ConsensusAgentImpl(io.nuls.consensus.entity.ConsensusAgentImpl)

Example 4 with Agent

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

the class AgentDepositValidator method validate.

@Override
public ValidateResult validate(RegisterAgentTransaction tx) {
    ValidateResult result = ValidateResult.getSuccessResult();
    Agent agent = tx.getTxData().getExtend();
    if (null == agent) {
        return ValidateResult.getFailedResult(ErrorCode.NULL_PARAMETER);
    }
    if (PocConsensusConstant.AGENT_DEPOSIT_LOWER_LIMIT.isGreaterThan(agent.getDeposit())) {
        return ValidateResult.getFailedResult(ErrorCode.DEPOSIT_NOT_ENOUGH);
    }
    if (!agent.getDeposit().equals(tx.getCoinData().getTotalNa())) {
        return ValidateResult.getFailedResult(SeverityLevelEnum.FLAGRANT_FOUL, ErrorCode.DEPOSIT_ERROR);
    }
    return result;
}
Also used : Agent(io.nuls.consensus.entity.member.Agent) ValidateResult(io.nuls.core.validate.ValidateResult)

Example 5 with Agent

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

the class ConsensusMeetingRunner method calcReward.

private List<ConsensusReward> calcReward(List<Transaction> txList, PocMeetingMember self) {
    List<ConsensusReward> rewardList = new ArrayList<>();
    Consensus<Agent> ca = self.getAgentConsensus();
    if (ca.getExtend().getSeed()) {
        long totalFee = 0;
        for (Transaction tx : txList) {
            totalFee += tx.getFee().getValue();
        }
        if (totalFee == 0L) {
            return rewardList;
        }
        double caReward = totalFee;
        ConsensusReward agentReword = new ConsensusReward();
        agentReword.setAddress(ca.getAddress());
        agentReword.setReward(Na.valueOf((long) caReward));
        rewardList.add(agentReword);
        return rewardList;
    }
    long totalFee = 0;
    for (Transaction tx : txList) {
        totalFee += tx.getFee().getValue();
    }
    double total = totalFee + DoubleUtils.mul(this.consensusManager.getCurrentRound().getMemberCount(), PocConsensusConstant.BLOCK_REWARD.getValue());
    ConsensusReward agentReword = new ConsensusReward();
    agentReword.setAddress(ca.getAddress());
    double caReward = DoubleUtils.mul(total, DoubleUtils.div(ca.getExtend().getDeposit().getValue(), this.consensusManager.getCurrentRound().getTotalDeposit().getValue()));
    caReward = caReward + DoubleUtils.mul(total, DoubleUtils.mul(DoubleUtils.div((this.consensusManager.getCurrentRound().getTotalDeposit().getValue() - ca.getExtend().getDeposit().getValue()), this.consensusManager.getCurrentRound().getTotalDeposit().getValue()), DoubleUtils.round(ca.getExtend().getCommissionRate() / 100, 2)));
    agentReword.setReward(Na.valueOf((long) caReward));
    Map<String, ConsensusReward> rewardMap = new HashMap<>();
    rewardMap.put(ca.getAddress(), agentReword);
    double delegateCommissionRate = DoubleUtils.div((100 - ca.getExtend().getCommissionRate()), 100, 2);
    for (Consensus<Deposit> cd : self.getDelegateList()) {
        double reward = DoubleUtils.mul(DoubleUtils.mul(total, delegateCommissionRate), DoubleUtils.div(cd.getExtend().getDeposit().getValue(), this.consensusManager.getCurrentRound().getTotalDeposit().getValue()));
        ConsensusReward delegateReword = rewardMap.get(cd.getAddress());
        if (null == delegateReword) {
            delegateReword = new ConsensusReward();
            delegateReword.setReward(Na.ZERO);
        }
        delegateReword.setAddress(cd.getAddress());
        delegateReword.setReward(delegateReword.getReward().add(Na.valueOf((long) reward)));
        rewardMap.put(cd.getAddress(), delegateReword);
    }
    rewardList.addAll(rewardMap.values());
    return rewardList;
}
Also used : Agent(io.nuls.consensus.entity.member.Agent) Deposit(io.nuls.consensus.entity.member.Deposit) ConsensusReward(io.nuls.consensus.entity.meeting.ConsensusReward) CoinBaseTransaction(io.nuls.ledger.entity.tx.CoinBaseTransaction) Transaction(io.nuls.core.chain.entity.Transaction) RedPunishTransaction(io.nuls.consensus.entity.tx.RedPunishTransaction) YellowPunishTransaction(io.nuls.consensus.entity.tx.YellowPunishTransaction)

Aggregations

Agent (io.nuls.consensus.entity.member.Agent)14 Consensus (io.nuls.consensus.entity.Consensus)7 Deposit (io.nuls.consensus.entity.member.Deposit)6 Account (io.nuls.account.entity.Account)3 ConsensusAgentImpl (io.nuls.consensus.entity.ConsensusAgentImpl)3 AgentPo (io.nuls.db.entity.AgentPo)3 ConsensusStatusInfo (io.nuls.consensus.entity.ConsensusStatusInfo)2 RegisterAgentTransaction (io.nuls.consensus.entity.tx.RegisterAgentTransaction)2 Transaction (io.nuls.core.chain.entity.Transaction)2 NulsRuntimeException (io.nuls.core.exception.NulsRuntimeException)2 ValidateResult (io.nuls.core.validate.ValidateResult)2 DepositPo (io.nuls.db.entity.DepositPo)2 EventBroadcaster (io.nuls.event.bus.service.intf.EventBroadcaster)2 Balance (io.nuls.ledger.entity.Balance)2 ConsensusReward (io.nuls.consensus.entity.meeting.ConsensusReward)1 PocMeetingMember (io.nuls.consensus.entity.meeting.PocMeetingMember)1 PocMeetingRound (io.nuls.consensus.entity.meeting.PocMeetingRound)1 JoinConsensusParam (io.nuls.consensus.entity.params.JoinConsensusParam)1 PocExitConsensusTransaction (io.nuls.consensus.entity.tx.PocExitConsensusTransaction)1 PocJoinConsensusTransaction (io.nuls.consensus.entity.tx.PocJoinConsensusTransaction)1