Add a blueprint policy command
Computes the policy ID of a minting policy; added guards for blueprint address to check that it's not a minting policy; Wasn't 100% sure where the errors should live, so I'm happy to move them if there's objections
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
pub mod address;
|
||||
pub mod policy;
|
||||
pub mod apply;
|
||||
pub mod convert;
|
||||
|
||||
@@ -8,6 +9,7 @@ use clap::Subcommand;
|
||||
#[derive(Subcommand)]
|
||||
pub enum Cmd {
|
||||
Address(address::Args),
|
||||
Policy(policy::Args),
|
||||
Apply(apply::Args),
|
||||
Convert(convert::Args),
|
||||
}
|
||||
@@ -15,6 +17,7 @@ pub enum Cmd {
|
||||
pub fn exec(cmd: Cmd) -> miette::Result<()> {
|
||||
match cmd {
|
||||
Cmd::Address(args) => address::exec(args),
|
||||
Cmd::Policy(args) => policy::exec(args),
|
||||
Cmd::Apply(args) => apply::exec(args),
|
||||
Cmd::Convert(args) => convert::exec(args),
|
||||
}
|
||||
|
||||
55
crates/aiken/src/cmd/blueprint/policy.rs
Normal file
55
crates/aiken/src/cmd/blueprint/policy.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use crate::with_project;
|
||||
use aiken_lang::ast::Tracing;
|
||||
use std::path::PathBuf;
|
||||
|
||||
/// Compute a validator's address.
|
||||
#[derive(clap::Args)]
|
||||
pub struct Args {
|
||||
/// Path to project
|
||||
directory: Option<PathBuf>,
|
||||
|
||||
/// Name of the validator's module within the project. Optional if there's only one validator
|
||||
#[clap(short, long)]
|
||||
module: Option<String>,
|
||||
|
||||
/// Name of the validator within the module. Optional if there's only one validator
|
||||
#[clap(short, long)]
|
||||
validator: Option<String>,
|
||||
|
||||
/// Force the project to be rebuilt, otherwise relies on existing artifacts (i.e. plutus.json)
|
||||
#[clap(long)]
|
||||
rebuild: bool,
|
||||
}
|
||||
|
||||
pub fn exec(
|
||||
Args {
|
||||
directory,
|
||||
module,
|
||||
validator,
|
||||
rebuild,
|
||||
}: Args,
|
||||
) -> miette::Result<()> {
|
||||
with_project(directory, |p| {
|
||||
if rebuild {
|
||||
p.build(false, Tracing::NoTraces)?;
|
||||
}
|
||||
|
||||
let title = module.as_ref().map(|m| {
|
||||
format!(
|
||||
"{m}{}",
|
||||
validator
|
||||
.as_ref()
|
||||
.map(|v| format!(".{v}"))
|
||||
.unwrap_or_default()
|
||||
)
|
||||
});
|
||||
|
||||
let title = title.as_ref().or(validator.as_ref());
|
||||
|
||||
let policy = p.policy(title)?;
|
||||
|
||||
println!("{}", policy);
|
||||
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user