Search in sources :

Example 6 with MeetingRound

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());
}
Also used : MeetingRound(io.nuls.consensus.poc.model.MeetingRound) BaseChainTest(io.nuls.consensus.poc.BaseChainTest) Test(org.junit.Test)

Example 7 with MeetingRound

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);
}
Also used : MeetingRound(io.nuls.consensus.poc.model.MeetingRound) BaseChainTest(io.nuls.consensus.poc.BaseChainTest) Test(org.junit.Test)

Example 8 with MeetingRound

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);
}
Also used : Chain(io.nuls.consensus.poc.model.Chain) MeetingRound(io.nuls.consensus.poc.model.MeetingRound) BaseChainTest(io.nuls.consensus.poc.BaseChainTest) Test(org.junit.Test)

Example 9 with MeetingRound

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();
}
Also used : StopAgent(io.nuls.consensus.poc.protocol.entity.StopAgent) Agent(io.nuls.consensus.poc.protocol.entity.Agent) MeetingRound(io.nuls.consensus.poc.model.MeetingRound) CoinDataResult(io.nuls.account.ledger.model.CoinDataResult)

Example 10 with MeetingRound

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();
}
Also used : StopAgent(io.nuls.consensus.poc.protocol.entity.StopAgent) Agent(io.nuls.consensus.poc.protocol.entity.Agent) Deposit(io.nuls.consensus.poc.protocol.entity.Deposit) CancelDeposit(io.nuls.consensus.poc.protocol.entity.CancelDeposit) MeetingMember(io.nuls.consensus.poc.model.MeetingMember) MeetingRound(io.nuls.consensus.poc.model.MeetingRound) CoinDataResult(io.nuls.account.ledger.model.CoinDataResult)

Aggregations

MeetingRound (io.nuls.consensus.poc.model.MeetingRound)12 MeetingMember (io.nuls.consensus.poc.model.MeetingMember)6 BaseChainTest (io.nuls.consensus.poc.BaseChainTest)4 Test (org.junit.Test)4 BlockExtendsData (io.nuls.consensus.poc.model.BlockExtendsData)3 Agent (io.nuls.consensus.poc.protocol.entity.Agent)3 IOException (java.io.IOException)3 CoinDataResult (io.nuls.account.ledger.model.CoinDataResult)2 StopAgent (io.nuls.consensus.poc.protocol.entity.StopAgent)2 ContractResult (io.nuls.contract.dto.ContractResult)2 NulsException (io.nuls.kernel.exception.NulsException)2 ValidateResult (io.nuls.kernel.validate.ValidateResult)2 Chain (io.nuls.consensus.poc.model.Chain)1 CancelDeposit (io.nuls.consensus.poc.protocol.entity.CancelDeposit)1 Deposit (io.nuls.consensus.poc.protocol.entity.Deposit)1 RedPunishData (io.nuls.consensus.poc.protocol.entity.RedPunishData)1 YellowPunishData (io.nuls.consensus.poc.protocol.entity.YellowPunishData)1 RedPunishTransaction (io.nuls.consensus.poc.protocol.tx.RedPunishTransaction)1 YellowPunishTransaction (io.nuls.consensus.poc.protocol.tx.YellowPunishTransaction)1 ProtocolContainer (io.nuls.protocol.base.version.ProtocolContainer)1