1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//! Commands for the Cardano Transaction Snapshot artifact & Cardano Transactions Proof
mod certify;
mod snapshot_list;
mod snapshot_show;

pub use certify::*;
pub use snapshot_list::*;
pub use snapshot_show::*;

use crate::CommandContext;
use clap::Subcommand;
use mithril_client::MithrilResult;

/// Cardano transactions management
#[derive(Subcommand, Debug, Clone)]
#[command(about = "Cardano transactions management (alias: ctx)")]
pub enum CardanoTransactionCommands {
    /// Cardano transaction snapshot commands
    #[clap(subcommand)]
    Snapshot(CardanoTransactionSnapshotCommands),

    /// Certify that a given list of transaction hashes are included in the Cardano transactions set
    #[clap(arg_required_else_help = false)]
    Certify(CardanoTransactionsCertifyCommand),
}

/// Cardano transactions set
#[derive(Subcommand, Debug, Clone)]
pub enum CardanoTransactionSnapshotCommands {
    /// List Cardano transaction sets
    #[clap(arg_required_else_help = false)]
    List(CardanoTransactionSnapshotListCommand),

    /// Show Cardano transaction sets
    #[clap(arg_required_else_help = false)]
    Show(CardanoTransactionsSnapshotShowCommand),
}

impl CardanoTransactionCommands {
    /// Execute Cardano transaction command
    pub async fn execute(&self, config_builder: CommandContext) -> MithrilResult<()> {
        match self {
            Self::Snapshot(cmd) => cmd.execute(config_builder).await,
            Self::Certify(cmd) => cmd.execute(config_builder).await,
        }
    }
}

impl CardanoTransactionSnapshotCommands {
    /// Execute Cardano transaction snapshot command
    pub async fn execute(&self, config_builder: CommandContext) -> MithrilResult<()> {
        match self {
            Self::List(cmd) => cmd.execute(config_builder).await,
            Self::Show(cmd) => cmd.execute(config_builder).await,
        }
    }
}