Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request stacks-network#4522 from stacks-network/fix/stacke…
Browse files Browse the repository at this point in the history
…d-amt-json-serialization

fix: `stacked_amt: u128` should serialize as string
  • Loading branch information
zone117x authored Mar 12, 2024
2 parents ae8a483 + b7e2590 commit 5150acf
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions stackslib/src/chainstate/stacks/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,30 @@ fn hex_deserialize<'de, D: serde::Deserializer<'de>>(
Ok(bytes)
}

fn serialize_u128_as_string<S>(value: &u128, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&value.to_string())
}

fn deserialize_u128_from_string<'de, D>(deserializer: D) -> Result<u128, D::Error>
where
D: serde::Deserializer<'de>,
{
use std::str::FromStr;
let s = String::deserialize(deserializer)?;
u128::from_str(&s).map_err(serde::de::Error::custom)
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct NakamotoSignerEntry {
#[serde(serialize_with = "hex_serialize", deserialize_with = "hex_deserialize")]
pub signing_key: [u8; 33],
#[serde(
serialize_with = "serialize_u128_as_string",
deserialize_with = "deserialize_u128_from_string"
)]
pub stacked_amt: u128,
pub weight: u32,
}
Expand Down

0 comments on commit 5150acf

Please sign in to comment.