From 98bb55d25bc615beba466b01692d8e204edb4fc8 Mon Sep 17 00:00:00 2001 From: leej1012 Date: Wed, 30 Oct 2024 16:48:58 +0800 Subject: [PATCH] Add getAddressRegisterNodeOnt --- .../ontio/controller/NodesController.java | 7 ++++ .../github/ontio/service/INodesService.java | 4 +++ .../ontio/service/impl/NodesServiceImpl.java | 35 +++++++++++++++++++ .../migration/V1.86__tbl_forbid_edit_node.sql | 6 ++++ 4 files changed, 52 insertions(+) create mode 100644 back-end-projects/Explorer/src/main/resources/db/migration/V1.86__tbl_forbid_edit_node.sql diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/NodesController.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/NodesController.java index 001a8e92..c55ee7df 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/NodesController.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/NodesController.java @@ -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); + } } diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/INodesService.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/INodesService.java index cd4b98f7..8565b207 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/INodesService.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/INodesService.java @@ -109,4 +109,8 @@ public interface INodesService { ResponseBean getMaxNodeDataCycle(); ResponseBean getBadNode(Integer cycle); + + ResponseBean getBestApr(); + + ResponseBean getAddressRegisterNodeOnt(String address); } diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/NodesServiceImpl.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/NodesServiceImpl.java index 4736e2a4..1ee297d6 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/NodesServiceImpl.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/NodesServiceImpl.java @@ -1298,13 +1298,48 @@ public ResponseBean getMaxNodeDataCycle() { return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), maxCycle); } + @Override public ResponseBean getBadNode(Integer cycle) { List 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 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); + } } diff --git a/back-end-projects/Explorer/src/main/resources/db/migration/V1.86__tbl_forbid_edit_node.sql b/back-end-projects/Explorer/src/main/resources/db/migration/V1.86__tbl_forbid_edit_node.sql new file mode 100644 index 00000000..b48067c3 --- /dev/null +++ b/back-end-projects/Explorer/src/main/resources/db/migration/V1.86__tbl_forbid_edit_node.sql @@ -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; \ No newline at end of file