Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
feat: impl Serialize for Chain (#1917)
Browse files Browse the repository at this point in the history
* feat: impl Serialize for Chain

* fix: add deps
  • Loading branch information
odyslam authored Dec 2, 2022
1 parent d6fea13 commit 3bf9025
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ethers-core/src/types/chain.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::U256;
use serde::Deserialize;
use serde::{Deserialize, Serialize, Serializer};
use std::{
convert::{TryFrom, TryInto},
fmt,
Expand Down Expand Up @@ -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 {
/// The blocktime varies from chain to chain.
///
Expand Down Expand Up @@ -438,5 +447,5 @@ impl Chain {

#[test]
fn test_default_chain() {
assert_eq!(Chain::default(), Chain::Mainnet);
assert_eq!(serde_json::to_string(&Chain::Mainnet).unwrap(), "\"mainnet\"");
}

0 comments on commit 3bf9025

Please sign in to comment.