fix
Helius
2022-08-01 09ffce575fbab168997262c8ce20b048f7e047b2
fix
5 files modified
1 files added
86 ■■■■■ changed files
src/main/java/cc/mrbird/febs/dapp/chain/ContractChainService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/chain/EthService.java 29 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/chain/TrxService.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/enumerate/CardPeriod.java 36 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java 5 ●●●●● patch | view | raw | blame | history
src/test/java/cc/mrbird/febs/ChainTest.java 9 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/chain/ContractChainService.java
@@ -25,5 +25,7 @@
    BigInteger totalSupply();
    BigInteger totalSupplyNFT();
    String safeMintNFT(String address);
}
src/main/java/cc/mrbird/febs/dapp/chain/EthService.java
@@ -362,6 +362,35 @@
    }
    @Override
    public BigInteger totalSupplyNFT() {
        try {
            String methodName = "totalSupply";
            List<Type> inputParameters = new ArrayList<>();
            List<TypeReference<?>> outputParameters = new ArrayList<>();
            TypeReference<Uint256> typeReference = new TypeReference<Uint256>() {
            };
            outputParameters.add(typeReference);
            Function function = new Function(methodName, inputParameters, outputParameters);
            String data = FunctionEncoder.encode(function);
            Transaction transaction = Transaction.createEthCallTransaction(null, contractAddress, data);
            EthCall ethCall;
            BigInteger totalSupply = BigInteger.ZERO;
            try {
                ethCall = web3j.ethCall(transaction, DefaultBlockParameterName.LATEST).send();
                List<Type> results = FunctionReturnDecoder.decode(ethCall.getValue(), function.getOutputParameters());
                totalSupply = (BigInteger) results.get(0).getValue();
                return totalSupply;
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return BigInteger.ZERO;
    }
    @Override
    public String safeMintNFT(String toAddress) {
        String gas = getGas();
src/main/java/cc/mrbird/febs/dapp/chain/TrxService.java
@@ -115,6 +115,11 @@
    }
    @Override
    public BigInteger totalSupplyNFT() {
        return null;
    }
    @Override
    public String safeMintNFT(String address) {
        return null;
    }
src/main/java/cc/mrbird/febs/dapp/enumerate/CardPeriod.java
New file
@@ -0,0 +1,36 @@
package cc.mrbird.febs.dapp.enumerate;
/**
 * 卡牌分期
 */
public enum CardPeriod {
    ONE(0,1000, 6),
    TWO(1001,1500, 9),
    THREE(2501,1500, 12);
    private int min;
    private int cardCnt;
    private int recommendCnt;
    CardPeriod(int min, int cardCnt, int recommendCnt) {
        this.min = min;
        this.cardCnt = cardCnt;
        this.recommendCnt = recommendCnt;
    }
    public int recommendCnt(int totalSupply) {
        for (CardPeriod value : CardPeriod.values()) {
            if (value.min <= totalSupply && totalSupply < (value.min + value.cardCnt)) {
                return value.recommendCnt;
            }
        }
        return 0;
    }
}
src/main/java/cc/mrbird/febs/dapp/service/impl/DappSystemServiceImpl.java
@@ -8,6 +8,7 @@
import cc.mrbird.febs.dapp.chain.ContractChainService;
import cc.mrbird.febs.dapp.dto.SystemDto;
import cc.mrbird.febs.dapp.entity.*;
import cc.mrbird.febs.dapp.enumerate.CardPeriod;
import cc.mrbird.febs.dapp.mapper.*;
import cc.mrbird.febs.dapp.service.DappSystemService;
import cc.mrbird.febs.dapp.utils.OnlineTransferUtil;
@@ -644,7 +645,7 @@
            return;
        }
        DataDictionaryCustom boxRecommendCnt = dataDictionaryCustomMapper.selectDicDataByTypeAndCode(AppContants.DIC_TYPE_SYSTEM_SETTING, AppContants.DIC_VALUE_BOX_RECOMMEND_CNT);
        BigInteger totalSupply = ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).totalSupplyNFT();
        int box = 0;
        // 需要第一次购买,才在推荐中加1
        Object parentRecommend = redisUtils.hget(AppContants.IDO_MEMBER_RECOMMEND_CNT, parent.getAddress());
@@ -654,7 +655,7 @@
            int i = (int) parentRecommend;
            // 如果超过10个,则新增一个盲盒,并重置推荐人数
            if (++i == new Integer(boxRecommendCnt.getValue())) {
            if (++i == CardPeriod.ONE.recommendCnt(totalSupply.intValue())) {
                box = 1;
                redisUtils.hset(AppContants.IDO_MEMBER_RECOMMEND_CNT, parent.getAddress(), 0);
            } else {
src/test/java/cc/mrbird/febs/ChainTest.java
@@ -5,6 +5,7 @@
import cc.mrbird.febs.dapp.chain.ContractChainService;
import cc.mrbird.febs.dapp.entity.DappFundFlowEntity;
import cc.mrbird.febs.dapp.entity.DappOnlineTransferEntity;
import cc.mrbird.febs.dapp.enumerate.CardPeriod;
import cc.mrbird.febs.dapp.mapper.DappFundFlowDao;
import cc.mrbird.febs.dapp.mapper.DappOnlineTransferDao;
import cc.mrbird.febs.dapp.service.DappSystemService;
@@ -119,4 +120,12 @@
    public void nftBalanceTest() {
        BigDecimal balance = ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).balanceOf("0x971c09aa9735eb98459b17ec8b48932d24cbb931");
        System.out.println(1);
    }
    @Test
    public void nftTotalSupplyTest() {
        BigInteger bigInteger = ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).totalSupplyNFT();
        int i = CardPeriod.ONE.recommendCnt(bigInteger.intValue());
        System.out.println(i);
    }}