Add a blueprint hash command

Similar to blueprint address and blueprint policy, this just prints the
hash of the validator; useful if you need the hash, and you don't want
to pipe the address to a bech32 decoder and juggle the hex.
This commit is contained in:
Pi Lanningham 2023-07-21 22:49:53 -04:00 committed by Lucas
parent be7a441205
commit 27c0f25606
3 changed files with 59 additions and 1 deletions

View File

@ -0,0 +1,55 @@
use crate::with_project;
use aiken_lang::ast::Tracing;
use std::path::PathBuf;
/// Compute a validator's hash
#[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 address = p.address(title, None)?;
println!("{}", address.payment().to_hex());
Ok(())
})
}

View File

@ -1,6 +1,7 @@
pub mod address; pub mod address;
pub mod apply; pub mod apply;
pub mod convert; pub mod convert;
pub mod hash;
pub mod policy; pub mod policy;
use clap::Subcommand; use clap::Subcommand;
@ -10,6 +11,7 @@ use clap::Subcommand;
pub enum Cmd { pub enum Cmd {
Address(address::Args), Address(address::Args),
Policy(policy::Args), Policy(policy::Args),
Hash(hash::Args),
Apply(apply::Args), Apply(apply::Args),
Convert(convert::Args), Convert(convert::Args),
} }
@ -18,6 +20,7 @@ pub fn exec(cmd: Cmd) -> miette::Result<()> {
match cmd { match cmd {
Cmd::Address(args) => address::exec(args), Cmd::Address(args) => address::exec(args),
Cmd::Policy(args) => policy::exec(args), Cmd::Policy(args) => policy::exec(args),
Cmd::Hash(args) => hash::exec(args),
Cmd::Apply(args) => apply::exec(args), Cmd::Apply(args) => apply::exec(args),
Cmd::Convert(args) => convert::exec(args), Cmd::Convert(args) => convert::exec(args),
} }

View File

@ -2,7 +2,7 @@ use crate::with_project;
use aiken_lang::ast::Tracing; use aiken_lang::ast::Tracing;
use std::path::PathBuf; use std::path::PathBuf;
/// Compute a validator's address. /// Compute a minting scripts Policy ID
#[derive(clap::Args)] #[derive(clap::Args)]
pub struct Args { pub struct Args {
/// Path to project /// Path to project