use crate::{diagnostic::Result, ir::Program};
pub const PREVIEW_COMPILER_TARGET: &str = "aeri-text-ir";
pub const PREVIEW_CARDANO_DEPLOYABLE: bool = false;
pub const PREVIEW_BLUEPRINT_FILE: &str = "blueprint.preview.json";
pub const PREVIEW_SCRIPT_EXTENSION: &str = "aeri.ir";
pub const UPLC_COMPILER_TARGET: &str = "cardano-uplc-cbor";
pub const UPLC_CARDANO_DEPLOYABLE: bool = true;
pub const UPLC_BLUEPRINT_FILE: &str = "blueprint.uplc.json";
pub const UPLC_V3_BLUEPRINT_FILE: &str = "blueprint.uplc-v3.json";
pub const UPLC_SCRIPT_EXTENSION: &str = "plutus.json";
pub const UPLC_PLUTUS_VERSION: &str = "PlutusV2";
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PlutusVersion {
V2,
V3,
}
impl PlutusVersion {
pub fn script_version(self) -> u8 {
match self {
Self::V2 => 2,
Self::V3 => 3,
}
}
pub fn blueprint_name(self) -> &'static str {
match self {
Self::V2 => UPLC_PLUTUS_VERSION,
Self::V3 => "PlutusV3",
}
}
pub(crate) fn context_fields(self) -> usize {
match self {
Self::V2 => 2,
Self::V3 => 3,
}
}
pub(crate) fn tx_info_fields(self) -> usize {
match self {
Self::V2 => 12,
Self::V3 => 16,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Target {
Preview,
Uplc,
UplcV3,
}
impl Target {
pub fn name(self) -> &'static str {
match self {
Self::Preview => "preview",
Self::Uplc => "uplc",
Self::UplcV3 => "uplc-v3",
}
}
pub fn implemented(self) -> bool {
true
}
pub fn ensure_supported(self, label: &str) -> Result<()> {
let _ = label;
Ok(())
}
pub fn compiler_target(self) -> Option<&'static str> {
match self {
Self::Preview => Some(PREVIEW_COMPILER_TARGET),
Self::Uplc | Self::UplcV3 => Some(UPLC_COMPILER_TARGET),
}
}
pub fn cardano_deployable(self) -> Option<bool> {
match self {
Self::Preview => Some(PREVIEW_CARDANO_DEPLOYABLE),
Self::Uplc | Self::UplcV3 => Some(UPLC_CARDANO_DEPLOYABLE),
}
}
pub fn plutus_version(self) -> Option<PlutusVersion> {
match self {
Self::Preview => None,
Self::Uplc => Some(PlutusVersion::V2),
Self::UplcV3 => Some(PlutusVersion::V3),
}
}
}
pub fn render_preview_program(program: &Program) -> String {
program.render()
}
pub fn unsupported_uplc_message() -> &'static str {
"target 'uplc' only supports validators that lower to the current serializable UPLC subset. Unsupported features still report explicit blockers."
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn preview_target_declares_non_deployable_text_ir() {
assert_eq!(Target::Preview.name(), "preview");
assert!(Target::Preview.implemented());
assert_eq!(Target::Preview.compiler_target(), Some("aeri-text-ir"));
assert_eq!(Target::Preview.cardano_deployable(), Some(false));
}
#[test]
fn uplc_target_has_no_fake_metadata() {
assert_eq!(Target::Uplc.name(), "uplc");
assert!(Target::Uplc.implemented());
assert_eq!(Target::Uplc.compiler_target(), Some("cardano-uplc-cbor"));
assert_eq!(Target::Uplc.cardano_deployable(), Some(true));
}
}