Skip to content

Commit

Permalink
Add staking rewards interface
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed Nov 21, 2024
1 parent 98bb55d commit 9930965
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 186 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,13 @@ public ResponseBean getBestApr() {
public ResponseBean getAddressRegisterNodeOnt(@RequestParam @Length(min = 34, max = 34, message = "Incorrect address format") String address) {
return nodesService.getAddressRegisterNodeOnt(address);
}

@RequestLimit(count = 60)
@ApiOperation(value = "get address staking rewards")
@GetMapping(value = "/staking-rewards")
public ResponseBean getAddressStakingRewards(@RequestParam @Length(min = 34, max = 34, message = "Incorrect address format") String address,
@RequestParam(value = "public_key", required = false) String publicKey,
@RequestParam(required = false) Integer round) {
return nodesService.getAddressStakingRewards(address, publicKey, round);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.ontio.mapper;

import com.github.ontio.model.dto.GovernanceInfoDto;
import com.github.ontio.model.dto.StakingRewardsDto;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

Expand All @@ -10,7 +11,7 @@
* @author LiuQi
*/
@Repository
public interface CommonMapper {
public interface GovernanceMapper {

List<GovernanceInfoDto> findGovernanceInfo(@Param("pubKey") String pubKey, @Param("start") int start, @Param("size") int size);

Expand All @@ -21,4 +22,6 @@ public interface CommonMapper {
List<String> getStakingAddressByPublicKey(@Param("pubKey") String pubKey);

List<String> getAllStakingAddress();

List<StakingRewardsDto> getStakingRewardsByAddress(String address, String publicKey, Integer round);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.github.ontio.model.dto;

import lombok.Data;

@Data
public class StakingRewardsDto {
private String address;
private String publicKey;
private String rewards;
private int round;
}

Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,6 @@ public interface INodesService {
ResponseBean getBestApr();

ResponseBean getAddressRegisterNodeOnt(String address);

ResponseBean getAddressStakingRewards(String address, String publicKey, Integer round);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.github.benmanes.caffeine.cache.LoadingCache;
import com.github.ontio.common.Address;
import com.github.ontio.common.Helper;
import com.github.ontio.mapper.CommonMapper;
import com.github.ontio.mapper.GovernanceMapper;
import com.github.ontio.mapper.NodeInfoOnChainMapper;
import com.github.ontio.mapper.Oep4TxDetailMapper;
import com.github.ontio.mapper.TxDetailMapper;
Expand All @@ -28,7 +28,7 @@
@Service
public class ActivityDataServiceImpl implements IActivityDataService {
@Autowired
private CommonMapper commonMapper;
private GovernanceMapper governanceMapper;
@Autowired
private TxDetailMapper txDetailMapper;
@Autowired
Expand All @@ -53,7 +53,7 @@ public class ActivityDataServiceImpl implements IActivityDataService {
@Override
public Anniversary6thDataDto queryAddress6thAnniversaryData(String address) {
// ONT质押数量
List<GovernanceInfoDto> stakingInfoByAddress = commonMapper.getStakingInfoByAddress(address);
List<GovernanceInfoDto> stakingInfoByAddress = governanceMapper.getStakingInfoByAddress(address);
long stakingAmount = 0;
for (GovernanceInfoDto governanceInfoDto : stakingInfoByAddress) {
Long consensusPos = governanceInfoDto.getConsensusPos();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ public class AddressServiceImpl implements IAddressService {
private final AddressDailyAggregationMapper addressDailyAggregationMapper;
private final RankingMapper rankingMapper;
private final NodeInfoOffChainMapper nodeInfoOffChainMapper;
private final CommonMapper commonMapper;
private final GovernanceMapper governanceMapper;


@Autowired
public AddressServiceImpl(Oep4Mapper oep4Mapper, Oep8Mapper oep8Mapper, Oep5Mapper oep5Mapper, Orc20Mapper orc20Mapper, Orc721Mapper orc721Mapper, Orc1155Mapper orc1155Mapper,
TxDetailMapper txDetailMapper, TxDetailIndexMapper txDetailIndexMapper, ParamsConfig paramsConfig, CommonService commonService,
AddressDailyAggregationMapper addressDailyAggregationMapper, RankingMapper rankingMapper, NodeInfoOffChainMapper nodeInfoOffChainMapper, CommonMapper commonMapper) {
AddressDailyAggregationMapper addressDailyAggregationMapper, RankingMapper rankingMapper, NodeInfoOffChainMapper nodeInfoOffChainMapper, GovernanceMapper governanceMapper) {
this.oep4Mapper = oep4Mapper;
this.oep8Mapper = oep8Mapper;
this.oep5Mapper = oep5Mapper;
Expand All @@ -81,7 +81,7 @@ public AddressServiceImpl(Oep4Mapper oep4Mapper, Oep8Mapper oep8Mapper, Oep5Mapp
this.addressDailyAggregationMapper = addressDailyAggregationMapper;
this.rankingMapper = rankingMapper;
this.nodeInfoOffChainMapper = nodeInfoOffChainMapper;
this.commonMapper = commonMapper;
this.governanceMapper = governanceMapper;
}

private OntologySDKService sdk;
Expand Down Expand Up @@ -1785,7 +1785,7 @@ private void putStakingInfoList(String stakingInfo, NodeInfoOffChain nodeInfoOff

@Override
public ResponseBean getAddressStakingInfoWhenRoundStart(String address) {
List<GovernanceInfoDto> stakingInfoList = commonMapper.getStakingInfoByAddress(address);
List<GovernanceInfoDto> stakingInfoList = governanceMapper.getStakingInfoByAddress(address);
List<NodeStakeDto> nodeStakeDtos = new ArrayList<>();
for (GovernanceInfoDto governanceInfoDto : stakingInfoList) {
putStakingInfoList(governanceInfoDto, nodeStakeDtos);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class NodesServiceImpl implements INodesService {

private final NodeInfoOffChainMapper nodeInfoOffChainMapper;

private final CommonMapper commonMapper;
private final GovernanceMapper governanceMapper;

private final NodeOverviewHistoryMapper nodeOverviewHistoryMapper;

Expand All @@ -88,7 +88,7 @@ public NodesServiceImpl(ParamsConfig paramsConfig,
NodeInfoOnChainMapper nodeInfoOnChainMapper,
NodeRankHistoryMapper nodeRankHistoryMapper,
NodeInfoOffChainMapper nodeInfoOffChainMapper,
CommonMapper commonMapper,
GovernanceMapper governanceMapper,
NodeOverviewHistoryMapper nodeOverviewHistoryMapper,
NodeInspireMapper nodeInspireMapper,
TokenServiceImpl tokenService,
Expand All @@ -104,7 +104,7 @@ public NodesServiceImpl(ParamsConfig paramsConfig,
this.nodeInfoOnChainMapper = nodeInfoOnChainMapper;
this.nodeRankHistoryMapper = nodeRankHistoryMapper;
this.nodeInfoOffChainMapper = nodeInfoOffChainMapper;
this.commonMapper = commonMapper;
this.governanceMapper = governanceMapper;
this.nodeOverviewHistoryMapper = nodeOverviewHistoryMapper;
this.nodeInspireMapper = nodeInspireMapper;
this.inspireCalculationParamsMapper = inspireCalculationParamsMapper;
Expand Down Expand Up @@ -498,8 +498,8 @@ public List<NodeRankHistory> getRecentNodeRankHistory() {
@Override
public PageResponseBean getGovernanceInfo(String pubKey, Integer pageNum, Integer pageSize) {
int start = Math.max(pageSize * (pageNum - 1), 0);
List<GovernanceInfoDto> result = commonMapper.findGovernanceInfo(pubKey, start, pageSize);
int count = commonMapper.countGovernanceInfo(pubKey);
List<GovernanceInfoDto> result = governanceMapper.findGovernanceInfo(pubKey, start, pageSize);
int count = governanceMapper.countGovernanceInfo(pubKey);
return new PageResponseBean(result, count);
}

Expand Down Expand Up @@ -1283,12 +1283,12 @@ public ResponseBean getNodeOnChainConfig(String address, String publicKey) {
}

public ResponseBean getAllStakingAddress() {
List<String> addressList = commonMapper.getAllStakingAddress();
List<String> addressList = governanceMapper.getAllStakingAddress();
return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), addressList);
}

public ResponseBean getStakingAddressByNode(String publicKey) {
List<String> addressList = commonMapper.getStakingAddressByPublicKey(publicKey);
List<String> addressList = governanceMapper.getStakingAddressByPublicKey(publicKey);
return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), addressList);
}

Expand Down Expand Up @@ -1342,4 +1342,10 @@ public ResponseBean getAddressRegisterNodeOnt(String address) {
}
return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), registerNodeOnt);
}

@Override
public ResponseBean getAddressStakingRewards(String address, String publicKey, Integer round) {
List<StakingRewardsDto> list = governanceMapper.getStakingRewardsByAddress(address, publicKey, round);
return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), list);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE TABLE `tbl_income_info`
(
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`peer_pub_key` char(80) NOT NULL,
`address` char(80) NOT NULL,
`ong_income` varchar(50) DEFAULT NULL,
`staking_pos` int(11) DEFAULT NULL,
`cycle` int(11) NOT NULL,
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_peer_address` (`peer_pub_key`,`address`) USING BTREE,
KEY `idx_address` (`address`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.github.ontio.mapper.CommonMapper">
<mapper namespace="com.github.ontio.mapper.GovernanceMapper">

<select id="findGovernanceInfo" resultType="com.github.ontio.model.dto.GovernanceInfoDto">
SELECT address,
Expand Down Expand Up @@ -48,4 +48,23 @@
FROM tbl_governance_info
WHERE consensus_pos > 0 OR candidate_pos > 0 OR withdraw_candidate_pos > 0
</select>

<select id="getStakingRewardsByAddress" resultType="com.github.ontio.model.dto.StakingRewardsDto">
SELECT
address,
peer_pub_key AS publicKey,
ong_income AS rewards,
cycle AS round
FROM tbl_income_info
<where>
address = #{address}
<if test="publicKey !=null and publicKey != ''">
AND peer_pub_key = #{publicKey}
</if>
<if test="round !=null">
AND cycle = #{round}
</if>
</where>
ORDER BY cycle DESC
</select>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ ontoservice.appId=test
ontoservice.appSecret=test

task.syncGovernanceInfo.interval=600000
task.syncGovernanceInfo.filePath=config/authorizePeers.json

cancel.approve.contract=d084a402153f6790ed90abccf9fe86546e6b7f76
eth.web3j.url=http://polaris1.ont.io:20339
1 change: 0 additions & 1 deletion back-end-projects/OntSynHandler/config/authorizePeers.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class ParamsConfig {

@Value("${batchInsert.sqlCount}")
public int BATCHINSERT_SQL_COUNT;

@Value("${reSync.enabled:true}")
public boolean reSyncEnabled = true;

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 9930965

Please sign in to comment.