Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: isolate event-dispatcher serialization code #4545

Merged
merged 6 commits into from
Mar 18, 2024
25 changes: 25 additions & 0 deletions stackslib/src/chainstate/stacks/boot/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,27 @@ where
u128::from_str(&s).map_err(serde::de::Error::custom)
}

fn serialize_pox_addresses<S>(value: &Vec<PoxAddress>, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.collect_seq(value.iter().cloned().map(|a| a.to_b58()))
}

fn deserialize_pox_addresses<'de, D>(deserializer: D) -> Result<Vec<PoxAddress>, D::Error>
where
D: serde::Deserializer<'de>,
{
Vec::<String>::deserialize(deserializer)?
.into_iter()
.map(|s| {
PoxAddress::from_b58(&s).ok_or_else(|| {
serde::de::Error::custom(format!("Failed to decode PoxAddress from Base58: {}", s))
})
})
.collect()
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct NakamotoSignerEntry {
#[serde(serialize_with = "hex_serialize", deserialize_with = "hex_deserialize")]
Expand All @@ -270,6 +291,10 @@ pub struct NakamotoSignerEntry {

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub struct RewardSet {
#[serde(
serialize_with = "serialize_pox_addresses",
deserialize_with = "deserialize_pox_addresses"
)]
pub rewarded_addresses: Vec<PoxAddress>,
pub start_cycle_state: PoxStartCycleInfo,
#[serde(skip_serializing_if = "Option::is_none", default)]
Expand Down