feat: impl Serialize for Chain (#1917)

* feat: impl Serialize for Chain

* fix: add deps
This commit is contained in:
odysseas.eth 2022-12-02 15:12:34 -05:00 committed by GitHub
parent d6fea13d23
commit 3bf9025d2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -1,5 +1,5 @@
use super::U256; use super::U256;
use serde::Deserialize; use serde::{Deserialize, Serialize, Serializer};
use std::{ use std::{
convert::{TryFrom, TryInto}, convert::{TryFrom, TryInto},
fmt, fmt,
@ -260,6 +260,15 @@ impl FromStr for Chain {
} }
} }
impl Serialize for Chain {
fn serialize<S>(&self, s: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
s.serialize_str(self.to_string().as_ref())
}
}
impl Chain { impl Chain {
/// The blocktime varies from chain to chain. /// The blocktime varies from chain to chain.
/// ///
@ -438,5 +447,5 @@ impl Chain {
#[test] #[test]
fn test_default_chain() { fn test_default_chain() {
assert_eq!(Chain::default(), Chain::Mainnet); assert_eq!(serde_json::to_string(&Chain::Mainnet).unwrap(), "\"mainnet\"");
} }