Skip to content

Commit

Permalink
Merge pull request #1920 from rvullriede/feature/eth-base-fee
Browse files Browse the repository at this point in the history
add the eth_baseFee call
  • Loading branch information
NickSneo committed Aug 2, 2023
2 parents 99fb8f7 + d58612c commit dca2524
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 1 deletion.
3 changes: 3 additions & 0 deletions core/src/main/java/org/web3j/protocol/core/Ethereum.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.web3j.protocol.core.methods.response.DbPutHex;
import org.web3j.protocol.core.methods.response.DbPutString;
import org.web3j.protocol.core.methods.response.EthAccounts;
import org.web3j.protocol.core.methods.response.EthBaseFee;
import org.web3j.protocol.core.methods.response.EthBlock;
import org.web3j.protocol.core.methods.response.EthBlockNumber;
import org.web3j.protocol.core.methods.response.EthChainId;
Expand Down Expand Up @@ -112,6 +113,8 @@ public interface Ethereum {

Request<?, EthMaxPriorityFeePerGas> ethMaxPriorityFeePerGas();

Request<?, EthBaseFee> ethBaseFee();

Request<?, EthFeeHistory> ethFeeHistory(
int blockCount, DefaultBlockParameter newestBlock, List<Double> rewardPercentiles);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.web3j.protocol.core.methods.response.DbPutHex;
import org.web3j.protocol.core.methods.response.DbPutString;
import org.web3j.protocol.core.methods.response.EthAccounts;
import org.web3j.protocol.core.methods.response.EthBaseFee;
import org.web3j.protocol.core.methods.response.EthBlock;
import org.web3j.protocol.core.methods.response.EthBlockNumber;
import org.web3j.protocol.core.methods.response.EthChainId;
Expand Down Expand Up @@ -233,6 +234,12 @@ public Request<?, EthMaxPriorityFeePerGas> ethMaxPriorityFeePerGas() {
EthMaxPriorityFeePerGas.class);
}

@Override
public Request<?, EthBaseFee> ethBaseFee() {
return new Request<>(
"eth_baseFee", Collections.<String>emptyList(), web3jService, EthBaseFee.class);
}

@Override
public Request<?, EthFeeHistory> ethFeeHistory(
int blockCount, DefaultBlockParameter newestBlock, List<Double> rewardPercentiles) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2019 Web3 Labs Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package org.web3j.protocol.core.methods.response;

import java.math.BigInteger;

import org.web3j.protocol.core.Response;
import org.web3j.utils.Numeric;

/** eth_baseFee. */
public class EthBaseFee extends Response<String> {

public BigInteger getBaseFee() {
return Numeric.decodeQuantity(getResult());
}
}
7 changes: 7 additions & 0 deletions core/src/test/java/org/web3j/protocol/core/RequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ public void testEthMaxPriorityFeePerGas() throws Exception {
"{\"jsonrpc\":\"2.0\",\"method\":\"eth_maxPriorityFeePerGas\",\"params\":[],\"id\":1}");
}

@Test
public void testEthBaseFee() throws Exception {
web3j.ethBaseFee().send();

verifyResult("{\"jsonrpc\":\"2.0\",\"method\":\"eth_baseFee\",\"params\":[],\"id\":1}");
}

@Test
public void testEthFeeHistory() throws Exception {
web3j.ethFeeHistory(1, DefaultBlockParameterName.LATEST, null).send();
Expand Down
14 changes: 14 additions & 0 deletions core/src/test/java/org/web3j/protocol/core/ResponseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.web3j.protocol.core.methods.response.DbPutHex;
import org.web3j.protocol.core.methods.response.DbPutString;
import org.web3j.protocol.core.methods.response.EthAccounts;
import org.web3j.protocol.core.methods.response.EthBaseFee;
import org.web3j.protocol.core.methods.response.EthBlock;
import org.web3j.protocol.core.methods.response.EthBlockNumber;
import org.web3j.protocol.core.methods.response.EthCall;
Expand Down Expand Up @@ -599,6 +600,19 @@ public void testEthEstimateGas() {
assertEquals(ethEstimateGas.getAmountUsed(), (BigInteger.valueOf(21000)));
}

@Test
public void testEthBaseFee() {
buildResponse(
"{\n"
+ " \"id\":1,\n"
+ " \"jsonrpc\": \"2.0\",\n"
+ " \"result\": \"0x5d21dba00\"\n"
+ "}");

EthBaseFee ethBaseFee = deserialiseResponse(EthBaseFee.class);
assertEquals(ethBaseFee.getBaseFee(), (BigInteger.valueOf(25000000000L)));
}

@Test
public void testEthBlockTransactionHashes() {

Expand Down
2 changes: 1 addition & 1 deletion gradle/publish/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ signing {
if (signingKey.exists()) {
useInMemoryPgpKeys(signingKey.getText('UTF-8'), System.getenv('GPG_PASSPHRASE'))
}
}
}

0 comments on commit dca2524

Please sign in to comment.