fix: surface eth_getStorageAt (#124)
* feat: surface eth_getStorageAt * add blocktag * cargo fmt
This commit is contained in:
parent
b449c1f674
commit
d8db74ede9
|
@ -344,8 +344,17 @@ impl<DB: Database> Client<DB> {
|
||||||
self.node.read().await.get_code(address, block).await
|
self.node.read().await.get_code(address, block).await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_storage_at(&self, address: &Address, slot: H256) -> Result<U256> {
|
pub async fn get_storage_at(
|
||||||
self.node.read().await.get_storage_at(address, slot).await
|
&self,
|
||||||
|
address: &Address,
|
||||||
|
slot: H256,
|
||||||
|
block: BlockTag,
|
||||||
|
) -> Result<U256> {
|
||||||
|
self.node
|
||||||
|
.read()
|
||||||
|
.await
|
||||||
|
.get_storage_at(address, slot, block)
|
||||||
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn send_raw_transaction(&self, bytes: &[u8]) -> Result<H256> {
|
pub async fn send_raw_transaction(&self, bytes: &[u8]) -> Result<H256> {
|
||||||
|
|
|
@ -163,10 +163,15 @@ impl Node {
|
||||||
Ok(account.code)
|
Ok(account.code)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_storage_at(&self, address: &Address, slot: H256) -> Result<U256> {
|
pub async fn get_storage_at(
|
||||||
|
&self,
|
||||||
|
address: &Address,
|
||||||
|
slot: H256,
|
||||||
|
block: BlockTag,
|
||||||
|
) -> Result<U256> {
|
||||||
self.check_head_age()?;
|
self.check_head_age()?;
|
||||||
|
|
||||||
let payload = self.get_payload(BlockTag::Latest)?;
|
let payload = self.get_payload(block)?;
|
||||||
let account = self
|
let account = self
|
||||||
.execution
|
.execution
|
||||||
.get_account(address, Some(&[slot]), payload)
|
.get_account(address, Some(&[slot]), payload)
|
||||||
|
|
|
@ -94,6 +94,13 @@ trait EthRpc {
|
||||||
async fn get_transaction_by_hash(&self, hash: &str) -> Result<Option<Transaction>, Error>;
|
async fn get_transaction_by_hash(&self, hash: &str) -> Result<Option<Transaction>, Error>;
|
||||||
#[method(name = "getLogs")]
|
#[method(name = "getLogs")]
|
||||||
async fn get_logs(&self, filter: Filter) -> Result<Vec<Log>, Error>;
|
async fn get_logs(&self, filter: Filter) -> Result<Vec<Log>, Error>;
|
||||||
|
#[method(name = "getStorageAt")]
|
||||||
|
async fn get_storage_at(
|
||||||
|
&self,
|
||||||
|
address: &str,
|
||||||
|
slot: H256,
|
||||||
|
block: BlockTag,
|
||||||
|
) -> Result<String, Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[rpc(client, server, namespace = "net")]
|
#[rpc(client, server, namespace = "net")]
|
||||||
|
@ -227,6 +234,19 @@ impl EthRpcServer for RpcInner {
|
||||||
let node = self.node.read().await;
|
let node = self.node.read().await;
|
||||||
convert_err(node.get_logs(&filter).await)
|
convert_err(node.get_logs(&filter).await)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn get_storage_at(
|
||||||
|
&self,
|
||||||
|
address: &str,
|
||||||
|
slot: H256,
|
||||||
|
block: BlockTag,
|
||||||
|
) -> Result<String, Error> {
|
||||||
|
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]
|
#[async_trait]
|
||||||
|
|
Loading…
Reference in New Issue