| | |
| | | |
| | | @Slf4j |
| | | @Component |
| | | @ConditionalOnProperty(prefix = "system", name = "chain-listener", havingValue = "true") |
| | | public class ChainListenerJob implements ApplicationRunner { |
| | | //public class ChainListenerJob implements ApplicationRunner { |
| | | public class ChainListenerJob{ |
| | | |
| | | @Autowired |
| | | private ContractEventService bscCoinContractEvent; |
| | |
| | | // 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); |
| | | } |
| | | // @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); |
| | | // } |
| | | |
| | | } |