partner_chains_db_sync_data_sources/mc_hash/
mod.rs1use crate::{block::BlockDataSourceImpl, metrics::McFollowerMetrics, observed_async_trait};
3use sidechain_domain::{MainchainBlock, McBlockHash};
4use sidechain_mc_hash::McHashDataSource;
5use sp_timestamp::Timestamp;
6use std::sync::Arc;
7
8pub struct McHashDataSourceImpl {
12 inner: Arc<BlockDataSourceImpl>,
14 metrics_opt: Option<McFollowerMetrics>,
16}
17
18impl McHashDataSourceImpl {
19 pub fn new(inner: Arc<BlockDataSourceImpl>, metrics_opt: Option<McFollowerMetrics>) -> Self {
21 Self { inner, metrics_opt }
22 }
23}
24
25observed_async_trait!(
26impl McHashDataSource for McHashDataSourceImpl {
27 async fn get_latest_stable_block_for(
28 &self,
29 reference_timestamp: sp_timestamp::Timestamp,
30 ) -> std::result::Result<Option<MainchainBlock>, Box<dyn std::error::Error + Send + Sync>> {
31 Ok(self
32 .inner
33 .get_latest_stable_block_for(Timestamp::new(reference_timestamp.as_millis()))
34 .await?)
35 }
36
37 async fn get_stable_block_for(
38 &self,
39 hash: McBlockHash,
40 reference_timestamp: sp_timestamp::Timestamp,
41 ) -> std::result::Result<Option<MainchainBlock>, Box<dyn std::error::Error + Send + Sync>> {
42 Ok(self
43 .inner
44 .get_stable_block_for(hash, Timestamp::new(reference_timestamp.as_millis()))
45 .await?)
46 }
47
48 async fn get_block_by_hash(
49 &self,
50 hash: McBlockHash,
51 ) -> std::result::Result<Option<MainchainBlock>, Box<dyn std::error::Error + Send + Sync>> {
52 Ok(self.inner.get_block_by_hash(hash).await?)
53 }
54}
55);