Skip to content

Commit

Permalink
Update getOffChainInfoByPublicKey
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed Jun 7, 2024
1 parent eab91aa commit 89f004f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(), "");
}
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeInfoOffChain> getCurrentOffChainInfo();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 89f004f

Please sign in to comment.