partner_chains_dolos_data_sources/
mc_hash.rs1use crate::Result;
2use crate::block::BlockDataSourceImpl;
3use async_trait::async_trait;
4use sidechain_domain::*;
5use sp_timestamp::Timestamp;
6use std::sync::Arc;
7
8pub struct McHashDataSourceImpl {
9 inner: Arc<BlockDataSourceImpl>,
11}
12
13impl McHashDataSourceImpl {
14 pub fn new(inner: Arc<BlockDataSourceImpl>) -> Self {
15 Self { inner }
16 }
17}
18
19#[async_trait]
20impl sidechain_mc_hash::McHashDataSource for McHashDataSourceImpl {
21 async fn get_latest_stable_block_for(
22 &self,
23 reference_timestamp: sp_timestamp::Timestamp,
24 ) -> Result<Option<MainchainBlock>> {
25 Ok(self
26 .inner
27 .get_latest_stable_block_for(Timestamp::new(reference_timestamp.as_millis()))
28 .await?)
29 }
30
31 async fn get_stable_block_for(
32 &self,
33 hash: McBlockHash,
34 reference_timestamp: sp_timestamp::Timestamp,
35 ) -> Result<Option<MainchainBlock>> {
36 Ok(self
37 .inner
38 .get_stable_block_for(hash, Timestamp::new(reference_timestamp.as_millis()))
39 .await?)
40 }
41
42 async fn get_block_by_hash(&self, hash: McBlockHash) -> Result<Option<MainchainBlock>> {
43 Ok(self.inner.get_block_by_hash(hash).await?)
44 }
45}