Newer
Older
Nicolas80
committed
mod database;
Nicolas80
committed
mod entities;
Nicolas80
committed
mod inputs;
use clap::builder::OsStr;
use colored::Colorize;
use display::DisplayEvent;
use serde::{Deserialize, Serialize};
use std::str::FromStr;
tx::{DefaultPayload, PairSigner, Payload, TxStatus},
// alias
pub type StaticPayload<Calldata> = DefaultPayload<Calldata>;
#[clap(subcommand)]
pub subcommand: Subcommand,
#[clap(short, long, conflicts_with_all=["no_indexer","network"])]
/// Do not use indexer
#[clap(long)]
no_indexer: bool,
/// Secret key or BIP39 mnemonic (only used when secret format is compatible)
/// (eventually followed by derivation path)
#[clap(short, long)]
secret: Option<String>,
/// Secret key format (seed, substrate, g1v1)
#[clap(short = 'S', long)]
secret_format: Option<SecretFormat>,
/// SS58 Address
#[clap(short, conflicts_with = "name")]
address: Option<AccountId>,
/// Name of an SS58 Address in the vault
#[clap(short = 'v')]
name: Option<String>,
/// Overwrite duniter websocket RPC endpoint
#[clap(short, long, conflicts_with = "network")]
/// Target network (local, gdev, gtest...)
#[clap(short, long)]
network: Option<String>,
/// prevent waiting for extrinsic completion
#[clap(long)]
no_wait: bool,
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/// Output format (human, json, ...)
#[clap(short = 'o', long, default_value = OutputFormat::Human)]
output_format: OutputFormat,
}
// TODO derive the fromstr implementation
/// secret format
#[derive(Clone, Copy, Debug, Eq, PartialEq, Default)]
enum OutputFormat {
/// Human
#[default]
Human,
/// JSON
Json,
}
impl FromStr for OutputFormat {
type Err = std::io::Error;
fn from_str(s: &str) -> std::io::Result<Self> {
match s {
"human" => Ok(OutputFormat::Human),
"json" => Ok(OutputFormat::Json),
_ => Err(std::io::Error::from(std::io::ErrorKind::InvalidInput)),
}
}
}
impl From<OutputFormat> for &'static str {
fn from(val: OutputFormat) -> &'static str {
match val {
OutputFormat::Human => "human",
OutputFormat::Json => "json",
}
}
}
impl From<OutputFormat> for OsStr {
fn from(val: OutputFormat) -> OsStr {
OsStr::from(Into::<&str>::into(val))
}
/// Account (balance, transfer...)
#[clap(subcommand)]
Account(commands::account::Subcommand),
/// Identity (get, create, confirm, revoke...)
#[clap(subcommand)]
Identity(commands::identity::Subcommand),
/// Smith (certify, go-online, go-offline...)
/// Sudo (set key, sudo calls...)
#[clap(hide = true)]
#[clap(subcommand)]
Sudo(commands::sudo::Subcommand),
/// Tech (list members, proposals, vote...)
#[clap(subcommand)]
Tech(commands::collective::Subcommand),
/// Universal Dividend (claim...)
#[clap(subcommand)]
Ud(commands::ud::Subcommand),
/// Oneshot account (balance, create, consume...)
#[clap(subcommand)]
Oneshot(commands::oneshot::Subcommand),
/// Blockchain (current block, runtime info...)
#[clap(subcommand)]
Blockchain(commands::blockchain::Subcommand),
/// Indexer (check, latest block)
Indexer(indexer::Subcommand),
/// Key management (import, generate, list...)
#[clap(subcommand)]
Vault(commands::vault::Subcommand),
/// Cesium
#[clap(subcommand, hide = true)]
Cesium(commands::cesium::Subcommand),
/// Publish a new git tag with actual version
#[clap(hide = true)]
Publish,
Nicolas80
committed
let data = Data::new(Args::parse()).await?;
let result = match data.args.subcommand.clone() {
Subcommand::Nothing => Ok(()),
commands::account::handle_command(data, subcommand).await
}
Subcommand::Identity(subcommand) => {
commands::identity::handle_command(data, subcommand).await
Subcommand::Smith(subcommand) => commands::smith::handle_command(data, subcommand).await,
Subcommand::Sudo(subcommand) => commands::sudo::handle_command(data, subcommand).await,
commands::collective::handle_command(data, subcommand).await
Subcommand::Ud(subcommand) => commands::ud::handle_command(data, subcommand).await,
Subcommand::Oneshot(subcommand) => {
commands::oneshot::handle_command(data, subcommand).await
Subcommand::Blockchain(subcommand) => {
commands::blockchain::handle_command(data, subcommand).await
Subcommand::Indexer(subcommand) => indexer::handle_command(data, subcommand).await,
Nicolas80
committed
Subcommand::Config(subcommand) => conf::handle_command(data, subcommand).await,
Subcommand::Vault(subcommand) => commands::vault::handle_command(data, subcommand).await,
Subcommand::Cesium(subcommand) => commands::cesium::handle_command(data, subcommand).await,
Subcommand::Publish => commands::publish::handle_command().await,
println!("{}", e.to_string().red())
// still return result for detailed error message
// println!();
// result
Ok(())