use alloy::primitives::Address;
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct IndexerId(Address);
impl IndexerId {
pub const fn new(address: Address) -> Self {
IndexerId(address)
}
pub fn into_inner(self) -> Address {
self.0
}
}
impl std::fmt::Display for IndexerId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
}
}
impl std::fmt::Debug for IndexerId {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Debug::fmt(&self.0, f)
}
}
impl std::fmt::LowerHex for IndexerId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::LowerHex::fmt(&self.0, f)
}
}
impl std::fmt::UpperHex for IndexerId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::UpperHex::fmt(&self.0, f)
}
}
impl From<Address> for IndexerId {
fn from(address: Address) -> Self {
IndexerId(address)
}
}
impl std::str::FromStr for IndexerId {
type Err = <Address as std::str::FromStr>::Err;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let address = std::str::FromStr::from_str(s)?;
Ok(IndexerId(address))
}
}
impl PartialEq<Address> for IndexerId {
fn eq(&self, other: &Address) -> bool {
self.0.eq(other)
}
}
impl AsRef<Address> for IndexerId {
fn as_ref(&self) -> &Address {
&self.0
}
}
impl std::ops::Deref for IndexerId {
type Target = Address;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[cfg(feature = "serde")]
impl<'de> serde::Deserialize<'de> for IndexerId {
fn deserialize<D>(deserializer: D) -> Result<IndexerId, D::Error>
where
D: serde::Deserializer<'de>,
{
let address = Address::deserialize(deserializer)?;
Ok(IndexerId(address))
}
}
#[cfg(feature = "serde")]
impl serde::Serialize for IndexerId {
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 IndexerId {
fn dummy_with_rng<R: fake::Rng + ?Sized>(_: &fake::Faker, rng: &mut R) -> Self {
use crate::fake_impl::alloy::Alloy;
Self(Address::dummy_with_rng(&Alloy, rng))
}
}
#[macro_export]
#[doc(hidden)]
macro_rules! __indexer_id {
() => {
$crate::IndexerId::new($crate::alloy::primitives::Address::ZERO)
};
($value:tt) => {
$crate::IndexerId::new($crate::alloy::primitives::address!($value))
};
}