use of io.nuls.consensus.poc.model.MeetingRound in project nuls by nuls-io.
the class RoundManagerTest method testAddRound.
@Test
public void testAddRound() {
assertNotNull(roundManager);
assertNotNull(roundManager.getChain());
assertEquals(0, roundManager.getRoundList().size());
MeetingRound round = new MeetingRound();
roundManager.addRound(round);
assertEquals(1, roundManager.getRoundList().size());
assertEquals(round, roundManager.getCurrentRound());
MeetingRound round2 = new MeetingRound();
roundManager.addRound(round2);
assertEquals(2, roundManager.getRoundList().size());
assertNotEquals(round, roundManager.getCurrentRound());
assertEquals(round2, roundManager.getCurrentRound());
}
use of io.nuls.consensus.poc.model.MeetingRound in project nuls by nuls-io.
the class RoundManagerTest method testGetRoundByIndex.
@Test
public void testGetRoundByIndex() {
assertNotNull(roundManager);
assertNotNull(roundManager.getChain());
long index = 1002L;
assertEquals(0, roundManager.getRoundList().size());
MeetingRound round = new MeetingRound();
round.setIndex(index);
roundManager.addRound(round);
assertEquals(1, roundManager.getRoundList().size());
MeetingRound round2 = roundManager.getRoundByIndex(index);
assertNotNull(round2);
assertEquals(round, round2);
}
use of io.nuls.consensus.poc.model.MeetingRound in project nuls by nuls-io.
the class RoundManagerTest method testInitRound.
@Test
public void testInitRound() {
assertNotNull(roundManager);
assertNotNull(roundManager.getChain());
Chain chain = roundManager.getChain();
assertNotNull(chain.getEndBlockHeader());
assert (chain.getAllBlockList().size() > 0);
MeetingRound round = roundManager.initRound();
assertNotNull(round);
assertEquals(round.getIndex(), 2L);
Assert.assertEquals(round.getStartTime(), ProtocolConstant.BLOCK_TIME_INTERVAL_MILLIS + 1L);
MeetingRound round2 = roundManager.getNextRound(null, false);
assertNotNull(round2);
assertEquals(round.getIndex(), round2.getIndex());
assertEquals(round.getStartTime(), round2.getStartTime());
round2 = roundManager.getNextRound(null, true);
assertNotNull(round2);
assert (round.getIndex() < round2.getIndex());
assert (round.getStartTime() < round2.getStartTime());
assertEquals("", 0d, round2.getTotalWeight(), 2200000d);
}
use of io.nuls.consensus.poc.model.MeetingRound in project nuls by nuls-io.
the class PocConsensusResource method getAgent.
@GET
@Path("/agent/{agentHash}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "查询共识节点详细信息 [3.6.7]", notes = "result.data: Map<String, Object>")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = Map.class) })
public RpcClientResult getAgent(@ApiParam(name = "agentHash", value = "节点标识", required = true) @PathParam("agentHash") String agentHash) throws NulsException {
if (!NulsDigestData.validHash(agentHash)) {
return Result.getFailed(PocConsensusErrorCode.AGENT_NOT_EXIST).toRpcClientResult();
}
Result result = Result.getSuccess();
List<Agent> agentList = PocConsensusContext.getChainManager().getMasterChain().getChain().getAgentList();
NulsDigestData agentHashData = NulsDigestData.fromDigestHex(agentHash);
for (Agent agent : agentList) {
if (agent.getTxHash().equals(agentHashData)) {
MeetingRound round = PocConsensusContext.getChainManager().getMasterChain().getCurrentRound();
this.fillAgent(agent, round, null);
String alias = accountService.getAlias(agent.getAgentAddress()).getData();
AgentDTO dto = new AgentDTO(agent, alias);
result.setData(dto);
return result.toRpcClientResult();
}
}
return Result.getFailed(PocConsensusErrorCode.AGENT_NOT_EXIST).toRpcClientResult();
}
use of io.nuls.consensus.poc.model.MeetingRound in project nuls by nuls-io.
the class PocConsensusResource method getWholeInfo.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Get the whole network consensus infomation! 查询全网共识总体信息 [3.6.1]")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = WholeNetConsensusInfoDTO.class) })
public RpcClientResult getWholeInfo() {
Result result = Result.getSuccess();
WholeNetConsensusInfoDTO dto = new WholeNetConsensusInfoDTO();
if (null == PocConsensusContext.getChainManager() || null == PocConsensusContext.getChainManager().getMasterChain()) {
return Result.getFailed(KernelErrorCode.DATA_NOT_FOUND).toRpcClientResult();
}
List<Agent> allAgentList = PocConsensusContext.getChainManager().getMasterChain().getChain().getAgentList();
long startBlockHeight = NulsContext.getInstance().getBestHeight();
List<Agent> agentList = new ArrayList<>();
long totalDeposit = 0;
for (int i = allAgentList.size() - 1; i >= 0; i--) {
Agent agent = allAgentList.get(i);
if (agent.getDelHeight() != -1L && agent.getDelHeight() <= startBlockHeight) {
continue;
} else if (agent.getBlockHeight() > startBlockHeight || agent.getBlockHeight() < 0L) {
continue;
}
totalDeposit += agent.getDeposit().getValue();
agentList.add(agent);
}
List<Deposit> deposits = PocConsensusContext.getChainManager().getMasterChain().getChain().getDepositList();
for (Deposit deposit : deposits) {
if (deposit.getDelHeight() > 0 && deposit.getDelHeight() <= startBlockHeight) {
continue;
} else if (deposit.getBlockHeight() > startBlockHeight || deposit.getBlockHeight() < 0L) {
continue;
}
totalDeposit += deposit.getDeposit().getValue();
}
MeetingRound round = PocConsensusContext.getChainManager().getMasterChain().getCurrentRound();
int packingAgentCount = 0;
if (null != round) {
for (MeetingMember member : round.getMemberList()) {
if (member.getAgent() != null) {
packingAgentCount++;
}
}
}
dto.setAgentCount(agentList.size());
dto.setTotalDeposit(totalDeposit);
dto.setConsensusAccountNumber(agentList.size());
dto.setPackingAgentCount(packingAgentCount);
result.setData(dto);
return result.toRpcClientResult();
}
Aggregations