Skip to content

Commit

Permalink
Update queryAddress6thAnniversaryData
Browse files Browse the repository at this point in the history
  • Loading branch information
leej1012 committed Dec 6, 2023
1 parent dd182cc commit 7ecfadf
Showing 1 changed file with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.github.ontio.service.impl;

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.Helper;
import com.github.ontio.mapper.CommonMapper;
import com.github.ontio.mapper.NodeInfoOnChainMapper;
import com.github.ontio.mapper.NodeOverviewHistoryMapper;
Expand All @@ -17,9 +21,8 @@

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.time.Duration;
import java.util.*;

@Slf4j
@Service
Expand Down Expand Up @@ -65,18 +68,19 @@ public Anniversary6thDataDto queryAddress6thAnniversaryData(String address) {
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) {
if (BigDecimal.ZERO.compareTo(mintAmount) != 0 && 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;

// 是否运行节点
List<String> publicKeyAddressList = Optional.ofNullable(nodePublicKeyAddress.get("1")).orElse(Collections.emptyList());
Example example = new Example(NodeInfoOnChain.class);
example.createCriteria().andEqualTo("address", address);
int count = nodeInfoOnChainMapper.selectCountByExample(example);
boolean runningNode = count > 0;
boolean runningNode = count > 0 || publicKeyAddressList.contains(address);

Anniversary6thDataDto anniversary6thDataDto = new Anniversary6thDataDto();
anniversary6thDataDto.setStakingAmount(stakingAmount);
Expand All @@ -85,4 +89,22 @@ public Anniversary6thDataDto queryAddress6thAnniversaryData(String address) {
anniversary6thDataDto.setRunningNode(runningNode);
return anniversary6thDataDto;
}

private LoadingCache<String, List<String>> nodePublicKeyAddress;

@Autowired
public void initNodePublicKeyAddress() {
nodePublicKeyAddress = Caffeine.newBuilder()
.expireAfterWrite(Duration.ofMinutes(5))
.build(key -> {
List<String> addressList = new ArrayList<>();
List<NodeInfoOnChain> nodeInfoOnChains = nodeInfoOnChainMapper.selectAll();
for (NodeInfoOnChain nodeInfoOnChain : nodeInfoOnChains) {
String publicKey = nodeInfoOnChain.getPublicKey();
String address = Address.addressFromPubKey(Helper.hexToBytes(publicKey)).toBase58();
addressList.add(address);
}
return addressList;
});
}
}

0 comments on commit 7ecfadf

Please sign in to comment.