solana_message/versions/
sanitized.rs1use {
2 super::VersionedMessage, crate::compiled_instruction::CompiledInstruction,
3 solana_address::Address, solana_sanitize::SanitizeError,
4};
5
6#[derive(Clone, Debug, PartialEq, Eq)]
8pub struct SanitizedVersionedMessage {
9 pub message: VersionedMessage,
10}
11
12impl TryFrom<VersionedMessage> for SanitizedVersionedMessage {
13 type Error = SanitizeError;
14 fn try_from(message: VersionedMessage) -> Result<Self, Self::Error> {
15 Self::try_new(message)
16 }
17}
18
19impl SanitizedVersionedMessage {
20 pub fn try_new(message: VersionedMessage) -> Result<Self, SanitizeError> {
21 message.sanitize()?;
22 Ok(Self { message })
23 }
24
25 pub fn instructions(&self) -> &[CompiledInstruction] {
28 self.message.instructions()
29 }
30
31 pub fn program_instructions_iter(
34 &self,
35 ) -> impl Iterator<Item = (&Address, &CompiledInstruction)> + Clone {
36 self.message.instructions().iter().map(move |ix| {
37 (
38 self.message
39 .static_account_keys()
40 .get(usize::from(ix.program_id_index))
41 .expect("program id index is sanitized"),
42 ix,
43 )
44 })
45 }
46}