From 30c1c9d16a57d2bbc7cd1511d02c5ddcc6a143f6 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Tue, 08 Jun 2021 16:10:44 +0800 Subject: [PATCH] modify --- src/main/java/com/xcong/excoin/quartz/job/BlockCoinUpdateJob.java | 44 ++++++++++++++++++++++++++++---------------- 1 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/xcong/excoin/quartz/job/BlockCoinUpdateJob.java b/src/main/java/com/xcong/excoin/quartz/job/BlockCoinUpdateJob.java index 4b2514f..342ecde 100644 --- a/src/main/java/com/xcong/excoin/quartz/job/BlockCoinUpdateJob.java +++ b/src/main/java/com/xcong/excoin/quartz/job/BlockCoinUpdateJob.java @@ -1,9 +1,12 @@ package com.xcong.excoin.quartz.job; +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.rabbit.producer.UsdtUpdateProducer; import com.xcong.excoin.utils.RedisUtils; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; @@ -33,6 +36,9 @@ @Resource RedisUtils redisUtils; + @Autowired + private UsdtUpdateProducer usdtUpdateProducer; + public static ConcurrentLinkedQueue<Long> TRC_BLOCK = new ConcurrentLinkedQueue<>(); @@ -40,31 +46,32 @@ * TRC20_USDT 同步 */ @Scheduled(cron = "0/2 * * * * ? ") - @Async +// @Async public void usdtTc20Update() { // 波场3秒出一个块 Long blocnNum = TRC_BLOCK.poll(); if (blocnNum == null) { return; } + usdtUpdateProducer.sendTrc20BlockMsg(blocnNum.toString()); redisUtils.set("USDT_TRC20_CURRENT_BLOCK_NUM", blocnNum); - try { - trxUsdtUpdateService.monitorCoinListener(blocnNum); - } catch (RestClientException e) { - // 此时是连接问题 这个块需要重新扫描 - log.info("查询区块超时:" + blocnNum); - TRC_BLOCK.add(blocnNum); - } catch (Exception e) { - e.printStackTrace(); - } +// 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 getnowblock = trxUsdtUpdateService.getnowblockFromTronScan() - 25; - // 生成块到队列 + // 拿到redis里最新区块 Object trc20BlockNum = redisUtils.get("USDT_TRC20_BLOCK_NUM"); if (trc20BlockNum == null) { // 没有则取最新的块 @@ -72,13 +79,18 @@ 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); } /** -- Gitblit v1.9.1