-
Notifications
You must be signed in to change notification settings - Fork 546
feat: add fc-api to improve fc-db #1076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e0595cd
feat: add fc-api to improve fc-db
koushiro 8c01fed
fix tests
koushiro 13e64da
Merge remote-tracking branch 'upstream/master' into add-fc-api
koushiro 80bdcb9
fix
koushiro d2b18f1
Merge remote-tracking branch 'upstream/master' into add-fc-api
koushiro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| [package] | ||
| name = "fc-api" | ||
| version = "1.0.0-dev" | ||
| license = "GPL-3.0-or-later WITH Classpath-exception-2.0" | ||
| description = "Frontier client interfaces" | ||
| authors = { workspace = true } | ||
| edition = { workspace = true } | ||
| repository = { workspace = true } | ||
|
|
||
| [package.metadata.docs.rs] | ||
| targets = ["x86_64-unknown-linux-gnu"] | ||
|
|
||
| [dependencies] | ||
| async-trait = { workspace = true } | ||
| scale-codec = { package = "parity-scale-codec", workspace = true } | ||
| # Substrate | ||
| sp-core = { workspace = true, features = ["default"] } | ||
| sp-runtime = { workspace = true, features = ["default"] } | ||
| # Frontier | ||
| fp-storage = { workspace = true, features = ["default"] } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
| // This file is part of Frontier. | ||
| // | ||
| // Copyright (c) 2023 Parity Technologies (UK) Ltd. | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| use scale_codec::{Decode, Encode}; | ||
| // Substrate | ||
| use sp_core::{H160, H256}; | ||
| use sp_runtime::traits::Block as BlockT; | ||
| // Frontier | ||
| use fp_storage::EthereumStorageSchema; | ||
|
|
||
| #[derive(Clone, Debug, Eq, PartialEq, Encode, Decode)] | ||
| pub struct TransactionMetadata<Block: BlockT> { | ||
| pub substrate_block_hash: Block::Hash, | ||
| pub ethereum_block_hash: H256, | ||
| pub ethereum_index: u32, | ||
| } | ||
|
|
||
| /// The frontier backend interface. | ||
| #[async_trait::async_trait] | ||
| pub trait Backend<Block: BlockT>: Send + Sync { | ||
| /// Get the substrate hash with the given ethereum block hash. | ||
| async fn block_hash( | ||
| &self, | ||
| ethereum_block_hash: &H256, | ||
| ) -> Result<Option<Vec<Block::Hash>>, String>; | ||
|
|
||
| /// Get the transaction metadata with the given ethereum block hash. | ||
| async fn transaction_metadata( | ||
| &self, | ||
| ethereum_transaction_hash: &H256, | ||
| ) -> Result<Vec<TransactionMetadata<Block>>, String>; | ||
|
|
||
| /// Returns reference to log indexer backend. | ||
| fn log_indexer(&self) -> &dyn LogIndexerBackend<Block>; | ||
|
|
||
| /// Indicate whether the log indexing feature is supported. | ||
| fn is_indexed(&self) -> bool { | ||
| self.log_indexer().is_indexed() | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug, Eq, PartialEq)] | ||
| pub struct FilteredLog<Block: BlockT> { | ||
| pub substrate_block_hash: Block::Hash, | ||
| pub ethereum_block_hash: H256, | ||
| pub block_number: u32, | ||
| pub ethereum_storage_schema: EthereumStorageSchema, | ||
| pub transaction_index: u32, | ||
| pub log_index: u32, | ||
| } | ||
|
|
||
| /// The log indexer backend interface. | ||
| #[async_trait::async_trait] | ||
| pub trait LogIndexerBackend<Block: BlockT>: Send + Sync { | ||
| /// Indicate whether the log indexing feature is supported. | ||
| fn is_indexed(&self) -> bool; | ||
|
|
||
| /// Filter the logs by the parameters. | ||
| async fn filter_logs( | ||
| &self, | ||
| from_block: u64, | ||
| to_block: u64, | ||
| addresses: Vec<H160>, | ||
| topics: Vec<Vec<Option<H256>>>, | ||
| ) -> Result<Vec<FilteredLog<Block>>, String>; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 | ||
| // This file is part of Frontier. | ||
| // | ||
| // Copyright (c) 2023 Parity Technologies (UK) Ltd. | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| #![deny(unused_crate_dependencies)] | ||
|
|
||
| pub mod backend; | ||
|
|
||
| pub use self::backend::*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think we name it
fc-db-apiinstead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this crate may not only contain db-related APIs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain more what you plan to add in the future? It's currently rather confusing for me though as another important "API" we have are the runtime APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's named
fc-api, so it should be a crate that includes client side API.Currently we only have db-related API, if I want to split the implementation of db into different crates, then the mapping-sync crate is likely to be refactored, and maybe related apis will be put into this crate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sorpaas wdyt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway let's go with this now. We can change the name later.