From 71756c5945f5174f53302b127e4ea5e437f8d53b Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Sat, 11 May 2024 10:06:40 +0800
Subject: [PATCH] 测试新
---
src/main/java/cc/mrbird/febs/job/ChainListenerJob.java | 148 +++++++++++++++++++------------------------------
1 files changed, 57 insertions(+), 91 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/job/ChainListenerJob.java b/src/main/java/cc/mrbird/febs/job/ChainListenerJob.java
index c59f2d3..d283806 100644
--- a/src/main/java/cc/mrbird/febs/job/ChainListenerJob.java
+++ b/src/main/java/cc/mrbird/febs/job/ChainListenerJob.java
@@ -1,105 +1,71 @@
package cc.mrbird.febs.job;
-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.ContractEventService;
import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.ApplicationArguments;
-import org.springframework.boot.ApplicationRunner;
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 javax.annotation.PostConstruct;
-import java.math.BigInteger;
@Slf4j
@Component
@ConditionalOnProperty(prefix = "system", name = "chain-listener", havingValue = "true")
-public class ChainListenerJob implements ApplicationRunner {
+public class ChainListenerJob{
+//public class ChainListenerJob implements ApplicationRunner {
- @Autowired
- private ContractEventService bscUsdtContractEvent;
- @Autowired
- private ContractEventService bscCoinContractEvent;
-
- @Autowired
- private RedisUtils redisUtils;
-
- @Scheduled(cron = "0 0/5 * * * ? ")
- public void chainBlockUpdate() {
- BigInteger blockNumber = ChainService.getInstance(ChainEnum.BSC_TFC.name()).blockNumber();
-
- redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM, blockNumber);
- }
-
- @Scheduled(cron = "0/2 * * * * ? ")
- public void chainIncrementBlock() {
- Object newestBlockObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM);
- BigInteger newestBlock;
- if (newestBlockObj == null) {
- newestBlock = ChainService.getInstance(ChainEnum.BSC_TFC.name()).blockNumber();
- } else {
- newestBlock = (BigInteger) newestBlockObj;
- }
-
- Object incrementObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM);
- BigInteger toIncrement;
- if (incrementObj == null) {
- toIncrement = newestBlock;
- } else {
- BigInteger incrementBlock = (BigInteger) incrementObj;
-
- // 最新区块小于增加区块
- if (newestBlock.compareTo(incrementBlock) <= 0) {
- return;
- }
- toIncrement = incrementBlock.add(BigInteger.ONE);
- }
-
- redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM, toIncrement);
- }
-
- @Override
- public void run(ApplicationArguments args) throws Exception {
- long start = System.currentTimeMillis();
- log.info("区块链监听开始启动");
- Object incrementObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM);
- BigInteger newest = ChainService.getInstance(ChainEnum.BSC_TFC.name()).blockNumber();
- BigInteger block;
- if (incrementObj == null) {
- block = newest;
- } else {
- block = (BigInteger) incrementObj;
- }
-
- ChainService.wssContractEventListener(block, bscUsdtContractEvent, ChainEnum.BSC_USDT_LISTENER.name());
- ChainService.wssContractEventListener(block, bscCoinContractEvent, ChainEnum.BSC_TFC_LISTENER.name());
-
-// BigInteger section = BigInteger.valueOf(5000);
-// while (newest.subtract(block).compareTo(section) > -1) {
-// BigInteger end = block.add(section);
+// @Autowired
+// private BaseCoinService baseCoinService;
//
-// BigInteger finalBlock = block;
-// new Thread(() -> {
-// log.info("监听:[{} - {}]", finalBlock, end);
-// ChainService.contractEventListener(finalBlock, end, bscUsdtContractEvent, ChainEnum.BSC_USDT_LISTENER.name());
-// ChainService.contractEventListener(finalBlock, end, bscCoinContractEvent, ChainEnum.BSC_TFC_LISTENER.name());
-// }).start();
+// @Autowired
+// private RedisUtils redisUtils;
//
-// block = block.add(section);
-// if (block.compareTo(newest) > 0) {
-// block = newest;
-// }
+// @Scheduled(cron = "0 0/5 * * * ? ")
+// public void chainBlockUpdate() {
+// BigInteger blockNumber = ChainService.getInstance(ChainEnum.BSC_TFC.name()).blockNumber();
+//
+// redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM, blockNumber);
+// }
+//
+// @Scheduled(cron = "0/2 * * * * ? ")
+// public void chainIncrementBlock() {
+// Object newestBlockObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM);
+// BigInteger newestBlock;
+// if (newestBlockObj == null) {
+// newestBlock = ChainService.getInstance(ChainEnum.BSC_TFC.name()).blockNumber();
+// } else {
+// newestBlock = (BigInteger) newestBlockObj;
// }
-// ChainService.contractEventListener(block, bscUsdtContractEvent, ChainEnum.BSC_USDT_LISTENER.name());
-// ChainService.contractEventListener(block, bscCoinContractEvent, ChainEnum.BSC_TFC_LISTENER.name());
-
- long end = System.currentTimeMillis();
- log.info("区块链监听启动完成, 消耗时间{}", end - start);
- }
+//
+// Object incrementObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM);
+// BigInteger toIncrement;
+// if (incrementObj == null) {
+// toIncrement = newestBlock;
+// } else {
+// BigInteger incrementBlock = (BigInteger) incrementObj;
+//
+// // 最新区块小于增加区块
+// if (newestBlock.compareTo(incrementBlock) <= 0) {
+// return;
+// }
+// toIncrement = incrementBlock.add(BigInteger.ONE);
+// }
+//
+// redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM, toIncrement);
+// }
+//
+// @Override
+// public void run(ApplicationArguments args) throws Exception {
+// long start = System.currentTimeMillis();
+// log.info("区块链监听开始启动");
+// Object incrementObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM);
+// BigInteger newest = ChainService.getInstance(ChainEnum.BSC_TFC.name()).blockNumber();
+// BigInteger block = null;
+// if (incrementObj == null) {
+// block = newest;
+// } else {
+// block = (BigInteger) incrementObj;
+// }
+//
+// ChainService.wssBaseCoinEventListener(block, baseCoinService);
+//
+// long end = System.currentTimeMillis();
+// log.info("区块链监听启动完成, 消耗时间{}", end - start);
+// }
}
--
Gitblit v1.9.1