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: implement eth_getFilterLogs #446

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -135,6 +135,10 @@ impl<N: NetworkSpec, C: Consensus<N::TransactionResponse>> Client<N, C> {
self.node.get_filter_changes(filter_id).await
}

pub async fn get_filter_logs(&self, filter_id: U256) -> Result<Vec<Log>> {
self.node.get_filter_logs(filter_id).await
}

pub async fn uninstall_filter(&self, filter_id: U256) -> Result<bool> {
self.node.uninstall_filter(filter_id).await
}
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 @@ -170,6 +170,10 @@ impl<N: NetworkSpec, C: Consensus<N::TransactionResponse>> Node<N, C> {
self.execution.get_filter_changes(filter_id).await
}

pub async fn get_filter_logs(&self, filter_id: U256) -> Result<Vec<Log>> {
self.execution.get_filter_logs(filter_id).await
}

pub async fn uninstall_filter(&self, filter_id: U256) -> Result<bool> {
self.execution.uninstall_filter(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 @@ -123,6 +123,8 @@ trait EthRpc<TX: TransactionResponse + RpcObject, TXR: RpcObject, R: ReceiptResp
async fn get_logs(&self, filter: Filter) -> Result<Vec<Log>, ErrorObjectOwned>;
#[method(name = "getFilterChanges")]
async fn get_filter_changes(&self, filter_id: U256) -> Result<Vec<Log>, ErrorObjectOwned>;
#[method(name = "getFilterLogs")]
async fn get_filter_logs(&self, filter_id: U256) -> Result<Vec<Log>, ErrorObjectOwned>;
#[method(name = "uninstallFilter")]
async fn uninstall_filter(&self, filter_id: U256) -> Result<bool, ErrorObjectOwned>;
#[method(name = "getNewFilter")]
Expand Down Expand Up @@ -329,6 +331,10 @@ impl<N: NetworkSpec, C: Consensus<N::TransactionResponse>>
convert_err(self.node.get_filter_changes(filter_id).await)
}

async fn get_filter_logs(&self, filter_id: U256) -> Result<Vec<Log>, ErrorObjectOwned> {
convert_err(self.node.get_filter_logs(filter_id).await)
}

async fn uninstall_filter(&self, filter_id: U256) -> Result<bool, ErrorObjectOwned> {
convert_err(self.node.uninstall_filter(filter_id).await)
}
Expand Down
11 changes: 11 additions & 0 deletions core/src/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,17 @@ impl<N: NetworkSpec, R: ExecutionRpc<N>> ExecutionClient<N, R> {
Ok(logs)
}

pub async fn get_filter_logs(&self, filter_id: U256) -> Result<Vec<Log>> {
let logs = self.rpc.get_filter_logs(filter_id).await?;
if logs.len() > MAX_SUPPORTED_LOGS_NUMBER {
return Err(
ExecutionError::TooManyLogsToProve(logs.len(), MAX_SUPPORTED_LOGS_NUMBER).into(),
);
}
self.verify_logs(&logs).await?;
Ok(logs)
}

pub async fn uninstall_filter(&self, filter_id: U256) -> Result<bool> {
self.rpc.uninstall_filter(filter_id).await
}
Expand Down
8 changes: 8 additions & 0 deletions core/src/execution/rpc/http_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ impl<N: NetworkSpec> ExecutionRpc<N> for HttpRpc<N> {
.map_err(|e| RpcError::new("get_filter_changes", e))?)
}

async fn get_filter_logs(&self, filter_id: U256) -> Result<Vec<Log>> {
Ok(self
.provider
.raw_request("eth_getFilterLogs".into(), (filter_id,))
.await
.map_err(|e| RpcError::new("get_filter_logs", e))?)
}

async fn uninstall_filter(&self, filter_id: U256) -> Result<bool> {
Ok(self
.provider
Expand Down
5 changes: 5 additions & 0 deletions core/src/execution/rpc/mock_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ impl<N: NetworkSpec> ExecutionRpc<N> for MockRpc {
Ok(serde_json::from_str(&logs)?)
}

async fn get_filter_logs(&self, _filter_id: U256) -> Result<Vec<Log>> {
let logs = read_to_string(self.path.join("logs.json"))?;
Ok(serde_json::from_str(&logs)?)
}

async fn uninstall_filter(&self, _filter_id: U256) -> Result<bool> {
Err(eyre!("not implemented"))
}
Expand Down
1 change: 1 addition & 0 deletions core/src/execution/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub trait ExecutionRpc<N: NetworkSpec>: Send + Clone + Sync + 'static {
async fn get_transaction(&self, tx_hash: B256) -> Result<Option<N::TransactionResponse>>;
async fn get_logs(&self, filter: &Filter) -> Result<Vec<Log>>;
async fn get_filter_changes(&self, filter_id: U256) -> Result<Vec<Log>>;
async fn get_filter_logs(&self, filter_id: U256) -> Result<Vec<Log>>;
async fn uninstall_filter(&self, filter_id: U256) -> Result<bool>;
async fn get_new_filter(&self, filter: &Filter) -> Result<U256>;
async fn get_new_block_filter(&self) -> Result<U256>;
Expand Down
2 changes: 2 additions & 0 deletions rpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Helios provides a variety of RPC methods for interacting with the Ethereum netwo
| `eth_getTransactionByBlockNumberAndIndex` | `get_transaction_by_block_number_and_index` | Returns information about a transaction by block number and transaction index position. | `client.get_transaction_by_block_number_and_index(&self, block: BlockTag, index: u64)`
| `eth_getBlockReceipts` | `get_block_receipts` | Returns all transaction receipts of a block by number. | `client.get_block_receipts(&self, block: BlockTag)` |
| `eth_getLogs` | `get_logs` | Returns an array of logs matching the filter. | `client.get_logs(&self, filter: Filter)` |
| `eth_getFilterChanges` | `get_filter_changes` | Polling method for a filter, which returns an array of logs which occurred since last poll. | `client.get_filter_changes(&self, filter_id: H256)` |
| `eth_getFilterLogs` | `get_filter_logs` | Returns an array of all logs matching filter with given id. | `client.get_filter_logs(&self, filter_id: H256)` |
| `eth_getStorageAt` | `get_storage_at` | Returns the value from a storage position at a given address. | `client.get_storage_at(&self, address: &str, slot: H256, block: BlockTag)` |
| `eth_getBlockTransactionCountByHash` | `get_block_transaction_count_by_hash` | Returns the number of transactions in a block from a block matching the transaction hash. | `client.get_block_transaction_count_by_hash(&self, hash: &str)` |
| `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)` |
Expand Down
Loading