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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations