feat: add display impl for BlockNumber (#1346)

This commit is contained in:
Matthias Seitz 2022-06-04 20:37:37 +02:00 committed by GitHub
parent 00b38c437a
commit 1dfe6d0cd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -9,7 +9,7 @@ use serde::{
ser::SerializeStruct,
Deserialize, Deserializer, Serialize, Serializer,
};
use std::{fmt::Formatter, str::FromStr};
use std::{fmt, fmt::Formatter, str::FromStr};
use thiserror::Error;
/// 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(not(feature = "celo"))]
mod tests {