Skip to content

Commit

Permalink
added Linea RPC APIs (#2150)
Browse files Browse the repository at this point in the history
* added LineaEstimateGas API

Signed-off-by: Nischal Sharma <nischal@web3labs.com>

* added changelog

Signed-off-by: Nischal Sharma <nischal@web3labs.com>

* added tests

Signed-off-by: Nischal Sharma <nischal@web3labs.com>

* added linea_getProof

Signed-off-by: Nischal Sharma <nischal@web3labs.com>

* added linea_getTransactionExclusionStatusV1

Signed-off-by: Nischal Sharma <nischal@web3labs.com>

---------

Signed-off-by: Nischal Sharma <nischal@web3labs.com>
  • Loading branch information
NickSneo authored Feb 17, 2025
1 parent 1ec2e2a commit 8a9fe0f
Show file tree
Hide file tree
Showing 10 changed files with 550 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline
### Features

* bump snapshot version to 4.12.4 [#2132](https://github.com/hyperledger-web3j/web3j/pull/2132)
* Added LineaEstimateGas api [#2150](https://github.com/hyperledger-web3j/web3j/pull/2150)


### BREAKING CHANGES
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/org/web3j/ens/NameHash.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ public static String labelHash(String ensName) {
return Numeric.toHexString(EMPTY);
} else {
String normalisedEnsName = normalise(ensName);
return Numeric.toHexString(Hash.sha3(normalisedEnsName.split("\\.")[0].getBytes(StandardCharsets.UTF_8)));
return Numeric.toHexString(
Hash.sha3(normalisedEnsName.split("\\.")[0].getBytes(StandardCharsets.UTF_8)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
public class DefaultIdProvider {
protected static final AtomicLong nextId = new AtomicLong(0);

protected DefaultIdProvider() {
}
protected DefaultIdProvider() {}

public static long getNextId() {
return nextId.getAndIncrement();
Expand Down
12 changes: 12 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 @@ -58,6 +58,9 @@
import org.web3j.protocol.core.methods.response.EthSyncing;
import org.web3j.protocol.core.methods.response.EthTransaction;
import org.web3j.protocol.core.methods.response.EthUninstallFilter;
import org.web3j.protocol.core.methods.response.LineaEstimateGas;
import org.web3j.protocol.core.methods.response.LineaGetProof;
import org.web3j.protocol.core.methods.response.LineaGetTransactionExclusionStatusV1;
import org.web3j.protocol.core.methods.response.NetListening;
import org.web3j.protocol.core.methods.response.NetPeerCount;
import org.web3j.protocol.core.methods.response.NetVersion;
Expand Down Expand Up @@ -160,6 +163,9 @@ Request<?, org.web3j.protocol.core.methods.response.EthCall> ethCall(
Request<?, EthEstimateGas> ethEstimateGas(
org.web3j.protocol.core.methods.request.Transaction transaction);

Request<?, LineaEstimateGas> lineaEstimateGas(
org.web3j.protocol.core.methods.request.Transaction transaction);

Request<?, EthBlock> ethGetBlockByHash(String blockHash, boolean returnFullTransactionObjects);

Request<?, EthBlock> ethGetBlockByNumber(
Expand Down Expand Up @@ -208,6 +214,9 @@ Request<?, EthBlock> ethGetUncleByBlockNumberAndIndex(

Request<?, EthGetProof> ethGetProof(String address, List<String> storageKeys, String quantity);

Request<?, LineaGetProof> lineaGetProof(
String address, List<String> storageKeys, String quantity);

Request<?, EthGetWork> ethGetWork();

Request<?, EthSubmitWork> ethSubmitWork(String nonce, String headerPowHash, String mixDigest);
Expand Down Expand Up @@ -244,4 +253,7 @@ Request<?, org.web3j.protocol.core.methods.response.ShhPost> shhPost(
Request<?, ShhMessages> shhGetMessages(BigInteger filterId);

Request<?, TxPoolStatus> txPoolStatus();

Request<?, LineaGetTransactionExclusionStatusV1> lineaGetTransactionExclusionStatusV1(
String transactionHash);
}
32 changes: 32 additions & 0 deletions core/src/main/java/org/web3j/protocol/core/JsonRpc2_0Web3j.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
import org.web3j.protocol.core.methods.response.EthSyncing;
import org.web3j.protocol.core.methods.response.EthTransaction;
import org.web3j.protocol.core.methods.response.EthUninstallFilter;
import org.web3j.protocol.core.methods.response.LineaEstimateGas;
import org.web3j.protocol.core.methods.response.LineaGetProof;
import org.web3j.protocol.core.methods.response.LineaGetTransactionExclusionStatusV1;
import org.web3j.protocol.core.methods.response.Log;
import org.web3j.protocol.core.methods.response.NetListening;
import org.web3j.protocol.core.methods.response.NetPeerCount;
Expand Down Expand Up @@ -398,6 +401,15 @@ public Request<?, EthEstimateGas> ethEstimateGas(Transaction transaction) {
"eth_estimateGas", Arrays.asList(transaction), web3jService, EthEstimateGas.class);
}

@Override
public Request<?, LineaEstimateGas> lineaEstimateGas(Transaction transaction) {
return new Request<>(
"linea_estimateGas",
Arrays.asList(transaction),
web3jService,
LineaEstimateGas.class);
}

@Override
public Request<?, EthBlock> ethGetBlockByHash(
String blockHash, boolean returnFullTransactionObjects) {
Expand Down Expand Up @@ -588,6 +600,16 @@ public Request<?, EthGetProof> ethGetProof(
EthGetProof.class);
}

@Override
public Request<?, LineaGetProof> lineaGetProof(
String address, List<String> storageKeys, String quantity) {
return new Request<>(
"linea_getProof",
Arrays.asList(address, storageKeys, quantity),
web3jService,
LineaGetProof.class);
}

@Override
public Request<?, EthGetWork> ethGetWork() {
return new Request<>(
Expand Down Expand Up @@ -762,6 +784,16 @@ public Flowable<LogNotification> logsNotifications(
LogNotification.class);
}

@Override
public Request<?, LineaGetTransactionExclusionStatusV1> lineaGetTransactionExclusionStatusV1(
String transactionHash) {
return new Request<>(
"linea_getTransactionExclusionStatusV1",
Arrays.asList(transactionHash),
web3jService,
LineaGetTransactionExclusionStatusV1.class);
}

private Map<String, Object> createLogsParams(List<String> addresses, List<String> topics) {
Map<String, Object> params = new HashMap<>();
if (!addresses.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/*
* Copyright 2025 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.io.IOException;
import java.math.BigInteger;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.ObjectReader;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

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

public class LineaEstimateGas extends Response<LineaEstimateGas.LineaEstimateGasResponse> {

@Override
@JsonDeserialize(using = LineaEstimateGas.ResponseDeserialiser.class)
public void setResult(LineaEstimateGas.LineaEstimateGasResponse result) {
super.setResult(result);
}

public LineaEstimateGas.LineaEstimateGasResponse getLineaEstimateGas() {
return getResult();
}

public static class LineaEstimateGasResponse {
private BigInteger baseFeePerGas;
private BigInteger gasLimit;
private BigInteger priorityFeePerGas;

public LineaEstimateGasResponse() {}

public LineaEstimateGasResponse(
BigInteger baseFeePerGas, BigInteger gasLimit, BigInteger priorityFeePerGas) {
this.baseFeePerGas = baseFeePerGas;
this.gasLimit = gasLimit;
this.priorityFeePerGas = priorityFeePerGas;
}

public BigInteger getBaseFeePerGas() {
return baseFeePerGas;
}

public void setBaseFeePerGas(String baseFeePerGas) {
this.baseFeePerGas = Numeric.decodeQuantity(baseFeePerGas);
}

public BigInteger getGasLimit() {
return gasLimit;
}

public void setGasLimit(String gasLimit) {
this.gasLimit = Numeric.decodeQuantity(gasLimit);
}

public BigInteger getPriorityFeePerGas() {
return priorityFeePerGas;
}

public void setPriorityFeePerGas(String priorityFeePerGas) {
this.priorityFeePerGas = Numeric.decodeQuantity(priorityFeePerGas);
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof LineaEstimateGasResponse)) {
return false;
}
LineaEstimateGasResponse res = (LineaEstimateGasResponse) o;

if (getGasLimit() != null
? !getGasLimit().equals(res.getGasLimit())
: res.getGasLimit() != null) {
return false;
}

if (getBaseFeePerGas() != null
? !getBaseFeePerGas().equals(res.getBaseFeePerGas())
: res.getBaseFeePerGas() != null) {
return false;
}

return getPriorityFeePerGas() != null
? getPriorityFeePerGas().equals(res.getPriorityFeePerGas())
: res.getPriorityFeePerGas() == null;
}
}

public static class ResponseDeserialiser
extends JsonDeserializer<LineaEstimateGas.LineaEstimateGasResponse> {

private ObjectReader objectReader = ObjectMapperFactory.getObjectReader();

@Override
public LineaEstimateGas.LineaEstimateGasResponse deserialize(
JsonParser jsonParser, DeserializationContext deserializationContext)
throws IOException {
if (jsonParser.getCurrentToken() != JsonToken.VALUE_NULL) {
return objectReader.readValue(
jsonParser, LineaEstimateGas.LineaEstimateGasResponse.class);
} else {
return null; // null is wrapped by Optional in above getter
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2025 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 com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import org.web3j.protocol.core.Response;

public class LineaGetProof extends Response<EthGetProof.Proof> {

@Override
@JsonDeserialize(using = EthGetProof.ResponseDeserializer.class)
public void setResult(EthGetProof.Proof result) {
super.setResult(result);
}

/**
* linea get proof result.
*
* @return proof result
*/
public EthGetProof.Proof getProof() {
return getResult();
}
}
Loading

0 comments on commit 8a9fe0f

Please sign in to comment.