From b3de1b048b0ad9eba8756f31538301dcadc7b3d9 Mon Sep 17 00:00:00 2001 From: rvcas Date: Thu, 2 Jan 2025 13:37:17 -0500 Subject: [PATCH] fix: blueprint still needs to load older plutus versions --- crates/aiken-lang/src/plutus_version.rs | 2 -- crates/aiken-project/src/config.rs | 14 +++++++++++++- crates/aiken/src/cmd/blueprint/convert.rs | 12 +++--------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/crates/aiken-lang/src/plutus_version.rs b/crates/aiken-lang/src/plutus_version.rs index f86631493..69c35701e 100644 --- a/crates/aiken-lang/src/plutus_version.rs +++ b/crates/aiken-lang/src/plutus_version.rs @@ -4,9 +4,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Default, Deserialize, Serialize, Clone, Copy, PartialEq)] #[serde(rename_all = "camelCase")] pub enum PlutusVersion { - #[serde(skip_deserializing)] V1, - #[serde(skip_deserializing)] V2, #[default] V3, diff --git a/crates/aiken-project/src/config.rs b/crates/aiken-project/src/config.rs index dea2b46e3..9764fc354 100644 --- a/crates/aiken-project/src/config.rs +++ b/crates/aiken-project/src/config.rs @@ -26,7 +26,7 @@ pub struct Config { default = "default_version" )] pub compiler: Version, - #[serde(default)] + #[serde(default, deserialize_with = "validate_v3_only")] pub plutus: PlutusVersion, pub license: Option, #[serde(default)] @@ -376,6 +376,18 @@ impl Config { } } +fn validate_v3_only<'de, D>(deserializer: D) -> Result +where + D: serde::Deserializer<'de>, +{ + let version = PlutusVersion::deserialize(deserializer)?; + + match version { + PlutusVersion::V3 => Ok(version), + _ => Err(serde::de::Error::custom("Aiken only supports Plutus V3")), + } +} + mod built_info { include!(concat!(env!("OUT_DIR"), "/built.rs")); } diff --git a/crates/aiken/src/cmd/blueprint/convert.rs b/crates/aiken/src/cmd/blueprint/convert.rs index 1fba7fb9d..fe900b20a 100644 --- a/crates/aiken/src/cmd/blueprint/convert.rs +++ b/crates/aiken/src/cmd/blueprint/convert.rs @@ -1,6 +1,5 @@ use aiken_project::{ blueprint::{error::Error as BlueprintError, Blueprint}, - config::Config, error::Error as ProjectError, }; use clap::ValueEnum; @@ -22,7 +21,7 @@ pub struct Args { #[clap(short, long)] validator: Option, - // Format to convert to + /// Format to convert to #[clap(long, default_value = "cardano-cli")] to: Format, } @@ -56,13 +55,6 @@ pub fn exec( let blueprint: Blueprint = serde_json::from_reader(BufReader::new(blueprint)).into_diagnostic()?; - let opt_config = Config::load(&project_path).ok(); - - let cardano_cli_type = opt_config - .map(|config| config.plutus) - .unwrap_or_default() - .cardano_cli_type(); - // Perform the conversion let when_too_many = |known_validators| ProjectError::MoreThanOneValidatorFound { known_validators }; @@ -85,6 +77,8 @@ pub fn exec( let cbor_hex = hex::encode(double_cbor_bytes); + let cardano_cli_type = blueprint.preamble.plutus_version.cardano_cli_type(); + Ok(json!({ "type": cardano_cli_type, "description": "Generated by Aiken",