-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sync): add StateSyncClient and SyncBlock
- Loading branch information
1 parent
87b728f
commit 76a1e57
Showing
7 changed files
with
86 additions
and
0 deletions.
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 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 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,16 @@ | ||
[package] | ||
name = "starknet_state_sync_types" | ||
version.workspace = true | ||
edition.workspace = true | ||
license.workspace = true | ||
repository.workspace = true | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
async-trait.workspace = true | ||
serde = { workspace = true, features = ["derive"] } | ||
starknet_api.workspace = true | ||
starknet_sequencer_infra.workspace = true | ||
thiserror.workspace = true |
This file contains 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,28 @@ | ||
use async_trait::async_trait; | ||
use starknet_api::block::BlockNumber; | ||
use starknet_sequencer_infra::component_client::ClientError; | ||
use thiserror::Error; | ||
|
||
use crate::errors::StateSyncError; | ||
use crate::state_sync_types::SyncBlock; | ||
|
||
#[async_trait] | ||
pub trait StateSyncClient: Send + Sync { | ||
async fn get_block( | ||
&self, | ||
block_number: BlockNumber, | ||
) -> StateSyncClientResult<Option<SyncBlock>>; | ||
|
||
// TODO: Add state reader methods for gateway. | ||
} | ||
|
||
#[derive(Clone, Debug, Error)] | ||
pub enum StateSyncClientError { | ||
#[error(transparent)] | ||
ClientError(#[from] ClientError), | ||
#[error(transparent)] | ||
StateSyncError(#[from] StateSyncError), | ||
} | ||
pub type StateSyncClientResult<T> = Result<T, StateSyncClientError>; | ||
|
||
// TODO: Add client types and request/response enums |
This file contains 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,6 @@ | ||
use serde::{Deserialize, Serialize}; | ||
use thiserror::Error; | ||
|
||
// This error is defined even though it's empty to be compatible with the other components. | ||
#[derive(Debug, Error, Serialize, Deserialize, Clone)] | ||
pub enum StateSyncError {} |
This file contains 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,3 @@ | ||
pub mod communication; | ||
pub mod errors; | ||
pub mod state_sync_types; |
This file contains 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,21 @@ | ||
use std::collections::HashMap; | ||
|
||
use starknet_api::block::BlockHash; | ||
use starknet_api::core::ClassHash; | ||
use starknet_api::deprecated_contract_class::ContractClass as DeprecatedContractClass; | ||
use starknet_api::state::{ContractClass, ThinStateDiff}; | ||
use starknet_api::transaction::TransactionHash; | ||
|
||
use crate::errors::StateSyncError; | ||
|
||
pub type StateSyncResult<T> = Result<T, StateSyncError>; | ||
|
||
pub struct SyncBlock { | ||
pub block_hash: BlockHash, | ||
pub parent_block_hash: BlockHash, | ||
pub state_diff: ThinStateDiff, | ||
pub classes: HashMap<ClassHash, ContractClass>, | ||
// TODO: Consider removing deprecated classes. | ||
pub deprecated_classes: HashMap<ClassHash, DeprecatedContractClass>, | ||
pub transaction_hashes: Vec<TransactionHash>, | ||
} |