use borsh::{BorshDeserialize, BorshSerialize}; use nssa_core::{ account::Nonce, program::{InstructionData, ProgramId}, }; use serde::{Deserialize, Serialize}; use crate::{AccountId, error::NssaError, program::Program}; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, BorshSerialize, BorshDeserialize)] pub struct Message { pub program_id: ProgramId, pub account_ids: Vec, pub nonces: Vec, pub instruction_data: InstructionData, } impl std::fmt::Debug for Message { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let program_id_hex = hex::encode( self.program_id .iter() .flat_map(|n| n.to_le_bytes()) .collect::>(), ); f.debug_struct("Message") .field("program_id", &program_id_hex) .field("account_ids", &self.account_ids) .field("nonces", &self.nonces) .field("instruction_data", &self.instruction_data) .finish() } } impl Message { pub fn try_new( program_id: ProgramId, account_ids: Vec, nonces: Vec, instruction: T, ) -> Result { let instruction_data = Program::serialize_instruction(instruction)?; Ok(Self { program_id, account_ids, nonces, instruction_data, }) } #[must_use] pub const fn new_preserialized( program_id: ProgramId, account_ids: Vec, nonces: Vec, instruction_data: InstructionData, ) -> Self { Self { program_id, account_ids, nonces, instruction_data, } } }