Skip to content

Commit

Permalink
support range functionality when getting logs (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
haider-rs authored Apr 18, 2024
1 parent 789a468 commit 950b028
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 23 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions chains/astar/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ mod tests {
.query(GetLogs {
contracts: vec![contract_address],
topics: vec![topic],
block: AtBlock::At(block_hash.into()),
block: AtBlock::At(block_hash.into()).into(),
})
.await
.unwrap();
Expand All @@ -443,7 +443,7 @@ mod tests {
.query(GetLogs {
contracts: vec![contract_address],
topics: vec![topic],
block: AtBlock::At(block_number.into()),
block: AtBlock::At(block_number.into()).into(),
})
.await
.unwrap();
Expand Down
1 change: 1 addition & 0 deletions chains/ethereum/config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ derivative = { version = "2.2", default-features = false, features = ["use_core"
hex-literal = { version = "0.4" }
rosetta-config-astar = { workspace = true }
rosetta-core.workspace = true
rosetta-ethereum-backend = { workspace = true, features = ["with-codec"] }
rosetta-ethereum-types = { workspace = true, features = ["with-rlp"] }
static_assertions = "1.1.0"

Expand Down
3 changes: 2 additions & 1 deletion chains/ethereum/config/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub use rosetta_ethereum_backend::FilterBlockOption;
pub use rosetta_ethereum_types::{
rpc::RpcTransaction, Address, AtBlock, Block, Bloom, EIP1186ProofResponse, Header, Log,
StorageProof, TransactionReceipt, H256, U256,
Expand Down Expand Up @@ -312,7 +313,7 @@ impl_query_item!(GetBlockByHash);
pub struct GetLogs {
pub contracts: Vec<Address>,
pub topics: Vec<H256>,
pub block: AtBlock,
pub block: FilterBlockOption,
}

impl QueryT for GetLogs {
Expand Down
20 changes: 2 additions & 18 deletions chains/ethereum/server/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use rosetta_ethereum_backend::{
core::client::{ClientT, SubscriptionClientT},
Adapter,
},
BlockRange, EthereumPubSub, EthereumRpc, ExitReason, FilterBlockOption,
BlockRange, EthereumPubSub, EthereumRpc, ExitReason,
};
use std::sync::{
atomic::{self, Ordering},
Expand Down Expand Up @@ -470,26 +470,10 @@ where
EthQueryResult::ChainId(chain_id)
},
EthQuery::GetLogs(logs) => {
use rosetta_config_ethereum::ext::types::BlockIdentifier as EthBlockIdentifier;
let block_range = BlockRange {
address: logs.contracts.clone(),
topics: logs.topics.clone(),
filter: match logs.block {
AtBlock::At(EthBlockIdentifier::Hash(block_hash)) => {
FilterBlockOption::AtBlockHash(block_hash)
},
AtBlock::At(EthBlockIdentifier::Number(block_number)) => {
FilterBlockOption::Range {
from_block: Some(AtBlock::At(EthBlockIdentifier::Number(
block_number,
))),
to_block: Some(AtBlock::At(EthBlockIdentifier::Number(
block_number,
))),
}
},
at => FilterBlockOption::Range { from_block: None, to_block: Some(at) },
},
filter: logs.block,
};
let logs = self.backend.get_logs(block_range).await?;
EthQueryResult::GetLogs(logs)
Expand Down
4 changes: 2 additions & 2 deletions chains/ethereum/server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ mod tests {
.query(GetLogs {
contracts: vec![contract_address],
topics: vec![topic],
block: AtBlock::At(block_hash.into()),
block: AtBlock::At(block_hash.into()).into(),
})
.await
.unwrap();
Expand All @@ -351,7 +351,7 @@ mod tests {
.query(GetLogs {
contracts: vec![contract_address],
topics: vec![topic],
block: AtBlock::At(block_number.into()),
block: AtBlock::At(block_number.into()).into(),
})
.await
.unwrap();
Expand Down

0 comments on commit 950b028

Please sign in to comment.