diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/AddressController.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/AddressController.java index 8b00d7c1..f692b482 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/AddressController.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/AddressController.java @@ -213,8 +213,9 @@ public void exportAddressTransferTxs( @ApiOperation(value = "get address staking info") @GetMapping(value = "/{address}/staking-info") public ResponseBean getAddressStakingInfo(@PathVariable @Length(min = 34, max = 34, message = "Incorrect address format") String address, - @RequestParam(required = false) String channel) { - return addressService.getAddressStakingInfo(address, channel); + @RequestParam(required = false) String channel, + @RequestParam(value = "public_key", required = false) String publicKey) { + return addressService.getAddressStakingInfo(address, channel, publicKey); } @RequestLimit(count = 30) diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/NodeInfoOffChainMapper.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/NodeInfoOffChainMapper.java index f299d238..206d6a65 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/NodeInfoOffChainMapper.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/NodeInfoOffChainMapper.java @@ -19,5 +19,7 @@ public interface NodeInfoOffChainMapper extends Mapper { List selectAllStakingNodeInfo(); + NodeInfoOffChain selectOneStakingNodeInfo(String publicKey); + List selectAllRegisterNodeInfo(String address); } \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/IAddressService.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/IAddressService.java index 11bd1754..15b29a04 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/IAddressService.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/IAddressService.java @@ -41,7 +41,7 @@ ResponseBean queryTransferTxsByTimeAndPage4Onto(String address, String assetName void exportAddressTransferTxs(String token, String language, String address, Integer start, Integer end, HttpServletResponse resp) throws IOException; - ResponseBean getAddressStakingInfo(String address, String channel); + ResponseBean getAddressStakingInfo(String address, String channel, String specificPublicKey); ResponseBean getAddressStakingInfoWhenRoundStart(String address); } diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/AddressServiceImpl.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/AddressServiceImpl.java index dc7dce70..0a0061cc 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/AddressServiceImpl.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/AddressServiceImpl.java @@ -1581,33 +1581,56 @@ private boolean verifyReCAPTCHAToken(String token) { } @Override - public ResponseBean getAddressStakingInfo(String address, String channel) { - List currentOffChainInfo = nodeInfoOffChainMapper.selectAllStakingNodeInfo(); + public ResponseBean getAddressStakingInfo(String address, String channel, String specificPublicKey) { List nodeStakeDtos = new ArrayList<>(); initSDK(); - if (ConstantParam.CHANNEL_ONTO.equalsIgnoreCase(channel)) { - int currentRound = sdk.getGovernanceView(); - for (NodeInfoOffChain nodeInfoOffChain : currentOffChainInfo) { - String publicKey = nodeInfoOffChain.getPublicKey(); + if (StringUtils.hasLength(specificPublicKey)) { + NodeInfoOffChain nodeInfoOffChain = nodeInfoOffChainMapper.selectOneStakingNodeInfo(specificPublicKey); + if (nodeInfoOffChain == null) { + throw new ExplorerException(ErrorInfo.NOT_FOUND); + } + if (ConstantParam.CHANNEL_ONTO.equalsIgnoreCase(channel)) { + int currentRound = sdk.getGovernanceView(); try { - if (!publicKey.startsWith(ConstantParam.FAKE_NODE_PUBKEY_PREFIX)) { - String stakingInfo = sdk.getAuthorizeInfo(publicKey, address); - putStakingInfoList4Onto(address, stakingInfo, nodeInfoOffChain, nodeStakeDtos, currentRound); - } + String stakingInfo = sdk.getAuthorizeInfo(specificPublicKey, address); + putStakingInfoList4Onto(address, stakingInfo, nodeInfoOffChain, nodeStakeDtos, currentRound); } catch (Exception e) { - log.error("getAddressStakingInfo error:{},{},{}", address, publicKey, e.getMessage()); + log.error("getAddressStakingInfo error:{},{},{}", address, specificPublicKey, e.getMessage()); + } + } else { + try { + String stakingInfo = sdk.getAuthorizeInfo(specificPublicKey, address); + putStakingInfoList(stakingInfo, nodeInfoOffChain, nodeStakeDtos); + } catch (Exception e) { + log.error("getAddressStakingInfo error:{},{},{}", address, specificPublicKey, e.getMessage()); } } } else { - for (NodeInfoOffChain nodeInfoOffChain : currentOffChainInfo) { - String publicKey = nodeInfoOffChain.getPublicKey(); - try { - if (!publicKey.startsWith(ConstantParam.FAKE_NODE_PUBKEY_PREFIX)) { - String stakingInfo = sdk.getAuthorizeInfo(publicKey, address); - putStakingInfoList(stakingInfo, nodeInfoOffChain, nodeStakeDtos); + List currentOffChainInfo = nodeInfoOffChainMapper.selectAllStakingNodeInfo(); + if (ConstantParam.CHANNEL_ONTO.equalsIgnoreCase(channel)) { + int currentRound = sdk.getGovernanceView(); + for (NodeInfoOffChain nodeInfoOffChain : currentOffChainInfo) { + String publicKey = nodeInfoOffChain.getPublicKey(); + try { + if (!publicKey.startsWith(ConstantParam.FAKE_NODE_PUBKEY_PREFIX)) { + String stakingInfo = sdk.getAuthorizeInfo(publicKey, address); + putStakingInfoList4Onto(address, stakingInfo, nodeInfoOffChain, nodeStakeDtos, currentRound); + } + } catch (Exception e) { + log.error("getAddressStakingInfo error:{},{},{}", address, publicKey, e.getMessage()); + } + } + } else { + for (NodeInfoOffChain nodeInfoOffChain : currentOffChainInfo) { + String publicKey = nodeInfoOffChain.getPublicKey(); + try { + if (!publicKey.startsWith(ConstantParam.FAKE_NODE_PUBKEY_PREFIX)) { + String stakingInfo = sdk.getAuthorizeInfo(publicKey, address); + putStakingInfoList(stakingInfo, nodeInfoOffChain, nodeStakeDtos); + } + } catch (Exception e) { + log.error("getAddressStakingInfo error:{},{},{}", address, publicKey, e.getMessage()); } - } catch (Exception e) { - log.error("getAddressStakingInfo error:{},{},{}", address, publicKey, e.getMessage()); } } } diff --git a/back-end-projects/Explorer/src/main/resources/mapper/NodeInfoOffChainMapper.xml b/back-end-projects/Explorer/src/main/resources/mapper/NodeInfoOffChainMapper.xml index b58f158a..daa7cb90 100644 --- a/back-end-projects/Explorer/src/main/resources/mapper/NodeInfoOffChainMapper.xml +++ b/back-end-projects/Explorer/src/main/resources/mapper/NodeInfoOffChainMapper.xml @@ -107,6 +107,22 @@ ORDER BY b.progress IS NULL, b.progress = '100.00%', a.public_key + +