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

cli: add types and enumeration when listing Outputs #955

Merged
merged 18 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
Thoralf-M marked this conversation as resolved.
Show resolved Hide resolved
println_log_info!("{}\t{}\t{}", i, &output_data.output_id, output_data.output.kind_str());
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
}
}

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 {
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
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
Loading