簡體   English   中英

無法使用web3j下載以太坊事件

[英]Cant download ethereum Events with web3j

當我嘗試從Blockhain下載事件時:

<!-- language: lang-js -->
    Web3j web3 = Web3j.build(new HttpService("https://rinkeby.infura.io/naqTNN4B2QavbM4vZI3q"));
    Credentials credentials =Credentials.create("94b5486c4657faf6d3834c2efd70d90a3cc746db101de32b997206e0ddb5234e");
    TenderFactory factory = TenderFactory.load("0x16606f347cf1b36c08690b150b96dba2031d6729", web3, credentials, GAS_PRICE, GAS_LIMIT);
    final Event event = new Event("NewContract",
    Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
    }),
    Arrays.<TypeReference<?>>asList(new TypeReference<Utf8String>() {
    }));
    EthFilter filter = new EthFilter(DefaultBlockParameterName.EARLIEST,
    DefaultBlockParameterName.EARLIEST, factory.getContractAddress());
    filter.addSingleTopic(EventEncoder.encode(event));
    Toolkit.getDefaultToolkit().beep();
    web3.ethLogObservable(filter).subscribe(log -> {
        LOG.info("log.getTopics=" + log.getTopics());
    });

我受到驚嚇:

    17:43:05.719 [main] INFO  r.s.tenderchain.Download - contractAddress = 0x16606f347cf1b36c08690b150b96dba2031d6729
    17:43:07.097 [main] DEBUG org.web3j.protocol.http.HttpService - --> POST https://rinkeby.infura.io/naqTNN4B2QavbM4vZI3q http/1.1
    17:43:07.098 [main] DEBUG org.web3j.protocol.http.HttpService - Content-Type: application/json; charset=utf-8
    17:43:07.098 [main] DEBUG org.web3j.protocol.http.HttpService - Content-Length: 243
    17:43:07.102 [main] DEBUG org.web3j.protocol.http.HttpService -
            17:43:07.103 [main] DEBUG org.web3j.protocol.http.HttpService - {"jsonrpc":"2.0","method":"eth_newFilter","params":[{"topics":["0xa291e5980c03d23637198189ac50f67cecef9d808328c0420a23fa32fc16084a"],"fromBlock":"earliest","toBlock":"earliest","address":["0x16606f347cf1b36c08690b150b96dba2031d6729"]}],"id":0}
    17:43:07.104 [main] DEBUG org.web3j.protocol.http.HttpService - --> END POST (243-byte body)
    17:43:08.688 [main] DEBUG org.web3j.protocol.http.HttpService - <-- 405 Method Not Allowed https://rinkeby.infura.io/naqTNN4B2QavbM4vZI3q (1582ms)
    17:43:08.689 [main] DEBUG org.web3j.protocol.http.HttpService - Date: Wed, 20 Dec 2017 14:43:08 GMT
    17:43:08.694 [main] DEBUG org.web3j.protocol.http.HttpService - Content-Type: text/plain; charset=utf-8
    17:43:08.694 [main] DEBUG org.web3j.protocol.http.HttpService - Content-Length: 0
    17:43:08.694 [main] DEBUG org.web3j.protocol.http.HttpService - Connection: keep-alive
    17:43:08.694 [main] DEBUG org.web3j.protocol.http.HttpService - Server: nginx/1.10.3 (Ubuntu)
            17:43:08.695 [main] DEBUG org.web3j.protocol.http.HttpService - Vary: Origin
    17:43:08.698 [main] DEBUG org.web3j.protocol.http.HttpService - <-- END HTTP (0-byte body)
    Exception in thread "main" rx.exceptions.OnErrorNotImplementedException: Invalid response received: okhttp3.internal.http.RealResponseBody@437e951d
    at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:386)
    at rx.internal.util.InternalObservableUtils$ErrorNotImplementedAction.call(InternalObservableUtils.java:383)
    at rx.internal.util.ActionSubscriber.onError(ActionSubscriber.java:44)
    at rx.observers.SafeSubscriber._onError(SafeSubscriber.java:153)
    at rx.observers.SafeSubscriber.onError(SafeSubscriber.java:115)
    at rx.Observable.subscribe(Observable.java:10249)
    at rx.Observable.subscribe(Observable.java:10205)
    at rx.Observable.subscribe(Observable.java:10010)
    at ru.simplex_software.tenderchain.Download.main(Download.java:82)
    Caused by: org.web3j.protocol.exceptions.ClientConnectionException: Invalid response received: okhttp3.internal.http.RealResponseBody@437e951d
    at org.web3j.protocol.http.HttpService.performIO(HttpService.java:116)
    at org.web3j.protocol.Service.send(Service.java:31)
    at org.web3j.protocol.core.Request.send(Request.java:71)
    at org.web3j.protocol.core.filters.LogFilter.sendRequest(LogFilter.java:31)
    at org.web3j.protocol.core.filters.Filter.run(Filter.java:40)

.... org.web3j.protocol.rx.JsonRpc2_0Rx.lambda $ ethLogObservable $ 10(JsonRpc2_0Rx.java:65)at rx.Observable.subscribe(Observable.java:10238)... 3更多

如何解決此問題並下載NewContract事件?

Infura現在支持主網,ropsten和rinkeby上的websocket端點,使您可以偵聽事件。 但是,web3j直到現在都不支持websockets,因此在連接到infura時無法在web3中使用過濾器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM