Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] #4093, #4110: Add public key mint and burn commands to iroha_client_cli #4408

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 67 additions & 3 deletions client_cli/src/main.rs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this work will be reverted by the 1st PR for #2085 in progress, which makes an account have a single public key in its ID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean the issues this PR addresses are obsolete?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. This is an unfortunate conflict, but after opening the PR I will check if the open issues are still valid

Expand Up @@ -117,6 +117,9 @@ enum Subcommand {
Blocks(blocks::Args),
/// The subcommand related to multi-instructions as Json or Json5
Json(json::Args),
/// The subcommand related to public keys
#[clap(subcommand)]
Key(key::Args),
}

/// Context inside which command is executed
Expand Down Expand Up @@ -172,7 +175,7 @@ macro_rules! match_all {
impl RunArgs for Subcommand {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
use Subcommand::*;
match_all!((self, context), { Domain, Account, Asset, Peer, Events, Wasm, Blocks, Json })
match_all!((self, context), { Domain, Account, Asset, Peer, Events, Wasm, Blocks, Json, Key })
}
}

Expand Down Expand Up @@ -514,6 +517,8 @@ mod account {
Grant(Grant),
/// List all account permissions
ListPermissions(ListPermissions),
/// Add new signatory to the account
AddSignatory(AddSignatory),
}

impl RunArgs for Args {
Expand All @@ -524,6 +529,7 @@ mod account {
Args::List,
Args::Grant,
Args::ListPermissions,
Args::AddSignatory,
})
}
}
Expand Down Expand Up @@ -692,6 +698,26 @@ mod account {
Ok(())
}
}

/// Add new signatory to account
#[derive(clap::Args, Debug)]
pub struct AddSignatory {
/// Account id in the format `name@domain_name'
#[arg(short, long)]
pub id: AccountId,
/// Public key of the signatory
#[arg(short, long)]
pub key: PublicKey,
}

impl RunArgs for AddSignatory {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let mint_public_key =
iroha_client::data_model::isi::Mint::account_public_key(self.key, self.id);
submit([mint_public_key], UnlimitedMetadata::new(), context)
.wrap_err("Failed to add the signatory to the account")
}
}
}

mod asset {
Expand Down Expand Up @@ -796,13 +822,13 @@ mod asset {
}
}

/// Command for minting asset in existing Iroha account
/// Command for burning asset in existing Iroha account
#[derive(clap::Args, Debug)]
pub struct Burn {
/// Asset id for the asset (in form of `asset##account@domain_name`)
#[arg(long)]
pub asset_id: AssetId,
/// Quantity to mint
/// Quantity to burn
#[arg(short, long)]
pub quantity: Numeric,
#[command(flatten)]
Expand Down Expand Up @@ -1100,6 +1126,44 @@ mod json {
}
}
}

mod key {
use super::*;

/// Arguments for the public key subcommand
#[derive(clap::Subcommand, Debug)]
pub enum Args {
/// Burn a public key from an account
Burn(Burn),
}

impl RunArgs for Args {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
match_all!((self, context), { Args::Burn })
}
}

/// Command for burning a public key from an existing account
#[derive(clap::Args, Debug)]
pub struct Burn {
/// Account from which to burn the public key (in the format `name@domain_name')
#[arg(short, long)]
pub account: AccountId,
/// Public key to be burned
#[arg(short, long)]
pub key: PublicKey,
}

impl RunArgs for Burn {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let burn_public_key =
iroha_client::data_model::isi::Burn::account_public_key(self.key, self.account);
submit([burn_public_key], UnlimitedMetadata::new(), context)
.wrap_err("Failed to burn public key")
}
}
}

#[cfg(test)]
mod tests {
use std::str::FromStr;
Expand Down