use of io.nuls.consensus.entity.Consensus in project nuls by nuls-io.
the class PocConsensusServiceImpl method getConsensusInfoByAddress.
private Map<String, Object> getConsensusInfoByAddress(String address) {
if (!Address.validAddress(address)) {
return null;
}
Consensus<Agent> agent = this.consensusCacheManager.getCachedAgentByAddress(address);
List<Consensus<Deposit>> depositList = this.consensusCacheManager.getCachedDepositListByAddress(address);
long totalDeposit = 0;
Set<String> joinedAgent = new HashSet<>();
for (Consensus<Deposit> cd : depositList) {
totalDeposit += cd.getExtend().getDeposit().getValue();
joinedAgent.add(cd.getExtend().getAgentHash());
}
Map<String, Object> map = new HashMap<>();
if (null != agent) {
map.put("agentCount", 1);
// totalDeposit += agent.getExtend().getDeposit().getValue();
} else {
map.put("agentCount", 0);
}
map.put("totalDeposit", totalDeposit);
long lastDayTime = TimeService.currentTimeMillis() - DateUtil.DATE_TIME;
long reward = ledgerService.getAccountReward(address, 0);
long rewardOfDay = ledgerService.getAccountReward(address, lastDayTime);
Balance balance = ledgerService.getBalance(address);
map.put("reward", reward);
map.put("joinAccountCount", joinedAgent.size());
if (null == balance || balance.getUsable() == null) {
map.put("usableBalance", 0);
} else {
map.put("usableBalance", balance.getUsable().getValue());
}
map.put("rewardOfDay", rewardOfDay);
return map;
}
use of io.nuls.consensus.entity.Consensus in project nuls by nuls-io.
the class AgentCountValidator method validate.
@Override
public ValidateResult validate(RegisterAgentTransaction tx) {
ValidateResult result = ValidateResult.getSuccessResult();
Agent agent = tx.getTxData().getExtend();
String agentName = agent.getAgentName();
List<Consensus<Agent>> caList = consensusCacheManager.getCachedAgentList();
if (caList != null) {
for (Consensus<Agent> ca : caList) {
if (ca.getHexHash().equals(tx.getTxData().getHexHash())) {
continue;
}
if (ca.getAddress().equals(tx.getTxData().getAddress())) {
return ValidateResult.getFailedResult("An address can only create one agent");
}
if (ca.getAddress().equals(agent.getPackingAddress())) {
return ValidateResult.getFailedResult("The address can only create one agent");
}
if (agent.getPackingAddress().equals(ca.getAddress())) {
return ValidateResult.getFailedResult("The packingAddress is an agentAddress");
}
if (agent.getPackingAddress().equals(ca.getExtend().getPackingAddress())) {
return ValidateResult.getFailedResult("The packingAddress is busy!");
}
if (agentName.equals(ca.getExtend().getAgentName())) {
return ValidateResult.getFailedResult("AgentName repetition!");
}
}
}
return result;
}
use of io.nuls.consensus.entity.Consensus 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);
}
Aggregations