Skip to content

Commit

Permalink
cli: add types and enumeration when listing Outputs (#955)
Browse files Browse the repository at this point in the history
* feat(wallet): add types to list of outputs

* remove vim-typo

* remove named parameters

* feat: add kind_str for Output

* fix kind_str

* lint

* changelog

* lint

* Update sdk/src/types/block/output/mod.rs

* remove ghost code

* Update cli/src/command/wallet.rs

* Update cli/src/command/wallet.rs

* add empty line

* feat: extend list of outputs for `unspent-outputs`

---------

Co-authored-by: Thibault Martinez <[email protected]>
  • Loading branch information
qrayven and thibault-martinez authored Jul 31, 2023
1 parent 571baed commit 35c8178
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`, `unspent-outputs` print a list that includes number and type of the output;

## 1.0.0 - 2023-07-27

Expand Down
13 changes: 8 additions & 5 deletions cli/src/command/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,11 @@ pub async fn outputs_command(account: &Account) -> Result<(), Error> {
if outputs.is_empty() {
println_log_info!("No outputs found");
} else {
let output_ids: Vec<OutputId> = outputs.iter().map(|o| o.output_id).collect();
println_log_info!("Outputs: {output_ids:#?}");
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());
}
}

Ok(())
}

Expand Down Expand Up @@ -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<OutputId> = 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(())
Expand Down
4 changes: 4 additions & 0 deletions sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions sdk/src/types/block/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,17 @@ impl Output {
}
}

/// Returns the output kind of an [`Output`] as a string.
pub fn kind_str(&self) -> &str {
match self {
Self::Alias(_) => "Alias",
Self::Basic(_) => "Basic",
Self::Foundry(_) => "Foundry",
Self::Nft(_) => "Nft",
Self::Treasury(_) => "Treasury",
}
}

/// Returns the amount of an [`Output`].
pub fn amount(&self) -> u64 {
match self {
Expand Down

0 comments on commit 35c8178

Please sign in to comment.