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 d6500a4c..f25c4127 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 @@ -8,10 +8,7 @@ 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; +import org.springframework.web.bind.annotation.*; @Validated @Slf4j @@ -29,4 +26,17 @@ public Anniversary6thDataDto queryAddress6thAnniversaryData(@PathVariable("addre return activityDataService.queryAddress6thAnniversaryData(address); } + @RequestLimit(count = 120) + @ApiOperation(value = "Get address tx count in a period") + @GetMapping(value = "/tx_count_in_period") + public Integer queryAddressTxCountInPeriod(@RequestParam @Length(min = 34, max = 42, message = "Incorrect address format") String address, @RequestParam(required = false) Integer startTime, @RequestParam(required = false) Integer endTime) { + return activityDataService.queryAddressTxCountInPeriod(address, startTime, endTime); + } + + @RequestLimit(count = 120) + @ApiOperation(value = "Get address balance at a certain time") + @GetMapping(value = "/certain_time_balance") + public String queryAddressCertainTimeBalance(@RequestParam @Length(min = 34, max = 42, message = "Incorrect address format") String address, @RequestParam Integer timestamp) { + return activityDataService.queryAddressCertainTimeBalance(address, timestamp); + } } 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 6eac26bb..23f8c233 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 @@ -6,6 +6,7 @@ import org.springframework.stereotype.Repository; import tk.mybatis.mapper.common.Mapper; +import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -80,4 +81,8 @@ List selectTransferTxsOfHashes(@Param("address") String address, Integer selectTransferTxsCountOfHashes(@Param("address") String address, @Param("hashes") List contractHashes, @Param("assetNames") List assetNames, @Param("tokenType") String tokenType); List> selectByAddressAndTxTime(@Param("address") String address, @Param("startTime") Integer startTime, @Param("endTime") Integer endTime); + + Integer selectFromTxCountInPeriod(String address, Integer startTime, Integer endTime); + + BigDecimal selectAssetTransferAmountByAddress(String assetName, String fromAddress, String toAddress, Integer time); } \ 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 1b14a781..969899b1 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 @@ -5,4 +5,8 @@ public interface IActivityDataService { Anniversary6thDataDto queryAddress6thAnniversaryData(String address); + + Integer queryAddressTxCountInPeriod(String address, Integer startTime, Integer endTime); + + String queryAddressCertainTimeBalance(String address, Integer timestamp); } 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 b3168fc3..877ba878 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 @@ -6,8 +6,8 @@ import com.github.ontio.common.Helper; 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.mapper.TxDetailMapper; import com.github.ontio.model.dao.NodeInfoOnChain; import com.github.ontio.model.dto.Anniversary6thDataDto; import com.github.ontio.model.dto.GovernanceInfoDto; @@ -30,7 +30,7 @@ public class ActivityDataServiceImpl implements IActivityDataService { @Autowired private CommonMapper commonMapper; @Autowired - private NodeOverviewHistoryMapper nodeOverviewHistoryMapper; + private TxDetailMapper txDetailMapper; @Autowired private Oep4TxDetailMapper oep4TxDetailMapper; @Autowired @@ -107,4 +107,18 @@ public void initNodePublicKeyAddress() { return addressList; }); } + + @Override + public Integer queryAddressTxCountInPeriod(String address, Integer startTime, Integer endTime) { + return txDetailMapper.selectFromTxCountInPeriod(address, startTime, endTime); + } + + @Override + public String queryAddressCertainTimeBalance(String address, Integer timestamp) { + BigDecimal ontBalance = new BigDecimal((String) sdk.getNativeAssetBalance(address).get(ConstantParam.ONT)); + BigDecimal fromAmount = txDetailMapper.selectAssetTransferAmountByAddress(ConstantParam.ONT, address, null, timestamp); + BigDecimal toAmount = txDetailMapper.selectAssetTransferAmountByAddress(ConstantParam.ONT, null, address, timestamp); + BigDecimal certainTimeBalance = ontBalance.add(fromAmount).subtract(toAmount); + return certainTimeBalance.stripTrailingZeros().toPlainString(); + } } 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 b0e73377..edf5e9c9 100644 --- a/back-end-projects/Explorer/src/main/resources/mapper/TxDetailMapper.xml +++ b/back-end-projects/Explorer/src/main/resources/mapper/TxDetailMapper.xml @@ -634,4 +634,33 @@ block_height, block_index LIMIT 5000; + + + + \ No newline at end of file