From 8bf5b52feaccafc21cbd8b6a785b28815377fe41 Mon Sep 17 00:00:00 2001 From: Eshaan Bansal Date: Wed, 27 Nov 2024 18:26:23 +0530 Subject: [PATCH] fix: remove incorrect get prefix from filter methods (#450) * fix: rm incorrect get prefix from filter methods * fixup! rpc.md --- core/src/client/mod.rs | 12 ++++++------ core/src/client/node.rs | 12 ++++++------ core/src/client/rpc.rs | 24 ++++++++++++------------ core/src/execution/mod.rs | 12 ++++++------ core/src/execution/rpc/http_rpc.rs | 12 ++++++------ core/src/execution/rpc/mock_rpc.rs | 17 ++++++++++------- core/src/execution/rpc/mod.rs | 6 +++--- core/testdata/filter_id.txt | 1 + rpc.md | 19 +++++++++++-------- 9 files changed, 61 insertions(+), 54 deletions(-) create mode 100644 core/testdata/filter_id.txt diff --git a/core/src/client/mod.rs b/core/src/client/mod.rs index bf636aa5..be9ff3db 100644 --- a/core/src/client/mod.rs +++ b/core/src/client/mod.rs @@ -143,16 +143,16 @@ impl> Client { self.node.uninstall_filter(filter_id).await } - pub async fn get_new_filter(&self, filter: &Filter) -> Result { - self.node.get_new_filter(filter).await + pub async fn new_filter(&self, filter: &Filter) -> Result { + self.node.new_filter(filter).await } - pub async fn get_new_block_filter(&self) -> Result { - self.node.get_new_block_filter().await + pub async fn new_block_filter(&self) -> Result { + self.node.new_block_filter().await } - pub async fn get_new_pending_transaction_filter(&self) -> Result { - self.node.get_new_pending_transaction_filter().await + pub async fn new_pending_transaction_filter(&self) -> Result { + self.node.new_pending_transaction_filter().await } pub async fn get_gas_price(&self) -> Result { diff --git a/core/src/client/node.rs b/core/src/client/node.rs index a8164d47..501d9d79 100644 --- a/core/src/client/node.rs +++ b/core/src/client/node.rs @@ -178,16 +178,16 @@ impl> Node { self.execution.uninstall_filter(filter_id).await } - pub async fn get_new_filter(&self, filter: &Filter) -> Result { - self.execution.get_new_filter(filter).await + pub async fn new_filter(&self, filter: &Filter) -> Result { + self.execution.new_filter(filter).await } - pub async fn get_new_block_filter(&self) -> Result { - self.execution.get_new_block_filter().await + pub async fn new_block_filter(&self) -> Result { + self.execution.new_block_filter().await } - pub async fn get_new_pending_transaction_filter(&self) -> Result { - self.execution.get_new_pending_transaction_filter().await + pub async fn new_pending_transaction_filter(&self) -> Result { + self.execution.new_pending_transaction_filter().await } // assumes tip of 1 gwei to prevent having to prove out every tx in the block diff --git a/core/src/client/rpc.rs b/core/src/client/rpc.rs index 23f29ad4..550cd7f9 100644 --- a/core/src/client/rpc.rs +++ b/core/src/client/rpc.rs @@ -127,12 +127,12 @@ trait EthRpc Result, ErrorObjectOwned>; #[method(name = "uninstallFilter")] async fn uninstall_filter(&self, filter_id: U256) -> Result; - #[method(name = "getNewFilter")] - async fn get_new_filter(&self, filter: Filter) -> Result; - #[method(name = "getNewBlockFilter")] - async fn get_new_block_filter(&self) -> Result; - #[method(name = "getNewPendingTransactionFilter")] - async fn get_new_pending_transaction_filter(&self) -> Result; + #[method(name = "newFilter")] + async fn new_filter(&self, filter: Filter) -> Result; + #[method(name = "newBlockFilter")] + async fn new_block_filter(&self) -> Result; + #[method(name = "newPendingTransactionFilter")] + async fn new_pending_transaction_filter(&self) -> Result; #[method(name = "getStorageAt")] async fn get_storage_at( &self, @@ -339,16 +339,16 @@ impl> convert_err(self.node.uninstall_filter(filter_id).await) } - async fn get_new_filter(&self, filter: Filter) -> Result { - convert_err(self.node.get_new_filter(&filter).await) + async fn new_filter(&self, filter: Filter) -> Result { + convert_err(self.node.new_filter(&filter).await) } - async fn get_new_block_filter(&self) -> Result { - convert_err(self.node.get_new_block_filter().await) + async fn new_block_filter(&self) -> Result { + convert_err(self.node.new_block_filter().await) } - async fn get_new_pending_transaction_filter(&self) -> Result { - convert_err(self.node.get_new_pending_transaction_filter().await) + async fn new_pending_transaction_filter(&self) -> Result { + convert_err(self.node.new_pending_transaction_filter().await) } async fn get_storage_at( diff --git a/core/src/execution/mod.rs b/core/src/execution/mod.rs index 6d592b94..1f57b1fd 100644 --- a/core/src/execution/mod.rs +++ b/core/src/execution/mod.rs @@ -322,7 +322,7 @@ impl> ExecutionClient { self.rpc.uninstall_filter(filter_id).await } - pub async fn get_new_filter(&self, filter: &Filter) -> Result { + pub async fn new_filter(&self, filter: &Filter) -> Result { let filter = filter.clone(); // avoid submitting a filter for logs for a block helios hasn't seen yet @@ -337,15 +337,15 @@ impl> ExecutionClient { } else { filter }; - self.rpc.get_new_filter(&filter).await + self.rpc.new_filter(&filter).await } - pub async fn get_new_block_filter(&self) -> Result { - self.rpc.get_new_block_filter().await + pub async fn new_block_filter(&self) -> Result { + self.rpc.new_block_filter().await } - pub async fn get_new_pending_transaction_filter(&self) -> Result { - self.rpc.get_new_pending_transaction_filter().await + pub async fn new_pending_transaction_filter(&self) -> Result { + self.rpc.new_pending_transaction_filter().await } async fn verify_logs(&self, logs: &[Log]) -> Result<()> { diff --git a/core/src/execution/rpc/http_rpc.rs b/core/src/execution/rpc/http_rpc.rs index 902fadbd..0aa5f828 100644 --- a/core/src/execution/rpc/http_rpc.rs +++ b/core/src/execution/rpc/http_rpc.rs @@ -174,28 +174,28 @@ impl ExecutionRpc for HttpRpc { .map_err(|e| RpcError::new("uninstall_filter", e))?) } - async fn get_new_filter(&self, filter: &Filter) -> Result { + async fn new_filter(&self, filter: &Filter) -> Result { Ok(self .provider .new_filter(filter) .await - .map_err(|e| RpcError::new("get_new_filter", e))?) + .map_err(|e| RpcError::new("new_filter", e))?) } - async fn get_new_block_filter(&self) -> Result { + async fn new_block_filter(&self) -> Result { Ok(self .provider .new_block_filter() .await - .map_err(|e| RpcError::new("get_new_block_filter", e))?) + .map_err(|e| RpcError::new("new_block_filter", e))?) } - async fn get_new_pending_transaction_filter(&self) -> Result { + async fn new_pending_transaction_filter(&self) -> Result { Ok(self .provider .new_pending_transactions_filter(true) .await - .map_err(|e| RpcError::new("get_new_pending_transactions", e))?) + .map_err(|e| RpcError::new("new_pending_transaction_filter", e))?) } async fn chain_id(&self) -> Result { diff --git a/core/src/execution/rpc/mock_rpc.rs b/core/src/execution/rpc/mock_rpc.rs index 4df98a86..5e947bea 100644 --- a/core/src/execution/rpc/mock_rpc.rs +++ b/core/src/execution/rpc/mock_rpc.rs @@ -1,4 +1,4 @@ -use std::{fs::read_to_string, path::PathBuf}; +use std::{fs::read_to_string, path::PathBuf, str::FromStr}; use alloy::primitives::{Address, B256, U256}; use alloy::rpc::types::{ @@ -88,16 +88,19 @@ impl ExecutionRpc for MockRpc { Err(eyre!("not implemented")) } - async fn get_new_filter(&self, _filter: &Filter) -> Result { - Err(eyre!("not implemented")) + async fn new_filter(&self, _filter: &Filter) -> Result { + let id = read_to_string(self.path.join("filter_id.txt"))?; + Ok(U256::from_str(&id)?) } - async fn get_new_block_filter(&self) -> Result { - Err(eyre!("not implemented")) + async fn new_block_filter(&self) -> Result { + let id = read_to_string(self.path.join("filter_id.txt"))?; + Ok(U256::from_str(&id)?) } - async fn get_new_pending_transaction_filter(&self) -> Result { - Err(eyre!("not implemented")) + async fn new_pending_transaction_filter(&self) -> Result { + let id = read_to_string(self.path.join("filter_id.txt"))?; + Ok(U256::from_str(&id)?) } async fn chain_id(&self) -> Result { diff --git a/core/src/execution/rpc/mod.rs b/core/src/execution/rpc/mod.rs index 02323fe6..e98f7b9d 100644 --- a/core/src/execution/rpc/mod.rs +++ b/core/src/execution/rpc/mod.rs @@ -40,9 +40,9 @@ pub trait ExecutionRpc: Send + Clone + Sync + 'static { async fn get_filter_changes(&self, filter_id: U256) -> Result>; async fn get_filter_logs(&self, filter_id: U256) -> Result>; async fn uninstall_filter(&self, filter_id: U256) -> Result; - async fn get_new_filter(&self, filter: &Filter) -> Result; - async fn get_new_block_filter(&self) -> Result; - async fn get_new_pending_transaction_filter(&self) -> Result; + async fn new_filter(&self, filter: &Filter) -> Result; + async fn new_block_filter(&self) -> Result; + async fn new_pending_transaction_filter(&self) -> Result; async fn chain_id(&self) -> Result; async fn get_block(&self, hash: B256) -> Result>; diff --git a/core/testdata/filter_id.txt b/core/testdata/filter_id.txt new file mode 100644 index 00000000..1899e4f9 --- /dev/null +++ b/core/testdata/filter_id.txt @@ -0,0 +1 @@ +0xa6385952ca398d91b046bf73e520ac80 \ No newline at end of file diff --git a/rpc.md b/rpc.md index 44128557..821af0ee 100644 --- a/rpc.md +++ b/rpc.md @@ -15,20 +15,23 @@ Helios provides a variety of RPC methods for interacting with the Ethereum netwo | `eth_gasPrice` | `gas_price` | Returns the current price per gas in wei. | `client.gas_price(&self)` | | `eth_maxPriorityFeePerGas` | `max_priority_fee_per_gas` | Returns the current max priority fee per gas in wei. | `client.max_priority_fee_per_gas(&self)` | | `eth_blockNumber` | `block_number` | Returns the number of the most recent block. | `client.block_number(&self)` | -| `eth_getBlockByNumber` | `get_block_by_number` | Returns the information of a block by number. | `get_block_by_number(&self, block: BlockTag, full_tx: bool)` | -| `eth_getBlockByHash` | `get_block_by_hash` | Returns the information of a block by hash. | `get_block_by_hash(&self, hash: &str, full_tx: bool)` | +| `eth_getBlockByNumber` | `get_block_by_number` | Returns the information of a block by number. | `client.get_block_by_number(&self, block: BlockTag, full_tx: bool)` | +| `eth_getBlockByHash` | `get_block_by_hash` | Returns the information of a block by hash. | `client.get_block_by_hash(&self, hash: &str, full_tx: bool)` | | `eth_sendRawTransaction` | `send_raw_transaction` | Submits a raw transaction to the network. | `client.send_raw_transaction(&self, bytes: &str)` | | `eth_getTransactionReceipt` | `get_transaction_receipt` | Returns the receipt of a transaction by transaction hash. | `client.get_transaction_receipt(&self, hash: &str)` | -| `eth_getTransactionByHash` | `get_transaction_by_hash` | Returns the information about a transaction requested by transaction hash. | `client.get_transaction_by_hash(&self, hash: &str)` -| `eth_getTransactionByBlockHashAndIndex` | `get_transaction_by_block_hash_and_index` | Returns information about a transaction by block hash and transaction index position. | `client.get_transaction_by_block_hash_and_index(&self, hash: &str, index: u64)` -| `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_getTransactionByHash` | `get_transaction_by_hash` | Returns the information about a transaction requested by transaction hash. | `client.get_transaction_by_hash(&self, hash: &str)` | +| `eth_getTransactionByBlockHashAndIndex` | `get_transaction_by_block_hash_and_index` | Returns information about a transaction by block hash and transaction index position. | `client.get_transaction_by_block_hash_and_index(&self, hash: &str, index: u64)` | +| `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_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)` | | `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_getFilterChanges` | `get_filter_changes` | Polling method for a filter, which returns an array of logs or transaction hashes or block hashes (depending on type of filter) 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_newFilter` | `new_filter` | Creates a filter object, based on filter options, to notify when the state changes (logs). | `client.new_filter(&self, filter: Filter)` | +| `eth_newBlockFilter` | `new_block_filter` | Creates a filter in the node, to notify when a new block arrives. | `client.new_block_filter(&self)` | +| `eth_newPendingTransactionFilter` | `new_pending_transaction_filter` | Creates a filter in the node, to notify when new pending transactions arrive. | `client.new_pending_transaction_filter(&self)` | | `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)` | | `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_clientVersion` | `client_version` | Returns the current version of the chain client. | `client.client_version(&self)` |