Add title to blueprint's validators
And use it to prefix UPLC artifacts' names.
This commit is contained in:
parent
f8970ecb9e
commit
59ffc6434f
|
@ -33,6 +33,7 @@ impl Blueprint {
|
||||||
let (_, redeemer, datum) = (args.next(), args.next().unwrap(), args.next());
|
let (_, redeemer, datum) = (args.next(), args.next().unwrap(), args.next());
|
||||||
|
|
||||||
validators.push(Validator {
|
validators.push(Validator {
|
||||||
|
title: validator.name.clone(),
|
||||||
description: None,
|
description: None,
|
||||||
purpose,
|
purpose,
|
||||||
datum: datum
|
datum: datum
|
||||||
|
|
|
@ -10,6 +10,7 @@ use uplc::ast::{NamedDeBruijn, Program};
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub struct Validator {
|
pub struct Validator {
|
||||||
|
pub title: String,
|
||||||
pub purpose: Purpose,
|
pub purpose: Purpose,
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
pub datum: Option<Schema>,
|
pub datum: Option<Schema>,
|
||||||
|
@ -22,6 +23,7 @@ impl Serialize for Validator {
|
||||||
let cbor = self.program.to_cbor().unwrap();
|
let cbor = self.program.to_cbor().unwrap();
|
||||||
let source_code = hex::encode(&cbor);
|
let source_code = hex::encode(&cbor);
|
||||||
let mut s = serializer.serialize_struct("Validator", 5)?;
|
let mut s = serializer.serialize_struct("Validator", 5)?;
|
||||||
|
s.serialize_field("title", &self.title)?;
|
||||||
s.serialize_field("purpose", &self.purpose)?;
|
s.serialize_field("purpose", &self.purpose)?;
|
||||||
let hash = cardano::PlutusV2Script(cbor.into()).compute_hash();
|
let hash = cardano::PlutusV2Script(cbor.into()).compute_hash();
|
||||||
s.serialize_field("hash", &hash)?;
|
s.serialize_field("hash", &hash)?;
|
||||||
|
@ -92,6 +94,7 @@ mod test {
|
||||||
.try_into()
|
.try_into()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let validator = Validator {
|
let validator = Validator {
|
||||||
|
title: "foo".to_string(),
|
||||||
description: Some("Lorem ipsum".to_string()),
|
description: Some("Lorem ipsum".to_string()),
|
||||||
purpose: Purpose::Spend,
|
purpose: Purpose::Spend,
|
||||||
datum: None,
|
datum: None,
|
||||||
|
@ -104,6 +107,7 @@ mod test {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::to_value(&validator).unwrap(),
|
serde_json::to_value(&validator).unwrap(),
|
||||||
json!({
|
json!({
|
||||||
|
"title": "foo",
|
||||||
"description": "Lorem ipsum",
|
"description": "Lorem ipsum",
|
||||||
"purpose": "spend",
|
"purpose": "spend",
|
||||||
"redeemer": {
|
"redeemer": {
|
||||||
|
|
|
@ -190,8 +190,9 @@ where
|
||||||
.handle_event(Event::DumpingUPLC { path: dir.clone() });
|
.handle_event(Event::DumpingUPLC { path: dir.clone() });
|
||||||
fs::create_dir_all(&dir)?;
|
fs::create_dir_all(&dir)?;
|
||||||
for validator in &blueprint.validators {
|
for validator in &blueprint.validators {
|
||||||
// TODO: Also include validator name.
|
let path = dir
|
||||||
let path = dir.clone().join(format!("{}.uplc", validator.purpose));
|
.clone()
|
||||||
|
.join(format!("{}::{}>.uplc", validator.title, validator.purpose));
|
||||||
fs::write(&path, validator.program.to_pretty())
|
fs::write(&path, validator.program.to_pretty())
|
||||||
.map_err(|error| Error::FileIo { error, path })?;
|
.map_err(|error| Error::FileIo { error, path })?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue