switch serde serialization to string
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
-use serde::{Deserialize, Serialize};
+use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
/// Represents the amount of NEAR tokens in "gas units" which are used to fund transactions.
#[derive(
@@ -12,8 +12,6 @@ use serde::{Deserialize, Serialize};
Eq,
BorshSerialize,
BorshDeserialize,
- Deserialize,
- Serialize,
Hash,
BorshSchema,
)]
@@ -25,6 +23,25 @@ impl Gas {
}
}
+impl Serialize for Gas {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
+ S: Serializer,
+ {
+ serializer.serialize_str(&self.0.to_string())
+ }
+}
+
+impl<'de> Deserialize<'de> for Gas {
+ fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
+ where
+ D: Deserializer<'de>,
+ {
+ let s: String = Deserialize::deserialize(deserializer)?;
+ s.parse::<u64>().map(Self).map_err(|err| de::Error::custom(err.to_string()))
+ }
+}
+
impl From<u64> for Gas {
fn from(amount: u64) -> Self {
Self(amount)
