34 lines
899 B
Rust
Raw Normal View History

use borsh::{BorshDeserialize, BorshSerialize};
use crate::{
2025-10-16 16:24:18 -03:00
V02State, error::NssaError, program::Program, program_deployment_transaction::message::Message,
};
2025-10-14 17:15:04 -03:00
#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize)]
2025-10-14 17:15:04 -03:00
pub struct ProgramDeploymentTransaction {
pub(crate) message: Message,
2025-10-14 17:15:04 -03:00
}
impl ProgramDeploymentTransaction {
pub fn new(message: Message) -> Self {
Self { message }
}
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,
) -> 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
}
}