| | |
| | | package cc.mrbird.febs.dapp.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.dapp.chain.ChainEnum; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | |
| | | import cc.mrbird.febs.dapp.chain.EthUsdtContract; |
| | | import cc.mrbird.febs.dapp.entity.DappFundFlowEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappMemberEntity; |
| | | import cc.mrbird.febs.dapp.entity.DappTransferRecordEntity; |
| | | import cc.mrbird.febs.dapp.mapper.DappFundFlowDao; |
| | | import cc.mrbird.febs.dapp.service.DappMemberService; |
| | | import cc.mrbird.febs.dapp.service.DappWalletService; |
| | | import cc.mrbird.febs.dapp.utils.OnlineTransferUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.math.RoundingMode; |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | | @Service |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void compile(EthUsdtContract.TransferEventResponse e) { |
| | | if (e.to != null && e.to.equals(ChainEnum.BSC_TFC.getAddress().toLowerCase())) { |
| | | log.info("触发TFC监听"); |
| | | if (e.to == null) { |
| | | return; |
| | | } |
| | | |
| | | // try { |
| | | // Thread.sleep(5000); |
| | | // } catch (InterruptedException ex) { |
| | | // ex.printStackTrace(); |
| | | // } |
| | | redisUtils.set(AppContants.REDIS_KEY_BLOCK_COIN_NUM, e.log.getBlockNumber()); |
| | | redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM, e.log.getBlockNumber()); |
| | | if ("0x0Ba249b2FAC0061dd9c388Bd607418E16490A3fd".toLowerCase().equals(e.to)) { |
| | | log.info("触发GE手续费监听"); |
| | | |
| | | int decimals = ChainService.getInstance(ChainEnum.BSC_TFC.name()).decimals(); |
| | | |
| | | // 更新余额 |
| | | // 账户是否已经注册 |
| | | DappMemberEntity fromMember = dappMemberService.findByAddress(e.from, null); |
| | | if (fromMember == null) { |
| | | return; |
| | |
| | | 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 != null && fundFlow.getStatus() != 1) { |
| | | return; |
| | | } |
| | | |
| | | if (fundFlow == null) { |
| | | List<DappFundFlowEntity> flows = dappFundFlowDao.selectFundFlowListByAddress(e.from, 1); |
| | | if (CollUtil.isEmpty(flows)) { |
| | | OnlineTransferUtil.addTransferRecord(e.from, e.to, amount, e.log.getTransactionHash(), DappTransferRecordEntity.TRANSFER_SOURCE_FLAG_ONLINE, AppContants.SYMBOL_COIN); |
| | | log.info("本地无交易:{}", e.log.getTransactionHash()); |
| | | return; |
| | | } |
| | | |
| | | for (DappFundFlowEntity flow : flows) { |
| | | if (flow.getStatus() == 1) { |
| | | if (amount.compareTo(flow.getAmount()) == 0) { |
| | | fundFlow = flow; |
| | | fundFlow.setFromHash(e.log.getTransactionHash()); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (fundFlow == null) { |
| | | return; |
| | | } |
| | | |