Skip to content

Commit 1e5aedb

Browse files
authored
Fix ETH feeHistory (#1834)
* fix fee
1 parent 2c33b37 commit 1e5aedb

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

core/src/main/java/org/web3j/protocol/core/Ethereum.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,22 @@ public interface Ethereum {
111111

112112
Request<?, EthMaxPriorityFeePerGas> ethMaxPriorityFeePerGas();
113113

114+
@Deprecated
115+
/**
116+
* Method receives wrong type parameter int for blockCount, according to documentation the type
117+
* should be String which is the encoded hex of the blocks number. This is kept for backward
118+
* compatibility
119+
*
120+
* @param blockCount Requested range of blocks
121+
* @param newestBlock Highest block of the requested range.
122+
* @param rewardPercentiles A monotonically increasing list of percentile values.
123+
*/
114124
Request<?, EthFeeHistory> ethFeeHistory(
115125
int blockCount, DefaultBlockParameter newestBlock, List<Double> rewardPercentiles);
116126

127+
Request<?, EthFeeHistory> ethFeeHistory(
128+
String blockCount, DefaultBlockParameter newestBlock, List<Double> rewardPercentiles);
129+
117130
Request<?, EthAccounts> ethAccounts();
118131

119132
Request<?, EthBlockNumber> ethBlockNumber();

core/src/main/java/org/web3j/protocol/core/JsonRpc2_0Web3j.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ public Request<?, EthMaxPriorityFeePerGas> ethMaxPriorityFeePerGas() {
233233
}
234234

235235
@Override
236+
@Deprecated
236237
public Request<?, EthFeeHistory> ethFeeHistory(
237238
int blockCount, DefaultBlockParameter newestBlock, List<Double> rewardPercentiles) {
238239
return new Request<>(
@@ -242,6 +243,16 @@ public Request<?, EthFeeHistory> ethFeeHistory(
242243
EthFeeHistory.class);
243244
}
244245

246+
@Override
247+
public Request<?, EthFeeHistory> ethFeeHistory(
248+
String blockCount, DefaultBlockParameter newestBlock, List<Double> rewardPercentiles) {
249+
return new Request<>(
250+
"eth_feeHistory",
251+
Arrays.asList(blockCount, newestBlock.getValue(), rewardPercentiles),
252+
web3jService,
253+
EthFeeHistory.class);
254+
}
255+
245256
@Override
246257
public Request<?, EthAccounts> ethAccounts() {
247258
return new Request<>(

core/src/test/java/org/web3j/protocol/core/RequestTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,14 @@ public void testEthMaxPriorityFeePerGas() throws Exception {
156156

157157
@Test
158158
public void testEthFeeHistory() throws Exception {
159-
web3j.ethFeeHistory(1, DefaultBlockParameterName.LATEST, null).send();
159+
web3j.ethFeeHistory(
160+
Numeric.toHexStringWithPrefixZeroPadded(BigInteger.valueOf(1), 1),
161+
DefaultBlockParameterName.LATEST,
162+
null)
163+
.send();
160164

161165
verifyResult(
162-
"{\"jsonrpc\":\"2.0\",\"method\":\"eth_feeHistory\",\"params\":[1,\"latest\",null],\"id\":1}");
166+
"{\"jsonrpc\":\"2.0\",\"method\":\"eth_feeHistory\",\"params\":[\"0x1\",\"latest\",null],\"id\":1}");
163167
}
164168

165169
@Test

0 commit comments

Comments
 (0)