| | |
| | | package com.xcong.excoin.quartz.job; |
| | | |
| | | import com.xcong.excoin.common.enumerates.CoinTypeEnum; |
| | | import cn.hutool.http.HttpException; |
| | | import com.xcong.excoin.modules.blackchain.service.TrxUsdtUpdateService; |
| | | import com.xcong.excoin.modules.coin.service.BlockCoinService; |
| | | import com.xcong.excoin.modules.member.dao.MemberCoinAddressDao; |
| | | import com.xcong.excoin.modules.member.entity.MemberCoinAddressEntity; |
| | | import com.xcong.excoin.utils.RedisUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.scheduling.annotation.Async; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.client.RestClientException; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.concurrent.ConcurrentLinkedQueue; |
| | | |
| | | /** |
| | |
| | | @Resource |
| | | RedisUtils redisUtils; |
| | | |
| | | // 创世区块时间 ,每三秒出一个块 |
| | | private final static Long TRX_CSQK=1530442002L; |
| | | |
| | | public static ConcurrentLinkedQueue<Long> TRC_BLOCK = new ConcurrentLinkedQueue<>(); |
| | | |
| | | /** |
| | | * TRC20_USDT 同步 |
| | | */ |
| | | @Scheduled(cron = "0/3 * * * * ? ") |
| | | @Scheduled(cron = "0/2 * * * * ? ") |
| | | @Async |
| | | public void usdtTc20Update() { |
| | | // 波场3秒出一个块 |
| | | Long blocnNum = TRC_BLOCK.poll(); |
| | | if(blocnNum==null){ |
| | | if (blocnNum == null) { |
| | | return; |
| | | } |
| | | trxUsdtUpdateService.monitorCoinListener(blocnNum); |
| | | redisUtils.set("USDT_TRC20_CURRENT_BLOCK_NUM", blocnNum); |
| | | try { |
| | | trxUsdtUpdateService.monitorCoinListener(blocnNum); |
| | | } catch (RestClientException | HttpException e) { |
| | | // 此时是连接问题 这个块需要重新扫描 |
| | | log.info("查询区块超时:" + blocnNum); |
| | | TRC_BLOCK.add(blocnNum); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Scheduled(cron = "0/2 * * * * ? ") |
| | | // @Scheduled(cron = "0 0/1 * * * ? ") |
| | | public void usdtTc20UpdateQueue() { |
| | | // 当前时间戳 |
| | | long currentTimeMillis = System.currentTimeMillis()/1000; |
| | | // 计算当前最新区块 |
| | | // 波场3秒出一个块 根据创世区块的时间可以计算出当前最新区块号 |
| | | Long count = (currentTimeMillis-TRX_CSQK)/3; |
| | | // 减去未确认的区块 |
| | | long getnowblock =count-25; |
| | | // 生成块到队列 |
| | | // 查询最新区块号 |
| | | long getnowblock = trxUsdtUpdateService.getnowblockFromTronScan() - 25; |
| | | // 拿到redis里最新区块 |
| | | Object trc20BlockNum = redisUtils.get("USDT_TRC20_BLOCK_NUM"); |
| | | if(trc20BlockNum==null){ |
| | | if (trc20BlockNum == null) { |
| | | // 没有则取最新的块 |
| | | trc20BlockNum =getnowblock; |
| | | redisUtils.set("USDT_TRC20_BLOCK_NUM",getnowblock); |
| | | trc20BlockNum = getnowblock; |
| | | redisUtils.set("USDT_TRC20_BLOCK_NUM", getnowblock); |
| | | } |
| | | Long blockNum = Long.valueOf(trc20BlockNum.toString()); |
| | | if(getnowblock<blockNum){ |
| | | if (getnowblock <= blockNum) { |
| | | // 如果当前区块比最新已确认区块还大,则不继续执行 |
| | | return; |
| | | } |
| | | // 将得到的区块+1 放入队列 |
| | | TRC_BLOCK.add(blockNum+1L); |
| | | redisUtils.incr("USDT_TRC20_BLOCK_NUM",1); |
| | | // 得到最新区块和当前区块的差值 |
| | | Long diff = getnowblock-blockNum; |
| | | for(long i=1;i<=diff;i++){ |
| | | blockNum++; |
| | | TRC_BLOCK.add(blockNum); |
| | | } |
| | | // 将最新的最大区块放入redis |
| | | redisUtils.set("USDT_TRC20_BLOCK_NUM", blockNum); |
| | | } |
| | | |
| | | /** |
| | | * ETH_USDT 同步 使用扫块 废弃这个定时任务 |
| | | */ |
| | |
| | | public void xrpUpdate() { |
| | | blockCoinService.updateXrp(); |
| | | } |
| | | |
| | | |
| | | } |