Support json parsing of epoch-rewards partition data sysvar accounts (#34914)
This commit is contained in:
parent
bd103865df
commit
b9947bd327
|
@ -9,6 +9,7 @@ use {
|
||||||
bv::BitVec,
|
bv::BitVec,
|
||||||
solana_sdk::{
|
solana_sdk::{
|
||||||
clock::{Clock, Epoch, Slot, UnixTimestamp},
|
clock::{Clock, Epoch, Slot, UnixTimestamp},
|
||||||
|
epoch_rewards_partition_data::EpochRewardsPartitionDataVersion,
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
pubkey::Pubkey,
|
pubkey::Pubkey,
|
||||||
rent::Rent,
|
rent::Rent,
|
||||||
|
@ -95,9 +96,26 @@ pub fn parse_sysvar(data: &[u8], pubkey: &Pubkey) -> Result<SysvarAccountType, P
|
||||||
deserialize::<EpochRewards>(data)
|
deserialize::<EpochRewards>(data)
|
||||||
.ok()
|
.ok()
|
||||||
.map(SysvarAccountType::EpochRewards)
|
.map(SysvarAccountType::EpochRewards)
|
||||||
|
} else {
|
||||||
|
// EpochRewards PartitionData accounts are owned by the sysvar
|
||||||
|
// program, but have dynamically generated addresses. Test on
|
||||||
|
// whether account content deserializes properly.
|
||||||
|
if let Ok(epoch_rewards_partition_data) =
|
||||||
|
deserialize::<EpochRewardsPartitionDataVersion>(data)
|
||||||
|
{
|
||||||
|
let EpochRewardsPartitionDataVersion::V0(partition_data) =
|
||||||
|
epoch_rewards_partition_data;
|
||||||
|
Some(SysvarAccountType::EpochRewardsPartitionData(
|
||||||
|
UiEpochRewardsPartitionData {
|
||||||
|
version: 0,
|
||||||
|
num_partitions: partition_data.num_partitions as u64,
|
||||||
|
parent_blockhash: partition_data.parent_blockhash.to_string(),
|
||||||
|
},
|
||||||
|
))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
parsed_account.ok_or(ParseAccountError::AccountNotParsable(
|
parsed_account.ok_or(ParseAccountError::AccountNotParsable(
|
||||||
ParsableAccount::Sysvar,
|
ParsableAccount::Sysvar,
|
||||||
|
@ -120,6 +138,7 @@ pub enum SysvarAccountType {
|
||||||
StakeHistory(Vec<UiStakeHistoryEntry>),
|
StakeHistory(Vec<UiStakeHistoryEntry>),
|
||||||
LastRestartSlot(UiLastRestartSlot),
|
LastRestartSlot(UiLastRestartSlot),
|
||||||
EpochRewards(EpochRewards),
|
EpochRewards(EpochRewards),
|
||||||
|
EpochRewardsPartitionData(UiEpochRewardsPartitionData),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
|
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||||
|
@ -239,6 +258,14 @@ pub struct UiLastRestartSlot {
|
||||||
pub last_restart_slot: Slot,
|
pub last_restart_slot: Slot,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Default)]
|
||||||
|
#[serde(rename_all = "camelCase")]
|
||||||
|
pub struct UiEpochRewardsPartitionData {
|
||||||
|
pub version: u32,
|
||||||
|
pub num_partitions: u64,
|
||||||
|
pub parent_blockhash: String,
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
|
|
Loading…
Reference in New Issue