From 85d03b75e55836f1d49b3d5aae601037f5b77f0d Mon Sep 17 00:00:00 2001 From: Asem Abdelhady Date: Tue, 23 Jan 2024 09:01:39 +0300 Subject: [PATCH] [refactor] #4167: asset subcommand in client CLI to be consistent (#4200) * [change]: cli asset parameters to be consistent Signed-off-by: Asem-Abdelhady * [fix] Update client cli command for tests Signed-off-by: alexstroke <111361420+astrokov7@users.noreply.github.com> --------- Signed-off-by: Asem-Abdelhady Signed-off-by: alexstroke <111361420+astrokov7@users.noreply.github.com> Co-authored-by: alexstroke --- .../pytests/src/client_cli/client_cli.py | 15 ++-- client_cli/src/main.rs | 85 +++++++------------ 2 files changed, 39 insertions(+), 61 deletions(-) diff --git a/client_cli/pytests/src/client_cli/client_cli.py b/client_cli/pytests/src/client_cli/client_cli.py index f715f31b246..cdd33b58c59 100644 --- a/client_cli/pytests/src/client_cli/client_cli.py +++ b/client_cli/pytests/src/client_cli/client_cli.py @@ -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() @@ -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 @@ -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 @@ -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 diff --git a/client_cli/src/main.rs b/client_cli/src/main.rs index 2084d35d562..0238fdc32c6 100644 --- a/client_cli/src/main.rs +++ b/client_cli/src/main.rs @@ -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, @@ -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(); @@ -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, @@ -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`") } @@ -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, @@ -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`") } @@ -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, @@ -920,17 +905,13 @@ 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") } } @@ -938,19 +919,15 @@ mod 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.")?; @@ -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 @@ -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 @@ -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