From 3bf9025d2f4ca1ec5a673cd42153f05a3dc868f6 Mon Sep 17 00:00:00 2001 From: "odysseas.eth" Date: Fri, 2 Dec 2022 15:12:34 -0500 Subject: [PATCH] feat: impl Serialize for Chain (#1917) * feat: impl Serialize for Chain * fix: add deps --- ethers-core/src/types/chain.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ethers-core/src/types/chain.rs b/ethers-core/src/types/chain.rs index 1e395091..5a1f1036 100644 --- a/ethers-core/src/types/chain.rs +++ b/ethers-core/src/types/chain.rs @@ -1,5 +1,5 @@ use super::U256; -use serde::Deserialize; +use serde::{Deserialize, Serialize, Serializer}; use std::{ convert::{TryFrom, TryInto}, fmt, @@ -260,6 +260,15 @@ impl FromStr for Chain { } } +impl Serialize for Chain { + fn serialize(&self, s: S) -> Result + where + S: Serializer, + { + s.serialize_str(self.to_string().as_ref()) + } +} + impl Chain { /// The blocktime varies from chain to chain. /// @@ -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\""); }