copy from src/main/java/cc/mrbird/febs/job/ChainListenerJob.java
copy to src/main/java/cc/mrbird/febs/job/ChainHuaDianJob.java
| File was copied from src/main/java/cc/mrbird/febs/job/ChainListenerJob.java |
| | |
| | | |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "system", name = "chain-listener", havingValue = "true") |
| | | @ConditionalOnProperty(prefix = "system", name = "huadian-transfer", havingValue = "true") |
| | | //public class ChainListenerJob implements ApplicationRunner { |
| | | public class ChainListenerJob{ |
| | | public class ChainHuaDianJob { |
| | | |
| | | @Autowired |
| | | private ContractEventService bscCoinContractEvent; |
| | |
| | | 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 * * * * ? ") |
| | | public void chainIncrementBlock() { |
| | | Object newestBlockObj = redisUtils.get(AppContants.REDIS_KEY_BLOCK_ETH_NEWEST_NUM); |
| | | 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); |
| | | 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); |
| | | } |
| | | |
| | | @Scheduled(cron = "0/2 * * * * ? ") |