diff --git a/CHANGELOG.md b/CHANGELOG.md index ff5448d10..e3098a5fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## unreleased +### Added + +- **aiken-project**: `export` output now supports the functions `return_type`. @rvcas + ### Changed - **aiken-project**: The `aiken.toml` file no longer supports `v1` and `v2` for the plutus version field. @rvcas diff --git a/crates/aiken-project/src/export.rs b/crates/aiken-project/src/export.rs index d0b7d86bb..46e5a3082 100644 --- a/crates/aiken-project/src/export.rs +++ b/crates/aiken-project/src/export.rs @@ -7,7 +7,11 @@ use crate::{ }, module::{CheckedModule, CheckedModules}, }; -use aiken_lang::{ast::TypedFunction, gen_uplc::CodeGenerator, plutus_version::PlutusVersion}; +use aiken_lang::{ + ast::{ArgName, Span, TypedArg, TypedFunction}, + gen_uplc::CodeGenerator, + plutus_version::PlutusVersion, +}; use miette::NamedSource; use uplc::ast::SerializableProgram; @@ -22,6 +26,8 @@ pub struct Export { #[serde(default)] pub parameters: Vec, + pub return_type: Parameter, + #[serde(flatten)] pub program: SerializableProgram, @@ -64,6 +70,38 @@ impl Export { }) .collect::>()?; + let return_type = Annotated::from_type( + modules.into(), + blueprint::validator::tipo_or_annotation( + module, + &TypedArg { + arg_name: ArgName::Discarded { + name: "".to_string(), + label: "".to_string(), + location: Span::empty(), + }, + location: Span::empty(), + annotation: func.return_annotation.clone(), + doc: None, + is_validator_param: false, + tipo: func.return_type.clone(), + }, + ), + &mut definitions, + ) + .map(|schema| Parameter { + title: Some("return_type".to_string()), + schema: Declaration::Referenced(schema), + }) + .map_err(|error| blueprint::Error::Schema { + error, + location: func.location, + source_code: NamedSource::new( + module.input_path.display().to_string(), + module.code.clone(), + ), + })?; + let program = generator .generate_raw(&func.body, &func.arguments, &module.name) .to_debruijn() @@ -79,6 +117,7 @@ impl Export { name: format!("{}.{}", &module.name, &func.name), doc: func.doc.clone(), parameters, + return_type, program, definitions, })