Skip to content

Commit

Permalink
Modify authorize info to staking info
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed Aug 29, 2023
1 parent 17dcc62 commit a45f220
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,16 @@ public void exportAddressTransferTxs(
}

@RequestLimit(count = 30)
@ApiOperation(value = "get address stake authorize info")
@GetMapping(value = "/{address}/authorize-info")
public ResponseBean getAddressAuthorizeInfo(@PathVariable @Length(min = 34, max = 42, message = "Incorrect address format") String address) {
return addressService.getAddressAuthorizeInfo(address);
@ApiOperation(value = "get address staking info")
@GetMapping(value = "/{address}/staking-info")
public ResponseBean getAddressStakingInfo(@PathVariable @Length(min = 34, max = 42, message = "Incorrect address format") String address) {
return addressService.getAddressStakingInfo(address);
}

@RequestLimit(count = 30)
@ApiOperation(value = "get address stake authorize info when round start")
@GetMapping(value = "/{address}/authorize-info/round-start")
public ResponseBean getAddressAuthorizeInfoWhenRoundStart(@PathVariable @Length(min = 34, max = 42, message = "Incorrect address format") String address) {
return addressService.getAddressAuthorizeInfoWhenRoundStart(address);
@ApiOperation(value = "get address staking info when round start")
@GetMapping(value = "/{address}/staking-info/round-start")
public ResponseBean getAddressStakingInfoWhenRoundStart(@PathVariable @Length(min = 34, max = 42, message = "Incorrect address format") String address) {
return addressService.getAddressStakingInfoWhenRoundStart(address);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public interface CommonMapper {

int countGovernanceInfo(@Param("pubKey") String pubKey);

List<GovernanceInfoDto> getAuthorizeInfoByAddress(@Param("address") String address);
List<GovernanceInfoDto> getStakingInfoByAddress(@Param("address") String address);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 getAddressAuthorizeInfo(String address);
ResponseBean getAddressStakingInfo(String address);

ResponseBean getAddressAuthorizeInfoWhenRoundStart(String address);
ResponseBean getAddressStakingInfoWhenRoundStart(String address);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,7 @@ private boolean verifyReCAPTCHAToken(String token) {
}

@Override
public ResponseBean getAddressAuthorizeInfo(String address) {
public ResponseBean getAddressStakingInfo(String address) {
List<NodeInfoOffChain> currentOffChainInfo = nodesService.getCurrentOffChainInfo();
List<NodeStakeDto> nodeStakeDtos = new ArrayList<>();
initSDK();
Expand All @@ -1590,25 +1590,25 @@ public ResponseBean getAddressAuthorizeInfo(String address) {
try {
if (!publicKey.startsWith(ConstantParam.FAKE_NODE_PUBKEY_PREFIX)) {
String name = nodeInfoOffChain.getName();
String authorizeInfo = sdk.getAuthorizeInfo(publicKey, address);
putAuthorizeInfoList(authorizeInfo, name, publicKey, nodeStakeDtos);
String stakingInfo = sdk.getAuthorizeInfo(publicKey, address);
putStakingInfoList(stakingInfo, name, publicKey, nodeStakeDtos);
}
} catch (Exception e) {
log.error("getAddressAuthorizeInfo error:{},{},{}", address, publicKey, e.getMessage());
log.error("getAddressStakingInfo error:{},{},{}", address, publicKey, e.getMessage());
}
}
return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), nodeStakeDtos);
}

private void putAuthorizeInfoList(String authorizeInfo, String nodeName, String publicKey, List<NodeStakeDto> nodeStakeDtos) {
if (authorizeInfo != null) {
JSONObject authorizeInfoObj = JSONObject.parseObject(authorizeInfo);
Long consensusPos = authorizeInfoObj.getLong("consensusPos");
Long freezePos = authorizeInfoObj.getLong("freezePos");
Long newPos = authorizeInfoObj.getLong("newPos");
Long withdrawPos = authorizeInfoObj.getLong("withdrawPos");
Long withdrawFreezePos = authorizeInfoObj.getLong("withdrawFreezePos");
Long withdrawUnfreezePos = authorizeInfoObj.getLong("withdrawUnfreezePos");
private void putStakingInfoList(String stakingInfo, String nodeName, String publicKey, List<NodeStakeDto> nodeStakeDtos) {
if (stakingInfo != null) {
JSONObject stakingInfoObj = JSONObject.parseObject(stakingInfo);
Long consensusPos = stakingInfoObj.getLong("consensusPos");
Long freezePos = stakingInfoObj.getLong("freezePos");
Long newPos = stakingInfoObj.getLong("newPos");
Long withdrawPos = stakingInfoObj.getLong("withdrawPos");
Long withdrawFreezePos = stakingInfoObj.getLong("withdrawFreezePos");
Long withdrawUnfreezePos = stakingInfoObj.getLong("withdrawUnfreezePos");

if (newPos > 0) {
NodeStakeDto dto = new NodeStakeDto();
Expand Down Expand Up @@ -1648,16 +1648,16 @@ private void putAuthorizeInfoList(String authorizeInfo, String nodeName, String
}

@Override
public ResponseBean getAddressAuthorizeInfoWhenRoundStart(String address) {
List<GovernanceInfoDto> authorizeInfoList = commonMapper.getAuthorizeInfoByAddress(address);
public ResponseBean getAddressStakingInfoWhenRoundStart(String address) {
List<GovernanceInfoDto> stakingInfoList = commonMapper.getStakingInfoByAddress(address);
List<NodeStakeDto> nodeStakeDtos = new ArrayList<>();
for (GovernanceInfoDto governanceInfoDto : authorizeInfoList) {
putAuthorizeInfoList(governanceInfoDto, nodeStakeDtos);
for (GovernanceInfoDto governanceInfoDto : stakingInfoList) {
putStakingInfoList(governanceInfoDto, nodeStakeDtos);
}
return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), nodeStakeDtos);
}

private void putAuthorizeInfoList(GovernanceInfoDto governanceInfoDto, List<NodeStakeDto> nodeStakeDtos) {
private void putStakingInfoList(GovernanceInfoDto governanceInfoDto, List<NodeStakeDto> nodeStakeDtos) {
Long consensusPos = governanceInfoDto.getConsensusPos();
Long freezePos = governanceInfoDto.getCandidatePos();
Long newPos = governanceInfoDto.getNewPos();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
WHERE peer_pub_key = #{pubKey}
</select>

<select id="getAuthorizeInfoByAddress" resultType="com.github.ontio.model.dto.GovernanceInfoDto">
<select id="getStakingInfoByAddress" resultType="com.github.ontio.model.dto.GovernanceInfoDto">
SELECT a.peer_pub_key AS publicKey,
b.name,
a.consensus_pos AS consensusPos,
Expand Down

0 comments on commit a45f220

Please sign in to comment.