forked from paradigmxyz/reth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Web3 namespace RPC handler (paradigmxyz#990)
- Loading branch information
Showing
5 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use crate::result::ToRpcResult; | ||
use async_trait::async_trait; | ||
use jsonrpsee::core::RpcResult; | ||
use reth_network::NetworkHandle; | ||
use reth_network_api::NetworkInfo; | ||
use reth_primitives::{keccak256, Bytes, H256}; | ||
use reth_rpc_api::Web3ApiServer; | ||
|
||
/// `web3` API implementation. | ||
/// | ||
/// This type provides the functionality for handling `web3` related requests. | ||
pub struct Web3Api { | ||
/// An interface to interact with the network | ||
network: NetworkHandle, | ||
} | ||
|
||
impl Web3Api { | ||
/// Creates a new instance of `Web3Api`. | ||
pub fn new(network: NetworkHandle) -> Web3Api { | ||
Web3Api { network } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Web3ApiServer for Web3Api { | ||
async fn client_version(&self) -> RpcResult<String> { | ||
let status = self.network.network_status().await.to_rpc_result()?; | ||
Ok(status.client_version) | ||
} | ||
|
||
fn sha3(&self, input: Bytes) -> RpcResult<H256> { | ||
Ok(keccak256(input)) | ||
} | ||
} | ||
|
||
impl std::fmt::Debug for Web3Api { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
f.debug_struct("Web3Api").finish_non_exhaustive() | ||
} | ||
} |