2025-11-18 17:52:46 +02:00
|
|
|
use borsh::{BorshDeserialize, BorshSerialize};
|
2025-08-10 18:51:55 -03:00
|
|
|
use nssa_core::{
|
|
|
|
|
account::Nonce,
|
|
|
|
|
program::{InstructionData, ProgramId},
|
|
|
|
|
};
|
2025-08-13 19:21:20 -03:00
|
|
|
use serde::Serialize;
|
2025-08-10 14:10:11 -03:00
|
|
|
|
2025-11-24 17:09:30 +03:00
|
|
|
use crate::{AccountId, error::NssaError, program::Program};
|
2025-08-10 14:10:11 -03:00
|
|
|
|
2025-11-18 17:52:46 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
|
2025-08-10 14:10:11 -03:00
|
|
|
pub struct Message {
|
2026-01-24 04:05:59 +03:00
|
|
|
pub program_id: ProgramId,
|
|
|
|
|
pub account_ids: Vec<AccountId>,
|
|
|
|
|
pub nonces: Vec<Nonce>,
|
|
|
|
|
pub instruction_data: InstructionData,
|
2025-08-10 14:10:11 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Message {
|
2025-08-11 12:07:30 -03:00
|
|
|
pub fn try_new<T: Serialize>(
|
2025-08-10 14:10:11 -03:00
|
|
|
program_id: ProgramId,
|
2025-11-24 17:09:30 +03:00
|
|
|
account_ids: Vec<AccountId>,
|
2025-08-10 14:10:11 -03:00
|
|
|
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 {
|
2025-08-10 14:10:11 -03:00
|
|
|
program_id,
|
2025-11-24 17:09:30 +03:00
|
|
|
account_ids,
|
2025-08-10 14:10:11 -03:00
|
|
|
nonces,
|
|
|
|
|
instruction_data,
|
2025-08-11 12:07:30 -03:00
|
|
|
})
|
2025-08-10 14:10:11 -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,
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-08-12 10:16:04 -03:00
|
|
|
}
|