utility_cli_rs/commands/account/create_account/
mod.rs

1#![allow(clippy::enum_variant_names, clippy::large_enum_variant)]
2use strum::{EnumDiscriminants, EnumIter, EnumMessage};
3
4mod create_implicit_account;
5mod fund_myself_create_account;
6pub mod sponsor_by_faucet_service;
7
8#[derive(Debug, Clone, interactive_clap::InteractiveClap)]
9#[interactive_clap(context = crate::GlobalContext)]
10pub struct CreateAccount {
11    #[interactive_clap(subcommand)]
12    account_actions: CoverCostsCreateAccount,
13}
14
15#[derive(Debug, EnumDiscriminants, Clone, interactive_clap::InteractiveClap)]
16#[interactive_clap(input_context = crate::GlobalContext)]
17#[interactive_clap(output_context = CoverCostsCreateAccountContext)]
18#[strum_discriminants(derive(EnumMessage, EnumIter))]
19/// How do you cover the costs of account creation?
20pub enum CoverCostsCreateAccount {
21    #[strum_discriminants(strum(
22        message = "sponsor-by-faucet-service    - I would like the faucet service sponsor to cover the cost of creating an account (testnet only for now)"
23    ))]
24    /// I would like the faucet service sponsor to cover the cost of creating an account (testnet only for now)
25    SponsorByFaucetService(self::sponsor_by_faucet_service::NewAccount),
26    #[strum_discriminants(strum(
27        message = "fund-myself                  - I would like fund myself to cover the cost of creating an account"
28    ))]
29    /// I would like fund myself to cover the cost of creating an account
30    FundMyself(self::fund_myself_create_account::NewAccount),
31    #[strum_discriminants(strum(
32        message = "fund-later                   - Create an implicit-account"
33    ))]
34    /// Create an implicit-account
35    FundLater(self::create_implicit_account::ImplicitAccount),
36}
37
38#[derive(Debug, Clone)]
39pub struct CoverCostsCreateAccountContext(crate::GlobalContext);
40
41impl CoverCostsCreateAccountContext {
42    pub fn from_previous_context(
43        previous_context: crate::GlobalContext,
44        scope: &<CoverCostsCreateAccount as interactive_clap::ToInteractiveClapContextScope>::InteractiveClapContextScope,
45    ) -> color_eyre::eyre::Result<Self> {
46        match scope {
47            CoverCostsCreateAccountDiscriminants::SponsorByFaucetService => {
48                if previous_context.offline {
49                    Err(color_eyre::Report::msg(
50                        "Error: Creating an account with a faucet sponsor is not possible offline.",
51                    ))
52                } else {
53                    Ok(Self(previous_context))
54                }
55            }
56            _ => Ok(Self(previous_context)),
57        }
58    }
59}
60
61impl From<CoverCostsCreateAccountContext> for crate::GlobalContext {
62    fn from(item: CoverCostsCreateAccountContext) -> Self {
63        item.0
64    }
65}