From d8db74ede9b37ad517c02443fa7aa502ce4cb0e4 Mon Sep 17 00:00:00 2001 From: sragss <65786432+sragss@users.noreply.github.com> Date: Thu, 8 Dec 2022 07:57:21 -0800 Subject: [PATCH] fix: surface eth_getStorageAt (#124) * feat: surface eth_getStorageAt * add blocktag * cargo fmt --- client/src/client.rs | 13 +++++++++++-- client/src/node.rs | 9 +++++++-- client/src/rpc.rs | 20 ++++++++++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/client/src/client.rs b/client/src/client.rs index 23c435c..353cc1c 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -344,8 +344,17 @@ impl Client { self.node.read().await.get_code(address, block).await } - pub async fn get_storage_at(&self, address: &Address, slot: H256) -> Result { - self.node.read().await.get_storage_at(address, slot).await + pub async fn get_storage_at( + &self, + address: &Address, + slot: H256, + block: BlockTag, + ) -> Result { + self.node + .read() + .await + .get_storage_at(address, slot, block) + .await } pub async fn send_raw_transaction(&self, bytes: &[u8]) -> Result { diff --git a/client/src/node.rs b/client/src/node.rs index fb98292..02d02af 100644 --- a/client/src/node.rs +++ b/client/src/node.rs @@ -163,10 +163,15 @@ impl Node { Ok(account.code) } - pub async fn get_storage_at(&self, address: &Address, slot: H256) -> Result { + pub async fn get_storage_at( + &self, + address: &Address, + slot: H256, + block: BlockTag, + ) -> Result { self.check_head_age()?; - let payload = self.get_payload(BlockTag::Latest)?; + let payload = self.get_payload(block)?; let account = self .execution .get_account(address, Some(&[slot]), payload) diff --git a/client/src/rpc.rs b/client/src/rpc.rs index 93832c3..3f72c7b 100644 --- a/client/src/rpc.rs +++ b/client/src/rpc.rs @@ -94,6 +94,13 @@ trait EthRpc { async fn get_transaction_by_hash(&self, hash: &str) -> Result, Error>; #[method(name = "getLogs")] async fn get_logs(&self, filter: Filter) -> Result, Error>; + #[method(name = "getStorageAt")] + async fn get_storage_at( + &self, + address: &str, + slot: H256, + block: BlockTag, + ) -> Result; } #[rpc(client, server, namespace = "net")] @@ -227,6 +234,19 @@ impl EthRpcServer for RpcInner { let node = self.node.read().await; convert_err(node.get_logs(&filter).await) } + + async fn get_storage_at( + &self, + address: &str, + slot: H256, + block: BlockTag, + ) -> Result { + let address = convert_err(Address::from_str(address))?; + let node = self.node.read().await; + let storage = convert_err(node.get_storage_at(&address, slot, block).await)?; + + Ok(format_hex(&storage)) + } } #[async_trait]