use alloc::vec::Vec;
use codec::{Decode, DecodeWithMemTracking, Encode, MaxEncodedLen};
use pezframe_support::{traits::ConstU32, BoundedVec};
use pezsp_runtime::RuntimeDebug;
use scale_info::TypeInfo;
#[derive(
Clone,
PartialEq,
Eq,
PartialOrd,
Ord,
RuntimeDebug,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
MaxEncodedLen,
)]
pub struct Multihash {
pub code: u64,
pub digest: BoundedVec<u8, ConstU32<68>>, }
impl Multihash {
pub fn size(&self) -> usize {
self.digest.len()
}
}
#[derive(
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
RuntimeDebug,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
MaxEncodedLen,
)]
pub enum Version {
V0,
V1,
}
#[derive(
Clone,
PartialEq,
Eq,
PartialOrd,
Ord,
RuntimeDebug,
Encode,
Decode,
DecodeWithMemTracking,
TypeInfo,
MaxEncodedLen,
)]
pub struct Cid {
pub version: Version,
pub codec: u64,
pub hash: Multihash,
}
impl Cid {
pub fn new_v0(sha2_256_digest: impl Into<Vec<u8>>) -> Self {
const DAG_PB: u64 = 0x70;
const SHA2_256: u64 = 0x12;
let digest = sha2_256_digest.into();
assert_eq!(digest.len(), 32);
Self {
version: Version::V0,
codec: DAG_PB,
hash: Multihash { code: SHA2_256, digest: digest.try_into().expect("msg") },
}
}
}
#[derive(
Copy,
Clone,
Encode,
Decode,
DecodeWithMemTracking,
Eq,
PartialEq,
RuntimeDebug,
MaxEncodedLen,
TypeInfo,
Default,
)]
pub struct DisbandWitness {
#[codec(compact)]
pub(super) fellow_members: u32,
#[codec(compact)]
pub(super) ally_members: u32,
}
#[cfg(test)]
impl DisbandWitness {
pub(super) fn new(fellow_members: u32, ally_members: u32) -> Self {
Self { fellow_members, ally_members }
}
}
impl DisbandWitness {
pub(super) fn is_zero(self) -> bool {
self == Self::default()
}
}