Skip to content

Commit

Permalink
add totalSupply api
Browse files Browse the repository at this point in the history
  • Loading branch information
zzsZhou committed Mar 11, 2020
1 parent fe2e78d commit 1d85f4f
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

@Slf4j
@RestController
@RequestMapping(value = "/v2/summary")
public class SummaryController {

private final String CLASS_NAME = this.getClass().getSimpleName();
Expand All @@ -27,15 +26,15 @@ public SummaryController(SummaryServiceImpl summaryService) {


@ApiOperation(value = "Get blockchain latest summary information")
@GetMapping(value = "/blockchain/latest-info")
@GetMapping(value = "/v2/summary/blockchain/latest-info")
public ResponseBean getBlockChainLatestInfo() {

log.info("####{}.{} begin...", CLASS_NAME, Helper.currentMethod());
return summaryService.getBlockChainLatestInfo();
}

@ApiOperation(value = "Get blockchain tps information")
@GetMapping(value = "/blockchain/tps")
@GetMapping(value = "/v2/summary/blockchain/tps")
public ResponseBean getBlockChainTps() {

log.info("####{}.{} begin...", CLASS_NAME, Helper.currentMethod());
Expand All @@ -45,7 +44,7 @@ public ResponseBean getBlockChainTps() {

@RequestLimit(count = 120)
@ApiOperation(value = "Get blockchain daily summary information")
@GetMapping(value = "/blockchain/daily")
@GetMapping(value = "/v2/summary/blockchain/daily")
public ResponseBean getBlockChainSummary(@RequestParam("start_time") Long startTime,
@RequestParam("end_time") Long endTime) {

Expand All @@ -60,7 +59,7 @@ public ResponseBean getBlockChainSummary(@RequestParam("start_time") Long startT

@RequestLimit(count = 120)
@ApiOperation(value = "Get contract daily summary information")
@GetMapping(value = "/contracts/{contract_hash}/daily")
@GetMapping(value = "/v2/summary/contracts/{contract_hash}/daily")
public ResponseBean getContractSummary(@PathVariable("contract_hash") @Length(min = 40, max = 40, message = "Incorrect contract hash") String contractHash,
@RequestParam("start_time") Long startTime,
@RequestParam("end_time") Long endTime) {
Expand All @@ -72,4 +71,24 @@ public ResponseBean getContractSummary(@PathVariable("contract_hash") @Length(mi
}
return summaryService.getContractDailySummary(contractHash, startTime, endTime);
}


@ApiOperation(value = "Get ONT,ONG total supply")
@GetMapping(value = "/v2/summary/native/totalsupply")
public ResponseBean queryNativeTotalSupply() {
log.info("####{}.{} begin...", CLASS_NAME, Helper.currentMethod());
ResponseBean rs = summaryService.getNativeTotalSupply();
return rs;
}


@ApiOperation(value = "Get ONT,ONG total supply")
@GetMapping(value = "/api/v1/explorer/summary/native/totalsupply")
public ResponseBean queryNativeTotalSupplyV1() {
log.info("####{}.{} begin...", CLASS_NAME, Helper.currentMethod());
ResponseBean rs = summaryService.getNativeTotalSupply();
return rs;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ public interface ISummaryService {
ResponseBean getBlockChainDailySummary(Long startTime, Long endTime);

ResponseBean getContractDailySummary(String contractHash, Long startTime, Long endTime);

ResponseBean getNativeTotalSupply();

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.github.ontio.util.ConstantParam;
import com.github.ontio.util.ErrorInfo;
import com.github.ontio.util.Helper;
import com.github.ontio.util.OntologySDKService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -25,21 +26,26 @@
@Service("SummaryService")
public class SummaryServiceImpl implements ISummaryService {

private static final Integer TIMESTAMP_20190630000000_UTC = 1561852800;
private static final Integer TIMESTAMP_20180630000000_UTC = 1530316800;

private final ParamsConfig paramsConfig;
private final TxEventLogMapper txEventLogMapper;
private final DailySummaryMapper dailySummaryMapper;
private final ContractDailySummaryMapper contractDailySummaryMapper;
private final CurrentMapper currentMapper;
private final AddressDailySummaryMapper addressDailySummaryMapper;
private final OntologySDKService ontologySDKService;

@Autowired
public SummaryServiceImpl(ParamsConfig paramsConfig, TxEventLogMapper txEventLogMapper, DailySummaryMapper dailySummaryMapper, ContractDailySummaryMapper contractDailySummaryMapper, CurrentMapper currentMapper, AddressDailySummaryMapper addressDailySummaryMapper) {
public SummaryServiceImpl(ParamsConfig paramsConfig, TxEventLogMapper txEventLogMapper, DailySummaryMapper dailySummaryMapper, ContractDailySummaryMapper contractDailySummaryMapper, CurrentMapper currentMapper, AddressDailySummaryMapper addressDailySummaryMapper, OntologySDKService ontologySDKService) {
this.paramsConfig = paramsConfig;
this.txEventLogMapper = txEventLogMapper;
this.dailySummaryMapper = dailySummaryMapper;
this.contractDailySummaryMapper = contractDailySummaryMapper;
this.currentMapper = currentMapper;
this.addressDailySummaryMapper = addressDailySummaryMapper;
this.ontologySDKService = ontologySDKService;
}


Expand Down Expand Up @@ -115,4 +121,27 @@ public ResponseBean getContractDailySummary(String contractHash, Long startTime,

return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), pageResponseBean);
}


@Override
public ResponseBean getNativeTotalSupply() {

BigDecimal specialAddrOnt = new BigDecimal("0");
for (String addr :
ConstantParam.SPECIALADDRLIST) {
Map<String, String> map = ontologySDKService.getNativeAssetBalance(addr);
specialAddrOnt = specialAddrOnt.add(new BigDecimal(map.get("ont")));
}
BigDecimal ontTotalSupply = ConstantParam.ONT_TOTAL.subtract(specialAddrOnt);

BigDecimal ong01 = new BigDecimal(TIMESTAMP_20190630000000_UTC).subtract(new BigDecimal(TIMESTAMP_20180630000000_UTC)).multiply(new BigDecimal(5));
BigDecimal ong02 = new BigDecimal(System.currentTimeMillis() / 1000L).subtract(new BigDecimal(TIMESTAMP_20190630000000_UTC)).multiply(paramsConfig.ONG_SECOND_GENERATE);
BigDecimal totalOng = ong01.add(ong02);
BigDecimal ongTotalSupply = totalOng.multiply(ontTotalSupply).divide(ConstantParam.ONT_TOTAL);

Map<String, BigDecimal> rsMap = new HashMap<>();
rsMap.put("ong", ongTotalSupply);
rsMap.put("ont", ontTotalSupply);
return new ResponseBean(ErrorInfo.SUCCESS.code(), ErrorInfo.SUCCESS.desc(), rsMap);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ public class ConstantParam {
//技术社区奖励锁仓地址
"AcdUMgeF16ScW9ts3kiD3pZkjYRMdYwtVQ",
//生态合作地址
"AMX6ZebrPDFELCYRMpSMbZWrhWkKbKg4y8");
"AMX6ZebrPDFELCYRMpSMbZWrhWkKbKg4y8",
//oge 地址
"ARHGtgY9Z8HdChFEjdPKKhpT4WDKfVntfC",
//社区地址
"ATBdqiUBKnNoJE4L53UkZZjWyFjd1AdamL",
//NEO counsel
"AR36E5jLdWDKW3Yg51qDFWPGKSLvfPhbqS",
//NGC
"Af48R4EUNYm6kg9kS7rn5xj4fneuFpbkXi");


//资产类型
Expand Down

0 comments on commit 1d85f4f

Please sign in to comment.