Add `Amount::serialize_as_string` helper method
A helper method that makes it easier to serialize an `Amount` as a string. This is needed for the response type of the `getaccountbalance` RPC.
This commit is contained in:
parent
d79e71e969
commit
01b432e3d2
|
@ -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<C> Amount<C> {
|
|||
{
|
||||
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<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
serializer.serialize_str(&self.0.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
impl<C> std::ops::Add<Amount<C>> for Amount<C>
|
||||
|
|
Loading…
Reference in New Issue