Skip to content

Commit

Permalink
Add getAddressRegisterNodeOnt
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed Oct 30, 2024
1 parent e136ca3 commit 98bb55d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,11 @@ public ResponseBean getBadNode(@RequestParam Integer cycle) {
public ResponseBean getBestApr() {
return nodesService.getBestApr();
}

@RequestLimit(count = 60)
@ApiOperation(value = "get address register node ONT")
@GetMapping(value = "/register-node-ont")
public ResponseBean getAddressRegisterNodeOnt(@RequestParam @Length(min = 34, max = 34, message = "Incorrect address format") String address) {
return nodesService.getAddressRegisterNodeOnt(address);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,8 @@ public interface INodesService {
ResponseBean getMaxNodeDataCycle();

ResponseBean getBadNode(Integer cycle);

ResponseBean getBestApr();

ResponseBean getAddressRegisterNodeOnt(String address);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1298,13 +1298,48 @@ public ResponseBean getMaxNodeDataCycle() {
return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), maxCycle);
}

@Override
public ResponseBean getBadNode(Integer cycle) {
List<BadNode> nodeList = badNodeMapper.selectBadNodeByCycle(cycle);
return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), nodeList);
}

@Override
public ResponseBean getBestApr() {
String apr = nodeInspireMapper.selectBestApr();
return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), apr);
}

@Override
public ResponseBean getAddressRegisterNodeOnt(String address) {
long registerNodeOnt = 0;
List<NodeInfoOffChain> registerNodeList = nodeInfoOffChainMapper.selectAllRegisterNodeInfo(address);
if (!CollectionUtils.isEmpty(registerNodeList)) {
try {
initSDK();
for (NodeInfoOffChain registerNodeInfo : registerNodeList) {
String publicKey = registerNodeInfo.getPublicKey();
String peerPoolInfoStr = sdk.getPeerPoolInfo(publicKey);
if (StringUtils.hasLength(peerPoolInfoStr)) {
JSONObject peerPoolInfo = JSONObject.parseObject(peerPoolInfoStr);
Long initPos = peerPoolInfo.getLong("initPos");
registerNodeOnt += initPos;
}
String authorizeInfoStr = sdk.getAuthorizeInfo(publicKey, address);
if (StringUtils.hasLength(authorizeInfoStr)) {
JSONObject authorizeInfo = JSONObject.parseObject(authorizeInfoStr);
Long withdrawPos = authorizeInfo.getLong("withdrawPos");
Long withdrawFreezePos = authorizeInfo.getLong("withdrawFreezePos");
Long withdrawUnfreezePos = authorizeInfo.getLong("withdrawUnfreezePos");
long lockedAmount = withdrawPos + withdrawFreezePos;
registerNodeOnt += lockedAmount;
registerNodeOnt += withdrawUnfreezePos;
}
}
} catch (Exception e) {
log.error("getAddressRegisterNodeOnt error:{},{}", address, e.getMessage());
}
}
return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), registerNodeOnt);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE `tbl_forbid_edit_node`
(
`public_key` varchar(70) NOT NULL COMMENT '节点公钥',
`end_cycle` int(11) NOT NULL COMMENT '直到该周期才能编辑',
PRIMARY KEY (`public_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

0 comments on commit 98bb55d

Please sign in to comment.