49 lines
1.2 KiB
Rust
Raw Normal View History

use borsh::{BorshDeserialize, BorshSerialize};
2025-08-10 18:51:55 -03:00
use nssa_core::{
account::Nonce,
program::{InstructionData, ProgramId},
};
use serde::Serialize;
use crate::{AccountId, error::NssaError, program::Program};
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
pub struct Message {
pub program_id: ProgramId,
pub account_ids: Vec<AccountId>,
pub nonces: Vec<Nonce>,
pub instruction_data: InstructionData,
}
impl Message {
2025-08-11 12:07:30 -03:00
pub fn try_new<T: Serialize>(
program_id: ProgramId,
account_ids: Vec<AccountId>,
nonces: Vec<Nonce>,
2025-08-10 18:59:29 -03:00
instruction: T,
2025-08-11 12:07:30 -03:00
) -> Result<Self, NssaError> {
let instruction_data = Program::serialize_instruction(instruction)?;
2025-12-17 14:21:36 +02:00
2025-08-11 12:07:30 -03:00
Ok(Self {
program_id,
account_ids,
nonces,
instruction_data,
2025-08-11 12:07:30 -03:00
})
}
2025-12-17 11:44:52 +02:00
pub fn new_preserialized(
program_id: ProgramId,
account_ids: Vec<AccountId>,
nonces: Vec<Nonce>,
2025-12-22 04:42:32 +02:00
instruction_data: InstructionData,
2025-12-17 11:44:52 +02:00
) -> Self {
Self {
program_id,
account_ids,
nonces,
instruction_data,
}
}
}