optimism-java / shisui

Ethereum Portal Network Client written in Go
https://www.ethportal.net/clients/shisui
GNU Lesser General Public License v3.0
5 stars 6 forks source link

Minimal eth namespace (RPC-API) with endpoints eth_chainId and eth_getBlockByHash #154

Closed r4f4ss closed 1 week ago

r4f4ss commented 2 weeks ago

This PR proposes the implementation of a minimal eth namespace and two methods: eth_chainId and eth_gtBlockByHash.

The RPC specification follows the [Execution APIs specification] (https://ethereum.github.io/execution-apis/api-documentation/). This design of offering APIs for external interaction is described in the documentation although there are other approaches such as embedding a Portal Network client in a lightweight wallet, for example.

This PR is inspired by the code from geth and fluffy

The following code, in JS using ethers, may be used to test the integration:

import { getDefaultProvider } from 'ethers';

const provider = getDefaultProvider("http://localhost:8545/");
const block = await provider.getBlock("0x4985f5ca3d2afbec36529aa96f74de3cc10a2a4a6c44f2157a57d2c6059a11bb", true);
console.log(block)
for (var i = 0; i < block.transactions.length; i++) {
    console.log(block.getPrefetchedTransaction(i))
}

Alternatively, rpc endpoints can be called with curl:

curl 127.0.0.1:8545/ -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_getBlockByHash","params":["0xb81fcfee29cea2922aa9f553644463bee1c49895e56bc87f4417834e681ad305",true],"id":1}'
curl 127.0.0.1:8545/ -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"eth_chainId","params":[],"id":1}'
GrapeBaBa commented 2 weeks ago

@r4f4ss almost LGTM, please fix lint