From 20790816e1e2f87472f598f44bb64d90dc6fc051 Mon Sep 17 00:00:00 2001 From: leej1012 Date: Tue, 21 Nov 2023 16:18:16 +0800 Subject: [PATCH] Add token price and fiat rate Add 6th anniversary interface --- .../controller/ActivityDataController.java | 31 +++++++ .../ontio/controller/SummaryController.java | 10 ++- .../ontio/mapper/CurrencyRateMapper.java | 24 +++++ .../ontio/mapper/DailySummaryMapper.java | 2 + .../ontio/mapper/Oep4TxDetailMapper.java | 3 + .../github/ontio/mapper/TokenPriceMapper.java | 26 ++++++ .../github/ontio/model/dao/CurrencyRate.java | 37 ++++++++ .../github/ontio/model/dao/TokenPrice.java | 41 +++++++++ .../model/dto/Anniversary6thDataDto.java | 14 +++ .../github/ontio/model/dto/TokenInfoDto.java | 28 ++++++ .../ontio/service/IActivityDataService.java | 8 ++ .../github/ontio/service/ISummaryService.java | 3 + .../service/impl/ActivityDataServiceImpl.java | 88 +++++++++++++++++++ .../service/impl/SummaryServiceImpl.java | 52 ++++++++++- .../V1.80__tbl_token_price_currency_rate.sql | 17 ++++ .../resources/mapper/Oep4TxDetailMapper.xml | 21 +++++ .../resources/mapper/TokenPriceMapper.xml | 17 ++++ 17 files changed, 418 insertions(+), 4 deletions(-) create mode 100644 back-end-projects/Explorer/src/main/java/com/github/ontio/controller/ActivityDataController.java create mode 100644 back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/CurrencyRateMapper.java create mode 100644 back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/TokenPriceMapper.java create mode 100644 back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/CurrencyRate.java create mode 100644 back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/TokenPrice.java create mode 100644 back-end-projects/Explorer/src/main/java/com/github/ontio/model/dto/Anniversary6thDataDto.java create mode 100644 back-end-projects/Explorer/src/main/java/com/github/ontio/model/dto/TokenInfoDto.java create mode 100644 back-end-projects/Explorer/src/main/java/com/github/ontio/service/IActivityDataService.java create mode 100644 back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/ActivityDataServiceImpl.java create mode 100644 back-end-projects/Explorer/src/main/resources/db/migration/V1.80__tbl_token_price_currency_rate.sql create mode 100644 back-end-projects/Explorer/src/main/resources/mapper/TokenPriceMapper.xml 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 new file mode 100644 index 00000000..3bced80d --- /dev/null +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/ActivityDataController.java @@ -0,0 +1,31 @@ +package com.github.ontio.controller; + +import com.github.ontio.model.dto.Anniversary6thDataDto; +import com.github.ontio.service.IActivityDataService; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.hibernate.validator.constraints.Length; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@Validated +@Slf4j +@RestController +@RequestMapping(value = "/v2/data") +public class ActivityDataController { + + @Autowired + private IActivityDataService activityDataService; + + + @ApiOperation(value = "Get address 6th anniversary data") + @GetMapping(value = "/6th_anniversary/{address}") + public Anniversary6thDataDto queryAddress6thAnniversaryData(@PathVariable("address") @Length(min = 34, max = 42, message = "Incorrect address format") String address) { + return activityDataService.queryAddress6thAnniversaryData(address); + } + +} diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/SummaryController.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/SummaryController.java index 1fe9d78d..d6e8457f 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/SummaryController.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/controller/SummaryController.java @@ -2,6 +2,7 @@ import com.github.ontio.aop.RequestLimit; import com.github.ontio.model.common.ResponseBean; +import com.github.ontio.model.dto.TokenInfoDto; import com.github.ontio.service.impl.SummaryServiceImpl; import com.github.ontio.util.ConstantParam; import com.github.ontio.util.ErrorInfo; @@ -16,6 +17,7 @@ import org.springframework.web.bind.annotation.RestController; import java.math.BigDecimal; +import java.util.List; @Slf4j @RestController @@ -96,7 +98,7 @@ public ResponseBean queryNativeTotalSupplyV1() { return rs; } - @ApiOperation(value = "Get ONT,ONG total supply") + @ApiOperation(value = "Get ONT,ONG total circulating supply") @GetMapping(value = "/v2/summary/native/circulating-supply/{token}") public BigDecimal queryNativeTotalCirculatingSupply(@PathVariable String token) { log.info("####{}.{} begin...", CLASS_NAME, Helper.currentMethod()); @@ -113,4 +115,10 @@ public BigDecimal queryNativeTotalSupply(@PathVariable String token) { return null; } } + + @ApiOperation(value = "Get ONT,ONG token info") + @GetMapping(value = "/api/{token}/info") + public List queryTokenInfo(@PathVariable String token) { + return summaryService.queryTokenInfo(token); + } } diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/CurrencyRateMapper.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/CurrencyRateMapper.java new file mode 100644 index 00000000..62ce449d --- /dev/null +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/CurrencyRateMapper.java @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2018 The ontology Authors + * This file is part of The ontology library. + * The ontology is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * The ontology is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The ontology. If not, see . + */ + +package com.github.ontio.mapper; + +import com.github.ontio.model.dao.CurrencyRate; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + +@Repository +public interface CurrencyRateMapper extends Mapper { +} \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/DailySummaryMapper.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/DailySummaryMapper.java index 592ec1e2..1e1d9342 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/DailySummaryMapper.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/DailySummaryMapper.java @@ -2,12 +2,14 @@ import com.github.ontio.model.dto.DailySummaryDto; import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; import tk.mybatis.mapper.common.Mapper; import java.math.BigDecimal; import java.util.List; import java.util.Map; +@Repository public interface DailySummaryMapper extends Mapper { List selectSummaryByTime(@Param("startTime") Long startTime, @Param("endTime") Long endTime); diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/Oep4TxDetailMapper.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/Oep4TxDetailMapper.java index 099ef8b9..05582cb7 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/Oep4TxDetailMapper.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/Oep4TxDetailMapper.java @@ -6,6 +6,7 @@ import org.springframework.stereotype.Repository; import tk.mybatis.mapper.common.Mapper; +import java.math.BigDecimal; import java.util.List; @Repository @@ -15,4 +16,6 @@ public interface Oep4TxDetailMapper extends Mapper { Integer selectCountByCalledContracthash(@Param("calledContractHash") String calledContractHash); + BigDecimal selectTransferSumByCondition(String fromAddress, String toAddress, List calledContractHash, String assetName, Integer fromBlock, Integer toBlock); + } \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/TokenPriceMapper.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/TokenPriceMapper.java new file mode 100644 index 00000000..e30580be --- /dev/null +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/TokenPriceMapper.java @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2018 The ontology Authors + * This file is part of The ontology library. + * The ontology is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * The ontology is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The ontology. If not, see . + */ + +package com.github.ontio.mapper; + +import com.github.ontio.model.dao.TokenPrice; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; +import tk.mybatis.mapper.common.Mapper; + +@Repository +public interface TokenPriceMapper extends Mapper { + TokenPrice selectTokenPriceBySymbol(@Param("symbol") String symbol); +} \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/CurrencyRate.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/CurrencyRate.java new file mode 100644 index 00000000..eb2d0554 --- /dev/null +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/CurrencyRate.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2018 The ontology Authors + * This file is part of The ontology library. + * The ontology is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * The ontology is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The ontology. If not, see . + */ + +package com.github.ontio.model.dao; + +import lombok.Data; + +import javax.persistence.Column; +import javax.persistence.Id; +import javax.persistence.Table; +import java.math.BigDecimal; +import java.util.Date; + +@Data +@Table(name = "tbl_currency_rate") +public class CurrencyRate { + @Id + @Column(name = "currency_name") + private String currencyName; + + private BigDecimal price; + + @Column(name = "update_time") + private Date updateTime; +} \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/TokenPrice.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/TokenPrice.java new file mode 100644 index 00000000..e2603b54 --- /dev/null +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/TokenPrice.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2018 The ontology Authors + * This file is part of The ontology library. + * The ontology is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * The ontology is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * You should have received a copy of the GNU Lesser General Public License + * along with The ontology. If not, see . + */ + +package com.github.ontio.model.dao; + +import lombok.Data; + +import javax.persistence.Column; +import javax.persistence.Id; +import javax.persistence.Table; +import java.math.BigDecimal; +import java.util.Date; + +@Data +@Table(name = "tbl_token_price") +public class TokenPrice { + @Id + private String symbol; + + private BigDecimal price; + + @Column(name = "percent_change_24h") + private BigDecimal percentChange24h; + + private Integer rank; + + @Column(name = "update_time") + private Date updateTime; +} \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dto/Anniversary6thDataDto.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dto/Anniversary6thDataDto.java new file mode 100644 index 00000000..c6d59a8b --- /dev/null +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dto/Anniversary6thDataDto.java @@ -0,0 +1,14 @@ +package com.github.ontio.model.dto; + +import lombok.Data; + +@Data +public class Anniversary6thDataDto { + private Long stakingAmount; + + private Boolean stakingStOnt; + + private Boolean stakingStOntIn221; + + private Boolean runningNode; +} diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dto/TokenInfoDto.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dto/TokenInfoDto.java new file mode 100644 index 00000000..1e8b7478 --- /dev/null +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/model/dto/TokenInfoDto.java @@ -0,0 +1,28 @@ +package com.github.ontio.model.dto; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; + +import java.math.BigDecimal; + +@Data +@JsonInclude(JsonInclude.Include.NON_NULL) +public class TokenInfoDto { + private String symbol; + + private String currencyCode; + + private BigDecimal price; + + private BigDecimal marketCap; + + private BigDecimal accTradePrice24h; + + private long circulatingSupply; + + private long maxSupply; + + private String provider = "Ontology Foundation"; + + private long lastUpdatedTimestamp = System.currentTimeMillis(); +} 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 new file mode 100644 index 00000000..1b14a781 --- /dev/null +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/IActivityDataService.java @@ -0,0 +1,8 @@ +package com.github.ontio.service; + +import com.github.ontio.model.dto.Anniversary6thDataDto; + +public interface IActivityDataService { + + Anniversary6thDataDto queryAddress6thAnniversaryData(String address); +} diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/ISummaryService.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/ISummaryService.java index 05fb6f1b..fb5fc470 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/ISummaryService.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/ISummaryService.java @@ -1,8 +1,10 @@ package com.github.ontio.service; import com.github.ontio.model.common.ResponseBean; +import com.github.ontio.model.dto.TokenInfoDto; import java.math.BigDecimal; +import java.util.List; public interface ISummaryService { @@ -18,4 +20,5 @@ public interface ISummaryService { BigDecimal queryNativeTotalCirculatingSupply(String token); + List queryTokenInfo(String token); } 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 new file mode 100644 index 00000000..984885d5 --- /dev/null +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/ActivityDataServiceImpl.java @@ -0,0 +1,88 @@ +package com.github.ontio.service.impl; + +import com.github.ontio.mapper.CommonMapper; +import com.github.ontio.mapper.NodeInfoOnChainMapper; +import com.github.ontio.mapper.NodeOverviewHistoryMapper; +import com.github.ontio.mapper.Oep4TxDetailMapper; +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.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 tk.mybatis.mapper.entity.Example; + +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +@Slf4j +@Service +public class ActivityDataServiceImpl implements IActivityDataService { + @Autowired + private CommonMapper commonMapper; + @Autowired + private NodeOverviewHistoryMapper nodeOverviewHistoryMapper; + @Autowired + private Oep4TxDetailMapper oep4TxDetailMapper; + @Autowired + private NodeInfoOnChainMapper nodeInfoOnChainMapper; + @Autowired + private OntologySDKService sdk; + + + private static final String OLD_STONT_NODE_CONTRACT = "6525d1b24228ef698d14c3214a5bb41f0a9112ea"; + + private static final String NEW_STONT_NODE_CONTRACT = "ededc698631ef4eccb3c3b98e7cc73a629be94b8"; + + private static final String STONT_CONTRACT = "e9ec04127b57c5686310f8fac28dc617f21f84cd"; + + private static final String ZERO_ADDRESS = "AFmseVrdL9f9oyCzZefL9tG6UbvhPbdYzM"; + + private static final int CYCLE_221_END_BLOCK = 16794299; + + + @Override + public Anniversary6thDataDto queryAddress6thAnniversaryData(String address) { + // ONT质押数量 + List stakingInfoByAddress = commonMapper.getStakingInfoByAddress(address); + long stakingAmount = 0; + for (GovernanceInfoDto governanceInfoDto : stakingInfoByAddress) { + Long consensusPos = governanceInfoDto.getConsensusPos(); + Long candidatePos = governanceInfoDto.getCandidatePos(); + stakingAmount = stakingAmount + consensusPos + candidatePos; + } + + // 是否参与stONT质押 + boolean stakingStOnt = false; + BigDecimal stOntBalance = new BigDecimal(sdk.getWasmvmOep4AssetBalance(address, STONT_CONTRACT)).divide(ConstantParam.NEW_ONT_DECIMAL, 9, RoundingMode.DOWN); + List list = Arrays.asList(OLD_STONT_NODE_CONTRACT, NEW_STONT_NODE_CONTRACT); + BigDecimal mintAmount = oep4TxDetailMapper.selectTransferSumByCondition(ZERO_ADDRESS, address, list, "stONT", null, null); + BigDecimal unstakeAmount = oep4TxDetailMapper.selectTransferSumByCondition(address, ZERO_ADDRESS, list, "stONT", null, null); + BigDecimal mintRemainAmount = mintAmount.subtract(unstakeAmount); + if (mintRemainAmount.compareTo(stOntBalance) >= 0) { + stakingStOnt = true; + } + // 是否参与221轮 stONT质押 + BigDecimal mintAmountBeforeCycle222 = oep4TxDetailMapper.selectTransferSumByCondition(ZERO_ADDRESS, address, Collections.singletonList(OLD_STONT_NODE_CONTRACT), "stONT", null, CYCLE_221_END_BLOCK); + boolean stakingStOntIn221 = BigDecimal.ZERO.compareTo(mintAmountBeforeCycle222) < 0; + + // 是否运行节点 + Example example = new Example(NodeInfoOnChain.class); + example.createCriteria().andEqualTo("address", address); + int count = nodeInfoOnChainMapper.selectCountByExample(example); + boolean runningNode = count > 0; + + Anniversary6thDataDto anniversary6thDataDto = new Anniversary6thDataDto(); + anniversary6thDataDto.setStakingAmount(stakingAmount); + anniversary6thDataDto.setStakingStOnt(stakingStOnt); + anniversary6thDataDto.setStakingStOntIn221(stakingStOntIn221); + anniversary6thDataDto.setRunningNode(runningNode); + return anniversary6thDataDto; + } +} diff --git a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/SummaryServiceImpl.java b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/SummaryServiceImpl.java index 0442a4b9..def85030 100644 --- a/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/SummaryServiceImpl.java +++ b/back-end-projects/Explorer/src/main/java/com/github/ontio/service/impl/SummaryServiceImpl.java @@ -4,10 +4,13 @@ import com.github.ontio.mapper.*; import com.github.ontio.model.common.PageResponseBean; import com.github.ontio.model.common.ResponseBean; +import com.github.ontio.model.dao.CurrencyRate; import com.github.ontio.model.dao.OngSupply; +import com.github.ontio.model.dao.TokenPrice; import com.github.ontio.model.dto.ContractDailySummaryDto; import com.github.ontio.model.dto.CurrentDto; import com.github.ontio.model.dto.DailySummaryDto; +import com.github.ontio.model.dto.TokenInfoDto; import com.github.ontio.service.ISummaryService; import com.github.ontio.util.ConstantParam; import com.github.ontio.util.ErrorInfo; @@ -19,7 +22,9 @@ import org.springframework.util.CollectionUtils; import java.math.BigDecimal; +import java.math.RoundingMode; import java.text.DecimalFormat; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -41,10 +46,12 @@ public class SummaryServiceImpl implements ISummaryService { private final AddressDailySummaryMapper addressDailySummaryMapper; private final OntologySDKService ontologySDKService; private final OngSupplyMapper ongSupplyMapper; + private final CurrencyRateMapper currencyRateMapper; + private final TokenPriceMapper tokenPriceMapper; @Autowired public SummaryServiceImpl(ParamsConfig paramsConfig, TxEventLogMapper txEventLogMapper, DailySummaryMapper dailySummaryMapper, ContractDailySummaryMapper contractDailySummaryMapper, CurrentMapper currentMapper, AddressDailySummaryMapper addressDailySummaryMapper, OntologySDKService ontologySDKService - , OngSupplyMapper ongSupplyMapper) { + , OngSupplyMapper ongSupplyMapper, CurrencyRateMapper currencyRateMapper, TokenPriceMapper tokenPriceMapper) { this.paramsConfig = paramsConfig; this.txEventLogMapper = txEventLogMapper; this.dailySummaryMapper = dailySummaryMapper; @@ -53,6 +60,8 @@ public SummaryServiceImpl(ParamsConfig paramsConfig, TxEventLogMapper txEventLog this.addressDailySummaryMapper = addressDailySummaryMapper; this.ontologySDKService = ontologySDKService; this.ongSupplyMapper = ongSupplyMapper; + this.currencyRateMapper = currencyRateMapper; + this.tokenPriceMapper = tokenPriceMapper; } @@ -169,11 +178,11 @@ public BigDecimal queryNativeTotalCirculatingSupply(String token) { } BigDecimal ontTotalSupply = ConstantParam.ONT_TOTAL.subtract(specialAddrOnt); - if (ConstantParam.ONT.equals(token.toLowerCase())) { + if (ConstantParam.ONT.equalsIgnoreCase(token)) { return ontTotalSupply; } - if (ConstantParam.ONG.equals(token.toLowerCase())) { + if (ConstantParam.ONG.equalsIgnoreCase(token)) { BigDecimal ong01 = new BigDecimal(TIMESTAMP_20190630000000_UTC).subtract(new BigDecimal(TIMESTAMP_20180630000000_UTC)).multiply(new BigDecimal(5)); BigDecimal ong02 = new BigDecimal(TIMESTAMP_20200629000000_UTC).subtract(new BigDecimal(TIMESTAMP_20190630000000_UTC)).multiply(new BigDecimal(4)); BigDecimal ong03 = new BigDecimal(TIMESTAMP_20200707000000_UTC).subtract(new BigDecimal(TIMESTAMP_20200629000000_UTC)).multiply(new BigDecimal(3)); @@ -194,4 +203,41 @@ public BigDecimal queryNativeTotalCirculatingSupply(String token) { } return null; } + + @Override + public List queryTokenInfo(String token) { + String symbol; + long maxSupply; + if (ConstantParam.ONT.equalsIgnoreCase(token)) { + symbol = ConstantParam.ONT.toUpperCase(); + maxSupply = 1000000000L; + } else if (ConstantParam.ONG.equalsIgnoreCase(token)) { + symbol = ConstantParam.ONG.toUpperCase(); + maxSupply = 1000000000L; + } else { + return null; + } + BigDecimal circulatingSupply = queryNativeTotalCirculatingSupply(symbol); + + TokenPrice tokenPrice = tokenPriceMapper.selectTokenPriceBySymbol(symbol); + BigDecimal price = tokenPrice.getPrice(); + + List currencyRates = currencyRateMapper.selectAll(); + List result = new ArrayList<>(); + for (CurrencyRate currencyRate : currencyRates) { + String currencyName = currencyRate.getCurrencyName(); + BigDecimal currencyRatePrice = currencyRate.getPrice(); + BigDecimal currencyPrice = price.multiply(currencyRatePrice).setScale(4, RoundingMode.DOWN); + BigDecimal marketCap = currencyPrice.multiply(circulatingSupply).stripTrailingZeros(); + TokenInfoDto tokenInfoDto = new TokenInfoDto(); + tokenInfoDto.setSymbol(symbol); + tokenInfoDto.setCurrencyCode(currencyName); + tokenInfoDto.setPrice(currencyPrice); + tokenInfoDto.setMarketCap(marketCap); + tokenInfoDto.setCirculatingSupply(circulatingSupply.longValue()); + tokenInfoDto.setMaxSupply(maxSupply); + result.add(tokenInfoDto); + } + return result; + } } diff --git a/back-end-projects/Explorer/src/main/resources/db/migration/V1.80__tbl_token_price_currency_rate.sql b/back-end-projects/Explorer/src/main/resources/db/migration/V1.80__tbl_token_price_currency_rate.sql new file mode 100644 index 00000000..1dda3d02 --- /dev/null +++ b/back-end-projects/Explorer/src/main/resources/db/migration/V1.80__tbl_token_price_currency_rate.sql @@ -0,0 +1,17 @@ +CREATE TABLE `tbl_token_price` +( + `symbol` varchar(50) NOT NULL COMMENT 'token符号', + `price` decimal(60, 20) DEFAULT NULL COMMENT 'token兑USDT价格', + `percent_change_24h` decimal(60, 20) DEFAULT NULL COMMENT '24小时价格变化', + `rank` int(11) DEFAULT NULL COMMENT '排名', + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + PRIMARY KEY (`symbol`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + +CREATE TABLE `tbl_currency_rate` +( + `currency_name` varchar(20) NOT NULL COMMENT '法币名称', + `price` decimal(64, 20) DEFAULT NULL COMMENT '价格', + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + PRIMARY KEY (`currency_name`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/resources/mapper/Oep4TxDetailMapper.xml b/back-end-projects/Explorer/src/main/resources/mapper/Oep4TxDetailMapper.xml index 7a7335e8..fef57e12 100644 --- a/back-end-projects/Explorer/src/main/resources/mapper/Oep4TxDetailMapper.xml +++ b/back-end-projects/Explorer/src/main/resources/mapper/Oep4TxDetailMapper.xml @@ -56,4 +56,25 @@ where called_contract_hash = #{calledContractHash} + + \ No newline at end of file diff --git a/back-end-projects/Explorer/src/main/resources/mapper/TokenPriceMapper.xml b/back-end-projects/Explorer/src/main/resources/mapper/TokenPriceMapper.xml new file mode 100644 index 00000000..91c03839 --- /dev/null +++ b/back-end-projects/Explorer/src/main/resources/mapper/TokenPriceMapper.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + \ No newline at end of file