serde_p2pk_witness.rs 623 B

12345678910111213141516171819202122
  1. //! Serde utils for P2PK Witness
  2. use serde::{de, ser, Deserialize, Deserializer, Serializer};
  3. use super::P2PKWitness;
  4. /// Serialize [P2PKWitness] as stringified JSON
  5. pub fn serialize<S>(x: &P2PKWitness, s: S) -> Result<S::Ok, S::Error>
  6. where
  7. S: Serializer,
  8. {
  9. s.serialize_str(&serde_json::to_string(&x).map_err(ser::Error::custom)?)
  10. }
  11. /// Deserialize [P2PKWitness] from stringified JSON
  12. pub fn deserialize<'de, D>(deserializer: D) -> Result<P2PKWitness, D::Error>
  13. where
  14. D: Deserializer<'de>,
  15. {
  16. let s: String = String::deserialize(deserializer)?;
  17. serde_json::from_str(&s).map_err(de::Error::custom)
  18. }