mod bytes;
mod serialize;
mod string;
use super::*;
use crate::{Deployment, Execution, Fee};
#[derive(Clone, PartialEq, Eq)]
pub enum Rejected<N: Network> {
Deployment(ProgramOwner<N>, Box<Deployment<N>>),
Execution(Execution<N>),
}
impl<N: Network> Rejected<N> {
pub fn new_deployment(program_owner: ProgramOwner<N>, deployment: Deployment<N>) -> Self {
Self::Deployment(program_owner, Box::new(deployment))
}
pub fn new_execution(execution: Execution<N>) -> Self {
Self::Execution(execution)
}
pub fn is_deployment(&self) -> bool {
matches!(self, Self::Deployment(..))
}
pub fn is_execution(&self) -> bool {
matches!(self, Self::Execution(..))
}
pub fn program_owner(&self) -> Option<&ProgramOwner<N>> {
match self {
Self::Deployment(program_owner, _) => Some(program_owner),
Self::Execution(_) => None,
}
}
pub fn deployment(&self) -> Option<&Deployment<N>> {
match self {
Self::Deployment(_, deployment) => Some(deployment),
Self::Execution(_) => None,
}
}
pub fn execution(&self) -> Option<&Execution<N>> {
match self {
Self::Deployment(_, _) => None,
Self::Execution(execution) => Some(execution),
}
}
pub fn to_id(&self) -> Result<Field<N>> {
match self {
Self::Deployment(_, deployment) => deployment.to_deployment_id(),
Self::Execution(execution) => execution.to_execution_id(),
}
}
pub fn to_unconfirmed_id(&self, fee: &Option<Fee<N>>) -> Result<Field<N>> {
match self {
Self::Deployment(_, deployment) => Ok(*Transaction::deployment_tree(deployment, fee.as_ref())?.root()),
Self::Execution(execution) => Ok(*Transaction::execution_tree(execution, fee)?.root()),
}
}
}
#[cfg(test)]
pub mod test_helpers {
use super::*;
use console::{account::PrivateKey, network::Testnet3};
type CurrentNetwork = Testnet3;
pub(crate) fn sample_rejected_deployment(is_fee_private: bool, rng: &mut TestRng) -> Rejected<CurrentNetwork> {
let deployment = match crate::transaction::test_helpers::sample_deployment_transaction(is_fee_private, rng) {
Transaction::Deploy(_, _, deployment, _) => (*deployment).clone(),
_ => unreachable!(),
};
let private_key = PrivateKey::new(rng).unwrap();
let deployment_id = deployment.to_deployment_id().unwrap();
let program_owner = ProgramOwner::new(&private_key, deployment_id, rng).unwrap();
Rejected::new_deployment(program_owner, deployment)
}
pub(crate) fn sample_rejected_execution(is_fee_private: bool, rng: &mut TestRng) -> Rejected<CurrentNetwork> {
let execution =
match crate::transaction::test_helpers::sample_execution_transaction_with_fee(is_fee_private, rng) {
Transaction::Execute(_, execution, _) => execution,
_ => unreachable!(),
};
Rejected::new_execution(execution)
}
pub(crate) fn sample_rejected_transactions() -> Vec<Rejected<CurrentNetwork>> {
let rng = &mut TestRng::default();
vec![
sample_rejected_deployment(true, rng),
sample_rejected_deployment(false, rng),
sample_rejected_execution(true, rng),
sample_rejected_execution(false, rng),
]
}
}