Skip to content

Commit

Permalink
feat: add eth_getLogs and eth_getFilterLogs (#130)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbaztec authored Sep 21, 2023
1 parent e2f07b2 commit 8b2f8c4
Show file tree
Hide file tree
Showing 4 changed files with 366 additions and 12 deletions.
68 changes: 65 additions & 3 deletions SUPPORTED_APIS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ The `status` options are:
| [`ETH`](#eth-namespace) | [`eth_call`](#eth_call) | `SUPPORTED` | Executes a new message call immediately without creating a transaction on the block chain |
| [`ETH`](#eth-namespace) | [`eth_sendRawTransaction`](#eth_sendrawtransaction) | `SUPPORTED` | Creates new message call transaction or a contract creation for signed transactions |
| [`ETH`](#eth-namespace) | [`eth_getCode`](#eth_getcode) | `SUPPORTED` | Returns code at a given address |
| [`ETH`](#eth-namespace) | [`eth_getFilterChanges`](#`eth_getFilterChanges) | `SUPPORTED` | Polling method for a filter, which returns an array of logs, block hashes, or transaction hashes, depending on the filter type, which occurred since last poll |
| `ETH` | `eth_getFilterLogs` | `NOT IMPLEMENTED`<br />[GitHub Issue #41](https://github.com/matter-labs/era-test-node/issues/41) | Returns an array of all logs matching filter with given id |
| `ETH` | `eth_getLogs` | `NOT IMPLEMENTED`<br />[GitHub Issue #40](https://github.com/matter-labs/era-test-node/issues/40) | Returns an array of all logs matching a given filter object |
| [`ETH`](#eth-namespace) | [`eth_getFilterChanges`](#`eth_getfilterchanges) | `SUPPORTED` | Polling method for a filter, which returns an array of logs, block hashes, or transaction hashes, depending on the filter type, which occurred since last poll |
| [`ETH`](#eth-namespace) | [`eth_getFilterLogs`](#eth_getfilterlogs) | `SUPPORTED` | Returns an array of all logs matching filter with given id |
| [`ETH`](#eth-namespace) | [`eth_getLogs`](#eth_getlogs) | `SUPPORTED` | Returns an array of all logs matching a given filter object |
| `ETH` | `eth_getProof` | `NOT IMPLEMENTED` | Returns the details for the account at the specified address and block number, the account's Merkle proof, and the storage values for the specified storage keys with their Merkle-proofs |
| `ETH` | `eth_getStorageAt` | `NOT IMPLEMENTED`<br />[GitHub Issue #45](https://github.com/matter-labs/era-test-node/issues/45) | Returns the value from a storage position at a given address |
| `ETH` | `eth_getTransactionByBlockHashAndIndex` | `NOT IMPLEMENTED`<br />[GitHub Issue #46](https://github.com/matter-labs/era-test-node/issues/46) | Returns information about a transaction by block hash and transaction index position |
Expand Down Expand Up @@ -737,6 +737,68 @@ curl --request POST \
}'
```


### `eth_getFilterLogs`

[source](src/node.rs)

Returns an array of all logs matching filter with given id

#### Arguments

+ `id: U256`

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{
"jsonrpc": "2.0",
"id": "1",
"method": "eth_getFilterLogs",
"params": ["0x1"]
}'
```

### `eth_getLogs`

[source](src/node.rs)

Returns an array of all logs matching a filter

#### Arguments

+ `filter: Filter`

#### Status

`SUPPORTED`

#### Example

```bash
curl --request POST \
--url http://localhost:8011/ \
--header 'content-type: application/json' \
--data '{
"jsonrpc": "2.0",
"id": "1",
"method": "eth_getLogs",
"params": [{
"fromBlock": "0xa",
"toBlock": "0xff",
"address": "0x6b175474e89094c44da98b954eedeac495271d0f",
"topics": []
}]
}'
```

### `eth_getCode`

[source](src/node.rs)
Expand Down
21 changes: 20 additions & 1 deletion src/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,22 @@ pub struct LogFilter {
}

impl LogFilter {
fn matches(&self, log: &Log, latest_block_number: U64) -> bool {
pub fn new(
from_block: BlockNumber,
to_block: BlockNumber,
addresses: Vec<H160>,
topics: [Option<HashSet<H256>>; 4],
) -> Self {
Self {
from_block,
to_block,
addresses,
topics,
updates: Default::default(),
}
}

pub fn matches(&self, log: &Log, latest_block_number: U64) -> bool {
let from = utils::to_real_block_number(self.from_block, latest_block_number);
let to = utils::to_real_block_number(self.to_block, latest_block_number);

Expand Down Expand Up @@ -185,6 +200,10 @@ impl EthFilters {
Ok(changes)
}

pub fn get_filter(&self, id: U256) -> Option<&FilterType> {
self.filters.get(&id)
}

/// Notify available filters of a newly produced block
pub fn notify_new_block(&mut self, hash: H256) {
self.filters.iter_mut().for_each(|(_, filter)| {
Expand Down
Loading

0 comments on commit 8b2f8c4

Please sign in to comment.