From 37afbc230472b4ffe6ea72943cea1c234443e47f Mon Sep 17 00:00:00 2001 From: lemunozm Date: Fri, 5 Apr 2024 08:23:26 +0200 Subject: [PATCH] fix fixed_point serialization for std --- libs/types/src/fixed_point.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/libs/types/src/fixed_point.rs b/libs/types/src/fixed_point.rs index d40ae45e7b..8f28a8de7e 100644 --- a/libs/types/src/fixed_point.rs +++ b/libs/types/src/fixed_point.rs @@ -13,7 +13,8 @@ //! Decimal Fixed Point implementations for Substrate runtime. //! Copied over from sp_arithmetic -use parity_scale_codec::{CompactAs, Decode, Encode, MaxEncodedLen}; +use parity_scale_codec::{alloc::string::ToString, CompactAs, Decode, Encode, MaxEncodedLen}; +use scale_info::prelude::string::String; use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use sp_arithmetic::{ helpers_128bit::multiply_by_rational_with_rounding, @@ -769,14 +770,12 @@ impl sp_std::fmt::Debug for FixedU128
{ } } -#[cfg(feature = "std")] impl sp_std::fmt::Display for FixedU128
{ fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result { write!(f, "{}", self.0) } } -#[cfg(feature = "std")] impl sp_std::str::FromStr for FixedU128
{ type Err = &'static str; @@ -788,8 +787,7 @@ impl sp_std::str::FromStr for FixedU128
{ } } -// Manual impl `Serialize` as serde_json does not support i128. -// TODO: remove impl if issue https://github.com/serde-rs/json/issues/548 fixed. +// See: https://github.com/paritytech/substrate/pull/9708 impl Serialize for FixedU128
{ fn serialize(&self, serializer: S) -> Result where @@ -799,8 +797,7 @@ impl Serialize for FixedU128
{ } } -// Manual impl `Deserialize` as serde_json does not support i128. -// TODO: remove impl if issue https://github.com/serde-rs/json/issues/548 fixed. +// See: https://github.com/paritytech/substrate/pull/9708 impl<'de, const DIV: u128> Deserialize<'de> for FixedU128
{ fn deserialize(deserializer: D) -> Result where