feat: Add tracing for common multivalidator issues
This commit is contained in:
parent
68d9a21c6a
commit
8964675670
|
@ -156,17 +156,18 @@ impl<'a> CodeGenerator<'a> {
|
||||||
|
|
||||||
let other_term = self.uplc_code_gen(full_vec_other);
|
let other_term = self.uplc_code_gen(full_vec_other);
|
||||||
|
|
||||||
let (spend, mint) = if other.arguments.len() > fun.arguments.len() {
|
let (spend, spend_name, mint, mint_name) =
|
||||||
(other_term, term)
|
if other.arguments.len() > fun.arguments.len() {
|
||||||
|
(other_term, other.name.clone(), term, fun.name.clone())
|
||||||
} else {
|
} else {
|
||||||
(term, other_term)
|
(term, fun.name.clone(), other_term, other.name.clone())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Special Case with multi_validators
|
// Special Case with multi_validators
|
||||||
self.special_functions.use_function(CONSTR_FIELDS_EXPOSER);
|
self.special_functions.use_function(CONSTR_FIELDS_EXPOSER);
|
||||||
self.special_functions.use_function(CONSTR_INDEX_EXPOSER);
|
self.special_functions.use_function(CONSTR_INDEX_EXPOSER);
|
||||||
|
|
||||||
term = wrap_as_multi_validator(spend, mint);
|
term = wrap_as_multi_validator(spend, mint, self.tracing, spend_name, mint_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
term = cast_validator_args(term, params);
|
term = cast_validator_args(term, params);
|
||||||
|
|
|
@ -1699,7 +1699,54 @@ pub fn special_case_builtin(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wrap_as_multi_validator(spend: Term<Name>, mint: Term<Name>) -> Term<Name> {
|
pub fn wrap_as_multi_validator(
|
||||||
|
spend: Term<Name>,
|
||||||
|
mint: Term<Name>,
|
||||||
|
trace: bool,
|
||||||
|
spend_name: String,
|
||||||
|
mint_name: String,
|
||||||
|
) -> Term<Name> {
|
||||||
|
if trace {
|
||||||
|
let trace_string = format!(
|
||||||
|
"Incorrect redeemer type for validator {}.
|
||||||
|
Double check you have wrapped the redeemer type as specified in your plutus.json",
|
||||||
|
spend_name
|
||||||
|
);
|
||||||
|
|
||||||
|
let error_term = Term::Error.trace(Term::var("__incorrect_second_arg_type"));
|
||||||
|
|
||||||
|
Term::var("__second_arg")
|
||||||
|
.delayed_choose_data(
|
||||||
|
Term::equals_integer()
|
||||||
|
.apply(Term::integer(0.into()))
|
||||||
|
.apply(Term::var(CONSTR_INDEX_EXPOSER).apply(Term::var("__second_arg")))
|
||||||
|
.delayed_if_else(
|
||||||
|
mint.apply(Term::var("__first_arg"))
|
||||||
|
.apply(Term::var("__second_arg"))
|
||||||
|
.trace(Term::string(format!(
|
||||||
|
"Running 2 arg validator {}",
|
||||||
|
mint_name
|
||||||
|
))),
|
||||||
|
spend
|
||||||
|
.apply(Term::var("__first_arg"))
|
||||||
|
.apply(Term::head_list().apply(
|
||||||
|
Term::var(CONSTR_FIELDS_EXPOSER).apply(Term::var("__second_arg")),
|
||||||
|
))
|
||||||
|
.trace(Term::string(format!(
|
||||||
|
"Running 3 arg validator {}",
|
||||||
|
spend_name
|
||||||
|
))),
|
||||||
|
),
|
||||||
|
error_term.clone(),
|
||||||
|
error_term.clone(),
|
||||||
|
error_term.clone(),
|
||||||
|
error_term,
|
||||||
|
)
|
||||||
|
.lambda("__incorrect_second_arg_type")
|
||||||
|
.apply(Term::string(trace_string))
|
||||||
|
.lambda("__second_arg")
|
||||||
|
.lambda("__first_arg")
|
||||||
|
} else {
|
||||||
Term::equals_integer()
|
Term::equals_integer()
|
||||||
.apply(Term::integer(0.into()))
|
.apply(Term::integer(0.into()))
|
||||||
.apply(Term::var(CONSTR_INDEX_EXPOSER).apply(Term::var("__second_arg")))
|
.apply(Term::var(CONSTR_INDEX_EXPOSER).apply(Term::var("__second_arg")))
|
||||||
|
@ -1714,6 +1761,7 @@ pub fn wrap_as_multi_validator(spend: Term<Name>, mint: Term<Name>) -> Term<Name
|
||||||
.lambda("__second_arg")
|
.lambda("__second_arg")
|
||||||
.lambda("__first_arg")
|
.lambda("__first_arg")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// If the pattern is a list the return the number of elements and if it has a tail
|
/// If the pattern is a list the return the number of elements and if it has a tail
|
||||||
/// Otherwise return None
|
/// Otherwise return None
|
||||||
|
|
|
@ -296,6 +296,25 @@ impl<T> Term<T> {
|
||||||
.force()
|
.force()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn delayed_choose_data(
|
||||||
|
self,
|
||||||
|
constr_case: Self,
|
||||||
|
map_case: Self,
|
||||||
|
array_case: Self,
|
||||||
|
int_case: Self,
|
||||||
|
bytes_case: Self,
|
||||||
|
) -> Self {
|
||||||
|
Term::Builtin(DefaultFunction::ChooseData)
|
||||||
|
.force()
|
||||||
|
.apply(self)
|
||||||
|
.apply(constr_case.delay())
|
||||||
|
.apply(map_case.delay())
|
||||||
|
.apply(array_case.delay())
|
||||||
|
.apply(int_case.delay())
|
||||||
|
.apply(bytes_case.delay())
|
||||||
|
.force()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn trace(self, msg_term: Self) -> Self {
|
pub fn trace(self, msg_term: Self) -> Self {
|
||||||
Term::Builtin(DefaultFunction::Trace)
|
Term::Builtin(DefaultFunction::Trace)
|
||||||
.force()
|
.force()
|
||||||
|
|
Loading…
Reference in New Issue