Refactor blueprint & handle annotated schemas
This also now introduce two levels of representable types (because it's needed at least for tuples): Plutus Data (a.k.a Data) and UPLC primitives / constants (a.k.a Schema). In practice, we don't want to specify blueprints that use direct UPLC primitives because there's little support for producing those in the ecosystem. So we should aim for producing only Data whenever we can. Yet we don't want to forbid it either in case people know what they're doing. Which means that we need to capture that difference well in the type modelling (in Rust and in the CIP-0057 specification). I've also simplified the error type for now, just to provide some degree of feedback while working on this. I'll refine it later with proper errors.
This commit is contained in:
@@ -2,28 +2,36 @@ use super::schema;
|
||||
use crate::module::CheckedModule;
|
||||
use aiken_lang::ast::{Span, TypedFunction};
|
||||
use miette::{Diagnostic, NamedSource};
|
||||
use owo_colors::OwoColorize;
|
||||
use std::{fmt::Debug, path::PathBuf};
|
||||
|
||||
#[derive(Debug, thiserror::Error, Diagnostic)]
|
||||
pub enum Error {
|
||||
#[error("Validator functions must return Bool")]
|
||||
#[error("A validator functions must return Bool")]
|
||||
#[diagnostic(code("aiken::blueprint::invalid::return_type"))]
|
||||
ValidatorMustReturnBool {
|
||||
path: PathBuf,
|
||||
src: String,
|
||||
#[source_code]
|
||||
named: NamedSource,
|
||||
#[label("invalid return type")]
|
||||
location: Span,
|
||||
},
|
||||
#[error("Validator\n\n{name}\n\nrequires at least {at_least} arguments")]
|
||||
#[error("A {} validator requires at least {at_least} arguments", name.purple().bold())]
|
||||
#[diagnostic(code("aiken::blueprint::invalid::arity"))]
|
||||
WrongValidatorArity {
|
||||
name: String,
|
||||
at_least: u8,
|
||||
#[label("not enough arguments")]
|
||||
location: Span,
|
||||
path: PathBuf,
|
||||
src: String,
|
||||
#[source_code]
|
||||
named: NamedSource,
|
||||
},
|
||||
#[error(transparent)]
|
||||
Schema(schema::Error),
|
||||
#[diagnostic(transparent)]
|
||||
Schema(#[diagnostic_source] schema::Error),
|
||||
}
|
||||
|
||||
pub fn assert_return_bool(module: &CheckedModule, def: &TypedFunction) -> Result<(), Error> {
|
||||
|
||||
Reference in New Issue
Block a user