Skip to content

Commit

Permalink
Merge pull request #4524 from stacks-network/feat/add-pox-threshold-e…
Browse files Browse the repository at this point in the history
…vent-data

feat: add `pox_stx_threshold` amount to `/new_block` event data
  • Loading branch information
zone117x committed Mar 13, 2024
2 parents 9058e22 + d38a9e6 commit fec1cb5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions stacks-signer/src/client/stacks_client.rs
Expand Up @@ -1143,6 +1143,7 @@ mod tests {
stacked_amt: rand::thread_rng().next_u64() as u128,
weight: 1,
}]),
pox_ustx_threshold: None,
};
let stackers_response = GetStackersResponse {
stacker_set: stacker_set.clone(),
Expand Down
1 change: 1 addition & 0 deletions stackslib/src/chainstate/coordinator/tests.rs
Expand Up @@ -511,6 +511,7 @@ impl RewardSetProvider for StubbedRewardSetProvider {
missed_reward_slots: vec![],
},
signers: None,
pox_ustx_threshold: None,
})
}

Expand Down
34 changes: 34 additions & 0 deletions stackslib/src/chainstate/stacks/boot/mod.rs
Expand Up @@ -213,6 +213,33 @@ fn hex_deserialize<'de, D: serde::Deserializer<'de>>(
Ok(bytes)
}

fn serialize_optional_u128_as_string<S>(
value: &Option<u128>,
serializer: S,
) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
match value {
Some(v) => serializer.serialize_str(&v.to_string()),
None => serializer.serialize_none(),
}
}

fn deserialize_optional_u128_from_string<'de, D>(deserializer: D) -> Result<Option<u128>, D::Error>
where
D: serde::Deserializer<'de>,
{
let s: Option<String> = Option::deserialize(deserializer)?;
match s {
Some(str_val) => str_val
.parse::<u128>()
.map(Some)
.map_err(serde::de::Error::custom),
None => Ok(None),
}
}

fn serialize_u128_as_string<S>(value: &u128, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
Expand Down Expand Up @@ -248,6 +275,11 @@ pub struct RewardSet {
#[serde(skip_serializing_if = "Option::is_none", default)]
// only generated for nakamoto reward sets
pub signers: Option<Vec<NakamotoSignerEntry>>,
#[serde(
serialize_with = "serialize_optional_u128_as_string",
deserialize_with = "deserialize_optional_u128_from_string"
)]
pub pox_ustx_threshold: Option<u128>,
}

#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -280,6 +312,7 @@ impl RewardSet {
missed_reward_slots: vec![],
},
signers: None,
pox_ustx_threshold: None,
}
}

Expand Down Expand Up @@ -863,6 +896,7 @@ impl StacksChainState {
missed_reward_slots: missed_slots,
},
signers: signer_set,
pox_ustx_threshold: Some(threshold),
}
}

Expand Down

0 comments on commit fec1cb5

Please sign in to comment.