From 2eb4c85c48a090271e9fc8593825c6ba34c13bc2 Mon Sep 17 00:00:00 2001 From: leej1012 Date: Fri, 20 Dec 2024 18:04:35 +0800 Subject: [PATCH] Add data interface --- .../config/application-dev.properties | 5 +- .../com/github/ontio/config/ParamsConfig.java | 3 +- .../controller/ActivityDataController.java | 22 +++++ .../github/ontio/mapper/GovernanceMapper.java | 2 + .../ontio/mapper/OntidTxDetailMapper.java | 1 + .../github/ontio/mapper/TxDetailMapper.java | 4 + .../ontio/service/IActivityDataService.java | 7 ++ .../service/impl/ActivityDataServiceImpl.java | 83 +++++++++++++++++-- .../resources/mapper/GovernanceMapper.xml | 14 ++++ .../resources/mapper/OntidTxDetailMapper.xml | 9 ++ .../main/resources/mapper/TxDetailMapper.xml | 18 ++++ 11 files changed, 160 insertions(+), 8 deletions(-) diff --git a/back-end-projects/Explorer/config/application-dev.properties b/back-end-projects/Explorer/config/application-dev.properties index a8545ea8..1570b4e2 100644 --- a/back-end-projects/Explorer/config/application-dev.properties +++ b/back-end-projects/Explorer/config/application-dev.properties @@ -79,4 +79,7 @@ foundation.addresses=ANZH6McmwUKABVKRbduGXfbbqhaz6Fxokd,AUtZgQxZQwnmzPa68zAphyxy eth.web3j.url=http://polaris1.ont.io:20339 -recaptcha.secret.key= \ No newline at end of file +recaptcha.secret.key= + +#block.end.2024 = 612800 +block.end.2024 = 18316350 \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/config/ParamsConfig.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/config/ParamsConfig.java index 393992d3..962990e0 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/config/ParamsConfig.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/config/ParamsConfig.java @@ -178,5 +178,6 @@ public String getContractHash(String token) { @Value("${recaptcha.secret.key}") public String RECAPTCHA_SECRET_KEY; - + @Value("${block.end.2024}") + public int BLOCK_END_2024; } \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/ActivityDataController.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/ActivityDataController.java index f25c4127..3dcef07a 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/ActivityDataController.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/ActivityDataController.java @@ -1,5 +1,6 @@ package com.github.ontio.controller; +import com.alibaba.fastjson.JSONObject; import com.github.ontio.aop.RequestLimit; import com.github.ontio.model.dto.Anniversary6thDataDto; import com.github.ontio.service.IActivityDataService; @@ -39,4 +40,25 @@ public Integer queryAddressTxCountInPeriod(@RequestParam @Length(min = 34, max = public String queryAddressCertainTimeBalance(@RequestParam @Length(min = 34, max = 42, message = "Incorrect address format") String address, @RequestParam Integer timestamp) { return activityDataService.queryAddressCertainTimeBalance(address, timestamp); } + + @RequestLimit(count = 120) + @ApiOperation(value = "Get ont id or address active time") + @GetMapping(value = "/active_time") + public JSONObject queryAddressActiveTime(@RequestParam @Length(min = 34, max = 42, message = "Incorrect address format") String address) { + return activityDataService.queryAddressActiveTime(address); + } + + @RequestLimit(count = 120) + @ApiOperation(value = "Get address send tx count and first tx time") + @GetMapping(value = "/send_tx_info") + public JSONObject queryAddressSendTxInfo(@RequestParam @Length(min = 34, max = 42, message = "Incorrect address format") String address) { + return activityDataService.queryAddressSendTxInfo(address); + } + + @RequestLimit(count = 120) + @ApiOperation(value = "Get running node info") + @GetMapping(value = "/running_node_info") + public JSONObject queryRunningNodeInfo(@RequestParam @Length(min = 34, max = 42, message = "Incorrect address format") String address) { + return activityDataService.queryRunningNodeInfo(address); + } } diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/GovernanceMapper.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/GovernanceMapper.java index 67710dba..f615d08f 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/GovernanceMapper.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/GovernanceMapper.java @@ -24,4 +24,6 @@ public interface GovernanceMapper { List getAllStakingAddress(); List getStakingRewardsByAddress(String address, String publicKey, Integer round); + + int getStakingAddressCount(List publicKeyList); } diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/OntidTxDetailMapper.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/OntidTxDetailMapper.java index 65955b72..2aecabb1 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/OntidTxDetailMapper.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/OntidTxDetailMapper.java @@ -16,4 +16,5 @@ public interface OntidTxDetailMapper extends Mapper { OntidTxDetailDto selectOneByTxHash(@Param("txHash") String txHash); + OntidTxDetailDto selectOntIdCreateTime(@Param("ontId") String ontId); } \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/TxDetailMapper.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/TxDetailMapper.java index 23f8c233..7cd71e8e 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/TxDetailMapper.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/TxDetailMapper.java @@ -85,4 +85,8 @@ List selectTransferTxsOfHashes(@Param("address") String address, Integer selectFromTxCountInPeriod(String address, Integer startTime, Integer endTime); BigDecimal selectAssetTransferAmountByAddress(String assetName, String fromAddress, String toAddress, Integer time); + + int selectSendTxCountByBlockHeight(String address, int startBlock, int endBlock); + + TxDetailDto selectFirstSendTxByBlockHeight(String address, int startBlock, int endBlock); } \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/IActivityDataService.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/IActivityDataService.java index 969899b1..b19adbc3 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/IActivityDataService.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/IActivityDataService.java @@ -1,5 +1,6 @@ package com.github.ontio.service; +import com.alibaba.fastjson.JSONObject; import com.github.ontio.model.dto.Anniversary6thDataDto; public interface IActivityDataService { @@ -9,4 +10,10 @@ public interface IActivityDataService { Integer queryAddressTxCountInPeriod(String address, Integer startTime, Integer endTime); String queryAddressCertainTimeBalance(String address, Integer timestamp); + + JSONObject queryAddressActiveTime(String address); + + JSONObject queryAddressSendTxInfo(String address); + + JSONObject queryRunningNodeInfo(String address); } diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/ActivityDataServiceImpl.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/ActivityDataServiceImpl.java index 1f4b44df..806d4fee 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/ActivityDataServiceImpl.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/ActivityDataServiceImpl.java @@ -1,22 +1,22 @@ package com.github.ontio.service.impl; +import com.alibaba.fastjson.JSONObject; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; import com.github.ontio.common.Address; +import com.github.ontio.common.Common; import com.github.ontio.common.Helper; -import com.github.ontio.mapper.GovernanceMapper; -import com.github.ontio.mapper.NodeInfoOnChainMapper; -import com.github.ontio.mapper.Oep4TxDetailMapper; -import com.github.ontio.mapper.TxDetailMapper; +import com.github.ontio.config.ParamsConfig; +import com.github.ontio.mapper.*; import com.github.ontio.model.dao.NodeInfoOnChain; -import com.github.ontio.model.dto.Anniversary6thDataDto; -import com.github.ontio.model.dto.GovernanceInfoDto; +import com.github.ontio.model.dto.*; import com.github.ontio.service.IActivityDataService; import com.github.ontio.util.ConstantParam; import com.github.ontio.util.OntologySDKService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import tk.mybatis.mapper.entity.Example; import java.math.BigDecimal; @@ -27,6 +27,8 @@ @Slf4j @Service public class ActivityDataServiceImpl implements IActivityDataService { + @Autowired + private ParamsConfig paramsConfig; @Autowired private GovernanceMapper governanceMapper; @Autowired @@ -36,6 +38,8 @@ public class ActivityDataServiceImpl implements IActivityDataService { @Autowired private NodeInfoOnChainMapper nodeInfoOnChainMapper; @Autowired + private OntidTxDetailMapper ontidTxDetailMapper; + @Autowired private OntologySDKService sdk; @@ -121,4 +125,71 @@ public String queryAddressCertainTimeBalance(String address, Integer timestamp) BigDecimal certainTimeBalance = ontBalance.add(fromAmount).subtract(toAmount); return certainTimeBalance.stripTrailingZeros().toPlainString(); } + + @Override + public JSONObject queryAddressActiveTime(String address) { + Integer activeTime = 0; + boolean registerOntId = false; + String ontId = Common.didont + address; + OntidTxDetailDto ontidTxDetailDto = ontidTxDetailMapper.selectOntIdCreateTime(ontId); + if (ontidTxDetailDto != null) { + activeTime = ontidTxDetailDto.getTxTime(); + registerOntId = true; + } else { + Example example = new Example(TxDetailDto.class); + example.selectProperties("txTime"); + example.createCriteria().andEqualTo("toAddress", address); + example.setOrderByClause("id LIMIT 1"); + TxDetailDto txDetailDto = txDetailMapper.selectOneByExample(example); + if (txDetailDto != null) { + activeTime = txDetailDto.getTxTime(); + } + } + JSONObject result = new JSONObject(); + result.put("registerOntId", registerOntId); + result.put("activeTime", activeTime); + return result; + } + + @Override + public JSONObject queryAddressSendTxInfo(String address) { + int firstTxTime = 0; + int startBlock2024 = 16980450; + int txCount = txDetailMapper.selectSendTxCountByBlockHeight(address, startBlock2024, paramsConfig.BLOCK_END_2024); + if (txCount > 0) { + TxDetailDto txDetailDto = txDetailMapper.selectFirstSendTxByBlockHeight(address, startBlock2024, paramsConfig.BLOCK_END_2024); + if (txDetailDto != null) { + firstTxTime = txDetailDto.getTxTime(); + } + } + JSONObject result = new JSONObject(); + result.put("txCount", txCount); + result.put("firstTxTime", firstTxTime); + return result; + } + + @Override + public JSONObject queryRunningNodeInfo(String address) { + String name = null; + int stakingAddress = 0; + List nodeInfoOnChainDtos = nodeInfoOnChainMapper.selectNodesByFilter("", address, "", 0, 0); + if (!CollectionUtils.isEmpty(nodeInfoOnChainDtos)) { + List publicKeyList = new ArrayList<>(); + for (NodeInfoOnChainDto nodeInfoOnChainDto : nodeInfoOnChainDtos) { + if (name == null) { + name = nodeInfoOnChainDto.getName(); + } + String publicKey = nodeInfoOnChainDto.getPublicKey(); + publicKeyList.add(publicKey); + } + stakingAddress = governanceMapper.getStakingAddressCount(publicKeyList); + } + boolean multipleNode = nodeInfoOnChainDtos.size() > 1; + + JSONObject result = new JSONObject(); + result.put("name", name); + result.put("stakingAddress", stakingAddress); + result.put("multipleNode", multipleNode); + return result; + } } diff --git a/back-end-projects/Explorer/src/main/resources/mapper/GovernanceMapper.xml b/back-end-projects/Explorer/src/main/resources/mapper/GovernanceMapper.xml index a8652588..aa31dfcf 100644 --- a/back-end-projects/Explorer/src/main/resources/mapper/GovernanceMapper.xml +++ b/back-end-projects/Explorer/src/main/resources/mapper/GovernanceMapper.xml @@ -12,6 +12,7 @@ withdraw_unfreeze_pos AS withdrawUnfreezePos FROM tbl_governance_info WHERE peer_pub_key = #{pubKey} + AND (consensus_pos > 0 OR candidate_pos > 0) ORDER BY consensus_pos + candidate_pos + new_pos DESC LIMIT #{start}, #{size} @@ -20,6 +21,7 @@ SELECT count(0) FROM tbl_governance_info WHERE peer_pub_key = #{pubKey} + AND (consensus_pos > 0 OR candidate_pos > 0) + + \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/resources/mapper/OntidTxDetailMapper.xml b/back-end-projects/Explorer/src/main/resources/mapper/OntidTxDetailMapper.xml index 71923b74..8964119c 100644 --- a/back-end-projects/Explorer/src/main/resources/mapper/OntidTxDetailMapper.xml +++ b/back-end-projects/Explorer/src/main/resources/mapper/OntidTxDetailMapper.xml @@ -60,4 +60,13 @@ where tx_hash = #{txHash} + + \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/resources/mapper/TxDetailMapper.xml b/back-end-projects/Explorer/src/main/resources/mapper/TxDetailMapper.xml index 60740ae8..ce6778c5 100644 --- a/back-end-projects/Explorer/src/main/resources/mapper/TxDetailMapper.xml +++ b/back-end-projects/Explorer/src/main/resources/mapper/TxDetailMapper.xml @@ -663,4 +663,22 @@ AND tx_time > #{time} + + + + \ No newline at end of file