use std::error as stderror;
use crate::{Block, Auxiliary};
pub trait Store {
type Block: Block;
type State;
type Auxiliary: Auxiliary<Self::Block>;
type Error: stderror::Error + 'static;
}
pub trait OperationError: stderror::Error {
fn invalid_operation() -> Self;
fn block_is_genesis() -> Self;
}
pub trait ChainQuery: Store {
fn genesis(&self) -> <Self::Block as Block>::Identifier;
fn head(&self) -> <Self::Block as Block>::Identifier;
fn contains(
&self,
hash: &<Self::Block as Block>::Identifier,
) -> Result<bool, Self::Error>;
fn is_canon(
&self,
hash: &<Self::Block as Block>::Identifier,
) -> Result<bool, Self::Error>;
fn lookup_canon_depth(
&self,
depth: usize,
) -> Result<Option<<Self::Block as Block>::Identifier>, Self::Error>;
fn auxiliary(
&self,
key: &<Self::Auxiliary as Auxiliary<Self::Block>>::Key,
) -> Result<Option<Self::Auxiliary>, Self::Error>;
fn depth_at(
&self,
hash: &<Self::Block as Block>::Identifier,
) -> Result<usize, Self::Error>;
fn children_at(
&self,
hash: &<Self::Block as Block>::Identifier,
) -> Result<Vec<<Self::Block as Block>::Identifier>, Self::Error>;
fn state_at(
&self,
hash: &<Self::Block as Block>::Identifier,
) -> Result<Self::State, Self::Error>;
fn block_at(
&self,
hash: &<Self::Block as Block>::Identifier,
) -> Result<Self::Block, Self::Error>;
}
pub trait ChainSettlement: Store {
fn insert_block(
&mut self,
id: <Self::Block as Block>::Identifier,
block: Self::Block,
state: Self::State,
depth: usize,
children: Vec<<Self::Block as Block>::Identifier>,
is_canon: bool
);
fn push_child(
&mut self,
id: <Self::Block as Block>::Identifier,
child: <Self::Block as Block>::Identifier,
);
fn set_canon(
&mut self,
id: <Self::Block as Block>::Identifier,
is_canon: bool
);
fn insert_canon_depth_mapping(
&mut self,
depth: usize,
id: <Self::Block as Block>::Identifier,
);
fn remove_canon_depth_mapping(
&mut self,
depth: &usize
);
fn insert_auxiliary(
&mut self,
key: <Self::Auxiliary as Auxiliary<Self::Block>>::Key,
value: Self::Auxiliary
);
fn remove_auxiliary(
&mut self,
key: &<Self::Auxiliary as Auxiliary<Self::Block>>::Key,
);
fn set_head(
&mut self,
head: <Self::Block as Block>::Identifier
);
}
pub trait Committable: Store {
type Operation;
fn commit(
&mut self,
operation: Self::Operation,
) -> Result<(), Self::Error>;
}
pub trait SharedCommittable: Store + Clone {
type Operation;
fn commit(
&self,
operation: Self::Operation,
) -> Result<(), Self::Error>;
}