From 89f004fab68f25b418a2f2e560876bfec19a9f8d Mon Sep 17 00:00:00 2001 From: leej1012 Date: Fri, 7 Jun 2024 15:33:57 +0800 Subject: [PATCH] Update getOffChainInfoByPublicKey --- .../ontio/controller/NodesController.java | 7 +++--- .../github/ontio/service/INodesService.java | 2 +- .../ontio/service/impl/NodesServiceImpl.java | 22 +++++++++++++++++-- 3 files changed, 25 insertions(+), 6 deletions(-) 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 d47d7de2..4195b1e5 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 @@ -149,8 +149,9 @@ public ResponseBean getOpenOffChainInfoByPublicKey(@RequestParam("public_key") @ @ApiOperation(value = "Get node register information by public key") @GetMapping(value = "/off-chain-info/public") - public ResponseBean getOffChainInfoByPublicKey(@RequestParam("public_key") @Length(min = 56, max = 128, message = "invalid public key") String publicKey) { - NodeInfoOffChain nodeInfoList = nodesService.getCurrentOffChainInfoPublic(publicKey, null); + public ResponseBean getOffChainInfoByPublicKey(@RequestParam("public_key") @Length(min = 56, max = 128, message = "invalid public key") String publicKey, + @RequestParam(value = "channel", required = false) String channel) { + NodeInfoOffChain nodeInfoList = nodesService.getCurrentOffChainInfoPublic(publicKey, null, channel); if (nodeInfoList == null) { return new ResponseBean(ErrorInfo.NOT_FOUND.code(), ErrorInfo.NOT_FOUND.desc(), ""); } @@ -384,6 +385,6 @@ public ResponseBean getAddressRegisterNodeList(@RequestParam @Length(min = 34, m @GetMapping(value = "/node-on-chain-config") public ResponseBean getNodeOnChainConfig(@RequestParam @Length(min = 34, max = 34, message = "Incorrect address format") String address, @RequestParam("public_key") @Length(min = 56, max = 128, message = "invalid public key") String publicKey) { - return nodesService.getNodeOnChainConfig(address,publicKey); + return nodesService.getNodeOnChainConfig(address, publicKey); } } 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 ee19168b..d6f6bebe 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 @@ -41,7 +41,7 @@ public interface INodesService { NodeInfoOffChain getCurrentOffChainInfo(String publicKey, Integer openFlag); - NodeInfoOffChain getCurrentOffChainInfoPublic(String publicKey, Integer openFlag); + NodeInfoOffChain getCurrentOffChainInfoPublic(String publicKey, Integer openFlag, String channel); List getCurrentOffChainInfo(); 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 140f6d27..78836f87 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 @@ -259,9 +259,27 @@ public NodeInfoOffChain getCurrentOffChainInfo(String publicKey, Integer openFla } @Override - public NodeInfoOffChain getCurrentOffChainInfoPublic(String publicKey, Integer openFlag) { + public NodeInfoOffChain getCurrentOffChainInfoPublic(String publicKey, Integer openFlag, String channel) { try { - return nodeInfoOffChainMapper.selectByPublicKey(publicKey, openFlag); + NodeInfoOffChainDto nodeInfoOffChainDto = nodeInfoOffChainMapper.selectByPublicKey(publicKey, openFlag); + if (nodeInfoOffChainDto != null && ConstantParam.CHANNEL_ONTO.equalsIgnoreCase(channel)) { + int nodeStatus; + initSDK(); + String peerPoolInfoStr = sdk.getPeerPoolInfo(publicKey); + if (StringUtils.hasLength(peerPoolInfoStr)) { + JSONObject peerPoolInfo = JSONObject.parseObject(peerPoolInfoStr); + int status = peerPoolInfo.getIntValue("status"); + if (status == 1 || status == 2) { + nodeStatus = 1; + } else { + nodeStatus = 2; + } + } else { + nodeStatus = 3; + } + nodeInfoOffChainDto.setStatus(nodeStatus); + } + return nodeInfoOffChainDto; } catch (Exception e) { log.warn("Select node off chain info by public key {} failed: {}", publicKey, e.getMessage()); return new NodeInfoOffChain();