Remove 'purpose' from blueprint's schema.
This has been removed from the CIP-0057 specification since validators are often re-used for multiple purposes (especially validators with arity 2). It's misleading to assign a validator a purpose since the purpose distinction actually happens _within_ the validator itself.
This commit is contained in:
parent
db0dfbbec1
commit
82a32a082b
|
@ -30,11 +30,5 @@ impl IdGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
pub const SPEND: &str = "spend";
|
||||
pub const PUBLISH: &str = "publish";
|
||||
pub const MINT: &str = "mint";
|
||||
pub const WITHDRAW: &str = "withdraw";
|
||||
pub const VALIDATOR_NAMES: [&str; 4] = [SPEND, PUBLISH, MINT, WITHDRAW];
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
|
|
@ -16,8 +16,6 @@ use uplc::ast::{DeBruijn, Program, Term};
|
|||
pub struct Validator<T> {
|
||||
pub title: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub purpose: Option<Purpose>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub description: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub datum: Option<Annotated<T>>,
|
||||
|
@ -29,15 +27,6 @@ pub struct Validator<T> {
|
|||
pub program: Program<DeBruijn>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, serde::Serialize, serde::Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum Purpose {
|
||||
Spend,
|
||||
Mint,
|
||||
Withdraw,
|
||||
Publish,
|
||||
}
|
||||
|
||||
impl Display for Validator<Schema> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let s = serde_json::to_string_pretty(self).map_err(|_| fmt::Error)?;
|
||||
|
@ -63,7 +52,6 @@ impl Validator<Schema> {
|
|||
Ok(Validator {
|
||||
title: format!("{}.{}", &module.name, &def.fun.name),
|
||||
description: None,
|
||||
purpose: None,
|
||||
parameters: def
|
||||
.params
|
||||
.iter()
|
||||
|
@ -137,40 +125,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl Purpose {
|
||||
pub fn min_arity(&self) -> u8 {
|
||||
match self {
|
||||
Purpose::Spend => 3,
|
||||
Purpose::Mint | Purpose::Withdraw | Purpose::Publish => 2,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Purpose {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
f.write_str(match self {
|
||||
Purpose::Spend => "spend",
|
||||
Purpose::Mint => "mint",
|
||||
Purpose::Withdraw => "withdraw",
|
||||
Purpose::Publish => "publish",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for Purpose {
|
||||
type Error = String;
|
||||
|
||||
fn try_from(purpose: String) -> Result<Purpose, Self::Error> {
|
||||
match &purpose[..] {
|
||||
"spend" => Ok(Purpose::Spend),
|
||||
"mint" => Ok(Purpose::Mint),
|
||||
"withdraw" => Ok(Purpose::Withdraw),
|
||||
"publish" => Ok(Purpose::Publish),
|
||||
unexpected => Err(format!("Can't turn '{unexpected}' into any Purpose")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
|
|
@ -399,8 +399,7 @@ where
|
|||
.into_iter()
|
||||
.map(|validator| {
|
||||
let same_title = validator.title == applied_validator.title;
|
||||
let same_purpose = validator.purpose == applied_validator.purpose;
|
||||
if same_title && same_purpose {
|
||||
if same_title {
|
||||
applied_validator.to_owned()
|
||||
} else {
|
||||
validator
|
||||
|
|
Loading…
Reference in New Issue