feat: add display impl for BlockNumber (#1346)
This commit is contained in:
parent
00b38c437a
commit
1dfe6d0cd2
|
@ -9,7 +9,7 @@ use serde::{
|
||||||
ser::SerializeStruct,
|
ser::SerializeStruct,
|
||||||
Deserialize, Deserializer, Serialize, Serializer,
|
Deserialize, Deserializer, Serialize, Serializer,
|
||||||
};
|
};
|
||||||
use std::{fmt::Formatter, str::FromStr};
|
use std::{fmt, fmt::Formatter, str::FromStr};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
/// The block type returned from RPC calls.
|
/// The block type returned from RPC calls.
|
||||||
|
@ -579,6 +579,17 @@ impl FromStr for BlockNumber {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for BlockNumber {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
match self {
|
||||||
|
BlockNumber::Number(ref x) => format!("0x{:x}", x).fmt(f),
|
||||||
|
BlockNumber::Latest => f.write_str("latest"),
|
||||||
|
BlockNumber::Earliest => f.write_str("earliest"),
|
||||||
|
BlockNumber::Pending => f.write_str("pending"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
#[cfg(not(feature = "celo"))]
|
#[cfg(not(feature = "celo"))]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
|
Loading…
Reference in New Issue