Do not compute addresses of parameterized validators
And leave a proper notice.
This commit is contained in:
parent
9b8ff590b8
commit
b04fb5962a
|
@ -44,7 +44,7 @@ pub enum Error {
|
||||||
#[diagnostic(code("aiken::blueprint::interface"))]
|
#[diagnostic(code("aiken::blueprint::interface"))]
|
||||||
Schema {
|
Schema {
|
||||||
error: schema::Error,
|
error: schema::Error,
|
||||||
#[label("invalid contract's boundary")]
|
#[label("invalid validator's boundary")]
|
||||||
location: Span,
|
location: Span,
|
||||||
#[source_code]
|
#[source_code]
|
||||||
source_code: NamedSource,
|
source_code: NamedSource,
|
||||||
|
@ -58,6 +58,11 @@ pub enum Error {
|
||||||
#[error("I didn't find any parameters to apply in the given validator.")]
|
#[error("I didn't find any parameters to apply in the given validator.")]
|
||||||
#[diagnostic(code("aiken::blueprint::apply::no_parameters"))]
|
#[diagnostic(code("aiken::blueprint::apply::no_parameters"))]
|
||||||
NoParametersToApply,
|
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> {
|
pub fn assert_return_bool(module: &CheckedModule, def: &TypedFunction) -> Result<(), Error> {
|
||||||
|
|
|
@ -316,9 +316,14 @@ where
|
||||||
|known_validators| Error::MoreThanOneValidatorFound { known_validators };
|
|known_validators| Error::MoreThanOneValidatorFound { known_validators };
|
||||||
let when_missing = |known_validators| Error::NoValidatorNotFound { known_validators };
|
let when_missing = |known_validators| Error::NoValidatorNotFound { known_validators };
|
||||||
blueprint.with_validator(title, purpose, when_too_many, when_missing, |validator| {
|
blueprint.with_validator(title, purpose, when_too_many, when_missing, |validator| {
|
||||||
Ok(validator
|
let n = validator.parameters.len();
|
||||||
.program
|
if n > 0 {
|
||||||
.address(Network::Testnet, delegation_part.to_owned()))
|
Err(blueprint::error::Error::ParameterizedValidator { n }.into())
|
||||||
|
} else {
|
||||||
|
Ok(validator
|
||||||
|
.program
|
||||||
|
.address(Network::Testnet, delegation_part.to_owned()))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue