Do not compute addresses of parameterized validators

And leave a proper notice.
This commit is contained in:
KtorZ 2023-02-04 11:49:56 +01:00
parent 9b8ff590b8
commit b04fb5962a
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
2 changed files with 14 additions and 4 deletions

View File

@ -44,7 +44,7 @@ pub enum Error {
#[diagnostic(code("aiken::blueprint::interface"))]
Schema {
error: schema::Error,
#[label("invalid contract's boundary")]
#[label("invalid validator's boundary")]
location: Span,
#[source_code]
source_code: NamedSource,
@ -58,6 +58,11 @@ pub enum Error {
#[error("I didn't find any parameters to apply in the given validator.")]
#[diagnostic(code("aiken::blueprint::apply::no_parameters"))]
NoParametersToApply,
#[error("I couldn't compute the address of the given validator because it's parameterized by {} parameter(s)!", format!("{n}").purple())]
#[diagnostic(code("aiken::blueprint::address::parameterized"))]
#[diagnostic(help("I can only compute addresses of validators that are fully applied. For example, a {keyword_spend} validator must have exactly 3 arguments: a datum, a redeemer and a context. If it has more, they need to be provided beforehand and applied directly in the validator. Applying parameters change the validator's compiled code, and thus the address.\n\nThis is why I need you to apply parmeters first.", keyword_spend = "spend".purple()))]
ParameterizedValidator { n: usize },
}
pub fn assert_return_bool(module: &CheckedModule, def: &TypedFunction) -> Result<(), Error> {

View File

@ -316,9 +316,14 @@ where
|known_validators| Error::MoreThanOneValidatorFound { known_validators };
let when_missing = |known_validators| Error::NoValidatorNotFound { known_validators };
blueprint.with_validator(title, purpose, when_too_many, when_missing, |validator| {
Ok(validator
.program
.address(Network::Testnet, delegation_part.to_owned()))
let n = validator.parameters.len();
if n > 0 {
Err(blueprint::error::Error::ParameterizedValidator { n }.into())
} else {
Ok(validator
.program
.address(Network::Testnet, delegation_part.to_owned()))
}
})
}