2025-11-19 14:28:18 +02:00
|
|
|
use borsh::{BorshDeserialize, BorshSerialize};
|
|
|
|
|
|
2025-10-15 17:25:26 -03:00
|
|
|
use crate::{
|
2025-10-16 16:24:18 -03:00
|
|
|
V02State, error::NssaError, program::Program, program_deployment_transaction::message::Message,
|
2025-10-15 17:25:26 -03:00
|
|
|
};
|
2025-10-14 17:15:04 -03:00
|
|
|
|
2025-11-19 14:28:18 +02:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
|
2025-10-14 17:15:04 -03:00
|
|
|
pub struct ProgramDeploymentTransaction {
|
2025-10-15 18:00:35 -03:00
|
|
|
pub(crate) message: Message,
|
2025-10-14 17:15:04 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ProgramDeploymentTransaction {
|
|
|
|
|
pub fn new(message: Message) -> Self {
|
|
|
|
|
Self { message }
|
|
|
|
|
}
|
2025-10-15 17:25:26 -03:00
|
|
|
|
2026-01-24 04:05:59 +03:00
|
|
|
pub fn into_message(self) -> Message {
|
|
|
|
|
self.message
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-14 17:15:04 -03:00
|
|
|
pub(crate) fn validate_and_produce_public_state_diff(
|
|
|
|
|
&self,
|
2025-10-16 16:24:18 -03:00
|
|
|
state: &V02State,
|
2025-10-15 17:25:26 -03:00
|
|
|
) -> Result<Program, NssaError> {
|
|
|
|
|
// TODO: remove clone
|
|
|
|
|
let program = Program::new(self.message.bytecode.clone())?;
|
|
|
|
|
if state.programs().contains_key(&program.id()) {
|
|
|
|
|
Err(NssaError::ProgramAlreadyExists)
|
|
|
|
|
} else {
|
|
|
|
|
Ok(program)
|
|
|
|
|
}
|
2025-10-14 17:15:04 -03:00
|
|
|
}
|
|
|
|
|
}
|