Skip to content

Commit

Permalink
fix: fixes namespaces from eth to web3
Browse files Browse the repository at this point in the history
  • Loading branch information
mw2000 committed Oct 30, 2024
1 parent e15a2f0 commit ead6118
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
4 changes: 2 additions & 2 deletions core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ impl<N: NetworkSpec, C: Consensus<N::TransactionResponse>> Client<N, C> {
self.node.get_block_number().await
}

pub async fn get_client_version(&self) -> Result<String> {
self.node.get_client_version().await
pub async fn client_version(&self) -> Result<String> {
self.node.client_version().await
}

pub async fn get_block_by_number(
Expand Down
2 changes: 1 addition & 1 deletion core/src/client/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl<N: NetworkSpec, C: Consensus<N::TransactionResponse>> Node<N, C> {
self.execution.get_logs(filter).await
}

pub async fn get_client_version(&self) -> Result<String> {
pub async fn client_version(&self) -> Result<String> {
self.execution.get_client_version().await
}

Expand Down
24 changes: 17 additions & 7 deletions core/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ trait EthRpc<TX: TransactionResponse + RpcObject, TXR: RpcObject, R: ReceiptResp
) -> Result<U64, ErrorObjectOwned>;
#[method(name = "getCode")]
async fn get_code(&self, address: Address, block: BlockTag) -> Result<Bytes, ErrorObjectOwned>;
#[method(name = "getClientVersion")]
async fn get_client_version(&self) -> Result<String, ErrorObjectOwned>;
#[method(name = "call")]
async fn call(&self, tx: TXR, block: BlockTag) -> Result<Bytes, ErrorObjectOwned>;
#[method(name = "estimateGas")]
Expand Down Expand Up @@ -143,6 +141,12 @@ trait NetRpc {
async fn version(&self) -> Result<u64, ErrorObjectOwned>;
}

#[rpc(client, server, namespace = "web3")]
trait Web3Rpc {
#[method(name = "clientVersion")]
async fn client_version(&self) -> Result<String, ErrorObjectOwned>;
}

struct RpcInner<N: NetworkSpec, C: Consensus<N::TransactionResponse>> {
node: Arc<Node<N, C>>,
address: SocketAddr,
Expand Down Expand Up @@ -196,10 +200,6 @@ impl<N: NetworkSpec, C: Consensus<N::TransactionResponse>>
convert_err(self.node.get_code(address, block).await)
}

async fn get_client_version(&self) -> Result<String, ErrorObjectOwned> {
convert_err(self.node.get_client_version().await)
}

async fn call(
&self,
tx: N::TransactionRequest,
Expand Down Expand Up @@ -324,6 +324,14 @@ impl<N: NetworkSpec, C: Consensus<N::TransactionResponse>> NetRpcServer for RpcI
}
}

#[async_trait]
impl<N: NetworkSpec, C: Consensus<N::TransactionResponse>> Web3RpcServer for RpcInner<N, C> {
async fn client_version(&self) -> Result<String, ErrorObjectOwned> {
convert_err(self.node.client_version().await)
}
}


async fn start<N: NetworkSpec, C: Consensus<N::TransactionResponse>>(
rpc: RpcInner<N, C>,
) -> Result<(ServerHandle, SocketAddr)> {
Expand All @@ -332,10 +340,12 @@ async fn start<N: NetworkSpec, C: Consensus<N::TransactionResponse>>(

let mut methods = Methods::new();
let eth_methods: Methods = EthRpcServer::into_rpc(rpc.clone()).into();
let net_methods: Methods = NetRpcServer::into_rpc(rpc).into();
let net_methods: Methods = NetRpcServer::into_rpc(rpc.clone()).into();
let web3_methods: Methods = Web3RpcServer::into_rpc(rpc).into();

methods.merge(eth_methods)?;
methods.merge(net_methods)?;
methods.merge(web3_methods)?;

let handle = server.start(methods);

Expand Down
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async fn main() -> Result<()> {
client.start().await?;
client.wait_synced().await;

let client_version = client.get_client_version().await?;
let client_version = client.client_version().await?;
let head_block_num = client.get_block_number().await?;
let addr = Address::from_str("0x00000000219ab540356cBB839Cbe05303d7705Fa")?;
let block = BlockTag::Latest;
Expand Down
2 changes: 1 addition & 1 deletion rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Helios provides a variety of RPC methods for interacting with the Ethereum netwo
| `eth_getBlockTransactionCountByNumber` | `get_block_transaction_count_by_number` | Returns the number of transactions in a block from a block matching the block number. | `client.get_block_transaction_count_by_number(&self, block: BlockTag)` |
| `eth_coinbase` | `get_coinbase` | Returns the client coinbase address. | `client.get_coinbase(&self)` |
| `eth_syncing` | `syncing` | Returns an object with data about the sync status or false. | `client.syncing(&self)` |
| `web3_getClientVersion` | `get_client_version` | Returns the current version of the chain client. | `client.get_client_version(&self)` |
| `web3_clientVersion` | `client_version` | Returns the current version of the chain client. | `client.client_version(&self)` |

0 comments on commit ead6118

Please sign in to comment.