Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(web3_clientVersion): Adds RPC method to fetch client version #414

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ 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 get_block_by_number(
&self,
block: BlockTag,
Expand Down
4 changes: 4 additions & 0 deletions core/src/client/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ 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> {
self.execution.get_client_version().await
}

pub async fn get_filter_changes(&self, filter_id: U256) -> Result<Vec<Log>> {
self.execution.get_filter_changes(filter_id).await
}
Expand Down
6 changes: 6 additions & 0 deletions core/src/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ 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")]
ncitron marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -194,6 +196,10 @@ 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
5 changes: 5 additions & 0 deletions core/src/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ impl<N: NetworkSpec, R: ExecutionRpc<N>> ExecutionClient<N, R> {
.await
}

pub async fn get_client_version(&self) -> Result<String> {
let helios_version = std::env!("CARGO_PKG_VERSION");
Ok(format!("helios-{}", helios_version))
}

pub async fn get_transaction_receipt(
&self,
tx_hash: B256,
Expand Down
2 changes: 2 additions & 0 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ async fn main() -> Result<()> {
client.start().await?;
client.wait_synced().await;

let client_version = client.get_client_version().await?;
let head_block_num = client.get_block_number().await?;
let addr = Address::from_str("0x00000000219ab540356cBB839Cbe05303d7705Fa")?;
let block = BlockTag::Latest;
let balance = client.get_balance(addr, block).await?;

info!("client version: {}", client_version);
info!("synced up to block: {}", head_block_num);
info!("balance of deposit contract: {}", format_ether(balance));

Expand Down
3 changes: 3 additions & 0 deletions helios-ts/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ export class HeliosProvider {
case "eth_getBlockByNumber": {
return this.#client.get_block_by_number(req.params[0], req.params[1]);
}
case "web3_clientVersion": {
return this.#client.get_client_version();
}
default: {
throw `method not implemented: ${req.method}`;
}
Expand Down
5 changes: 5 additions & 0 deletions helios-ts/src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,9 @@ impl EthereumClient {
let logs = map_err(self.inner.get_logs(&filter).await)?;
Ok(serde_wasm_bindgen::to_value(&logs)?)
}

#[wasm_bindgen]
pub async fn get_client_version(&self) -> Result<String, JsError> {
map_err(self.inner.get_client_version().await)
}
}
6 changes: 6 additions & 0 deletions helios-ts/src/opstack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,10 @@ impl OpStackClient {
let logs = map_err(self.inner.get_logs(&filter).await)?;
Ok(serde_wasm_bindgen::to_value(&logs)?)
}

#[wasm_bindgen]
pub async fn get_client_version(&self) -> Result<String, JsError> {
let version = map_err(self.inner.get_client_version().await)?;
Ok(version)
}
}
1 change: 1 addition & 0 deletions rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +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)` |