use crate::fuel_core_graphql_api::ports::{ DatabaseBlocks, OnChainDatabase, }; use fuel_core_storage::{ iter::{ BoxedIter, IterDirection, }, Result as StorageResult, }; use fuel_core_types::{ blockchain::{ block::CompressedBlock, consensus::Consensus, }, fuel_types::BlockHeight, }; pub trait SimpleBlockData: Send + Sync { fn block(&self, id: &BlockHeight) -> StorageResult; } impl SimpleBlockData for D where D: OnChainDatabase + DatabaseBlocks + ?Sized, { fn block(&self, id: &BlockHeight) -> StorageResult { self.block(id) } } pub trait BlockQueryData: Send + Sync + SimpleBlockData { fn latest_block_height(&self) -> StorageResult; fn latest_block(&self) -> StorageResult; fn compressed_blocks( &self, height: Option, direction: IterDirection, ) -> BoxedIter>; fn consensus(&self, id: &BlockHeight) -> StorageResult; } impl BlockQueryData for D where D: OnChainDatabase + DatabaseBlocks + ?Sized, { fn latest_block_height(&self) -> StorageResult { self.latest_height() } fn latest_block(&self) -> StorageResult { self.block(&self.latest_block_height()?) } fn compressed_blocks( &self, height: Option, direction: IterDirection, ) -> BoxedIter> { self.blocks(height, direction) } fn consensus(&self, id: &BlockHeight) -> StorageResult { self.consensus(id) } }