1use scale_codec::{Decode, Encode};
20use sp_core::{H160, H256};
22use sp_runtime::traits::Block as BlockT;
23use fp_storage::EthereumStorageSchema;
25
26#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode)]
27pub struct TransactionMetadata<Block: BlockT> {
28 pub substrate_block_hash: Block::Hash,
29 pub ethereum_block_hash: H256,
30 pub ethereum_index: u32,
31}
32
33#[async_trait::async_trait]
35pub trait Backend<Block: BlockT>: Send + Sync {
36 async fn block_hash(
38 &self,
39 ethereum_block_hash: &H256,
40 ) -> Result<Option<Vec<Block::Hash>>, String>;
41
42 async fn transaction_metadata(
44 &self,
45 ethereum_transaction_hash: &H256,
46 ) -> Result<Vec<TransactionMetadata<Block>>, String>;
47
48 fn log_indexer(&self) -> &dyn LogIndexerBackend<Block>;
50
51 fn is_indexed(&self) -> bool {
53 self.log_indexer().is_indexed()
54 }
55
56 async fn first_block_hash(&self) -> Result<Block::Hash, String>;
58
59 async fn latest_block_hash(&self) -> Result<Block::Hash, String>;
61}
62
63#[derive(Debug, Eq, PartialEq)]
64pub struct FilteredLog<Block: BlockT> {
65 pub substrate_block_hash: Block::Hash,
66 pub ethereum_block_hash: H256,
67 pub block_number: u32,
68 pub ethereum_storage_schema: EthereumStorageSchema,
69 pub transaction_index: u32,
70 pub log_index: u32,
71}
72
73#[async_trait::async_trait]
75pub trait LogIndexerBackend<Block: BlockT>: Send + Sync {
76 fn is_indexed(&self) -> bool;
78
79 async fn filter_logs(
81 &self,
82 from_block: u64,
83 to_block: u64,
84 addresses: Vec<H160>,
85 topics: Vec<Vec<Option<H256>>>,
86 ) -> Result<Vec<FilteredLog<Block>>, String>;
87}