use of io.nuls.consensus.poc.model.MeetingMember in project nuls by nuls-io.
the class PocConsensusResource method queryDepositListByAgentAddress.
@GET
@Path("/deposit/agent/{agentHash}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "查询共识节点受托列表信息 [3.6.9]", notes = "result.data.page.list: List<Map<String, Object>>")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = Page.class) })
public RpcClientResult queryDepositListByAgentAddress(@ApiParam(name = "agentHash", value = "指定代理节点标识", required = true) @PathParam("agentHash") String agentHash, @ApiParam(name = "pageNumber", value = "页码") @QueryParam("pageNumber") Integer pageNumber, @ApiParam(name = "pageSize", value = "每页条数") @QueryParam("pageSize") Integer pageSize) throws NulsException {
AssertUtil.canNotEmpty(agentHash);
if (null == pageNumber || pageNumber == 0) {
pageNumber = 1;
}
if (null == pageSize || pageSize == 0) {
pageSize = 10;
}
if (pageNumber < 0 || pageSize < 0 || pageSize > 100) {
return Result.getFailed(KernelErrorCode.PARAMETER_ERROR).toRpcClientResult();
}
Result result = Result.getSuccess();
List<Deposit> allList = PocConsensusContext.getChainManager().getMasterChain().getChain().getDepositList();
List<Deposit> depositList = new ArrayList<>();
long startBlockHeight = NulsContext.getInstance().getBestHeight();
NulsDigestData agentDigestData = NulsDigestData.fromDigestHex(agentHash);
for (Deposit deposit : allList) {
if (deposit.getDelHeight() != -1L && deposit.getDelHeight() <= startBlockHeight) {
continue;
}
if (deposit.getBlockHeight() > startBlockHeight || deposit.getBlockHeight() < 0L) {
continue;
}
if (!deposit.getAgentHash().equals(agentDigestData)) {
continue;
}
depositList.add(deposit);
}
int start = pageNumber * pageSize - pageSize;
Page<DepositDTO> page = new Page<>(pageNumber, pageSize, depositList.size());
if (start >= depositList.size()) {
result.setData(page);
return result.toRpcClientResult();
}
Map<NulsDigestData, Integer> map = new HashMap<>();
for (MeetingMember member : PocConsensusContext.getChainManager().getMasterChain().getCurrentRound().getMemberList()) {
if (null != member.getAgent()) {
map.put(member.getAgent().getTxHash(), 1);
}
}
List<DepositDTO> resultList = new ArrayList<>();
for (int i = start; i < depositList.size() && i < (start + pageSize); i++) {
Deposit deposit = depositList.get(i);
deposit.setStatus(map.get(deposit.getAgentHash()) == null ? 0 : 1);
resultList.add(new DepositDTO(deposit));
}
page.setList(resultList);
result.setData(page);
return result.toRpcClientResult();
}
use of io.nuls.consensus.poc.model.MeetingMember in project nuls by nuls-io.
the class PocConsensusResource method getDepositListByAddress.
@GET
@Path("/deposit/address/{address}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "查询指定地址参与的所有委托信息列表 [3.6.8]", notes = "result.data.page.list: List<Map<String, Object>>")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = Page.class) })
public RpcClientResult getDepositListByAddress(@ApiParam(name = "address", value = "账户地址", required = true) @PathParam("address") String address, @ApiParam(name = "pageNumber", value = "页码") @QueryParam("pageNumber") Integer pageNumber, @ApiParam(name = "pageSize", value = "每页条数") @QueryParam("pageSize") Integer pageSize, @ApiParam(name = "agentHash", value = "指定代理节点标识(不传查所有)") @QueryParam("agentHash") String agentHash) {
AssertUtil.canNotEmpty(address);
if (!AddressTool.validAddress(address)) {
return Result.getFailed(AccountErrorCode.ADDRESS_ERROR).toRpcClientResult();
}
if (null == pageNumber || pageNumber == 0) {
pageNumber = 1;
}
if (null == pageSize || pageSize == 0) {
pageSize = 10;
}
if (pageNumber < 0 || pageSize < 0 || pageSize > 100) {
return Result.getFailed(KernelErrorCode.PARAMETER_ERROR).toRpcClientResult();
}
if (null != agentHash && !NulsDigestData.validHash(agentHash)) {
return Result.getFailed(PocConsensusErrorCode.AGENT_NOT_EXIST).toRpcClientResult();
}
Result result = Result.getSuccess();
List<Deposit> allList = PocConsensusContext.getChainManager().getMasterChain().getChain().getDepositList();
List<Deposit> depositList = new ArrayList<>();
long startBlockHeight = NulsContext.getInstance().getBestHeight();
byte[] addressBytes = AddressTool.getAddress(address);
for (Deposit deposit : allList) {
if (deposit.getDelHeight() != -1L && deposit.getDelHeight() <= startBlockHeight) {
continue;
}
if (deposit.getBlockHeight() > startBlockHeight || deposit.getBlockHeight() < 0L) {
continue;
}
if (!Arrays.equals(deposit.getAddress(), addressBytes)) {
continue;
}
if (agentHash != null && !deposit.getAgentHash().getDigestHex().equals(agentHash)) {
continue;
}
depositList.add(deposit);
}
int start = pageNumber * pageSize - pageSize;
Page<DepositDTO> page = new Page<>(pageNumber, pageSize, depositList.size());
if (start >= depositList.size()) {
result.setData(page);
return result.toRpcClientResult();
}
Map<NulsDigestData, Agent> map = new HashMap<>();
for (MeetingMember member : PocConsensusContext.getChainManager().getMasterChain().getCurrentRound().getMemberList()) {
if (null != member.getAgent()) {
map.put(member.getAgent().getTxHash(), member.getAgent());
}
}
List<DepositDTO> resultList = new ArrayList<>();
for (int i = start; i < depositList.size() && i < (start + pageSize); i++) {
Deposit deposit = depositList.get(i);
List<Agent> agentList = PocConsensusContext.getChainManager().getMasterChain().getChain().getAgentList();
Agent agent = null;
for (Agent a : agentList) {
if (a.getTxHash().equals(deposit.getAgentHash())) {
agent = a;
break;
}
}
deposit.setStatus(agent == null ? 0 : agent.getStatus());
resultList.add(new DepositDTO(deposit, agent));
}
page.setList(resultList);
result.setData(page);
return result.toRpcClientResult();
}
use of io.nuls.consensus.poc.model.MeetingMember 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();
}
use of io.nuls.consensus.poc.model.MeetingMember in project nuls by nuls-io.
the class PocConsensusResource method fillAgent.
private void fillAgent(Agent agent, MeetingRound round, List<Deposit> depositList) {
if (null == depositList || depositList.isEmpty()) {
depositList = PocConsensusContext.getChainManager().getMasterChain().getChain().getDepositList();
}
Set<String> memberSet = new HashSet<>();
Na total = Na.ZERO;
for (int i = 0; i < depositList.size(); i++) {
Deposit deposit = depositList.get(i);
if (!agent.getTxHash().equals(deposit.getAgentHash())) {
continue;
}
if (deposit.getDelHeight() >= 0) {
continue;
}
total = total.add(deposit.getDeposit());
memberSet.add(AddressTool.getStringAddressByBytes(deposit.getAddress()));
}
agent.setMemberCount(memberSet.size());
agent.setTotalDeposit(total.getValue());
if (round == null) {
return;
}
MeetingMember member = round.getMember(agent.getPackingAddress());
if (null == member) {
agent.setStatus(0);
agent.setCreditVal(0);
return;
}
agent.setStatus(1);
agent.setCreditVal(member.getCreditVal());
}
use of io.nuls.consensus.poc.model.MeetingMember in project nuls by nuls-io.
the class ConsensusTool method createYellowPunishTx.
public static YellowPunishTransaction createYellowPunishTx(Block preBlock, MeetingMember self, MeetingRound round) throws NulsException, IOException {
BlockExtendsData preBlockRoundData = new BlockExtendsData(preBlock.getHeader().getExtend());
if (self.getRoundIndex() - preBlockRoundData.getRoundIndex() > 1) {
return null;
}
int yellowCount = 0;
if (self.getRoundIndex() == preBlockRoundData.getRoundIndex() && self.getPackingIndexOfRound() != preBlockRoundData.getPackingIndexOfRound() + 1) {
yellowCount = self.getPackingIndexOfRound() - preBlockRoundData.getPackingIndexOfRound() - 1;
}
if (self.getRoundIndex() != preBlockRoundData.getRoundIndex() && (self.getPackingIndexOfRound() != 1 || preBlockRoundData.getPackingIndexOfRound() != preBlockRoundData.getConsensusMemberCount())) {
yellowCount = self.getPackingIndexOfRound() + preBlockRoundData.getConsensusMemberCount() - preBlockRoundData.getPackingIndexOfRound() - 1;
}
if (yellowCount == 0) {
return null;
}
List<byte[]> addressList = new ArrayList<>();
for (int i = 1; i <= yellowCount; i++) {
int index = self.getPackingIndexOfRound() - i;
if (index > 0) {
MeetingMember member = round.getMember(index);
if (member.getAgent() == null) {
continue;
} else if (member.getAgent().getDelHeight() > 0) {
continue;
}
addressList.add(member.getAgentAddress());
} else {
MeetingRound preRound = round.getPreRound();
MeetingMember member = preRound.getMember(index + preRound.getMemberCount());
if (member.getAgent() == null || member.getAgent().getDelHeight() > 0) {
continue;
}
addressList.add(member.getAgentAddress());
}
}
if (addressList.isEmpty()) {
return null;
}
YellowPunishTransaction punishTx = new YellowPunishTransaction();
YellowPunishData data = new YellowPunishData();
data.setAddressList(addressList);
punishTx.setTxData(data);
punishTx.setTime(self.getPackEndTime());
punishTx.setHash(NulsDigestData.calcDigestData(punishTx.serializeForHash()));
return punishTx;
}
Aggregations