From 4fd36143be178220f05f86c8ec172f9020900daf Mon Sep 17 00:00:00 2001 From: wzy <wzy19931122ai@163.com> Date: Sun, 07 Aug 2022 13:32:06 +0800 Subject: [PATCH] fix:web3j version --- src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java | 33 ++++++++++++++++++++++----------- 1 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java b/src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java index 641d88b..a771eb9 100644 --- a/src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java +++ b/src/main/java/cc/mrbird/febs/dapp/chain/ChainService.java @@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; import io.reactivex.Flowable; import lombok.extern.slf4j.Slf4j; +import okhttp3.OkHttpClient; import org.springframework.data.repository.query.ParameterOutOfBoundsException; import org.web3j.crypto.Credentials; import org.web3j.protocol.Web3j; @@ -23,6 +24,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.TimeUnit; /** * @author @@ -82,7 +84,14 @@ 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))); + return EthUsdtContract.load(contractAddress, + Web3j.build(new HttpService(url, new OkHttpClient().newBuilder() + .connectTimeout(100, TimeUnit.SECONDS) + .writeTimeout(100, TimeUnit.SECONDS) + .readTimeout(100, TimeUnit.SECONDS) + .build())), + credentials, + new StaticGasProvider(BigInteger.valueOf(4500000L), BigInteger.valueOf(200000L))); } private static EthFilter getFilter(BigInteger startBlock, String contractAddress) { @@ -108,17 +117,19 @@ } public static void main(String[] args) { - ChainEnum chain = ChainEnum.getValueByName(ChainEnum.BSC_TFC.name()); - assert chain != null; +// ChainEnum chain = ChainEnum.getValueByName(ChainEnum.BSC_TFC.name()); +// assert chain != null; +// +// EthUsdtContract contract = contract(chain.getPrivateKey(), chain.getContractAddress(), chain.getUrl()); +// EthFilter filter = getFilter(new BigInteger("18097238"), chain.getContractAddress()); +// +// contract.transferEventFlowable(filter).subscribe(e -> { +// System.out.println(1); +// }, error -> { +// log.error("--->", error); +// }); - EthUsdtContract contract = contract(chain.getPrivateKey(), chain.getContractAddress(), chain.getUrl()); - EthFilter filter = getFilter(new BigInteger("18097238"), chain.getContractAddress()); - - contract.transferEventFlowable(filter).subscribe(e -> { - System.out.println(1); - }, error -> { - log.error("--->", error); - }); + System.out.println(ChainService.getInstance(ChainEnum.BSC_TFC.name()).totalSupply()); } } -- Gitblit v1.9.1