From 6750bad09a6c2f88bc48274efc84c082fde44a2b Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Mon, 20 May 2024 14:05:45 +0800
Subject: [PATCH] 滑点监控
---
src/main/java/cc/mrbird/febs/job/ChainListenerJob.java | 145 +++++++++++++++++++++++++++++++++++------------
1 files changed, 107 insertions(+), 38 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/job/ChainListenerJob.java b/src/main/java/cc/mrbird/febs/job/ChainListenerJob.java
index 4a25c8a..476209e 100644
--- a/src/main/java/cc/mrbird/febs/job/ChainListenerJob.java
+++ b/src/main/java/cc/mrbird/febs/job/ChainListenerJob.java
@@ -8,17 +8,16 @@
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;
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 {
+//public class ChainListenerJob implements ApplicationRunner {
+public class ChainListenerJob{
@Autowired
private ContractEventService bscCoinContractEvent;
@@ -29,43 +28,13 @@
@Autowired
private RedisUtils redisUtils;
- @PostConstruct
- public void chainListenerJob() {
- 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;
- }
-
- BigInteger section = BigInteger.valueOf(5000);
- while (newest.subtract(block).compareTo(section) > -1) {
- BigInteger end = block.add(section);
- log.info("监听:[{} - {}]", block, end);
- ChainService.contractEventListener(block, end, bscUsdtContractEvent, ChainEnum.BSC_USDT.name());
- ChainService.contractEventListener(block, end, bscCoinContractEvent, ChainEnum.BSC_TFC.name());
-
- block = block.add(section);
- if (block.compareTo(newest) > 0) {
- block = newest;
- }
- }
- ChainService.contractEventListener(block, bscUsdtContractEvent, ChainEnum.BSC_USDT.name());
- ChainService.contractEventListener(block, bscCoinContractEvent, ChainEnum.BSC_TFC.name());
-
- long end = System.currentTimeMillis();
- log.info("区块链监听启动完成, 消耗时间{}", end - start);
- }
-
@Scheduled(cron = "0 0/5 * * * ? ")
public void chainBlockUpdate() {
- BigInteger blockNumber = ChainService.getInstance(ChainEnum.BSC_TFC.name()).blockNumber();
+ log.info("最新区块更新");
+ BigInteger blockNumber = ChainService.getInstance(ChainEnum.BSC_GFA.name()).blockNumber();
redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM, blockNumber);
+ redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM_HUA_DIAN, blockNumber);
}
@Scheduled(cron = "0/2 * * * * ? ")
@@ -73,7 +42,7 @@
Object newestBlockObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM);
BigInteger newestBlock;
if (newestBlockObj == null) {
- newestBlock = ChainService.getInstance(ChainEnum.BSC_TFC.name()).blockNumber();
+ newestBlock = ChainService.getInstance(ChainEnum.BSC_GFA.name()).blockNumber();
} else {
newestBlock = (BigInteger) newestBlockObj;
}
@@ -86,7 +55,7 @@
BigInteger incrementBlock = (BigInteger) incrementObj;
// 最新区块小于增加区块
- if (newestBlock.compareTo(incrementBlock) < 0) {
+ if (newestBlock.compareTo(incrementBlock) <= 0) {
return;
}
toIncrement = incrementBlock.add(BigInteger.ONE);
@@ -95,4 +64,104 @@
redisUtils.set(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM, toIncrement);
}
+ @Scheduled(cron = "0/2 * * * * ? ")
+ public void chainIncrementBlockHuaDian() {
+ Object newestBlockObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM_HUA_DIAN);
+ BigInteger newestBlock;
+ if (newestBlockObj == null) {
+ newestBlock = ChainService.getInstance(ChainEnum.BSC_GFA.name()).blockNumber();
+ } else {
+ newestBlock = (BigInteger) newestBlockObj;
+ }
+
+ Object incrementObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_INCREMENT_NUM_HUA_DIAN);
+ 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_HUA_DIAN, 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;
+// }
+//
+// BigInteger section = BigInteger.valueOf(5000);
+// while (newest.subtract(block).compareTo(section) > -1) {
+// BigInteger end = block.add(section);
+// log.info("监听:[{} - {}]", block, end);
+//// ChainService.contractEventListener(block, end, bscUsdtContractEvent, ChainEnum.BSC_USDT.name());
+// /**
+// * 检测团队收益,质押数量的20%到一个钱包a,
+// * 监控A钱包,
+// */
+//// ChainService.contractEventListener(block, end, bscCoinContractEvent, ChainEnum.BSC_TFC.name());
+// ChainService.coinRewardEventListener(block, end, bscCoinContractEvent, ChainEnum.BSC_TFC.name());
+//
+// block = block.add(section);
+// if (block.compareTo(newest) > 0) {
+// block = newest;
+// }
+// }
+//// ChainService.contractEventListener(block, bscUsdtContractEvent, ChainEnum.BSC_USDT.name());
+//// ChainService.contractEventListener(block, bscCoinContractEvent, ChainEnum.BSC_TFC.name());
+//
+// long end = System.currentTimeMillis();
+// log.info("区块链监听启动完成, 消耗时间{}", end - start);
+// }
+
+// @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_GFA.name()).blockNumber();
+//// Object incrementObj = BigInteger.valueOf(39780699);
+//// BigInteger newest = BigInteger.valueOf(39780739);
+// BigInteger block;
+// if (incrementObj == null) {
+// block = newest;
+// } else {
+// block = (BigInteger) incrementObj;
+// }
+//
+// BigInteger section = BigInteger.valueOf(5000);
+// BigInteger subtract = newest.subtract(block);
+// log.info("监听:[{} - {} - {}]", newest,block,newest.subtract(block).compareTo(section) > -1);
+// while (newest.subtract(block).compareTo(section) > -1) {
+// BigInteger end = block.add(section);
+// log.info("监听:[{} - {}]", block, end);
+// ChainService.coinRewardEventListener(block, end, bscCoinContractEvent, ChainEnum.BSC_GFA.name());
+//
+// block = block.add(section);
+// if (block.compareTo(newest) > 0) {
+// block = newest;
+// }
+// }
+//
+// ChainService.coinRewardEventListener(block, null, bscCoinContractEvent, ChainEnum.BSC_GFA.name());
+//
+// long end = System.currentTimeMillis();
+// log.info("区块链监听启动完成, 消耗时间{}", end - start);
+// }
+
}
--
Gitblit v1.9.1