use alloy::primitives::B256;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[doc(alias = "poi")]
pub struct ProofOfIndexing(B256);
impl ProofOfIndexing {
pub const ZERO: Self = Self(B256::ZERO);
pub const fn new(bytes: B256) -> Self {
Self(bytes)
}
}
impl AsRef<B256> for ProofOfIndexing {
fn as_ref(&self) -> &B256 {
&self.0
}
}
impl AsRef<[u8]> for ProofOfIndexing {
fn as_ref(&self) -> &[u8] {
self.0.as_ref()
}
}
impl AsRef<[u8; 32]> for ProofOfIndexing {
fn as_ref(&self) -> &[u8; 32] {
self.0.as_ref()
}
}
impl std::borrow::Borrow<[u8]> for ProofOfIndexing {
fn borrow(&self) -> &[u8] {
self.0.borrow()
}
}
impl std::borrow::Borrow<[u8; 32]> for ProofOfIndexing {
fn borrow(&self) -> &[u8; 32] {
self.0.borrow()
}
}
impl std::ops::Deref for ProofOfIndexing {
type Target = B256;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl From<B256> for ProofOfIndexing {
fn from(bytes: B256) -> Self {
Self(bytes)
}
}
impl From<[u8; 32]> for ProofOfIndexing {
fn from(value: [u8; 32]) -> Self {
Self(value.into())
}
}
impl<'a> From<&'a [u8; 32]> for ProofOfIndexing {
fn from(value: &'a [u8; 32]) -> Self {
Self(value.into())
}
}
impl<'a> TryFrom<&'a [u8]> for ProofOfIndexing {
type Error = <B256 as TryFrom<&'a [u8]>>::Error;
fn try_from(value: &[u8]) -> Result<Self, Self::Error> {
value.try_into().map(Self)
}
}
impl From<ProofOfIndexing> for B256 {
fn from(id: ProofOfIndexing) -> Self {
id.0
}
}
impl From<&ProofOfIndexing> for B256 {
fn from(id: &ProofOfIndexing) -> Self {
id.0
}
}
impl PartialEq<B256> for ProofOfIndexing {
fn eq(&self, other: &B256) -> bool {
self.0.eq(other)
}
}
impl std::fmt::Display for ProofOfIndexing {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}
impl std::fmt::Debug for ProofOfIndexing {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "ProofOfIndexing({})", self.0)
}
}
#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for ProofOfIndexing {
fn deserialize<D>(deserializer: D) -> Result<ProofOfIndexing, D::Error>
where
D: serde::Deserializer<'de>,
{
serde::Deserialize::deserialize(deserializer).map(Self)
}
}
#[cfg(feature = "serde")]
impl serde::Serialize for ProofOfIndexing {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
self.0.serialize(serializer)
}
}
#[cfg(feature = "fake")]
impl fake::Dummy<fake::Faker> for ProofOfIndexing {
fn dummy_with_rng<R: fake::Rng + ?Sized>(config: &fake::Faker, rng: &mut R) -> Self {
let bytes = <[u8; 32]>::dummy_with_rng(config, rng);
Self(B256::new(bytes))
}
}
#[macro_export]
#[doc(hidden)]
macro_rules! __proof_of_indexing {
() => {
$crate::ProofOfIndexing::ZERO
};
($id:tt) => {
$crate::ProofOfIndexing::new($crate::alloy::primitives::b256!($id))
};
}