Trait floresta_chain::pruned_utreexo::ChainStore
source · pub trait ChainStore {
type Error: DatabaseError;
// Required methods
fn save_roots(&self, roots: Vec<u8>) -> Result<(), Self::Error>;
fn load_roots(&self) -> Result<Option<Vec<u8>>, Self::Error>;
fn load_height(&self) -> Result<Option<BestChain>, Self::Error>;
fn save_height(&self, height: &BestChain) -> Result<(), Self::Error>;
fn get_header(
&self,
block_hash: &BlockHash
) -> Result<Option<DiskBlockHeader>, Self::Error>;
fn save_header(&self, header: &DiskBlockHeader) -> Result<(), Self::Error>;
fn get_block_hash(
&self,
height: u32
) -> Result<Option<BlockHash>, Self::Error>;
fn flush(&self) -> Result<(), Self::Error>;
fn update_block_index(
&self,
height: u32,
hash: BlockHash
) -> Result<(), Self::Error>;
}
Expand description
ChainStore is a trait defining how we interact with our chain database. This definitions will be used by the [ChainState] to save and retrieve data about the blockchain, likely on disk. Right now, you can use the [KvChainStore] in your code, it implements this trait and uses a key-value store to save data. The DatabaseError is a simple trait that can be implemented by any error type that implements [std::error::Error] and [std::fmt::Display]. This is useful to abstract the database implementation from the blockchain. See the documentation of DatabaseError for more info.
Required Associated Types§
type Error: DatabaseError
Required Methods§
sourcefn save_roots(&self, roots: Vec<u8>) -> Result<(), Self::Error>
fn save_roots(&self, roots: Vec<u8>) -> Result<(), Self::Error>
Saves the current state of our accumulator.
sourcefn load_roots(&self) -> Result<Option<Vec<u8>>, Self::Error>
fn load_roots(&self) -> Result<Option<Vec<u8>>, Self::Error>
Loads the state of our accumulator.
sourcefn save_height(&self, height: &BestChain) -> Result<(), Self::Error>
fn save_height(&self, height: &BestChain) -> Result<(), Self::Error>
Saves the blockchain height.
sourcefn get_header(
&self,
block_hash: &BlockHash
) -> Result<Option<DiskBlockHeader>, Self::Error>
fn get_header( &self, block_hash: &BlockHash ) -> Result<Option<DiskBlockHeader>, Self::Error>
Get a block header from our database. See DiskBlockHeader for more info about the data we save.
sourcefn save_header(&self, header: &DiskBlockHeader) -> Result<(), Self::Error>
fn save_header(&self, header: &DiskBlockHeader) -> Result<(), Self::Error>
Saves a block header to our database. See DiskBlockHeader for more info about the data we save.
sourcefn get_block_hash(&self, height: u32) -> Result<Option<BlockHash>, Self::Error>
fn get_block_hash(&self, height: u32) -> Result<Option<BlockHash>, Self::Error>
Returns the block hash for a given height.