diff --git a/zebra-chain/src/amount.rs b/zebra-chain/src/amount.rs index 7ca036acc..87e2d3b71 100644 --- a/zebra-chain/src/amount.rs +++ b/zebra-chain/src/amount.rs @@ -15,6 +15,7 @@ use std::{ use crate::serialization::{ZcashDeserialize, ZcashSerialize}; use byteorder::{ByteOrder, LittleEndian, ReadBytesExt, WriteBytesExt}; +use serde::Serializer; #[cfg(any(test, feature = "proptest-impl"))] pub mod arbitrary; @@ -82,6 +83,16 @@ impl Amount { { 0.try_into().expect("an amount of 0 is always valid") } + + /// Serialize this [`Amount`] as a string instead of an integer. + /// + /// The string contains the amount of Zatoshis in the amount. + pub fn serialize_as_string(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_str(&self.0.to_string()) + } } impl std::ops::Add> for Amount