fix(cli): aiken address

This commit is contained in:
rvcas
2023-02-15 22:04:45 -05:00
committed by Lucas
parent 8b4985498b
commit a311531508
6 changed files with 62 additions and 77 deletions

View File

@@ -1,5 +1,4 @@
use crate::with_project;
use aiken_lang::VALIDATOR_NAMES;
use std::path::PathBuf;
#[derive(clap::Args)]
@@ -11,11 +10,11 @@ pub struct Args {
/// Name of the validator's module within the project. Optional if there's only one validator.
#[clap(short, long)]
validator: Option<String>,
module: Option<String>,
/// Purpose of the validator within the module. Optional if there's only one validator.
#[clap(short, long, possible_values=&VALIDATOR_NAMES)]
purpose: Option<String>,
/// Name of the validator within the module. Optional if there's only one validator.
#[clap(short, long)]
validator: Option<String>,
/// Stake address to attach, if any.
#[clap(long)]
@@ -29,8 +28,8 @@ pub struct Args {
pub fn exec(
Args {
directory,
module,
validator,
purpose,
delegated_to,
rebuild,
}: Args,
@@ -39,15 +38,23 @@ pub fn exec(
if rebuild {
p.build(false)?;
}
let address = p.address(
validator.as_ref(),
purpose
.as_ref()
.map(|p| p.clone().try_into().unwrap())
.as_ref(),
delegated_to.as_ref(),
)?;
let title = module.as_ref().map(|m| {
format!(
"{m}{}",
validator
.as_ref()
.map(|v| format!(".{v}"))
.unwrap_or("".to_string())
)
});
let title = title.as_ref().or(validator.as_ref());
let address = p.address(title, delegated_to.as_ref())?;
println!("{}", address.to_bech32().unwrap());
Ok(())
})
}

View File

@@ -1,5 +1,4 @@
use crate::with_project;
use aiken_lang::VALIDATOR_NAMES;
use aiken_project::error::Error;
use miette::IntoDiagnostic;
use std::{fs, path::PathBuf};
@@ -17,11 +16,11 @@ pub struct Args {
/// Name of the validator's module within the project. Optional if there's only one validator.
#[clap(short, long)]
validator: Option<String>,
module: Option<String>,
/// Purpose of the validator within the module. Optional if there's only one validator.
#[clap(short, long, possible_values=&VALIDATOR_NAMES)]
purpose: Option<String>,
/// Name of the validator within the module. Optional if there's only one validator.
#[clap(short, long)]
validator: Option<String>,
/// The parameter, using high-level UPLC-syntax
parameter: String,
@@ -30,8 +29,8 @@ pub struct Args {
pub fn exec(
Args {
directory,
module,
validator,
purpose,
parameter,
}: Args,
) -> miette::Result<()> {
@@ -41,16 +40,22 @@ pub fn exec(
.into_diagnostic()?;
with_project(directory, |p| {
let blueprint = p.apply_parameter(
validator.as_ref(),
purpose
.as_ref()
.map(|p| p.clone().try_into().unwrap())
.as_ref(),
&term,
)?;
let title = module.as_ref().map(|m| {
format!(
"{m}{}",
validator
.as_ref()
.map(|v| format!(".{v}"))
.unwrap_or("".to_string())
)
});
let title = title.as_ref().or(validator.as_ref());
let blueprint = p.apply_parameter(title, &term)?;
let json = serde_json::to_string_pretty(&blueprint).unwrap();
fs::write(p.blueprint_path(), json).map_err(|error| Error::FileIo {
error,
path: p.blueprint_path(),