Skip to content

Commit

Permalink
[refactor] #4167: asset subcommand in client CLI to be consistent (#4200
Browse files Browse the repository at this point in the history
)

* [change]: cli asset parameters to be consistent

Signed-off-by: Asem-Abdelhady <[email protected]>

* [fix] Update client cli command for tests

Signed-off-by: alexstroke <[email protected]>


---------

Signed-off-by: Asem-Abdelhady <[email protected]>
Signed-off-by: alexstroke <[email protected]>
Co-authored-by: alexstroke <[email protected]>
  • Loading branch information
Asem-Abdelhady and alexstroke authored Jan 23, 2024
1 parent 57f87af commit 85d03b7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 61 deletions.
15 changes: 8 additions & 7 deletions client_cli/pytests/src/client_cli/client_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ def asset(self, asset_definition=None, account=None, value_of_value_type=None):
"""
self.command.insert(3, 'asset')
if asset_definition and account and value_of_value_type:
self.command.append('--account=' + account.name + '@' + asset_definition.domain)
self.command.append('--asset=' + repr(asset_definition))
self.command.append(
'--asset-id='
+ asset_definition.name + '#' + account.domain + '#' + account.name + '@' + asset_definition.domain)
self.command.append(
'--' + asset_definition.value_type.lower() + '=' + value_of_value_type)
self.execute()
Expand All @@ -190,9 +191,9 @@ def transfer(self, asset, source_account, target_account, quantity: str):
"""
self.command.append('asset')
self.command.append('transfer')
self.command.append('--from=' + repr(source_account))
self.command.append('--to=' + repr(target_account))
self.command.append('--asset-id=' + repr(asset))
self.command.append(
'--asset-id=' + asset.name + '#' + source_account.domain + '#' + source_account.name + '@' + asset.domain)
self.command.append('--quantity=' + quantity)
self.execute()
return self
Expand All @@ -211,8 +212,8 @@ def burn(self, account, asset, quantity: str):
"""
self.command.append('asset')
self.command.append('burn')
self.command.append('--account=' + repr(account))
self.command.append('--asset=' + repr(asset))
self.command.append(
'--asset-id=' + asset.name + '#' + account.domain + '#' + account.name + '@' + asset.domain)
self.command.append('--quantity=' + quantity)
self.execute()
return self
Expand All @@ -230,7 +231,7 @@ def definition(self, asset: str, domain: str, value_type: str):
:return: The current ClientCli object.
:rtype: ClientCli
"""
self.command.append('--id=' + asset + '#' + domain)
self.command.append('--definition-id=' + asset + '#' + domain)
self.command.append('--value-type=' + value_type)
self.execute()
return self
Expand Down
85 changes: 31 additions & 54 deletions client_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -795,9 +795,9 @@ mod asset {
/// Register subcommand of asset
#[derive(clap::Args, Debug)]
pub struct Register {
/// Asset id for registering (in form of `name#domain_name')
#[arg(short, long)]
pub id: AssetDefinitionId,
/// Asset definition id for registering (in form of `asset#domain_name`)
#[arg(long)]
pub definition_id: AssetDefinitionId,
/// Mintability of asset
#[arg(short, long)]
pub unmintable: bool,
Expand All @@ -811,16 +811,16 @@ mod asset {
impl RunArgs for Register {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self {
id,
definition_id,
value_type,
unmintable,
metadata,
} = self;
let mut asset_definition = match value_type {
AssetValueType::Quantity => AssetDefinition::quantity(id),
AssetValueType::BigQuantity => AssetDefinition::big_quantity(id),
AssetValueType::Fixed => AssetDefinition::fixed(id),
AssetValueType::Store => AssetDefinition::store(id),
AssetValueType::Quantity => AssetDefinition::quantity(definition_id),
AssetValueType::BigQuantity => AssetDefinition::big_quantity(definition_id),
AssetValueType::Fixed => AssetDefinition::fixed(definition_id),
AssetValueType::Store => AssetDefinition::store(definition_id),
};
if unmintable {
asset_definition = asset_definition.mintable_once();
Expand All @@ -835,12 +835,9 @@ mod asset {
/// Command for minting asset in existing Iroha account
#[derive(clap::Args, Debug)]
pub struct Mint {
/// Account id where asset is stored (in form of `name@domain_name')
#[arg(long)]
pub account: AccountId,
/// Asset id from which to mint (in form of `name#domain_name')
/// Asset id for the asset (in form of `asset##account@domain_name`)
#[arg(long)]
pub asset: AssetDefinitionId,
pub asset_id: AssetId,
/// Quantity to mint
#[arg(short, long)]
pub quantity: u32,
Expand All @@ -851,15 +848,12 @@ mod asset {
impl RunArgs for Mint {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self {
account,
asset,
asset_id,
quantity,
metadata,
} = self;
let mint_asset = iroha_client::data_model::isi::Mint::asset_quantity(
quantity,
AssetId::new(asset, account),
);
let mint_asset =
iroha_client::data_model::isi::Mint::asset_quantity(quantity, asset_id);
submit([mint_asset], metadata.load()?, context)
.wrap_err("Failed to mint asset of type `NumericValue::U32`")
}
Expand All @@ -868,12 +862,9 @@ mod asset {
/// Command for minting asset in existing Iroha account
#[derive(clap::Args, Debug)]
pub struct Burn {
/// Account id where asset is stored (in form of `name@domain_name')
/// Asset id for the asset (in form of `asset##account@domain_name`)
#[arg(long)]
pub account: AccountId,
/// Asset id from which to mint (in form of `name#domain_name')
#[arg(long)]
pub asset: AssetDefinitionId,
pub asset_id: AssetId,
/// Quantity to mint
#[arg(short, long)]
pub quantity: u32,
Expand All @@ -884,15 +875,12 @@ mod asset {
impl RunArgs for Burn {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self {
account,
asset,
asset_id,
quantity,
metadata,
} = self;
let burn_asset = iroha_client::data_model::isi::Burn::asset_quantity(
quantity,
AssetId::new(asset, account),
);
let burn_asset =
iroha_client::data_model::isi::Burn::asset_quantity(quantity, asset_id);
submit([burn_asset], metadata.load()?, context)
.wrap_err("Failed to burn asset of type `NumericValue::U32`")
}
Expand All @@ -901,15 +889,12 @@ mod asset {
/// Transfer asset between accounts
#[derive(clap::Args, Debug)]
pub struct Transfer {
/// Account from which to transfer (in form `name@domain_name')
#[arg(short, long)]
pub from: AccountId,
/// Account to which to transfer (in form `name@domain_name')
#[arg(short, long)]
/// Account to which to transfer (in form `name@domain_name`)
#[arg(long)]
pub to: AccountId,
/// Asset id to transfer (in form like `name#domain_name')
#[arg(short, long)]
pub asset_id: AssetDefinitionId,
/// Asset id to transfer (in form like `asset##account@domain_name`)
#[arg(long)]
pub asset_id: AssetId,
/// Quantity of asset as number
#[arg(short, long)]
pub quantity: u32,
Expand All @@ -920,37 +905,29 @@ mod asset {
impl RunArgs for Transfer {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self {
from,
to,
asset_id,
quantity,
metadata,
} = self;
let transfer_asset = iroha_client::data_model::isi::Transfer::asset_quantity(
AssetId::new(asset_id, from),
quantity,
to,
);
let transfer_asset =
iroha_client::data_model::isi::Transfer::asset_quantity(asset_id, quantity, to);
submit([transfer_asset], metadata.load()?, context).wrap_err("Failed to transfer asset")
}
}

/// Get info of asset
#[derive(clap::Args, Debug)]
pub struct Get {
/// Account where asset is stored (in form of `name@domain_name')
#[arg(long)]
pub account: AccountId,
/// Asset name to lookup (in form of `name#domain_name')
/// Asset id for the asset (in form of `asset##account@domain_name`)
#[arg(long)]
pub asset: AssetDefinitionId,
pub asset_id: AssetId,
}

impl RunArgs for Get {
fn run(self, context: &mut dyn RunContext) -> Result<()> {
let Self { account, asset } = self;
let Self { asset_id } = self;
let iroha_client = Client::new(context.configuration())?;
let asset_id = AssetId::new(asset, account);
let asset = iroha_client
.request(asset::by_id(asset_id))
.wrap_err("Failed to get asset.")?;
Expand Down Expand Up @@ -989,7 +966,7 @@ mod asset {

#[derive(clap::Args, Debug)]
pub struct SetKeyValue {
/// AssetId for the Store asset (in form of `asset##account@domain_name')
/// Asset id for the Store asset (in form of `asset##account@domain_name`)
#[clap(long)]
pub asset_id: AssetId,
/// The key for the store value
Expand Down Expand Up @@ -1021,7 +998,7 @@ mod asset {
}
#[derive(clap::Args, Debug)]
pub struct RemoveKeyValue {
/// AssetId for the Store asset (in form of `asset##account@domain_name')
/// Asset id for the Store asset (in form of `asset##account@domain_name`)
#[clap(long)]
pub asset_id: AssetId,
/// The key for the store value
Expand All @@ -1040,7 +1017,7 @@ mod asset {

#[derive(clap::Args, Debug)]
pub struct GetKeyValue {
/// AssetId for the Store asset (in form of `asset##account@domain_name')
/// Asset id for the Store asset (in form of `asset##account@domain_name`)
#[clap(long)]
pub asset_id: AssetId,
/// The key for the store value
Expand Down

0 comments on commit 85d03b7

Please sign in to comment.