Implement new command: address

This calculates a validator's address from validators found in a blueprint. It also provides a convenient way to attach a delegation part to the validator if needs be. The command is meant to provide a nice user experience and works 'out of the box' for projects that have only a single validator. Just call 'aiken address' to get the validator's address.

  Note that the command-line doesn't provide any option to configure the target network. This automatically assumes testnet, and will until we deem the project ready for mainnet. Those brave enough to run an Aiken's program on mainnet will find a way anyway.
This commit is contained in:
KtorZ
2023-01-31 15:30:52 +01:00
parent 1aa12fb368
commit daee8e39d6
8 changed files with 212 additions and 10 deletions

View File

@@ -28,3 +28,4 @@ aiken-lang = { path = "../aiken-lang", version = "0.0.28" }
aiken-lsp = { path = "../aiken-lsp", version = "0.0.28" }
aiken-project = { path = '../aiken-project', version = "0.0.28" }
uplc = { path = '../uplc', version = "0.0.28" }
serde_json = "1.0.91"

View File

@@ -0,0 +1,53 @@
use crate::with_project;
use aiken_lang::VALIDATOR_NAMES;
use std::path::PathBuf;
#[derive(clap::Args)]
#[clap(setting(clap::AppSettings::DeriveDisplayOrder))]
/// Compute a validator's address.
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)]
validator: 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>,
/// Stake address to attach, if any.
#[clap(long)]
delegated_to: 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,
validator,
purpose,
delegated_to,
rebuild,
}: Args,
) -> miette::Result<()> {
with_project(directory, |p| {
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(),
)?;
println!("{}", address.to_bech32().unwrap());
Ok(())
})
}

View File

@@ -1,3 +1,4 @@
pub mod address;
pub mod build;
pub mod check;
pub mod docs;

View File

@@ -1,5 +1,5 @@
use aiken::cmd::{
build, check, docs, fmt, lsp, new,
address, build, check, docs, fmt, lsp, new,
packages::{self, add},
tx, uplc,
};
@@ -14,6 +14,7 @@ pub enum Cmd {
New(new::Args),
Fmt(fmt::Args),
Build(build::Args),
Address(address::Args),
Check(check::Args),
Docs(docs::Args),
Add(add::Args),
@@ -43,6 +44,7 @@ fn main() -> miette::Result<()> {
Cmd::New(args) => new::exec(args),
Cmd::Fmt(args) => fmt::exec(args),
Cmd::Build(args) => build::exec(args),
Cmd::Address(args) => address::exec(args),
Cmd::Check(args) => check::exec(args),
Cmd::Docs(args) => docs::exec(args),
Cmd::Add(args) => add::exec(args),