fix
Helius
2022-06-06 b7e79b1a0a954a6d15dc45d835e0024b6b51c211
src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java
@@ -4,6 +4,7 @@
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import io.reactivex.Flowable;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.repository.query.ParameterOutOfBoundsException;
import org.web3j.crypto.Credentials;
@@ -60,25 +61,30 @@
     * @param startBlock 开始区块
     */
    public static void contractEventListener(BigInteger startBlock, ContractEventService event, String type) {
        contractEventListener(startBlock, null, event, type);
    }
    public static void contractEventListener(BigInteger startBlock, BigInteger endBlock, ContractEventService event, String type) {
        ChainEnum chain = ChainEnum.getValueByName(type);
        assert chain != null;
        EthUsdtContract contract = contract(chain.getPrivateKey(), chain.getContractAddress(), chain.getUrl());
        EthFilter filter = getFilter(startBlock, chain.getContractAddress());
        EthFilter filter = getFilter(startBlock, endBlock, chain.getContractAddress());
        contract.transferEventFlowable(filter).subscribe(e -> {
        Flowable<EthUsdtContract.TransferEventResponse> eventFlowable = contract.transferEventFlowable(filter);
        eventFlowable.subscribe(e -> {
            event.compile(e);
        }, error -> {
            log.error("--->", error);
            log.error("合约监听启动报错", error);
        });
    }
    private static EthUsdtContract contract(String privateKey, String contractAddress, String url) {
        Credentials credentials = Credentials.create(privateKey);
        return EthUsdtContract.load(contractAddress, Web3j.build(new HttpService(url)), credentials, new StaticGasProvider(BigInteger.valueOf(4500000L), BigInteger.valueOf(200000L)));
    }
    // 18097238  18098663
    private static EthFilter getFilter(BigInteger startBlock, String contractAddress) {
        return getFilter(startBlock, null, contractAddress);
    }
@@ -106,7 +112,7 @@
        assert chain != null;
        EthUsdtContract contract = contract(chain.getPrivateKey(), chain.getContractAddress(), chain.getUrl());
        EthFilter filter = getFilter(new BigInteger("18097238"), new BigInteger("18098663"), chain.getContractAddress());
        EthFilter filter = getFilter(new BigInteger("18097238"), chain.getContractAddress());
        contract.transferEventFlowable(filter).subscribe(e -> {
            System.out.println(1);