-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 6th anniversary interface
- Loading branch information
Showing
17 changed files
with
418 additions
and
4 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...d-projects/Explorer/src/main/java/com/github/ontio/controller/ActivityDataController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/CurrencyRateMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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<CurrencyRate> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
back-end-projects/Explorer/src/main/java/com/github/ontio/mapper/TokenPriceMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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> { | ||
TokenPrice selectTokenPriceBySymbol(@Param("symbol") String symbol); | ||
} |
37 changes: 37 additions & 0 deletions
37
back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/CurrencyRate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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; | ||
} |
41 changes: 41 additions & 0 deletions
41
back-end-projects/Explorer/src/main/java/com/github/ontio/model/dao/TokenPrice.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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; | ||
} |
14 changes: 14 additions & 0 deletions
14
...end-projects/Explorer/src/main/java/com/github/ontio/model/dto/Anniversary6thDataDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
28 changes: 28 additions & 0 deletions
28
back-end-projects/Explorer/src/main/java/com/github/ontio/model/dto/TokenInfoDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} |
8 changes: 8 additions & 0 deletions
8
back-end-projects/Explorer/src/main/java/com/github/ontio/service/IActivityDataService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.github.ontio.service; | ||
|
||
import com.github.ontio.model.dto.Anniversary6thDataDto; | ||
|
||
public interface IActivityDataService { | ||
|
||
Anniversary6thDataDto queryAddress6thAnniversaryData(String address); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
...rojects/Explorer/src/main/java/com/github/ontio/service/impl/ActivityDataServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<GovernanceInfoDto> 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<String> 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; | ||
} | ||
} |
Oops, something went wrong.