-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): move block-strider traits to separate files
- Loading branch information
1 parent
f151205
commit c8ca671
Showing
7 changed files
with
252 additions
and
99 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
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
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use everscale_types::models::BlockId; | ||
|
||
pub trait BlockStriderState: Send + Sync + 'static { | ||
fn load_last_traversed_master_block_id(&self) -> BlockId; | ||
fn is_traversed(&self, block_id: &BlockId) -> bool; | ||
fn commit_traversed(&self, block_id: BlockId); | ||
} | ||
|
||
impl<T: BlockStriderState> BlockStriderState for Box<T> { | ||
fn load_last_traversed_master_block_id(&self) -> BlockId { | ||
<T as BlockStriderState>::load_last_traversed_master_block_id(self) | ||
} | ||
|
||
fn is_traversed(&self, block_id: &BlockId) -> bool { | ||
<T as BlockStriderState>::is_traversed(self, block_id) | ||
} | ||
|
||
fn commit_traversed(&self, block_id: BlockId) { | ||
<T as BlockStriderState>::commit_traversed(self, block_id); | ||
} | ||
} |
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,36 @@ | ||
use everscale_types::models::Block; | ||
use futures_util::future; | ||
use std::future::Future; | ||
|
||
pub trait BlockSubscriber: Send + Sync + 'static { | ||
type HandleBlockFut: Future<Output = anyhow::Result<()>> + Send + 'static; | ||
|
||
fn handle_block(&self, block: &Block) -> Self::HandleBlockFut; | ||
} | ||
|
||
impl<T: BlockSubscriber> BlockSubscriber for Box<T> { | ||
type HandleBlockFut = T::HandleBlockFut; | ||
|
||
fn handle_block(&self, block: &Block) -> Self::HandleBlockFut { | ||
<T as BlockSubscriber>::handle_block(self, block) | ||
} | ||
} | ||
|
||
pub struct FanoutBlockSubscriber<T1, T2> { | ||
pub left: T1, | ||
pub right: T2, | ||
} | ||
|
||
impl<T1: BlockSubscriber, T2: BlockSubscriber> BlockSubscriber for FanoutBlockSubscriber<T1, T2> { | ||
type HandleBlockFut = future::BoxFuture<'static, anyhow::Result<()>>; | ||
|
||
fn handle_block(&self, block: &Block) -> Self::HandleBlockFut { | ||
let left = self.left.handle_block(block); | ||
let right = self.right.handle_block(block); | ||
|
||
Box::pin(async move { | ||
let (l, r) = future::join(left, right).await; | ||
l.and(r) | ||
}) | ||
} | ||
} |