From 73761909ba124a6c7a3805941516de8ec3366136 Mon Sep 17 00:00:00 2001 From: Yun Date: Thu, 29 Feb 2024 15:09:32 -1000 Subject: [PATCH] Additional madara params (#34) --- schema.json | 132 +++++++++++++++++++++ src/command/deployments/accounts.rs | 11 +- src/command/deployments/create.rs | 15 ++- src/command/deployments/describe.rs | 3 +- src/command/deployments/logs.rs | 1 + src/command/deployments/services/madara.rs | 89 ++++++++++++-- src/command/deployments/services/mod.rs | 3 +- src/command/deployments/update.rs | 2 +- 8 files changed, 235 insertions(+), 21 deletions(-) diff --git a/schema.json b/schema.json index 1c4c772..049c7fd 100644 --- a/schema.json +++ b/schema.json @@ -11597,6 +11597,66 @@ "name": "String", "ofType": null } + }, + { + "defaultValue": null, + "description": null, + "name": "validator", + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "noGrandpa", + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "chain", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "basePath", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "dev", + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "sealing", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } } ], "interfaces": [], @@ -18909,6 +18969,78 @@ "name": "String", "ofType": null } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "validator", + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "noGrandpa", + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "chain", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "basePath", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "dev", + "type": { + "kind": "SCALAR", + "name": "Boolean", + "ofType": null + } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "sealing", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } } ], "inputFields": [], diff --git a/src/command/deployments/accounts.rs b/src/command/deployments/accounts.rs index 0538f50..821f8c6 100644 --- a/src/command/deployments/accounts.rs +++ b/src/command/deployments/accounts.rs @@ -71,10 +71,9 @@ impl AccountsArgs { let accounts = DevAllocationsGenerator::new(total) .with_seed(parse_seed(&config.seed)) .generate(); - + let mut genesis = Genesis::default(); - genesis - .extend_allocations(accounts.into_iter().map(|(k, v)| (k, v.into()))); + genesis.extend_allocations(accounts.into_iter().map(|(k, v)| (k, v.into()))); print_genesis_accounts(genesis.accounts().peekable(), Some(&config.seed)); } } @@ -115,13 +114,13 @@ PREFUNDED ACCOUNTS } if let Some(seed) = seed { - println!( - r" + println!( + r" ACCOUNTS SEED ============= {seed} " - ); + ); } } diff --git a/src/command/deployments/create.rs b/src/command/deployments/create.rs index 698814c..5ff425a 100644 --- a/src/command/deployments/create.rs +++ b/src/command/deployments/create.rs @@ -7,7 +7,9 @@ use graphql_client::{GraphQLQuery, Response}; use crate::{ api::ApiClient, command::deployments::create::create_deployment::{ - CreateDeploymentCreateDeployment::{KatanaConfig, ToriiConfig, MadaraConfig}, CreateKatanaConfigInput, CreateMadaraConfigInput, CreateServiceConfigInput, CreateServiceInput, CreateToriiConfigInput, DeploymentService, DeploymentTier, Variables + CreateDeploymentCreateDeployment::{KatanaConfig, MadaraConfig, ToriiConfig}, + CreateKatanaConfigInput, CreateMadaraConfigInput, CreateServiceConfigInput, + CreateServiceInput, CreateToriiConfigInput, DeploymentService, DeploymentTier, Variables, }, }; @@ -60,7 +62,6 @@ impl CreateArgs { }), torii: None, madara: None, - }), }, CreateServiceCommands::Torii(config) => CreateServiceInput { @@ -83,7 +84,13 @@ impl CreateArgs { katana: None, torii: None, madara: Some(CreateMadaraConfigInput { - name: config.name.clone() + name: config.name.clone(), + base_path: config.base_path.clone(), + dev: config.dev.then_some(true), + no_grandpa: config.no_grandpa.then_some(true), + validator: config.validator.then_some(true), + sealing: config.sealing.clone().map(|s| s.to_string()), + chain: config.chain.clone().map(|c| c.to_string()), }), }), }, @@ -126,7 +133,7 @@ impl CreateArgs { println!("\nEndpoints:"); println!(" RPC: {}", config.rpc); } - MadaraConfig(config) => { + MadaraConfig(config) => { println!("\nEndpoints:"); println!(" RPC: {}", config.rpc); } diff --git a/src/command/deployments/describe.rs b/src/command/deployments/describe.rs index 2fda4af..1a3bc89 100644 --- a/src/command/deployments/describe.rs +++ b/src/command/deployments/describe.rs @@ -8,7 +8,7 @@ use crate::api::ApiClient; use self::describe_deployment::{ DeploymentService, - DescribeDeploymentDeploymentConfig::{KatanaConfig, ToriiConfig, MadaraConfig}, + DescribeDeploymentDeploymentConfig::{KatanaConfig, MadaraConfig, ToriiConfig}, ResponseData, Variables, }; @@ -39,6 +39,7 @@ impl DescribeArgs { let service = match self.service { Service::Torii => DeploymentService::torii, Service::Katana => DeploymentService::katana, + Service::Madara => DeploymentService::madara, }; let request_body = DescribeDeployment::build_query(Variables { diff --git a/src/command/deployments/logs.rs b/src/command/deployments/logs.rs index 58f1547..a90ca56 100644 --- a/src/command/deployments/logs.rs +++ b/src/command/deployments/logs.rs @@ -88,6 +88,7 @@ impl LogReader { let service = match self.service { Service::Katana => DeploymentService::katana, Service::Torii => DeploymentService::torii, + Service::Madara => DeploymentService::madara, }; let request_body = DeploymentLogs::build_query(Variables { diff --git a/src/command/deployments/services/madara.rs b/src/command/deployments/services/madara.rs index d5cd4b1..e870fd1 100644 --- a/src/command/deployments/services/madara.rs +++ b/src/command/deployments/services/madara.rs @@ -1,13 +1,86 @@ -use clap::Args; +use core::fmt; -#[derive(Debug, Args, serde::Serialize)] +use clap::{Args, ValueEnum}; +use serde::Serialize; + +#[derive(Debug, Args, Serialize)] #[command(next_help_heading = "Madara create options")] pub struct MadaraCreateArgs { - #[arg(long, short, value_name = "version")] - #[arg(help = "Service version to use.")] - pub version: Option, + #[arg(long, short, value_name = "version")] + #[arg(help = "Service version to use.")] + pub version: Option, + + #[arg(long, value_name = "dev")] + #[arg( + help = "Specify the development chain. This flag sets `--chain=dev`, `--force-authoring`, `--rpc-cors=all`, `--alice`, and `--tmp` flags, unless explicitly overridden" + )] + pub dev: bool, + + #[arg(long, value_name = "name")] + #[arg(help = "The human-readable name for this node. It's used as network node name.")] + pub name: Option, + + #[arg(long, value_name = "validator")] + #[arg( + help = "Enable validator mode. The node will be started with the authority role and actively participate in any consensus task that it can (e.g. depending on availability of local keys)" + )] + pub validator: bool, + + #[arg(long, value_name = "no_grandpa")] + #[arg( + help = "Disable GRANDPA voter when running in validator mode, otherwise disable the GRANDPA observer" + )] + pub no_grandpa: bool, + + #[arg(long, value_name = "chain")] + #[arg(help = "Specify the chain specification. It can be one of the predefined ones")] + pub chain: Option, + + #[arg(long, value_name = "base_path")] + #[arg(help = "Specify custom base path")] + pub base_path: Option, + + #[arg(long, value_name = "chain")] + #[arg(help = "Choose sealing method")] + pub sealing: Option, + + #[arg(long, value_name = "from_remote")] + #[arg( + help = "Prior to starting the node, the setup cmd will be executed using this value. If none is provided, setup will use the default config." + )] + pub from_remote: Option, +} + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Serialize)] +pub enum SealingMethod { + Manual, + Instant, + InstantFinality, +} + +impl fmt::Display for SealingMethod { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + SealingMethod::Manual => write!(f, "manual"), + SealingMethod::Instant => write!(f, "instant"), + SealingMethod::InstantFinality => write!(f, "instant-finality"), + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, Serialize)] +pub enum ChainOption { + Dev, + Local, + Staging, +} - #[arg(long, short, value_name = "name")] - #[arg(help = "Name.")] - pub name: Option, +impl fmt::Display for ChainOption { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + ChainOption::Dev => write!(f, "dev"), + ChainOption::Local => write!(f, "local"), + ChainOption::Staging => write!(f, "staging"), + } + } } diff --git a/src/command/deployments/services/mod.rs b/src/command/deployments/services/mod.rs index 62a4317..f53ff88 100644 --- a/src/command/deployments/services/mod.rs +++ b/src/command/deployments/services/mod.rs @@ -2,8 +2,8 @@ use clap::{Subcommand, ValueEnum}; use self::{ katana::{KatanaAccountArgs, KatanaCreateArgs, KatanaForkArgs, KatanaUpdateArgs}, - torii::{ToriiCreateArgs, ToriiUpdateArgs}, madara::MadaraCreateArgs, + torii::{ToriiCreateArgs, ToriiUpdateArgs}, }; mod katana; @@ -50,4 +50,5 @@ pub enum KatanaAccountCommands { pub enum Service { Katana, Torii, + Madara, } diff --git a/src/command/deployments/update.rs b/src/command/deployments/update.rs index abb9d5a..0e56da8 100644 --- a/src/command/deployments/update.rs +++ b/src/command/deployments/update.rs @@ -9,7 +9,7 @@ use crate::{ api::ApiClient, command::deployments::update::update_deployment::{ DeploymentService, DeploymentTier, - UpdateDeploymentUpdateDeployment::{KatanaConfig, ToriiConfig, MadaraConfig}, + UpdateDeploymentUpdateDeployment::{KatanaConfig, MadaraConfig, ToriiConfig}, UpdateKatanaConfigInput, UpdateServiceConfigInput, Variables, }, };