fuel_core_compression/
ports.rsuse fuel_core_types::{
fuel_compression::RegistryKey,
fuel_tx::{
Address,
AssetId,
CompressedUtxoId,
UtxoId,
Word,
},
fuel_types::Nonce,
tai64::Tai64,
};
pub trait TemporalRegistry<T> {
fn read_registry(&self, key: &RegistryKey) -> anyhow::Result<T>;
fn read_timestamp(&self, key: &RegistryKey) -> anyhow::Result<Tai64>;
fn write_registry(
&mut self,
key: &RegistryKey,
value: &T,
timestamp: Tai64,
) -> anyhow::Result<()>;
fn registry_index_lookup(&self, value: &T) -> anyhow::Result<Option<RegistryKey>>;
}
impl<D, T> TemporalRegistry<T> for &mut D
where
D: TemporalRegistry<T>,
{
fn read_registry(&self, key: &RegistryKey) -> anyhow::Result<T> {
<D as TemporalRegistry<T>>::read_registry(self, key)
}
fn read_timestamp(&self, key: &RegistryKey) -> anyhow::Result<Tai64> {
<D as TemporalRegistry<T>>::read_timestamp(self, key)
}
fn write_registry(
&mut self,
key: &RegistryKey,
value: &T,
timestamp: Tai64,
) -> anyhow::Result<()> {
<D as TemporalRegistry<T>>::write_registry(self, key, value, timestamp)
}
fn registry_index_lookup(&self, value: &T) -> anyhow::Result<Option<RegistryKey>> {
<D as TemporalRegistry<T>>::registry_index_lookup(self, value)
}
}
pub trait UtxoIdToPointer {
fn lookup(&self, utxo_id: UtxoId) -> anyhow::Result<CompressedUtxoId>;
}
impl<D> UtxoIdToPointer for &mut D
where
D: UtxoIdToPointer,
{
fn lookup(&self, utxo_id: UtxoId) -> anyhow::Result<CompressedUtxoId> {
<D as UtxoIdToPointer>::lookup(self, utxo_id)
}
}
pub trait HistoryLookup {
fn utxo_id(&self, c: CompressedUtxoId) -> anyhow::Result<UtxoId>;
fn coin(&self, utxo_id: UtxoId) -> anyhow::Result<CoinInfo>;
fn message(&self, nonce: Nonce) -> anyhow::Result<MessageInfo>;
}
#[derive(Debug, Clone)]
pub struct CoinInfo {
pub owner: Address,
pub amount: u64,
pub asset_id: AssetId,
}
#[derive(Debug, Clone)]
pub struct MessageInfo {
pub sender: Address,
pub recipient: Address,
pub amount: Word,
pub data: Vec<u8>,
}
pub trait EvictorDb<T> {
fn get_latest_assigned_key(&self) -> anyhow::Result<Option<RegistryKey>>;
fn set_latest_assigned_key(&mut self, key: RegistryKey) -> anyhow::Result<()>;
}
impl<D, T> EvictorDb<T> for &mut D
where
D: EvictorDb<T>,
{
fn get_latest_assigned_key(&self) -> anyhow::Result<Option<RegistryKey>> {
<D as EvictorDb<T>>::get_latest_assigned_key(self)
}
fn set_latest_assigned_key(&mut self, key: RegistryKey) -> anyhow::Result<()> {
<D as EvictorDb<T>>::set_latest_assigned_key(self, key)
}
}