From ab7a7634a00a5dc6bb803f4c43a71dea704f6f2c Mon Sep 17 00:00:00 2001 From: Pawel Iwan Date: Thu, 27 Jul 2023 13:51:38 +0200 Subject: [PATCH 01/14] feat(wallet): add types to list of outputs --- cli/src/command/account.rs | 17 +++++++++++++---- cli/src/helper.rs | 11 +++++++++++ .../block/output/unlock_condition/address.rs | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/cli/src/command/account.rs b/cli/src/command/account.rs index eea411c7ae..ebb301045d 100644 --- a/cli/src/command/account.rs +++ b/cli/src/command/account.rs @@ -25,7 +25,11 @@ use iota_sdk::{ U256, }; -use crate::{error::Error, helper::to_utc_date_time, println_log_info}; +use crate::{ + error::Error, + helper::{get_output_type_str, to_utc_date_time}, + println_log_info, +}; #[derive(Debug, Parser)] #[command(author, version, about, long_about = None, propagate_version = true)] @@ -627,10 +631,15 @@ pub async fn outputs_command(account: &Account) -> Result<(), Error> { if outputs.is_empty() { println_log_info!("No outputs found"); } else { - let output_ids: Vec = outputs.iter().map(|o| o.output_id).collect(); - println_log_info!("Outputs: {output_ids:#?}"); + for (i, output_data) in outputs.into_iter().enumerate() { + println_log_info!( + "{i}\t{output_id}\t{output_type}", + i = i, + output_id = &output_data.output_id, + output_type = get_output_type_str(&output_data.output) + ); + } } - Ok(()) } diff --git a/cli/src/helper.rs b/cli/src/helper.rs index 05f84293f2..e8cdff862b 100644 --- a/cli/src/helper.rs +++ b/cli/src/helper.rs @@ -9,6 +9,7 @@ use dialoguer::{console::Term, theme::ColorfulTheme, Input, Select}; use iota_sdk::{ client::{utils::Password, verify_mnemonic}, crypto::keys::bip39::Mnemonic, + types::block::output::Output, wallet::{Account, Wallet}, }; use tokio::{ @@ -267,3 +268,13 @@ pub async fn check_file_exists(path: &Path) -> Result<(), Error> { } Ok(()) } + +pub fn get_output_type_str(output: &Output) -> &str { + match output { + Output::Alias(_) => "Alias", + Output::Basic(_) => "Basic", + Output::Foundry(_) => "Foundry", + Output::Nft(_) => "Nft", + Output::Treasury(_) => "Treasury", + } +} diff --git a/sdk/src/types/block/output/unlock_condition/address.rs b/sdk/src/types/block/output/unlock_condition/address.rs index 2fd42cc7b1..b263a54767 100644 --- a/sdk/src/types/block/output/unlock_condition/address.rs +++ b/sdk/src/types/block/output/unlock_condition/address.rs @@ -13,7 +13,7 @@ impl AddressUnlockCondition { /// The [`UnlockCondition`](crate::types::block::output::UnlockCondition) kind of an [`AddressUnlockCondition`]. pub const KIND: u8 = 0; - /// Creates a new [`AddressUnlockCondition`]. + /// Creates a new [`AddressUnloikCondition`]. #[inline(always)] pub fn new(address: impl Into
) -> Self { Self(address.into()) From 3c55c87dcc9024117b4553fd8eb4492aa8a4d9a5 Mon Sep 17 00:00:00 2001 From: Pawel Iwan Date: Thu, 27 Jul 2023 13:59:29 +0200 Subject: [PATCH 02/14] remove vim-typo --- sdk/src/types/block/output/unlock_condition/address.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/types/block/output/unlock_condition/address.rs b/sdk/src/types/block/output/unlock_condition/address.rs index b263a54767..2fd42cc7b1 100644 --- a/sdk/src/types/block/output/unlock_condition/address.rs +++ b/sdk/src/types/block/output/unlock_condition/address.rs @@ -13,7 +13,7 @@ impl AddressUnlockCondition { /// The [`UnlockCondition`](crate::types::block::output::UnlockCondition) kind of an [`AddressUnlockCondition`]. pub const KIND: u8 = 0; - /// Creates a new [`AddressUnloikCondition`]. + /// Creates a new [`AddressUnlockCondition`]. #[inline(always)] pub fn new(address: impl Into
) -> Self { Self(address.into()) From 30f830e716a32408c7f9d5bd81d8487514a57800 Mon Sep 17 00:00:00 2001 From: Pawel Iwan Date: Thu, 27 Jul 2023 15:08:25 +0200 Subject: [PATCH 03/14] remove named parameters --- cli/src/command/account.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/src/command/account.rs b/cli/src/command/account.rs index ebb301045d..557ef0421d 100644 --- a/cli/src/command/account.rs +++ b/cli/src/command/account.rs @@ -633,10 +633,10 @@ pub async fn outputs_command(account: &Account) -> Result<(), Error> { } else { for (i, output_data) in outputs.into_iter().enumerate() { println_log_info!( - "{i}\t{output_id}\t{output_type}", - i = i, - output_id = &output_data.output_id, - output_type = get_output_type_str(&output_data.output) + "{}\t{}\t{}", + i, + &output_data.output_id, + get_output_type_str(&output_data.output), ); } } From b5c59207e55c080b869244c74befe9655fb01985 Mon Sep 17 00:00:00 2001 From: Pawel Iwan Date: Fri, 28 Jul 2023 09:05:15 +0200 Subject: [PATCH 04/14] feat: add kind_str for Output --- cli/src/command/account.rs | 7 +------ cli/src/command/wallet.rs | 1 + cli/src/helper.rs | 10 ---------- sdk/src/types/block/output/mod.rs | 11 +++++++++++ 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/cli/src/command/account.rs b/cli/src/command/account.rs index 557ef0421d..91e73620ae 100644 --- a/cli/src/command/account.rs +++ b/cli/src/command/account.rs @@ -632,12 +632,7 @@ pub async fn outputs_command(account: &Account) -> Result<(), Error> { println_log_info!("No outputs found"); } else { for (i, output_data) in outputs.into_iter().enumerate() { - println_log_info!( - "{}\t{}\t{}", - i, - &output_data.output_id, - get_output_type_str(&output_data.output), - ); + println_log_info!("{}\t{}\t{}", i, &output_data.output_id, output_data.output.kind_str()); } } Ok(()) diff --git a/cli/src/command/wallet.rs b/cli/src/command/wallet.rs index 0200637b7a..cebd5a7664 100644 --- a/cli/src/command/wallet.rs +++ b/cli/src/command/wallet.rs @@ -216,6 +216,7 @@ pub async fn new_account_command( pub async fn node_info_command(storage_path: &Path) -> Result { let wallet = unlock_wallet(storage_path, None, None).await?; let node_info = wallet.client().get_info().await?; + println_log_info!("{:?}", wallet.get_account_aliases().await.unwrap()); println_log_info!("Current node info: {}", serde_json::to_string_pretty(&node_info)?); diff --git a/cli/src/helper.rs b/cli/src/helper.rs index e8cdff862b..08dee5bdc1 100644 --- a/cli/src/helper.rs +++ b/cli/src/helper.rs @@ -268,13 +268,3 @@ pub async fn check_file_exists(path: &Path) -> Result<(), Error> { } Ok(()) } - -pub fn get_output_type_str(output: &Output) -> &str { - match output { - Output::Alias(_) => "Alias", - Output::Basic(_) => "Basic", - Output::Foundry(_) => "Foundry", - Output::Nft(_) => "Nft", - Output::Treasury(_) => "Treasury", - } -} diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index 4c6cb7d6f7..5bce4acbf8 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -417,6 +417,17 @@ impl Output { Ok(()) } + + /// Return the output kind string of an [`Output`]. + pub fn kind_str(&self) -> &str { + match self { + Output::Alias(_) => "Alias", + Output::Basic(_) => "Basic", + Output::Foundry(_) => "Foundry", + Output::Nft(_) => "Nft", + Output::Treasury(_) => "Treasury", + } + } } impl Packable for Output { From 9dcee43d6bb6826a27edc851aa10164f548e1204 Mon Sep 17 00:00:00 2001 From: Pawel Iwan Date: Fri, 28 Jul 2023 09:12:38 +0200 Subject: [PATCH 05/14] fix kind_str --- sdk/src/types/block/output/mod.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index 5bce4acbf8..2b06a7ee33 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -164,6 +164,17 @@ impl Output { } } + /// Return the output kind of an [`Output`] as a string. + pub fn kind_str(&self) -> &str { + match self { + Output::Alias(_) => "Alias", + Output::Basic(_) => "Basic", + Output::Foundry(_) => "Foundry", + Output::Nft(_) => "Nft", + Output::Treasury(_) => "Treasury", + } + } + /// Returns the amount of an [`Output`]. pub fn amount(&self) -> u64 { match self { @@ -417,17 +428,6 @@ impl Output { Ok(()) } - - /// Return the output kind string of an [`Output`]. - pub fn kind_str(&self) -> &str { - match self { - Output::Alias(_) => "Alias", - Output::Basic(_) => "Basic", - Output::Foundry(_) => "Foundry", - Output::Nft(_) => "Nft", - Output::Treasury(_) => "Treasury", - } - } } impl Packable for Output { From 7e62395302162e94ae7d65647d93784fb7ebf582 Mon Sep 17 00:00:00 2001 From: Pawel Iwan Date: Fri, 28 Jul 2023 09:22:07 +0200 Subject: [PATCH 06/14] lint --- sdk/src/types/block/output/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index 2b06a7ee33..53663ccb27 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -167,11 +167,11 @@ impl Output { /// Return the output kind of an [`Output`] as a string. pub fn kind_str(&self) -> &str { match self { - Output::Alias(_) => "Alias", - Output::Basic(_) => "Basic", - Output::Foundry(_) => "Foundry", - Output::Nft(_) => "Nft", - Output::Treasury(_) => "Treasury", + Self::Alias(_) => "Alias", + Self::Basic(_) => "Basic", + Self::Foundry(_) => "Foundry", + Self::Nft(_) => "Nft", + Self::Treasury(_) => "Treasury", } } From 63cf17b215098f0a470171b5dbb70764a4897316 Mon Sep 17 00:00:00 2001 From: Pawel Iwan Date: Fri, 28 Jul 2023 12:35:55 +0200 Subject: [PATCH 07/14] changelog --- cli/CHANGELOG.md | 1 + sdk/CHANGELOG.md | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index b063c4b294..443d0a23f5 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `WalletCommand::Accounts` variant to list all available accounts in a wallet; - `addresses` now additionally prints the hex version of the address; +- `outputs` prints a list that includes number and type of the output; ## 1.0.0 - 2023-07-27 diff --git a/sdk/CHANGELOG.md b/sdk/CHANGELOG.md index 76b8c9337c..091c4c3cf1 100644 --- a/sdk/CHANGELOG.md +++ b/sdk/CHANGELOG.md @@ -21,6 +21,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 1.1.0 - 2023-MM-DD +### Added + +- `Output::kind_str()` method; + ### Changed - `StrongholdAdapterBuilder` updated to be slightly more ergonomic; From 7bda23b870bfb55e1b96a510f3d1478ae08e6dae Mon Sep 17 00:00:00 2001 From: Pawel Iwan Date: Fri, 28 Jul 2023 12:37:29 +0200 Subject: [PATCH 08/14] lint --- cli/src/command/account.rs | 6 +----- cli/src/helper.rs | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/cli/src/command/account.rs b/cli/src/command/account.rs index 4a7fa61a6c..fce198add9 100644 --- a/cli/src/command/account.rs +++ b/cli/src/command/account.rs @@ -25,11 +25,7 @@ use iota_sdk::{ U256, }; -use crate::{ - error::Error, - helper::{get_output_type_str, to_utc_date_time}, - println_log_info, -}; +use crate::{error::Error, helper::to_utc_date_time, println_log_info}; #[derive(Debug, Parser)] #[command(author, version, about, long_about = None, propagate_version = true)] diff --git a/cli/src/helper.rs b/cli/src/helper.rs index 08dee5bdc1..05f84293f2 100644 --- a/cli/src/helper.rs +++ b/cli/src/helper.rs @@ -9,7 +9,6 @@ use dialoguer::{console::Term, theme::ColorfulTheme, Input, Select}; use iota_sdk::{ client::{utils::Password, verify_mnemonic}, crypto::keys::bip39::Mnemonic, - types::block::output::Output, wallet::{Account, Wallet}, }; use tokio::{ From 71138bf35443b1a2f92d86e8dcdde8f817e3bd28 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 28 Jul 2023 12:39:33 +0200 Subject: [PATCH 09/14] Update sdk/src/types/block/output/mod.rs --- sdk/src/types/block/output/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/types/block/output/mod.rs b/sdk/src/types/block/output/mod.rs index 53663ccb27..6cf6365424 100644 --- a/sdk/src/types/block/output/mod.rs +++ b/sdk/src/types/block/output/mod.rs @@ -164,7 +164,7 @@ impl Output { } } - /// Return the output kind of an [`Output`] as a string. + /// Returns the output kind of an [`Output`] as a string. pub fn kind_str(&self) -> &str { match self { Self::Alias(_) => "Alias", From 161b1dd233ab576c45bf59a7880d5edd76bdc221 Mon Sep 17 00:00:00 2001 From: Pawel Iwan Date: Fri, 28 Jul 2023 12:56:31 +0200 Subject: [PATCH 10/14] remove ghost code --- cli/src/command/wallet.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/cli/src/command/wallet.rs b/cli/src/command/wallet.rs index cebd5a7664..58b2e2d9ea 100644 --- a/cli/src/command/wallet.rs +++ b/cli/src/command/wallet.rs @@ -216,8 +216,6 @@ pub async fn new_account_command( pub async fn node_info_command(storage_path: &Path) -> Result { let wallet = unlock_wallet(storage_path, None, None).await?; let node_info = wallet.client().get_info().await?; - println_log_info!("{:?}", wallet.get_account_aliases().await.unwrap()); - println_log_info!("Current node info: {}", serde_json::to_string_pretty(&node_info)?); Ok(wallet) From 509492f050874211e790fc2f815fb0d2e58a212b Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 28 Jul 2023 15:13:03 +0200 Subject: [PATCH 11/14] Update cli/src/command/wallet.rs --- cli/src/command/wallet.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/src/command/wallet.rs b/cli/src/command/wallet.rs index 58b2e2d9ea..2448ac690a 100644 --- a/cli/src/command/wallet.rs +++ b/cli/src/command/wallet.rs @@ -216,6 +216,7 @@ pub async fn new_account_command( pub async fn node_info_command(storage_path: &Path) -> Result { let wallet = unlock_wallet(storage_path, None, None).await?; let node_info = wallet.client().get_info().await?; + println_log_info!("Current node info: {}", serde_json::to_string_pretty(&node_info)?); Ok(wallet) From 330b866de776287a0d1e0c07bcf3d9c4af2fff92 Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Fri, 28 Jul 2023 15:13:24 +0200 Subject: [PATCH 12/14] Update cli/src/command/wallet.rs --- cli/src/command/wallet.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/src/command/wallet.rs b/cli/src/command/wallet.rs index 2448ac690a..58b2e2d9ea 100644 --- a/cli/src/command/wallet.rs +++ b/cli/src/command/wallet.rs @@ -216,7 +216,6 @@ pub async fn new_account_command( pub async fn node_info_command(storage_path: &Path) -> Result { let wallet = unlock_wallet(storage_path, None, None).await?; let node_info = wallet.client().get_info().await?; - println_log_info!("Current node info: {}", serde_json::to_string_pretty(&node_info)?); Ok(wallet) From d6d46735304b1c1f1db3dc5f86cc1b8ba355393c Mon Sep 17 00:00:00 2001 From: Pawel Iwan Date: Fri, 28 Jul 2023 15:56:54 +0200 Subject: [PATCH 13/14] add empty line --- cli/src/command/wallet.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/src/command/wallet.rs b/cli/src/command/wallet.rs index 58b2e2d9ea..0200637b7a 100644 --- a/cli/src/command/wallet.rs +++ b/cli/src/command/wallet.rs @@ -216,6 +216,7 @@ pub async fn new_account_command( pub async fn node_info_command(storage_path: &Path) -> Result { let wallet = unlock_wallet(storage_path, None, None).await?; let node_info = wallet.client().get_info().await?; + println_log_info!("Current node info: {}", serde_json::to_string_pretty(&node_info)?); Ok(wallet) From 5b24b6d0c976cd27b75c864f6bde071fabb89242 Mon Sep 17 00:00:00 2001 From: Pawel Iwan Date: Fri, 28 Jul 2023 19:32:42 +0200 Subject: [PATCH 14/14] feat: extend list of outputs for `unspent-outputs` --- cli/CHANGELOG.md | 2 +- cli/src/command/account.rs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 443d0a23f5..172c5ad0d6 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -25,7 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `WalletCommand::Accounts` variant to list all available accounts in a wallet; - `addresses` now additionally prints the hex version of the address; -- `outputs` prints a list that includes number and type of the output; +- `outputs`, `unspent-outputs` print a list that includes number and type of the output; ## 1.0.0 - 2023-07-27 diff --git a/cli/src/command/account.rs b/cli/src/command/account.rs index fce198add9..6192099b14 100644 --- a/cli/src/command/account.rs +++ b/cli/src/command/account.rs @@ -627,6 +627,7 @@ pub async fn outputs_command(account: &Account) -> Result<(), Error> { if outputs.is_empty() { println_log_info!("No outputs found"); } else { + println_log_info!("Outputs:"); for (i, output_data) in outputs.into_iter().enumerate() { println_log_info!("{}\t{}\t{}", i, &output_data.output_id, output_data.output.kind_str()); } @@ -786,8 +787,10 @@ pub async fn unspent_outputs_command(account: &Account) -> Result<(), Error> { if outputs.is_empty() { println_log_info!("No outputs found"); } else { - let output_ids: Vec = outputs.iter().map(|o| o.output_id).collect(); - println_log_info!("Unspent outputs: {output_ids:#?}"); + println_log_info!("Unspent outputs:"); + for (i, output_data) in outputs.into_iter().enumerate() { + println_log_info!("{}\t{}\t{}", i, &output_data.output_id, output_data.output.kind_str()); + } } Ok(())