| | |
| | | import org.web3j.protocol.core.methods.request.EthFilter; |
| | | import org.web3j.protocol.core.methods.response.TransactionReceipt; |
| | | import org.web3j.protocol.http.HttpService; |
| | | import org.web3j.protocol.websocket.WebSocketClient; |
| | | import org.web3j.protocol.websocket.WebSocketService; |
| | | import org.web3j.tx.gas.StaticGasProvider; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import java.math.BigInteger; |
| | | import java.net.ConnectException; |
| | | import java.net.URI; |
| | | import java.net.URISyntaxException; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.rmi.activation.UnknownObjectException; |
| | | import java.util.HashMap; |
| | |
| | | }); |
| | | } |
| | | |
| | | public static void wssContractEventListener(BigInteger startBlock, ContractEventService event, String type) { |
| | | WebSocketService ws =null; |
| | | WebSocketClient webSocketClient=null; |
| | | Web3j web3j = null; |
| | | |
| | | try { |
| | | webSocketClient=new WebSocketClient(new URI("wss://bsc-mainnet.blockvision.org/v1/2Dz4hDxe5vNtQxWkLXNwnzDePKp")); |
| | | ws = new WebSocketService(webSocketClient, false); |
| | | ws.connect(); |
| | | web3j = Web3j.build(ws); |
| | | ChainEnum chain = ChainEnum.getValueByName(type); |
| | | assert chain != null; |
| | | EthFilter filter = getFilter(startBlock, null, chain.getContractAddress()); |
| | | web3j.ethLogFlowable(filter).subscribe(log -> { |
| | | System.out.println(111); |
| | | }); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | private static EthUsdtContract contract(String privateKey, String contractAddress, String url) { |
| | | Credentials credentials = Credentials.create(privateKey); |