Skip to content

Commit 17afb2c

Browse files
authored
Merge pull request #1516 from input-output-hk/ensemble/1469/enhance-cli-standard-output
Enhance client-cli standard output
2 parents 0d47097 + 1ffa53c commit 17afb2c

File tree

31 files changed

+420
-208
lines changed

31 files changed

+420
-208
lines changed

Cargo.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/website/root/manual/developer-docs/nodes/mithril-client.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ Mithril client is responsible for restoring the **Cardano** blockchain on an emp
1515

1616
:::tip
1717

18-
* For more information about the **Mithril network**, please see the [architecture](../../../mithril/mithril-network/architecture.md) overview.
18+
* For more information about the **Mithril network**, please see
19+
the [architecture](../../../mithril/mithril-network/architecture.md) overview.
1920

20-
* For more information about the **Mithril client** node, please see [this overview](../../../mithril/mithril-network/client.md).
21+
* For more information about the **Mithril client** node, please
22+
see [this overview](../../../mithril/mithril-network/client.md).
2123

2224
* Check out the [`Bootstrap a Cardano node`](../../getting-started/bootstrap-cardano-node.md) guide.
2325

@@ -29,7 +31,6 @@ Mithril client is responsible for restoring the **Cardano** blockchain on an emp
2931

3032
:::
3133

32-
3334
## Resources
3435

3536
| Node | Source repository | Rust documentation | Docker packages |
@@ -38,7 +39,8 @@ Mithril client is responsible for restoring the **Cardano** blockchain on an emp
3839

3940
## Pre-requisites
4041

41-
* Install the latest stable version of the [correctly configured](https://www.rust-lang.org/learn/get-started) Rust toolchain.
42+
* Install the latest stable version of the [correctly configured](https://www.rust-lang.org/learn/get-started) Rust
43+
toolchain.
4244

4345
* Install OpenSSL development libraries. For example, on Ubuntu/Debian/Mint, run `apt install libssl-dev`
4446

@@ -64,7 +66,7 @@ Switch to the desired branch/tag:
6466
git checkout **YOUR_BUILD_BRANCH_OR_TAG**
6567
```
6668

67-
Change the directory:
69+
Change the directory:
6870

6971
```bash
7072
cd mithril/mithril-client-cli
@@ -198,7 +200,8 @@ If you wish to delve deeper and access several levels of logs from the Mithril c
198200

199201
### Registry image
200202

201-
A list of available images on the registry can be found [here](https://github.com/input-output-hk/mithril/pkgs/container/mithril-client).
203+
A list of available images on the registry can be
204+
found [here](https://github.com/input-output-hk/mithril/pkgs/container/mithril-client).
202205

203206
To prepare the environment variables, retrieve the values from the above **Mithril networks** table.
204207

@@ -249,11 +252,11 @@ mithril_client mithril-stake-distribution list
249252
# 6- Download and verify the given Mithril stake distribution
250253
mithril_client mithril-stake-distribution download $MITHRIL_STAKE_DISTRIBUTION_ARTIFACT_HASH
251254

252-
# 7- List Cardano transaction sets
253-
mithril_client --unstable cardano-transaction sets list
255+
# 7- List Cardano transaction commitments
256+
mithril_client --unstable cardano-transaction commitment list
254257

255-
# 8- Show detailed information about a Cardano transaction sets
256-
mithril_client --unstable cardano-transaction sets show $CARDANO_TRANSACTION_SETS_HASH
258+
# 8- Show detailed information about a Cardano transaction commitment
259+
mithril_client --unstable cardano-transaction commitment show $CARDANO_TRANSACTION_COMMITMENT_HASH
257260

258261
# 9- Certify that given list of transactions hashes are included in the Cardano transactions set
259262
mithril_client --unstable cardano-transaction certify $TRANSACTION_HASH_1,$TRANSACTION_HASH_2
@@ -299,15 +302,16 @@ Here are the subcommands available:
299302
| Subcommand | Performed action |
300303
|------------|------------------|
301304
| **certify** | Certifies that given list of transactions hashes are included in the Cardano transactions set|
305+
| **commitment list** | Lists available Cardano transactions commitments|
306+
| **commitment show** | Shows information about a Cardano transactions commitment|
302307
| **help** | Prints this message or the help for the given subcommand(s)|
303-
| **sets list** | Lists available Cardano transactions sets|
304-
| **sets show** | Shows information about a Cardano transaction sets|
305308

306309
## Configuration parameters
307310

308311
The configuration parameters can be set in either of the following ways:
309312

310-
1. In a configuration file, depending on the `--run-mode` parameter. If the runtime mode is `testnet`, the file is located in `./conf/testnet.json`.
313+
1. In a configuration file, depending on the `--run-mode` parameter. If the runtime mode is `testnet`, the file is
314+
located in `./conf/testnet.json`.
311315

312316
2. The value can be overridden by an environment variable with the parameter name in uppercase.
313317

@@ -358,20 +362,20 @@ Here is a list of the available parameters:
358362
| `artifact_hash` | `--artifact-hash` | - | - | Hash of the Mithril stake distribution artifact or `latest` for the latest artifact | - | - | :heavy_check_mark: |
359363
| `download_dir` | `--download-dir` | - | - | Directory where the Mithril stake distribution will be downloaded | . | - | - |
360364

361-
`cardano-transaction --unstable sets show` command:
365+
`cardano-transaction commitment show` command:
362366

363367
| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory |
364368
|-----------|---------------------|:---------------------:|----------------------|-------------|---------------|---------|:---------:|
365-
| `hash` | `--hash` | - | `HASH` | Cardano transaction sets hash or `latest` for the latest Cardano transaction sets | - | - | :heavy_check_mark: |
369+
| `hash` | `--hash` | - | `HASH` | Cardano transaction commitment hash or `latest` for the latest Cardano transaction commitment | - | - | :heavy_check_mark: |
366370
| `json` | `--json` | - | - | Enable JSON output for command results | - | - | - |
367371

368-
`cardano-transaction --unstable sets list` command:
372+
`cardano-transaction commitment list` command:
369373

370374
| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory |
371375
|-----------|---------------------|:---------------------:|----------------------|-------------|---------------|---------|:---------:|
372376
| `json` | `--json` | - | - | Enable JSON output for command results | - | - | - |
373377

374-
`cardano-transaction --unstable download` command:
378+
`cardano-transaction certify` command:
375379

376380
| Parameter | Command line (long) | Command line (short) | Environment variable | Description | Default value | Example | Mandatory |
377381
|-----------|---------------------|:---------------------:|----------------------|-------------|---------------|---------|:---------:|

examples/client-cardano-transaction/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "client-cardano-transaction"
33
description = "Mithril client cardano-transaction example"
4-
version = "0.1.0"
4+
version = "0.1.1"
55
66
documentation = "https://mithril.network/doc"
77
edition = "2021"

examples/client-cardano-transaction/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async fn main() -> MithrilResult<()> {
5050

5151
info!(logger, "Fetching a proof for the given transactions...",);
5252
let cardano_transaction_proof = client
53-
.cardano_transaction_proof()
53+
.cardano_transaction()
5454
.get_proofs(transactions_hashes)
5555
.await
5656
.unwrap();

examples/client-mithril-stake-distribution/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "client-mithril-stake-distribution"
33
description = "Mithril client stake distribution example"
4-
version = "0.1.7"
4+
version = "0.1.8"
55
66
documentation = "https://mithril.network/doc"
77
edition = "2021"

examples/client-mithril-stake-distribution/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! This example shows how to implement a Mithril client and use its features.
22
//!
33
//! In this example, the client interacts by default with a real aggregator (`testing-preview`) to get the data.
4-
//!
5-
//! The [SlogFeedbackReceiver] is used to report the progress to the console.
64
75
use anyhow::anyhow;
86
use clap::Parser;

mithril-client-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-client-cli"
3-
version = "0.6.2"
3+
version = "0.7.0"
44
description = "A Mithril Client"
55
authors = { workspace = true }
66
edition = { workspace = true }

mithril-client-cli/src/commands/cardano_transaction/certify.rs

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use anyhow::{anyhow, Context};
22
use clap::Parser;
3+
use cli_table::{print_stdout, Cell, Table};
34
use config::{builder::DefaultState, ConfigBuilder, Map, Source, Value, ValueKind};
45
use slog_scope::debug;
56
use std::{collections::HashMap, sync::Arc};
67

78
use mithril_client::{
8-
common::TransactionHash, MessageBuilder, MithrilCertificate, MithrilResult,
9-
VerifiedCardanoTransactions,
9+
common::TransactionHash, CardanoTransactionsProofs, MessageBuilder, MithrilCertificate,
10+
MithrilResult, VerifiedCardanoTransactions, VerifyCardanoTransactionsProofsError,
1011
};
1112

1213
use crate::utils::{IndicatifFeedbackReceiver, ProgressOutputType, ProgressPrinter};
@@ -48,7 +49,7 @@ impl CardanoTransactionsCertifyCommand {
4849

4950
progress_printer.report_step(1, "Fetching a proof for the given transactions…")?;
5051
let cardano_transaction_proof = client
51-
.cardano_transaction_proof()
52+
.cardano_transaction()
5253
.get_proofs(&self.transactions_hashes)
5354
.await
5455
.with_context(|| {
@@ -62,11 +63,8 @@ impl CardanoTransactionsCertifyCommand {
6263
cardano_transaction_proof
6364
);
6465

65-
progress_printer.report_step(2, "Verifying the proof…")?;
66-
let verified_transactions = cardano_transaction_proof
67-
.verify()
68-
.with_context(|| "Proof verification failed")?;
69-
debug!("Verified Transactions: {:?}", verified_transactions);
66+
let verified_transactions =
67+
Self::verify_proof_validity(2, &progress_printer, &cardano_transaction_proof)?;
7068

7169
progress_printer.report_step(
7270
3,
@@ -97,6 +95,23 @@ impl CardanoTransactionsCertifyCommand {
9795
)
9896
}
9997

98+
fn verify_proof_validity(
99+
step_number: u16,
100+
progress_printer: &ProgressPrinter,
101+
cardano_transaction_proof: &CardanoTransactionsProofs,
102+
) -> MithrilResult<VerifiedCardanoTransactions> {
103+
progress_printer.report_step(step_number, "Verifying the proof…")?;
104+
match cardano_transaction_proof.verify() {
105+
Ok(verified_transactions) => Ok(verified_transactions),
106+
Err(VerifyCardanoTransactionsProofsError::NoCertifiedTransaction) => Err(anyhow!(
107+
"Mithril could not certify any of the given transactions.
108+
109+
Mithril may not have signed those transactions yet, please try again later."
110+
)),
111+
err => err.with_context(|| "Proof verification failed"),
112+
}
113+
}
114+
100115
fn verify_proof_match_certificate(
101116
step_number: u16,
102117
progress_printer: &ProgressPrinter,
@@ -132,18 +147,35 @@ impl CardanoTransactionsCertifyCommand {
132147
);
133148
} else {
134149
println!(
135-
r###"Cardano transactions with hashes "'{}'" have been successfully checked against Mithril multi-signature contained in the certificate."###,
136-
verified_transactions.certified_transactions().join(","),
150+
r###"Cardano transactions proof has been successfully signed in the associated Mithril certificate."###,
137151
);
138152

139153
if !non_certified_transactions.is_empty() {
140154
println!(
141-
r###"No proof could be computed for Cardano transactions with hashes "'{}'".
142-
143-
Mithril may not have signed those transactions yet, please try again later."###,
144-
non_certified_transactions.join(","),
155+
r###"
156+
No proof could be computed for some Cardano transactions. Mithril may not have signed those transactions yet, please try again later."###,
145157
);
146158
}
159+
160+
let result_table = verified_transactions
161+
.certified_transactions()
162+
.iter()
163+
.map(|tx| {
164+
vec![
165+
tx.cell(),
166+
"✅".cell().justify(cli_table::format::Justify::Center),
167+
]
168+
})
169+
.chain(non_certified_transactions.iter().map(|tx| {
170+
vec![
171+
tx.cell(),
172+
"❌".cell().justify(cli_table::format::Justify::Center),
173+
]
174+
}))
175+
.table()
176+
.title(vec!["Transaction Hash", "Certified"]);
177+
178+
print_stdout(result_table)?
147179
}
148180

149181
Ok(())

mithril-client-cli/src/commands/cardano_transaction/sets_list.rs renamed to mithril-client-cli/src/commands/cardano_transaction/commitment_list.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,21 @@ use crate::commands::client_builder_with_fallback_genesis_key;
88
use crate::configuration::ConfigParameters;
99
use mithril_client::MithrilResult;
1010

11-
/// Cardano transaction commitment LIST command
11+
/// Cardano transaction commitment list command
1212
#[derive(Parser, Debug, Clone)]
13-
pub struct CardanoTransactionSetsListCommand {
13+
pub struct CardanoTransactionCommitmentListCommand {
1414
/// Enable JSON output.
1515
#[clap(long)]
1616
json: bool,
1717
}
1818

19-
impl CardanoTransactionSetsListCommand {
19+
impl CardanoTransactionCommitmentListCommand {
2020
/// Main command execution
2121
pub async fn execute(&self, config_builder: ConfigBuilder<DefaultState>) -> MithrilResult<()> {
2222
let config = config_builder.build()?;
2323
let params = ConfigParameters::new(config.try_deserialize::<HashMap<String, String>>()?);
2424
let client = client_builder_with_fallback_genesis_key(&params)?.build()?;
25-
let lines = client.cardano_transaction_proof().list().await?;
25+
let lines = client.cardano_transaction().list_commitments().await?;
2626

2727
if self.json {
2828
println!("{}", serde_json::to_string(&lines)?);

0 commit comments

Comments
 (0)