1// This file is part of Frontier.
23// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
56// This program is free software: you can redistribute it and/or modify
7// it under the terms of the GNU General Public License as published by
8// the Free Software Foundation, either version 3 of the License, or
9// (at your option) any later version.
1011// This program is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
1516// You should have received a copy of the GNU General Public License
17// along with this program. If not, see <https://www.gnu.org/licenses/>.
1819use scale_codec::{Decode, Encode};
20// Substrate
21use sp_core::{H160, H256};
22use sp_runtime::traits::Block as BlockT;
23// Frontier
24use fp_storage::EthereumStorageSchema;
2526#[derive(Clone, Debug, Eq, PartialEq, Encode, Decode)]
27pub struct TransactionMetadata<Block: BlockT> {
28pub substrate_block_hash: Block::Hash,
29pub ethereum_block_hash: H256,
30pub ethereum_index: u32,
31}
3233/// The frontier backend interface.
34#[async_trait::async_trait]
35pub trait Backend<Block: BlockT>: Send + Sync {
36/// Get the substrate hash with the given ethereum block hash.
37async fn block_hash(
38&self,
39 ethereum_block_hash: &H256,
40 ) -> Result<Option<Vec<Block::Hash>>, String>;
4142/// Get the transaction metadata with the given ethereum block hash.
43async fn transaction_metadata(
44&self,
45 ethereum_transaction_hash: &H256,
46 ) -> Result<Vec<TransactionMetadata<Block>>, String>;
4748/// Returns reference to log indexer backend.
49fn log_indexer(&self) -> &dyn LogIndexerBackend<Block>;
5051/// Indicate whether the log indexing feature is supported.
52fn is_indexed(&self) -> bool {
53self.log_indexer().is_indexed()
54 }
5556/// Get the hash of the oldest substrate block fully indexed by the backend.
57async fn first_block_hash(&self) -> Result<Block::Hash, String>;
5859/// Get the hash of the latest substrate block fully indexed by the backend.
60async fn latest_block_hash(&self) -> Result<Block::Hash, String>;
61}
6263#[derive(Debug, Eq, PartialEq)]
64pub struct FilteredLog<Block: BlockT> {
65pub substrate_block_hash: Block::Hash,
66pub ethereum_block_hash: H256,
67pub block_number: u32,
68pub ethereum_storage_schema: EthereumStorageSchema,
69pub transaction_index: u32,
70pub log_index: u32,
71}
7273/// The log indexer backend interface.
74#[async_trait::async_trait]
75pub trait LogIndexerBackend<Block: BlockT>: Send + Sync {
76/// Indicate whether the log indexing feature is supported.
77fn is_indexed(&self) -> bool;
7879/// Filter the logs by the parameters.
80async 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}