solana_program/message/versions/
sanitized.rsuse {
super::VersionedMessage,
crate::{instruction::CompiledInstruction, pubkey::Pubkey, sanitize::SanitizeError},
};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SanitizedVersionedMessage {
pub message: VersionedMessage,
}
impl TryFrom<VersionedMessage> for SanitizedVersionedMessage {
type Error = SanitizeError;
fn try_from(message: VersionedMessage) -> Result<Self, Self::Error> {
Self::try_new(message)
}
}
impl SanitizedVersionedMessage {
pub fn try_new(message: VersionedMessage) -> Result<Self, SanitizeError> {
message.sanitize()?;
Ok(Self { message })
}
pub fn instructions(&self) -> &[CompiledInstruction] {
self.message.instructions()
}
pub fn program_instructions_iter(
&self,
) -> impl Iterator<Item = (&Pubkey, &CompiledInstruction)> {
self.message.instructions().iter().map(move |ix| {
(
self.message
.static_account_keys()
.get(usize::from(ix.program_id_index))
.expect("program id index is sanitized"),
ix,
)
})
}
}