Skip to content

Commit

Permalink
Update getAddressStakingInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed Jul 26, 2024
1 parent 39b1322 commit 6e94f3f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public interface NodeInfoOffChainMapper extends Mapper<NodeInfoOffChain> {

List<NodeInfoOffChain> selectAllStakingNodeInfo();

NodeInfoOffChain selectOneStakingNodeInfo(String publicKey);

List<NodeInfoOffChain> selectAllRegisterNodeInfo(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 getAddressStakingInfo(String address, String channel);
ResponseBean getAddressStakingInfo(String address, String channel, String specificPublicKey);

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

@Override
public ResponseBean getAddressStakingInfo(String address, String channel) {
List<NodeInfoOffChain> currentOffChainInfo = nodeInfoOffChainMapper.selectAllStakingNodeInfo();
public ResponseBean getAddressStakingInfo(String address, String channel, String specificPublicKey) {
List<NodeStakeDto> 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<NodeInfoOffChain> 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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@
ORDER BY b.progress IS NULL, b.progress = '100.00%', a.public_key
</select>

<select id="selectOneStakingNodeInfo" resultType="com.github.ontio.model.dao.NodeInfoOffChain" useCache="true">
SELECT
a.public_key,
a.name,
a.address,
a.node_type,
b.progress,
b.total_pos,
b.max_authorize,
c.user_apy
FROM tbl_node_info_off_chain a
LEFT JOIN tbl_node_info_on_chain b ON a.public_key = b.public_key
LEFT JOIN tbl_node_inspire c ON a.public_key = c.public_key
WHERE a.public_key = #{publicKey}
</select>

<select id="selectAllRegisterNodeInfo" resultType="com.github.ontio.model.dao.NodeInfoOffChain">
SELECT
<include refid="baseColumns"/>
Expand Down

0 comments on commit 6e94f3f

Please sign in to comment.