| | |
| | | package cc.mrbird.febs.dapp.service.impl; |
| | | |
| | | import cc.mrbird.febs.common.contants.AppContants; |
| | | import cc.mrbird.febs.common.enumerates.DataDicEnum; |
| | | import cc.mrbird.febs.common.enumerates.FlowTypeEnum; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.common.utils.ShareCodeUtil; |
| | | import cc.mrbird.febs.dapp.chain.ChainEnum; |
| | | import cc.mrbird.febs.dapp.chain.ChainService; |
| | | import cc.mrbird.febs.dapp.chain.ContractEventService; |
| | | import cc.mrbird.febs.dapp.chain.EthUsdtContract; |
| | | import cc.mrbird.febs.dapp.entity.*; |
| | | import cc.mrbird.febs.dapp.mapper.DappFundFlowDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappMemberDao; |
| | | import cc.mrbird.febs.dapp.mapper.DappMemberFundMapper; |
| | | import cc.mrbird.febs.dapp.mapper.DappOnlineTransferDao; |
| | | import cc.mrbird.febs.dapp.mapper.*; |
| | | import cc.mrbird.febs.dapp.service.DappMemberService; |
| | | import cc.mrbird.febs.dapp.service.DappSystemService; |
| | | import cc.mrbird.febs.dapp.utils.OnlineTransferUtil; |
| | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | import java.math.RoundingMode; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Locale; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | |
| | | |
| | | @Resource |
| | | private ChainProducer chainProducer; |
| | | |
| | | @Resource |
| | | private DappHdRecordMapper dappHdRecordMapper; |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(Numeric.toBigInt("0x12e4e85")); |
| | |
| | | * 生成对应的产矿流水 |
| | | */ |
| | | String address = e.adr; |
| | | String blockHash = e.blockHash; |
| | | DappMemberEntity dappMemberEntity = dappMemberDao.selectByAddress(address, null); |
| | | if(ObjectUtil.isEmpty(dappMemberEntity)){ |
| | | return; |
| | | } |
| | | int decimals = ChainService.getInstance(ChainEnum.BSC_TFC.name()).decimals(); |
| | | BigDecimal amount = new BigDecimal(e.amount.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN); |
| | | BigDecimal price = new BigDecimal(e.price.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN); |
| | | BigDecimal sameCoin = new BigDecimal(e.sameCoin.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN); |
| | | BigDecimal finxMineCoin = new BigDecimal(e.finxMineCoin.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN); |
| | | int decimals = ChainService.getInstance(ChainEnum.BSC_GFA.name()).decimals(); |
| | | BigDecimal amount = new BigDecimal(e.amount.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN); |
| | | BigDecimal price = new BigDecimal(e.price.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN); |
| | | BigDecimal usdtTarget = new BigDecimal(e.usdtTarget.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN); |
| | | BigDecimal coinTarget = new BigDecimal(e.coinTarget.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN); |
| | | BigDecimal usdtCoin = new BigDecimal(e.usdtCoin.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN); |
| | | BigInteger lastMineTime = e.lastMineTime; |
| | | BigInteger thisMineTime = e.thisMineTime; |
| | | |
| | | Long memberId = dappMemberEntity.getId(); |
| | | DappMemberFund dappMemberFund = new DappMemberFund(); |
| | | dappMemberFund.setMemberId(memberId); |
| | | dappMemberFund.setAddress(address); |
| | | dappMemberFund.setAmount(amount); |
| | | dappMemberFund.setPrice(price); |
| | | dappMemberFund.setSameCoin(sameCoin); |
| | | dappMemberFund.setFinxMineCoin(finxMineCoin); |
| | | dappMemberFund.setLastMineTime(lastMineTime.toString()); |
| | | dappMemberFund.setThisMineTime(thisMineTime.toString()); |
| | | dappMemberFundMapper.insert(dappMemberFund); |
| | | QueryWrapper<DappMemberFund> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("block_hash",blockHash); |
| | | objectQueryWrapper.eq("address",address); |
| | | objectQueryWrapper.eq("price",price); |
| | | objectQueryWrapper.eq("usdt_target",usdtTarget); |
| | | objectQueryWrapper.eq("coin_target",coinTarget); |
| | | List<DappMemberFund> dappMemberFunds = dappMemberFundMapper.selectList(objectQueryWrapper); |
| | | if(CollUtil.isEmpty(dappMemberFunds)){ |
| | | Long memberId = dappMemberEntity.getId(); |
| | | DappMemberFund dappMemberFund = new DappMemberFund(); |
| | | dappMemberFund.setMemberId(memberId); |
| | | dappMemberFund.setAddress(address); |
| | | dappMemberFund.setBlockHash(blockHash); |
| | | dappMemberFund.setAmount(amount); |
| | | dappMemberFund.setPrice(price); |
| | | dappMemberFund.setUsdtTarget(usdtTarget); |
| | | dappMemberFund.setCoinTarget(coinTarget); |
| | | dappMemberFund.setUsdtCoin(usdtCoin); |
| | | dappMemberFund.setLastMineTime(lastMineTime.toString()); |
| | | dappMemberFundMapper.insert(dappMemberFund); |
| | | |
| | | DappFundFlowEntity fundFlowTuiJian1 = new DappFundFlowEntity( |
| | | memberId, |
| | | usdtTarget, |
| | | FlowTypeEnum.ZHIYA_CHA_CHU.getValue(), |
| | | DappFundFlowEntity.WITHDRAW_STATUS_AGREE, |
| | | StrUtil.format("金本位{},价格{}。",usdtTarget,price)); |
| | | |
| | | DappFundFlowEntity fundFlowTuiJian1 = new DappFundFlowEntity( |
| | | memberId, |
| | | amount, |
| | | FlowTypeEnum.ZHIYA_CHA_CHU.getValue(), |
| | | DappFundFlowEntity.WITHDRAW_STATUS_AGREE, |
| | | StrUtil.format("金本位{}",sameCoin)); |
| | | dappFundFlowDao.insert(fundFlowTuiJian1); |
| | | |
| | | dappFundFlowDao.insert(fundFlowTuiJian1); |
| | | DappFundFlowEntity fundFlowTuiJian2 = new DappFundFlowEntity( |
| | | memberId, |
| | | coinTarget, |
| | | FlowTypeEnum.ZHIYA_CHA_CHU.getValue(), |
| | | DappFundFlowEntity.WITHDRAW_STATUS_AGREE, |
| | | StrUtil.format("币本位{},价格{}。",coinTarget,price)); |
| | | dappFundFlowDao.insert(fundFlowTuiJian2); |
| | | log.info("本地交易:{},amount-{},price-{}", e.adr,amount,price); |
| | | } |
| | | } |
| | | |
| | | DappFundFlowEntity fundFlowTuiJian2 = new DappFundFlowEntity( |
| | | memberId, |
| | | amount, |
| | | FlowTypeEnum.ZHIYA_CHA_CHU.getValue(), |
| | | DappFundFlowEntity.WITHDRAW_STATUS_AGREE, |
| | | StrUtil.format("币本位{},价格{}。",finxMineCoin,price)); |
| | | dappFundFlowDao.insert(fundFlowTuiJian2); |
| | | log.info("本地交易:{},amount-{},price-{}", e.adr,amount,price); |
| | | @Override |
| | | public void huadian(EthUsdtContract.TransferEventResponse e) { |
| | | log.info("滑点奖励"); |
| | | if (e.to == null) { |
| | | return; |
| | | } |
| | | String address = e.to; |
| | | String transactionHash = e.log.getTransactionHash(); |
| | | List<DappHdRecord> transaction_hash = dappHdRecordMapper.selectList(new QueryWrapper<DappHdRecord>().eq("transaction_hash", transactionHash)); |
| | | if(ObjectUtil.isNotEmpty(transaction_hash)){ |
| | | return; |
| | | } |
| | | if(!address.toUpperCase(Locale.ROOT).equals("0x1Ea392645f816BF15f1Fc87728eA010585bAAE7D".toUpperCase())){ |
| | | return; |
| | | } |
| | | //获取滑点钱包的余额 |
| | | BigDecimal coinPrice = ChainService.getInstance(ChainEnum.BSC_GFA.name()).getPrice("0x1Ea392645f816BF15f1Fc87728eA010585bAAE7D").setScale(8,BigDecimal.ROUND_DOWN); |
| | | |
| | | //更新此刻的USDT数量 |
| | | String existToken = redisUtils.getString(DataDicEnum.GFA_HUA_DIAN_WALLET_USDT_AMOUNT.getValue()); |
| | | if (StrUtil.isNotBlank(existToken)) { |
| | | redisUtils.del(existToken); |
| | | } |
| | | int decimals = ChainService.getInstance(ChainEnum.BSC_GFA.name()).decimals(); |
| | | BigDecimal amount = new BigDecimal(e.tokens.toString()).divide(BigDecimal.TEN.pow(decimals), decimals, RoundingMode.HALF_DOWN).setScale(8,BigDecimal.ROUND_DOWN); |
| | | //获取这个时刻的滑点入账数量 |
| | | BigDecimal multiply = coinPrice.multiply(amount).multiply(new BigDecimal("0.97")).setScale(8,BigDecimal.ROUND_DOWN); |
| | | //更新这个时间段的滑点数量 |
| | | redisUtils.set(DataDicEnum.GFA_HUA_DIAN_WALLET_USDT_AMOUNT.getValue(), multiply, 0); |
| | | log.info("滑点奖励:"+amount); |
| | | //生成一条记录 |
| | | DappHdRecord dappHdRecordAdd = new DappHdRecord(); |
| | | dappHdRecordAdd.setPrice(coinPrice); |
| | | dappHdRecordAdd.setUsdtEvery(multiply); |
| | | dappHdRecordAdd.setCoinEvery(amount); |
| | | dappHdRecordAdd.setCoinAmount(BigDecimal.ZERO); |
| | | dappHdRecordAdd.setTransactionHash(transactionHash); |
| | | dappHdRecordMapper.insert(dappHdRecordAdd); |
| | | chainProducer.sendDitribProfit(1L); |
| | | |
| | | // dappSystemService.tradeProfitDistribute(1L); |
| | | } |
| | | } |