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.stereotype.Component; import java.math.BigInteger; @Slf4j @Component @ConditionalOnProperty(prefix = "system", name = "charge-transfer", havingValue = "true") public class ChainSDMChargeRunner implements ApplicationRunner { @Autowired private ContractEventService bscCoinContractEvent; @Autowired private RedisUtils redisUtils; @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_CHARGE); 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); 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.receivePeopleEventListener(block, end, bscCoinContractEvent, ChainEnum.BSC_TFC.name()); block = block.add(section); if (block.compareTo(newest) > 0) { block = newest; } } ChainService.receivePeopleEventListener(block, null, bscCoinContractEvent, ChainEnum.BSC_TFC.name()); long end = System.currentTimeMillis(); log.info("区块链存储启动完成, 消耗时间{}", end - start); } }