mod bytes;
mod serialize;
mod string;
use super::*;
#[derive(Clone, PartialEq, Eq)]
pub enum RejectedReason<N: Network> {
DuplicateProgramID(ProgramID<N>),
Finalize { program_id: ProgramID<N>, edition: u16, resource: Identifier<N>, index: usize, command: Box<Command<N>> },
VM(Option<(ProgramID<N>, u16)>, Option<Identifier<N>>),
}
impl<N: Network> RejectedReason<N> {
pub fn from_indexed_finalize_error<C: ToString>(error: IndexedFinalizeError<N, C>) -> Self {
let program_id = error.program_id;
let resource = error.resource;
match error.command.map(|b| *b) {
Some((index, command)) => {
match (program_id, resource, command.to_string().parse::<Command<N>>()) {
(Some((program_id, edition)), Some(resource), Ok(command)) => {
Self::Finalize { program_id, edition, resource, index, command: Box::new(command) }
}
(program_id, resource, _) => Self::VM(program_id, resource),
}
}
None => Self::VM(program_id, resource),
}
}
}
#[cfg(test)]
pub mod test_helpers {
use super::*;
use std::str::FromStr;
pub(crate) fn sample_rejected_reasons<N: Network>() -> Vec<RejectedReason<N>> {
let program = ProgramID::<N>::from_str("dummy_program.aleo").unwrap();
let credits = ProgramID::<N>::from_str("credits.aleo").unwrap();
let transfer = Identifier::<N>::from_str("transfer_public").unwrap();
let bond = Identifier::<N>::from_str("bond_public").unwrap();
let command = Command::<N>::from_str("assert.eq r0 r1;").unwrap();
vec![
RejectedReason::DuplicateProgramID(program),
RejectedReason::Finalize {
program_id: credits,
edition: 1,
resource: transfer,
index: 3,
command: Box::new(command),
},
RejectedReason::VM(Some((credits, 0u16)), Some(bond)),
RejectedReason::VM(None, Some(bond)),
RejectedReason::VM(Some((credits, 0u16)), None),
RejectedReason::VM(None, None),
]
}
}