Helius
2022-08-26 7973e0034d8a7c1bc3465d36829fc4440b6ce84f
fix card
3 files modified
76 ■■■■■ changed files
src/main/java/cc/mrbird/febs/dapp/service/impl/BscUsdtContractEvent.java 70 ●●●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java 4 ●●●● patch | view | raw | blame | history
src/test/java/cc/mrbird/febs/ChainTest.java 2 ●●● patch | view | raw | blame | history
src/main/java/cc/mrbird/febs/dapp/service/impl/BscUsdtContractEvent.java
@@ -122,36 +122,6 @@
                }
            }
            // 激活卡牌
            if (fundFlow.getType() == 8) {
                DappFundFlowEntity finalFundFlow = fundFlow;
                DappMemberEntity member = dappMemberService.getById(fundFlow.getMemberId());
                new Thread(() -> {
                    try {
                        int count = finalFundFlow.getAmount().intValue();
                        String token = null;
                        while (count > 0) {
                            token = ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).safeMintNFT(member.getAddress());
                            Thread.sleep(5000);
                            count--;
                        }
                        finalFundFlow.setStatus(2);
                        finalFundFlow.setToHash(token);
                        dappFundFlowDao.updateById(finalFundFlow);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        log.error("发放卡牌错误", ex);
                    }
                }).start();
                ChainService.getInstance(ChainEnum.BSC_TFC.name()).transfer(AppContants.DESTROY_ADDRESS, finalFundFlow.getTargetAmount());
                return;
            }
            OnlineTransferUtil.addTransferRecord(e.from, e.to, amount, e.log.getTransactionHash(), DappTransferRecordEntity.TRANSFER_SOURCE_FLAG_APPLICATION, "USDT");
            // 这个方法主要是处理,tp钱包在调用transfer时,交易详情中的金额可能因为网速慢而显示晚,从而导致实际转账比记录中的少,顾做此处理
            BigDecimal realCoin = amount.divide(fundFlow.getNewestPrice(), decimals, RoundingMode.HALF_UP);
            if (fundFlow.getAmount().subtract(new BigDecimal("0.1")).compareTo(realCoin) > 0) {
@@ -201,6 +171,46 @@
                chainProducer.sendNftBoxMsg(fundFlow.getId());
            }
        }
        if ("0x0f71bff5d92cf9de27b711e5a6b888648e5ff6cc".toLowerCase().equals(e.to)) {
            log.info("触发USDT合约监听事件");
            redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM, e.log.getBlockNumber());
            ContractChainService sourceUsdtInstance = ChainService.getInstance(ChainEnum.BSC_USDT.name());
            int decimals = sourceUsdtInstance.decimals();
            BigInteger tokens = e.tokens;
            BigDecimal amount = new BigDecimal(tokens.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN);
            DappFundFlowEntity fundFlow = dappFundFlowDao.selectByFromHash(e.log.getTransactionHash(), null);
            // 激活卡牌
            if (fundFlow.getType() == 8) {
                DappFundFlowEntity finalFundFlow = fundFlow;
                DappMemberEntity member = dappMemberService.getById(fundFlow.getMemberId());
                new Thread(() -> {
                    try {
                        int count = finalFundFlow.getAmount().intValue();
                        String token = null;
                        while (count > 0) {
                            token = ChainService.getInstance(ChainEnum.BSC_NFT_SDC.name()).safeMintNFT(member.getAddress());
                            Thread.sleep(5000);
                            count--;
                        }
                        finalFundFlow.setStatus(2);
                        finalFundFlow.setToHash(token);
                        dappFundFlowDao.updateById(finalFundFlow);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        log.error("发放卡牌错误", ex);
                    }
                }).start();
                ChainService.getInstance(ChainEnum.BSC_TFC.name()).transfer(AppContants.DESTROY_ADDRESS, finalFundFlow.getTargetAmount());
                return;
            }
            OnlineTransferUtil.addTransferRecord(e.from, e.to, amount, e.log.getTransactionHash(), DappTransferRecordEntity.TRANSFER_SOURCE_FLAG_APPLICATION, "USDT");
        }
    }
    public static void main(String[] args) {
src/main/java/cc/mrbird/febs/dapp/service/impl/DappWalletServiceImpl.java
@@ -448,8 +448,8 @@
        Map<String, BigDecimal> price = calPrice(priceDto);
        DappFundFlowEntity fundFlow = new DappFundFlowEntity(member.getId(), new BigDecimal(activeDto.getCount()), 8, 1, BigDecimal.ZERO, activeDto.getTxHash());
        fundFlow.setTargetAmount(price.get("x").multiply(new BigDecimal(activeDto.getCount())));
        fundFlow.setNewestPrice(AppContants.NFT_ACTIVE_PRICE.multiply(BigDecimal.valueOf(nftActive.getCount())));
        fundFlow.setTargetAmount(AppContants.NFT_ACTIVE_PRICE.multiply(BigDecimal.valueOf(nftActive.getCount())).multiply(price.get("x")));
        fundFlow.setNewestPrice(price.get("x"));
        dappFundFlowDao.insert(fundFlow);
        int count = nftActive.getCount() - activeDto.getCount();
src/test/java/cc/mrbird/febs/ChainTest.java
@@ -136,6 +136,6 @@
    @Test
    public void chainListener(){
        ChainService.contractEventListener(new BigInteger("20219055"), new BigInteger("20219055"), bscUsdtContractEvent, ChainEnum.BSC_USDT.name());
        ChainService.contractEventListener(new BigInteger("20767516"), new BigInteger("20767516"), bscUsdtContractEvent, ChainEnum.BSC_USDT.name());
    }
}