| | |
| | | package cc.mrbird.febs.mall.chain.job; |
| | | |
| | | import cc.mrbird.febs.common.utils.AppContants; |
| | | import cc.mrbird.febs.common.utils.RedisUtils; |
| | | import cc.mrbird.febs.mall.chain.constants.ChainConstants; |
| | | import cc.mrbird.febs.mall.chain.enums.ChainEnum; |
| | | import cc.mrbird.febs.mall.chain.enums.EthService; |
| | | import cc.mrbird.febs.mall.chain.service.ChainService; |
| | | import cc.mrbird.febs.mall.chain.service.ContractChainService; |
| | | import cc.mrbird.febs.mall.chain.service.TrxUsdtUpdateService; |
| | | import cc.mrbird.febs.mall.entity.MemberCoinAddressEntity; |
| | | import cc.mrbird.febs.mall.mapper.MemberCoinAddressDao; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.web3j.utils.Convert; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.util.Set; |
| | | import java.util.concurrent.ExecutionException; |
| | | |
| | | /** |
| | | * 归集定时任务 |
| | |
| | | |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "system", name = "block-job", havingValue = "true") |
| | | @ConditionalOnProperty(prefix = "system", name = "chain-listener", havingValue = "true") |
| | | public class NotionalPoolingJob { |
| | | |
| | | @Resource |
| | | private RedisUtils redisUtils; |
| | | |
| | | @Resource |
| | | private TrxUsdtUpdateService trxUsdtUpdateService; |
| | | |
| | | // /** |
| | | // * usdt 归集 |
| | | // */ |
| | | // @Scheduled(cron = "0 5/30 * * * ? ") |
| | | // public void poolUsdtEth() { |
| | | // try { |
| | | // log.info("USDT归集开始"); |
| | | // usdtEthService.pool(); |
| | | // log.info("USDT归集结束"); |
| | | // } catch (ExecutionException | InterruptedException e) { |
| | | // log.error("#usdt归集错误#", e); |
| | | // } |
| | | // } |
| | | // |
| | | // /** |
| | | // * 使用扫块 不需要这个 |
| | | // */ |
| | | // //@Scheduled(cron = "0 2/8 * * * ? ") |
| | | // @Deprecated |
| | | // public void usdtEthPoolCheck() { |
| | | // log.info("USDTETH归集结果扫描开始"); |
| | | // usdtEthService.usdtEthPoolCheck(); |
| | | // } |
| | | // |
| | | // @Scheduled(cron = "0 2/30 * * * ? ") |
| | | // public void poolEth() { |
| | | // try { |
| | | // usdtEthService.ethPool(); |
| | | // } catch (ExecutionException | InterruptedException e) { |
| | | // log.info("#ETH归集错误#", e); |
| | | // } |
| | | // } |
| | | private MemberCoinAddressDao memberCoinAddressDao; |
| | | |
| | | /** |
| | | * 归集TRC20 |
| | | * 归集ERC20 |
| | | */ |
| | | @Scheduled(cron = "0 0/30 * * * ? ") |
| | | @Scheduled(cron = "0 0/5 * * * ? ") |
| | | public void poolUsdtTrc20() { |
| | | // TODO 执行BSC归集逻辑 |
| | | log.info("归集TRC20执行"); |
| | | // Set<Object> poolAddress = redisUtils.sGet(ChainConstants.REDIS_KEY_POOL_ADDRESS); |
| | | // if (poolAddress == null || poolAddress.isEmpty()) { |
| | | // return; |
| | | // } |
| | | log.info("归集ERC20执行"); |
| | | Set<Object> poolAddress = redisUtils.sGet(ChainConstants.REDIS_KEY_SYSTEM_ADDRESS); |
| | | if (poolAddress == null || poolAddress.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | for (Object address : poolAddress) { |
| | | String next = (String) address; |
| | | log.info("归集地址:{}", next); |
| | | //查询USDT余额 |
| | | MemberCoinAddressEntity memberCoinAddressEntity = memberCoinAddressDao.selectCoinAddressByAddressAndSymbolTag(next, "USDT", "ERC20"); |
| | | if(ObjectUtil.isEmpty(memberCoinAddressEntity)){ |
| | | continue; |
| | | } |
| | | BigDecimal balanceOf = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf(next); |
| | | if (balanceOf == null || balanceOf.compareTo(new BigDecimal("0.05")) < 1) { |
| | | continue; |
| | | } |
| | | //查询手续费 |
| | | BigDecimal balanceOfBaseToken = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOfBaseToken(next); |
| | | |
| | | BigDecimal gas = new BigDecimal(ChainService.getInstance(ChainEnum.BSC_USDT.name()).getGas()).multiply(new BigDecimal(0.0001)); |
| | | if(balanceOfBaseToken.compareTo(gas) < 0){ |
| | | //转手续费 |
| | | ChainService.getInstance(ChainEnum.BSC_USDT.name()).transferBaseToken(next, gas); |
| | | } |
| | | |
| | | ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(memberCoinAddressEntity.getPrivateKey(), |
| | | memberCoinAddressEntity.getAddress(), |
| | | AppContants.ERC20_POOL_ADDRESS, |
| | | balanceOf.toString()); |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | String addressTo = "0xA60AaC0da34C76F3f60207ee09e9F75043319ab4"; |
| | | String address = "0xc1be17a02127e5cc1e6b2298436e8b467531f798"; |
| | | // BigInteger allowance = ChainService.getInstance(ChainEnum.BSC_USDT.name()).allowance(address); |
| | | // System.out.println(allowance); |
| | | // |
| | | // for (Object address : poolAddress) { |
| | | // String next = (String) address; |
| | | // log.info("归集地址:{}", next); |
| | | // trxUsdtUpdateService.poolByAddress(next); |
| | | // BigDecimal balanceOf = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf(addressTo); |
| | | // System.out.println(balanceOf); |
| | | // |
| | | // BigInteger balanceOfUnDecimal = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOfUnDecimal(address); |
| | | // System.out.println(balanceOfUnDecimal); |
| | | // |
| | | // BigInteger blockNumber = ChainService.getInstance(ChainEnum.BSC_USDT.name()).blockNumber(); |
| | | // System.out.println(blockNumber); |
| | | |
| | | // BigDecimal balanceOfBaseToken = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOfBaseToken(addressTo); |
| | | // System.out.println(balanceOfBaseToken); |
| | | // |
| | | String s = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transferBaseToken(address, new BigDecimal(0.0005)); |
| | | System.out.println(s); |
| | | BigDecimal balanceOf = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOf(address); |
| | | if (balanceOf == null || balanceOf.compareTo(new BigDecimal("0.05")) < 1) { |
| | | return; |
| | | } |
| | | // System.out.println(balanceOf); |
| | | // //查询手续费 |
| | | // BigDecimal balanceOfBaseToken = ChainService.getInstance(ChainEnum.BSC_USDT.name()).balanceOfBaseToken(address); |
| | | // |
| | | // System.out.println(balanceOfBaseToken); |
| | | // String gas = "5"; |
| | | // if(balanceOfBaseToken.compareTo(new BigDecimal(gas).multiply(new BigDecimal(0.0001))) < 0){ |
| | | // //转手续费 |
| | | // String s1 = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transferBaseToken(address, new BigDecimal(gas)); |
| | | // } |
| | | // String transfer = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer(address,new BigDecimal(1)); |
| | | |
| | | // ContractChainService contract = new EthService("https://bsc-dataseed1.ninicoin.io", |
| | | // address, |
| | | // "7761233246f68ab3d35eba04c2fbc794714652d2acc15ee5b27ecd1c4005d279", |
| | | // "0x55d398326f99059fF775485246999027B3197955"); |
| | | // String transfer = ChainService.getInstance(ChainEnum.BSC_USDT.name()).transfer( |
| | | // "7761233246f68ab3d35eba04c2fbc794714652d2acc15ee5b27ecd1c4005d279", |
| | | // address, |
| | | // AppContants.ERC20_POOL_ADDRESS, |
| | | // balanceOf.toString()); |
| | | // System.out.println(transfer); |
| | | |
| | | // ChainService.getInstance(ChainEnum.BSC_USDT.name()).poolErc(address); |
| | | |
| | | } |
| | | } |