31 lines
750 B
Rust
31 lines
750 B
Rust
pub type Error = Box<dyn std::error::Error>;
|
|
|
|
pub trait Fragment<'a>
|
|
where
|
|
Self: Sized,
|
|
{
|
|
fn encode_fragment(&self) -> Result<Vec<u8>, Error>;
|
|
fn decode_fragment(bytes: &'a [u8]) -> Result<Self, Error>;
|
|
}
|
|
|
|
impl<'a, T> Fragment<'a> for T
|
|
where
|
|
T: minicbor::Encode + minicbor::Decode<'a> + Sized,
|
|
{
|
|
fn encode_fragment(&self) -> Result<Vec<u8>, Error> {
|
|
minicbor::to_vec(self).map_err(|e| e.into())
|
|
}
|
|
|
|
fn decode_fragment(bytes: &'a [u8]) -> Result<Self, Error> {
|
|
minicbor::decode(bytes).map_err(|e| e.into())
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
|
pub enum Era {
|
|
Byron,
|
|
Shelley,
|
|
Allegra, // time-locks
|
|
Mary, // multi-assets
|
|
Alonzo, // smart-contracts
|
|
}
|