| | |
| | | Web3j web3j = null; |
| | | ChainEnum chain = ChainEnum.getValueByName(type); |
| | | |
| | | // try { |
| | | // webSocketClient = new WebSocketClient(new URI("wss://bsc-mainnet.nodereal.io/ws/v1/78074065950e4915aef4f12b6f357d16")); |
| | | // ws = new WebSocketService(webSocketClient, true); |
| | | // ws.connect(); |
| | | // } catch (Exception e) { |
| | | // try { |
| | | // ws.close(); |
| | | // //TODO |
| | | // if(ObjectUtil.isEmpty(webSocketClient)){ |
| | | // webSocketClient = new WebSocketClient(new URI("wss://bsc-mainnet.nodereal.io/ws/v1/78074065950e4915aef4f12b6f357d16")); |
| | | // ws = new WebSocketService(webSocketClient, true); |
| | | // ws.connect(); |
| | | // } |
| | | // WebSocket.READYSTATE readyState = webSocketClient.getReadyState(); |
| | | // if((WebSocket.READYSTATE.OPEN != readyState |
| | | // && WebSocket.READYSTATE.CONNECTING != readyState)){ |
| | | // webSocketClient = new WebSocketClient(new URI("wss://bsc-mainnet.nodereal.io/ws/v1/78074065950e4915aef4f12b6f357d16")); |
| | | // ws = new WebSocketService(webSocketClient, true); |
| | | // ws.connect(); |
| | | // } |
| | | // } catch (Exception connectException) { |
| | | // connectException.printStackTrace(); |
| | | // } |
| | | // } |
| | | |
| | | |
| | | try { |
| | | webSocketClient = new WebSocketClient(new URI("wss://bsc-mainnet.nodereal.io/ws/v1/78074065950e4915aef4f12b6f357d16")); |
| | | ws = new WebSocketService(webSocketClient, true); |
| | | ws.connect(); |
| | | } catch (Exception e) { |
| | | try { |
| | | ws.close(); |
| | | //TODO |
| | | if(ObjectUtil.isEmpty(webSocketClient)){ |
| | | webSocketClient = new WebSocketClient(new URI("wss://bsc-mainnet.nodereal.io/ws/v1/78074065950e4915aef4f12b6f357d16")); |
| | | ws = new WebSocketService(webSocketClient, true); |
| | | ws.connect(); |
| | | } |
| | | WebSocket.READYSTATE readyState = webSocketClient.getReadyState(); |
| | | if((WebSocket.READYSTATE.OPEN != readyState |
| | | && WebSocket.READYSTATE.CONNECTING != readyState)){ |
| | | webSocketClient = new WebSocketClient(new URI("wss://bsc-mainnet.nodereal.io/ws/v1/78074065950e4915aef4f12b6f357d16")); |
| | | ws = new WebSocketService(webSocketClient, true); |
| | | ws.connect(); |
| | | } |
| | | } catch (Exception connectException) { |
| | | connectException.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | try { |
| | | web3j = Web3j.build(ws); |
| | | |
| | | assert chain != null; |
| | | try{ |
| | | EthUsdtContract ethUsdtContract = wssContract(chain.getPrivateKey(), chain.getContractAddress(), web3j); |
| | | EthFilter filter = getFilter(startBlock, startBlock, chain.getContractAddress()); |
| | | |
| | | |
| | | Flowable<EthUsdtContract.TransferEventResponse> eventFlowable = ethUsdtContract.transferEventFlowable(filter); |
| | | Disposable subscribe = eventFlowable.subscribe(event::compile, error -> { |
| | | log.error("币安监听异常", error); |
| | |
| | | }); |
| | | }catch(WebsocketNotConnectedException e){ |
| | | ws.close(); |
| | | if(ObjectUtil.isEmpty(webSocketClient)){ |
| | | webSocketClient = new WebSocketClient(new URI("wss://bsc-mainnet.nodereal.io/ws/v1/78074065950e4915aef4f12b6f357d16")); |
| | | ws = new WebSocketService(webSocketClient, true); |
| | | ws.connect(); |
| | | } |
| | | WebSocket.READYSTATE readyState = webSocketClient.getReadyState(); |
| | | if((WebSocket.READYSTATE.OPEN != readyState |
| | | && WebSocket.READYSTATE.CONNECTING != readyState)){ |
| | | webSocketClient = new WebSocketClient(new URI("wss://bsc-mainnet.nodereal.io/ws/v1/78074065950e4915aef4f12b6f357d16")); |
| | | ws = new WebSocketService(webSocketClient, true); |
| | | ws.connect(); |
| | | } |
| | | webSocketClient = new WebSocketClient(new URI("wss://bsc-mainnet.nodereal.io/ws/v1/78074065950e4915aef4f12b6f357d16")); |
| | | ws = new WebSocketService(webSocketClient, true); |
| | | ws.connect(); |
| | | web3j = Web3j.build(ws); |
| | | assert chain != null; |
| | | EthUsdtContract ethUsdtContract = wssContract(chain.getPrivateKey(), chain.getContractAddress(), web3j); |
| | | EthFilter filter = getFilter(startBlock, startBlock, chain.getContractAddress()); |
| | | |
| | | |
| | | Flowable<EthUsdtContract.TransferEventResponse> eventFlowable = ethUsdtContract.transferEventFlowable(filter); |
| | | Disposable subscribe = eventFlowable.subscribe(event::compile, error -> { |
| | | log.error("币安监听异常", error); |