| | |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Service |
| | | public class UsdtErc20UpdateService { |
| | |
| | | } |
| | | |
| | | private static String blockchainNode = "http://120.55.86.146:8545"; |
| | | // private static String blockchainNode = "http://114.55.250.231:8545"; |
| | | |
| | | private static String contractAddr = "0xdac17f958d2ee523a2206206994597c13d831ec7"; |
| | | |
| | |
| | | // 获取最新区块 |
| | | String string = redisUtils.getString(USDT_BLOCK_NUM_GOLDEN); |
| | | if(string==null){ |
| | | string = "11014249"; |
| | | string = "11236151"; |
| | | } |
| | | BigInteger blockNum = new BigInteger(string); |
| | | Credentials credentials = Credentials.create(privateKey); |
| | | EthUsdtContract contract = EthUsdtContract.load(contractAddr, getInstance(), credentials, getStaticGasProvider()); |
| | | EthFilter filter = getFilter(blockNum); |
| | | Map<String,BigInteger> map = new HashMap<String,BigInteger>(); |
| | | map.put("blockNum",blockNum); |
| | | contract.transferEventFlowable(filter).subscribe(e->{ |
| | | if(e!=null && StringUtils.isNotBlank(e.to)){ |
| | | if(e!=null && StringUtils.isNotBlank(e.to) && e.log.getBlockNumber()!=null){ |
| | | String transactionHash = e.log.getTransactionHash(); |
| | | BigInteger blockNumber1 = e.log.getBlockNumber(); |
| | | String toAddress = e.to; |
| | |
| | | EthUsdtChargeDto dto = new EthUsdtChargeDto(toAddress,transactionHash,divide); |
| | | usdtUpdateProducer.sendMsg(JSONObject.toJSONString(dto)); |
| | | } |
| | | |
| | | redisUtils.set(USDT_BLOCK_NUM_GOLDEN,blockNumber1.toString()); |
| | | if(map.get("blockNum").compareTo(blockNumber1)!=0){ |
| | | redisUtils.set(USDT_BLOCK_NUM_GOLDEN,blockNumber1.toString()); |
| | | map.put("blockNum",blockNumber1); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | private static EthFilter getFilter(BigInteger startBlock) { |
| | | if (startBlock != null) { |
| | | EthFilter filter = new EthFilter(new DefaultBlockParameterNumber(startBlock), |