| | |
| | | package cc.mrbird.febs.job; |
| | | |
| | | 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.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.PostConstruct; |
| | | import java.math.BigInteger; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class ChainListenerJob { |
| | | @ConditionalOnProperty(prefix = "system", name = "chain-listener", havingValue = "true") |
| | | public class ChainListenerJob{ |
| | | //public class ChainListenerJob implements ApplicationRunner { |
| | | |
| | | @Autowired |
| | | private ContractEventService bscCoinContractEvent; |
| | | |
| | | @Autowired |
| | | private ContractEventService bscUsdtContractEvent; |
| | | |
| | | @PostConstruct |
| | | public void chainListenerJob() { |
| | | log.info("监听打开"); |
| | | // ChainService.contractEventListener(new BigInteger("18097238"), bscUsdtContractEvent, ChainEnum.BSC_USDT.name()); |
| | | // ChainService.contractEventListener(new BigInteger("18097238"), bscCoinContractEvent, ChainEnum.BSC_TFC.name()); |
| | | } |
| | | // @Autowired |
| | | // private BaseCoinService baseCoinService; |
| | | // |
| | | // @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 = null; |
| | | // if (incrementObj == null) { |
| | | // block = newest; |
| | | // } else { |
| | | // block = (BigInteger) incrementObj; |
| | | // } |
| | | // |
| | | // ChainService.wssBaseCoinEventListener(block, baseCoinService); |
| | | // |
| | | // long end = System.currentTimeMillis(); |
| | | // log.info("区块链监听启动完成, 消耗时间{}", end - start); |
| | | // } |
| | | } |