diff --git a/core/src/main/java/org/web3j/protocol/core/methods/request/EthFilter.java b/core/src/main/java/org/web3j/protocol/core/methods/request/EthFilter.java index 59a35220e..304a316f1 100644 --- a/core/src/main/java/org/web3j/protocol/core/methods/request/EthFilter.java +++ b/core/src/main/java/org/web3j/protocol/core/methods/request/EthFilter.java @@ -12,7 +12,7 @@ */ package org.web3j.protocol.core.methods.request; -import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.web3j.protocol.core.DefaultBlockParameter; @@ -24,6 +24,7 @@ public class EthFilter extends Filter { private DefaultBlockParameter fromBlock; // optional, params - defaults to latest for both private DefaultBlockParameter toBlock; + private String blockHash; // optional, cannot be used together with fromBlock/toBlock private List address; // spec. implies this can be single address as string or list public EthFilter() { @@ -40,7 +41,17 @@ public EthFilter( public EthFilter( DefaultBlockParameter fromBlock, DefaultBlockParameter toBlock, String address) { - this(fromBlock, toBlock, Arrays.asList(address)); + this(fromBlock, toBlock, Collections.singletonList(address)); + } + + public EthFilter(String blockHash) { + super(); + this.blockHash = blockHash; + } + + public EthFilter(String blockHash, String address) { + this(null, null, Collections.singletonList(address)); + this.blockHash = blockHash; } public DefaultBlockParameter getFromBlock() { @@ -51,6 +62,10 @@ public DefaultBlockParameter getToBlock() { return toBlock; } + public String getBlockHash() { + return blockHash; + } + public List getAddress() { return address; } diff --git a/core/src/test/java/org/web3j/protocol/RequestTester.java b/core/src/test/java/org/web3j/protocol/RequestTester.java index 0f51829ac..1c943387d 100644 --- a/core/src/test/java/org/web3j/protocol/RequestTester.java +++ b/core/src/test/java/org/web3j/protocol/RequestTester.java @@ -54,7 +54,7 @@ protected void verifyResult(String expected) throws Exception { Buffer buffer = new Buffer(); requestBody.writeTo(buffer); - assertEquals(replaceRequestId(buffer.readUtf8()), (replaceRequestId(expected))); + assertEquals((replaceRequestId(expected)), replaceRequestId(buffer.readUtf8())); } private String replaceRequestId(String json) { diff --git a/core/src/test/java/org/web3j/protocol/core/RequestTest.java b/core/src/test/java/org/web3j/protocol/core/RequestTest.java index f6ceb1059..c700c016a 100644 --- a/core/src/test/java/org/web3j/protocol/core/RequestTest.java +++ b/core/src/test/java/org/web3j/protocol/core/RequestTest.java @@ -563,6 +563,21 @@ public void testEthGetLogsWithNumericBlockRange() throws Exception { + "\"toBlock\":\"latest\",\"address\":[\"\"]}],\"id\":1}"); } + @Test + public void testEthGetLogsWithBlockHash() throws Exception { + web3j.ethGetLogs( + new EthFilter( + "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331", + "")) + .send(); + + verifyResult( + "{\"jsonrpc\":\"2.0\",\"method\":\"eth_getLogs\"," + + "\"params\":[{\"topics\":[]," + + "\"blockHash\":\"0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1527331\"," + + "\"address\":[\"\"]}],\"id\":}"); + } + @Test public void testEthGetWork() throws Exception { web3j.ethGetWork().send();