From c68ece871b9f4f069f61d4fbf6b08dee89c617c8 Mon Sep 17 00:00:00 2001 From: broody Date: Wed, 14 Feb 2024 14:32:12 -1000 Subject: [PATCH 1/3] Implement retrieving predeployed accounts --- Cargo.lock | 1 + Cargo.toml | 1 + schema.json | 192 ++++++++++++++++++++- src/command/deployments/accounts.graphql | 15 ++ src/command/deployments/accounts.rs | 142 +++++++++++++++ src/command/deployments/mod.rs | 8 +- src/command/deployments/services/katana.rs | 4 + src/command/deployments/services/mod.rs | 9 +- 8 files changed, 368 insertions(+), 4 deletions(-) create mode 100644 src/command/deployments/accounts.graphql create mode 100644 src/command/deployments/accounts.rs diff --git a/Cargo.lock b/Cargo.lock index 84c9959..cb7b591 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4414,6 +4414,7 @@ version = "0.5.9" dependencies = [ "anyhow", "axum", + "base64 0.21.3", "chrono", "clap", "ctrlc", diff --git a/Cargo.toml b/Cargo.toml index de7a96c..888f8c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ katana-primitives = { git = "https://github.com/dojoengine/dojo", rev = "c83936" ] } anyhow = "1.0.75" axum = "0.6" +base64 = "0.21.2" clap = { version = "4.2", features = ["derive"] } chrono = "0.4.31" ctrlc = "3.4.1" diff --git a/schema.json b/schema.json index e90cac1..cfecf39 100644 --- a/schema.json +++ b/schema.json @@ -11569,7 +11569,7 @@ }, { "defaultValue": null, - "description": "Base64 encoded genesis file with all the classes embedded in the file itself (if any).", + "description": null, "name": "genesis", "type": { "kind": "SCALAR", @@ -11869,6 +11869,22 @@ } } }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "region", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + }, { "args": [], "deprecationReason": null, @@ -12982,6 +12998,152 @@ } } }, + { + "defaultValue": null, + "description": "region field predicates", + "name": "region", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "regionNEQ", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "regionIn", + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + } + }, + { + "defaultValue": null, + "description": null, + "name": "regionNotIn", + "type": { + "kind": "LIST", + "name": null, + "ofType": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + } + }, + { + "defaultValue": null, + "description": null, + "name": "regionGT", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "regionGTE", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "regionLT", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "regionLTE", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "regionContains", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "regionHasPrefix", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "regionHasSuffix", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "regionEqualFold", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, + { + "defaultValue": null, + "description": null, + "name": "regionContainsFold", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, { "defaultValue": null, "description": "auto_upgrade field predicates", @@ -18404,6 +18566,34 @@ "ofType": null } }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "seed", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "genesis", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + }, { "args": [], "deprecationReason": null, diff --git a/src/command/deployments/accounts.graphql b/src/command/deployments/accounts.graphql new file mode 100644 index 0000000..8274ad8 --- /dev/null +++ b/src/command/deployments/accounts.graphql @@ -0,0 +1,15 @@ +query KatanaAccounts($project: String!) { + deployment(name: $project, service: katana) { + project + branch + tier + config { + __typename + ... on KatanaConfig { + seed + genesis + accounts + } + } + } +} diff --git a/src/command/deployments/accounts.rs b/src/command/deployments/accounts.rs new file mode 100644 index 0000000..fc45475 --- /dev/null +++ b/src/command/deployments/accounts.rs @@ -0,0 +1,142 @@ +#![allow(clippy::enum_variant_names)] + +use anyhow::Result; +use base64::prelude::*; +use clap::Args; +use graphql_client::{GraphQLQuery, Response}; +use katana_primitives::contract::ContractAddress; +use katana_primitives::genesis::allocation::DevAllocationsGenerator; +use katana_primitives::genesis::Genesis; +use katana_primitives::genesis::{allocation::GenesisAccountAlloc, json::GenesisJson}; +use std::str::FromStr; + +use crate::api::ApiClient; + +use super::services::KatanaAccountCommands; + +use self::katana_accounts::{ + KatanaAccountsDeploymentConfig::KatanaConfig, ResponseData, Variables, +}; + +#[derive(GraphQLQuery)] +#[graphql( + schema_path = "schema.json", + query_path = "src/command/deployments/accounts.graphql", + response_derives = "Debug" +)] +pub struct KatanaAccounts; + +#[derive(Debug, Args)] +#[command(next_help_heading = "Accounts options")] +pub struct AccountsArgs { + #[arg(help = "The name of the project.")] + pub project: String, + + #[command(subcommand)] + accounts_commands: KatanaAccountCommands, +} + +impl AccountsArgs { + pub async fn run(&self) -> Result<()> { + let request_body = KatanaAccounts::build_query(Variables { + project: self.project.clone(), + }); + + let client = ApiClient::new(); + let res: Response = client.post(&request_body).await?; + if let Some(errors) = res.errors.clone() { + for err in errors { + println!("Error: {}", err.message); + } + } + + if let Some(data) = res.data { + if let Some(deployment) = data.deployment { + if let KatanaConfig(config) = deployment.config { + // genesis overrides seed + if let Some(genesis) = config.genesis { + let decoded = BASE64_STANDARD.decode(genesis)?; + let json = GenesisJson::from_str(&String::from_utf8(decoded)?)?; + let genesis = Genesis::try_from(json)?; + print_genesis_accounts(genesis.accounts().peekable(), None); + + return Ok(()); + } + + if !config.seed.is_empty() { + let total = match config.accounts { + Some(accounts) => accounts as u16, + None => 10, + }; + + 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()))); + print_genesis_accounts(genesis.accounts().peekable(), Some(&config.seed)); + } + } + } + } + + Ok(()) + } +} + +fn print_genesis_accounts<'a, Accounts>(accounts: Accounts, seed: Option<&str>) +where + Accounts: Iterator, +{ + println!( + r" + +PREFUNDED ACCOUNTS +==================" + ); + + for (addr, account) in accounts { + if let Some(pk) = account.private_key() { + println!( + r" +| Account address | {addr} +| Private key | {pk:#x} +| Public key | {:#x}", + account.public_key() + ) + } else { + println!( + r" +| Account address | {addr} +| Public key | {:#x}", + account.public_key() + ) + } + } + + if let Some(seed) = seed { + println!( + r" +ACCOUNTS SEED +============= +{seed} +" + ); + } +} + +fn parse_seed(seed: &str) -> [u8; 32] { + let seed = seed.as_bytes(); + + if seed.len() >= 32 { + unsafe { *(seed[..32].as_ptr() as *const [u8; 32]) } + } else { + let mut actual_seed = [0u8; 32]; + seed.iter() + .enumerate() + .for_each(|(i, b)| actual_seed[i] = *b); + actual_seed + } +} diff --git a/src/command/deployments/mod.rs b/src/command/deployments/mod.rs index 6bd565f..b418f3d 100644 --- a/src/command/deployments/mod.rs +++ b/src/command/deployments/mod.rs @@ -2,10 +2,11 @@ use anyhow::Result; use clap::Subcommand; use self::{ - create::CreateArgs, delete::DeleteArgs, describe::DescribeArgs, fork::ForkArgs, list::ListArgs, - logs::LogsArgs, update::UpdateArgs, + accounts::AccountsArgs, create::CreateArgs, delete::DeleteArgs, describe::DescribeArgs, + fork::ForkArgs, list::ListArgs, logs::LogsArgs, update::UpdateArgs, }; +mod accounts; mod create; mod delete; mod describe; @@ -33,6 +34,8 @@ pub enum Deployments { List(ListArgs), #[command(about = "Fetch logs for a deployment.")] Logs(LogsArgs), + #[command(about = "Fetch Katana accounts.")] + Accounts(AccountsArgs), } impl Deployments { @@ -45,6 +48,7 @@ impl Deployments { Deployments::Describe(args) => args.run().await, Deployments::List(args) => args.run().await, Deployments::Logs(args) => args.run().await, + Deployments::Accounts(args) => args.run().await, } } } diff --git a/src/command/deployments/services/katana.rs b/src/command/deployments/services/katana.rs index 2297cea..95c1138 100644 --- a/src/command/deployments/services/katana.rs +++ b/src/command/deployments/services/katana.rs @@ -104,6 +104,10 @@ pub struct KatanaForkArgs { pub fork_block_number: Option, } +#[derive(Debug, Args, serde::Serialize)] +#[command(next_help_heading = "Katana account options")] +pub struct KatanaAccountArgs {} + fn genesis_value_parser(path: &str) -> Result { let path = PathBuf::from(shellexpand::full(path)?.into_owned()); let genesis = GenesisJson::load(path)?; diff --git a/src/command/deployments/services/mod.rs b/src/command/deployments/services/mod.rs index b132415..ef0530f 100644 --- a/src/command/deployments/services/mod.rs +++ b/src/command/deployments/services/mod.rs @@ -1,7 +1,7 @@ use clap::{Subcommand, ValueEnum}; use self::{ - katana::{KatanaCreateArgs, KatanaForkArgs, KatanaUpdateArgs}, + katana::{KatanaAccountArgs, KatanaCreateArgs, KatanaForkArgs, KatanaUpdateArgs}, torii::{ToriiCreateArgs, ToriiUpdateArgs}, }; @@ -36,6 +36,13 @@ pub enum ForkServiceCommands { // Torii(ToriiUpdateArgs), } +#[derive(Debug, Subcommand, serde::Serialize)] +#[serde(untagged)] +pub enum KatanaAccountCommands { + #[command(about = "Katana deployment.")] + Katana(KatanaAccountArgs), +} + #[derive(Clone, Debug, ValueEnum, serde::Serialize)] pub enum Service { Katana, From 9b20e9f87505a3e7ca5b1247bffa7851daf9384b Mon Sep 17 00:00:00 2001 From: broody Date: Tue, 27 Feb 2024 19:21:23 -1000 Subject: [PATCH 2/3] Madara deployment support --- schema.json | 97 ++++++++++++++++++++++ src/command/deployments/accounts.rs | 28 +++---- src/command/deployments/create.graphql | 4 + src/command/deployments/create.rs | 23 ++++- src/command/deployments/delete.rs | 2 + src/command/deployments/describe.graphql | 5 ++ src/command/deployments/describe.rs | 7 +- src/command/deployments/services/madara.rs | 12 ++- src/command/deployments/services/mod.rs | 3 + src/command/deployments/update.graphql | 1 + src/command/deployments/update.rs | 3 +- 11 files changed, 163 insertions(+), 22 deletions(-) diff --git a/schema.json b/schema.json index cfecf39..1c4c772 100644 --- a/schema.json +++ b/schema.json @@ -11583,6 +11583,27 @@ "name": "CreateKatanaConfigInput", "possibleTypes": [] }, + { + "description": null, + "enumValues": [], + "fields": [], + "inputFields": [ + { + "defaultValue": null, + "description": null, + "name": "name", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + ], + "interfaces": [], + "kind": "INPUT_OBJECT", + "name": "CreateMadaraConfigInput", + "possibleTypes": [] + }, { "description": null, "enumValues": [], @@ -11607,6 +11628,16 @@ "name": "CreateToriiConfigInput", "ofType": null } + }, + { + "defaultValue": null, + "description": null, + "name": "madara", + "type": { + "kind": "INPUT_OBJECT", + "name": "CreateMadaraConfigInput", + "ofType": null + } } ], "interfaces": [], @@ -12110,6 +12141,11 @@ "kind": "OBJECT", "name": "ToriiConfig", "ofType": null + }, + { + "kind": "OBJECT", + "name": "MadaraConfig", + "ofType": null } ] }, @@ -12281,6 +12317,12 @@ "description": null, "isDeprecated": false, "name": "torii" + }, + { + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "madara" } ], "fields": [], @@ -18820,6 +18862,61 @@ "name": "Long", "possibleTypes": [] }, + { + "description": null, + "enumValues": [], + "fields": [ + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "version", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "rpc", + "type": { + "kind": "NON_NULL", + "name": null, + "ofType": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + }, + { + "args": [], + "deprecationReason": null, + "description": null, + "isDeprecated": false, + "name": "name", + "type": { + "kind": "SCALAR", + "name": "String", + "ofType": null + } + } + ], + "inputFields": [], + "interfaces": [], + "kind": "OBJECT", + "name": "MadaraConfig", + "possibleTypes": [] + }, { "description": null, "enumValues": [], diff --git a/src/command/deployments/accounts.rs b/src/command/deployments/accounts.rs index fc45475..0538f50 100644 --- a/src/command/deployments/accounts.rs +++ b/src/command/deployments/accounts.rs @@ -63,21 +63,19 @@ impl AccountsArgs { return Ok(()); } - if !config.seed.is_empty() { - let total = match config.accounts { - Some(accounts) => accounts as u16, - None => 10, - }; - - 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()))); - print_genesis_accounts(genesis.accounts().peekable(), Some(&config.seed)); - } + let total = match config.accounts { + Some(accounts) => accounts as u16, + None => 10, + }; + + 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()))); + print_genesis_accounts(genesis.accounts().peekable(), Some(&config.seed)); } } } diff --git a/src/command/deployments/create.graphql b/src/command/deployments/create.graphql index 6b20741..233d08a 100644 --- a/src/command/deployments/create.graphql +++ b/src/command/deployments/create.graphql @@ -21,5 +21,9 @@ mutation CreateDeployment( world startBlock } + ... on MadaraConfig { + rpc + name + } } } diff --git a/src/command/deployments/create.rs b/src/command/deployments/create.rs index 18a70b2..698814c 100644 --- a/src/command/deployments/create.rs +++ b/src/command/deployments/create.rs @@ -7,9 +7,7 @@ use graphql_client::{GraphQLQuery, Response}; use crate::{ api::ApiClient, command::deployments::create::create_deployment::{ - CreateDeploymentCreateDeployment::{KatanaConfig, ToriiConfig}, - CreateKatanaConfigInput, CreateServiceConfigInput, CreateServiceInput, - CreateToriiConfigInput, DeploymentService, DeploymentTier, Variables, + CreateDeploymentCreateDeployment::{KatanaConfig, ToriiConfig, MadaraConfig}, CreateKatanaConfigInput, CreateMadaraConfigInput, CreateServiceConfigInput, CreateServiceInput, CreateToriiConfigInput, DeploymentService, DeploymentTier, Variables }, }; @@ -61,6 +59,8 @@ impl CreateArgs { genesis: config.genesis.clone(), }), torii: None, + madara: None, + }), }, CreateServiceCommands::Torii(config) => CreateServiceInput { @@ -68,6 +68,7 @@ impl CreateArgs { version: config.version.clone(), config: Some(CreateServiceConfigInput { katana: None, + madara: None, torii: Some(CreateToriiConfigInput { rpc: config.rpc.clone(), world: format!("{:#x}", config.world), @@ -75,6 +76,17 @@ impl CreateArgs { }), }), }, + CreateServiceCommands::Madara(config) => CreateServiceInput { + type_: DeploymentService::madara, + version: config.version.clone(), + config: Some(CreateServiceConfigInput { + katana: None, + torii: None, + madara: Some(CreateMadaraConfigInput { + name: config.name.clone() + }), + }), + }, }; let tier = match &self.tier { @@ -114,12 +126,17 @@ impl CreateArgs { println!("\nEndpoints:"); println!(" RPC: {}", config.rpc); } + MadaraConfig(config) => { + println!("\nEndpoints:"); + println!(" RPC: {}", config.rpc); + } } } let service = match &self.create_commands { CreateServiceCommands::Katana(_) => "katana", CreateServiceCommands::Torii(_) => "torii", + CreateServiceCommands::Madara(_) => "madara", }; println!( diff --git a/src/command/deployments/delete.rs b/src/command/deployments/delete.rs index 2c1b8ac..ae42ace 100644 --- a/src/command/deployments/delete.rs +++ b/src/command/deployments/delete.rs @@ -21,6 +21,7 @@ pub struct DeleteDeployment; pub enum Service { Katana, Torii, + Madara, } #[derive(Debug, Args)] @@ -38,6 +39,7 @@ impl DeleteArgs { let service = match &self.service { Service::Katana => DeploymentService::katana, Service::Torii => DeploymentService::torii, + Service::Madara => DeploymentService::madara, }; let request_body = DeleteDeployment::build_query(Variables { diff --git a/src/command/deployments/describe.graphql b/src/command/deployments/describe.graphql index 8b7a1f7..6d6a67c 100644 --- a/src/command/deployments/describe.graphql +++ b/src/command/deployments/describe.graphql @@ -17,6 +17,11 @@ query DescribeDeployment($project: String!, $service: DeploymentService!) { world startBlock } + ... on MadaraConfig { + version + rpc + name + } } } } diff --git a/src/command/deployments/describe.rs b/src/command/deployments/describe.rs index ef679b0..2fda4af 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}, + DescribeDeploymentDeploymentConfig::{KatanaConfig, ToriiConfig, MadaraConfig}, ResponseData, Variables, }; @@ -79,6 +79,11 @@ impl DescribeArgs { println!(" Version: {}", config.version); println!(" RPC: {}", config.rpc); } + MadaraConfig(config) => { + println!("\nEndpoints:"); + println!(" Version: {}", config.version); + println!(" RPC: {}", config.rpc); + } } } } diff --git a/src/command/deployments/services/madara.rs b/src/command/deployments/services/madara.rs index 9d4b7b1..d5cd4b1 100644 --- a/src/command/deployments/services/madara.rs +++ b/src/command/deployments/services/madara.rs @@ -1,5 +1,13 @@ use clap::Args; #[derive(Debug, Args, serde::Serialize)] -#[command(next_help_heading = "Madara options")] -pub struct MadaraArgs {} +#[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 = "name")] + #[arg(help = "Name.")] + pub name: Option, +} diff --git a/src/command/deployments/services/mod.rs b/src/command/deployments/services/mod.rs index ef0530f..62a4317 100644 --- a/src/command/deployments/services/mod.rs +++ b/src/command/deployments/services/mod.rs @@ -3,6 +3,7 @@ use clap::{Subcommand, ValueEnum}; use self::{ katana::{KatanaAccountArgs, KatanaCreateArgs, KatanaForkArgs, KatanaUpdateArgs}, torii::{ToriiCreateArgs, ToriiUpdateArgs}, + madara::MadaraCreateArgs, }; mod katana; @@ -16,6 +17,8 @@ pub enum CreateServiceCommands { Katana(KatanaCreateArgs), #[command(about = "Torii deployment.")] Torii(ToriiCreateArgs), + #[command(about = "Madara deployment.")] + Madara(MadaraCreateArgs), } #[derive(Debug, Subcommand, serde::Serialize)] diff --git a/src/command/deployments/update.graphql b/src/command/deployments/update.graphql index e746e65..329bd38 100644 --- a/src/command/deployments/update.graphql +++ b/src/command/deployments/update.graphql @@ -21,5 +21,6 @@ mutation UpdateDeployment( world startBlock } + # TODO: handle update } } diff --git a/src/command/deployments/update.rs b/src/command/deployments/update.rs index 55c98d3..abb9d5a 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}, + UpdateDeploymentUpdateDeployment::{KatanaConfig, ToriiConfig, MadaraConfig}, UpdateKatanaConfigInput, UpdateServiceConfigInput, Variables, }, }; @@ -107,6 +107,7 @@ impl UpdateArgs { println!("\nEndpoints:"); println!(" RPC: {}", config.rpc); } + MadaraConfig => {} // TODO: implement } } From 7ea6e2078937b07846a5d918f4defb434cb3d9cf Mon Sep 17 00:00:00 2001 From: broody Date: Tue, 27 Feb 2024 21:01:09 -1000 Subject: [PATCH 3/3] Revert "Implement retrieving predeployed accounts" This reverts commit c68ece871b9f4f069f61d4fbf6b08dee89c617c8. --- Cargo.lock | 1 - Cargo.toml | 1 - schema.json | 192 +-------------------- src/command/deployments/accounts.graphql | 15 -- src/command/deployments/accounts.rs | 140 --------------- src/command/deployments/describe.rs | 1 + src/command/deployments/logs.rs | 1 + src/command/deployments/mod.rs | 8 +- src/command/deployments/services/katana.rs | 4 - src/command/deployments/services/mod.rs | 10 +- 10 files changed, 7 insertions(+), 366 deletions(-) delete mode 100644 src/command/deployments/accounts.graphql delete mode 100644 src/command/deployments/accounts.rs diff --git a/Cargo.lock b/Cargo.lock index cb7b591..84c9959 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4414,7 +4414,6 @@ version = "0.5.9" dependencies = [ "anyhow", "axum", - "base64 0.21.3", "chrono", "clap", "ctrlc", diff --git a/Cargo.toml b/Cargo.toml index 888f8c2..de7a96c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ katana-primitives = { git = "https://github.com/dojoengine/dojo", rev = "c83936" ] } anyhow = "1.0.75" axum = "0.6" -base64 = "0.21.2" clap = { version = "4.2", features = ["derive"] } chrono = "0.4.31" ctrlc = "3.4.1" diff --git a/schema.json b/schema.json index 1c4c772..e3df68f 100644 --- a/schema.json +++ b/schema.json @@ -11569,7 +11569,7 @@ }, { "defaultValue": null, - "description": null, + "description": "Base64 encoded genesis file with all the classes embedded in the file itself (if any).", "name": "genesis", "type": { "kind": "SCALAR", @@ -11900,22 +11900,6 @@ } } }, - { - "args": [], - "deprecationReason": null, - "description": null, - "isDeprecated": false, - "name": "region", - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - } - }, { "args": [], "deprecationReason": null, @@ -13040,152 +13024,6 @@ } } }, - { - "defaultValue": null, - "description": "region field predicates", - "name": "region", - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - { - "defaultValue": null, - "description": null, - "name": "regionNEQ", - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - { - "defaultValue": null, - "description": null, - "name": "regionIn", - "type": { - "kind": "LIST", - "name": null, - "ofType": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - } - } - }, - { - "defaultValue": null, - "description": null, - "name": "regionNotIn", - "type": { - "kind": "LIST", - "name": null, - "ofType": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - } - } - }, - { - "defaultValue": null, - "description": null, - "name": "regionGT", - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - { - "defaultValue": null, - "description": null, - "name": "regionGTE", - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - { - "defaultValue": null, - "description": null, - "name": "regionLT", - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - { - "defaultValue": null, - "description": null, - "name": "regionLTE", - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - { - "defaultValue": null, - "description": null, - "name": "regionContains", - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - { - "defaultValue": null, - "description": null, - "name": "regionHasPrefix", - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - { - "defaultValue": null, - "description": null, - "name": "regionHasSuffix", - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - { - "defaultValue": null, - "description": null, - "name": "regionEqualFold", - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, - { - "defaultValue": null, - "description": null, - "name": "regionContainsFold", - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, { "defaultValue": null, "description": "auto_upgrade field predicates", @@ -18608,34 +18446,6 @@ "ofType": null } }, - { - "args": [], - "deprecationReason": null, - "description": null, - "isDeprecated": false, - "name": "seed", - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - } - }, - { - "args": [], - "deprecationReason": null, - "description": null, - "isDeprecated": false, - "name": "genesis", - "type": { - "kind": "SCALAR", - "name": "String", - "ofType": null - } - }, { "args": [], "deprecationReason": null, diff --git a/src/command/deployments/accounts.graphql b/src/command/deployments/accounts.graphql deleted file mode 100644 index 8274ad8..0000000 --- a/src/command/deployments/accounts.graphql +++ /dev/null @@ -1,15 +0,0 @@ -query KatanaAccounts($project: String!) { - deployment(name: $project, service: katana) { - project - branch - tier - config { - __typename - ... on KatanaConfig { - seed - genesis - accounts - } - } - } -} diff --git a/src/command/deployments/accounts.rs b/src/command/deployments/accounts.rs deleted file mode 100644 index 0538f50..0000000 --- a/src/command/deployments/accounts.rs +++ /dev/null @@ -1,140 +0,0 @@ -#![allow(clippy::enum_variant_names)] - -use anyhow::Result; -use base64::prelude::*; -use clap::Args; -use graphql_client::{GraphQLQuery, Response}; -use katana_primitives::contract::ContractAddress; -use katana_primitives::genesis::allocation::DevAllocationsGenerator; -use katana_primitives::genesis::Genesis; -use katana_primitives::genesis::{allocation::GenesisAccountAlloc, json::GenesisJson}; -use std::str::FromStr; - -use crate::api::ApiClient; - -use super::services::KatanaAccountCommands; - -use self::katana_accounts::{ - KatanaAccountsDeploymentConfig::KatanaConfig, ResponseData, Variables, -}; - -#[derive(GraphQLQuery)] -#[graphql( - schema_path = "schema.json", - query_path = "src/command/deployments/accounts.graphql", - response_derives = "Debug" -)] -pub struct KatanaAccounts; - -#[derive(Debug, Args)] -#[command(next_help_heading = "Accounts options")] -pub struct AccountsArgs { - #[arg(help = "The name of the project.")] - pub project: String, - - #[command(subcommand)] - accounts_commands: KatanaAccountCommands, -} - -impl AccountsArgs { - pub async fn run(&self) -> Result<()> { - let request_body = KatanaAccounts::build_query(Variables { - project: self.project.clone(), - }); - - let client = ApiClient::new(); - let res: Response = client.post(&request_body).await?; - if let Some(errors) = res.errors.clone() { - for err in errors { - println!("Error: {}", err.message); - } - } - - if let Some(data) = res.data { - if let Some(deployment) = data.deployment { - if let KatanaConfig(config) = deployment.config { - // genesis overrides seed - if let Some(genesis) = config.genesis { - let decoded = BASE64_STANDARD.decode(genesis)?; - let json = GenesisJson::from_str(&String::from_utf8(decoded)?)?; - let genesis = Genesis::try_from(json)?; - print_genesis_accounts(genesis.accounts().peekable(), None); - - return Ok(()); - } - - let total = match config.accounts { - Some(accounts) => accounts as u16, - None => 10, - }; - - 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()))); - print_genesis_accounts(genesis.accounts().peekable(), Some(&config.seed)); - } - } - } - - Ok(()) - } -} - -fn print_genesis_accounts<'a, Accounts>(accounts: Accounts, seed: Option<&str>) -where - Accounts: Iterator, -{ - println!( - r" - -PREFUNDED ACCOUNTS -==================" - ); - - for (addr, account) in accounts { - if let Some(pk) = account.private_key() { - println!( - r" -| Account address | {addr} -| Private key | {pk:#x} -| Public key | {:#x}", - account.public_key() - ) - } else { - println!( - r" -| Account address | {addr} -| Public key | {:#x}", - account.public_key() - ) - } - } - - if let Some(seed) = seed { - println!( - r" -ACCOUNTS SEED -============= -{seed} -" - ); - } -} - -fn parse_seed(seed: &str) -> [u8; 32] { - let seed = seed.as_bytes(); - - if seed.len() >= 32 { - unsafe { *(seed[..32].as_ptr() as *const [u8; 32]) } - } else { - let mut actual_seed = [0u8; 32]; - seed.iter() - .enumerate() - .for_each(|(i, b)| actual_seed[i] = *b); - actual_seed - } -} diff --git a/src/command/deployments/describe.rs b/src/command/deployments/describe.rs index 2fda4af..160a1e8 100644 --- a/src/command/deployments/describe.rs +++ b/src/command/deployments/describe.rs @@ -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/mod.rs b/src/command/deployments/mod.rs index b418f3d..6bd565f 100644 --- a/src/command/deployments/mod.rs +++ b/src/command/deployments/mod.rs @@ -2,11 +2,10 @@ use anyhow::Result; use clap::Subcommand; use self::{ - accounts::AccountsArgs, create::CreateArgs, delete::DeleteArgs, describe::DescribeArgs, - fork::ForkArgs, list::ListArgs, logs::LogsArgs, update::UpdateArgs, + create::CreateArgs, delete::DeleteArgs, describe::DescribeArgs, fork::ForkArgs, list::ListArgs, + logs::LogsArgs, update::UpdateArgs, }; -mod accounts; mod create; mod delete; mod describe; @@ -34,8 +33,6 @@ pub enum Deployments { List(ListArgs), #[command(about = "Fetch logs for a deployment.")] Logs(LogsArgs), - #[command(about = "Fetch Katana accounts.")] - Accounts(AccountsArgs), } impl Deployments { @@ -48,7 +45,6 @@ impl Deployments { Deployments::Describe(args) => args.run().await, Deployments::List(args) => args.run().await, Deployments::Logs(args) => args.run().await, - Deployments::Accounts(args) => args.run().await, } } } diff --git a/src/command/deployments/services/katana.rs b/src/command/deployments/services/katana.rs index 95c1138..2297cea 100644 --- a/src/command/deployments/services/katana.rs +++ b/src/command/deployments/services/katana.rs @@ -104,10 +104,6 @@ pub struct KatanaForkArgs { pub fork_block_number: Option, } -#[derive(Debug, Args, serde::Serialize)] -#[command(next_help_heading = "Katana account options")] -pub struct KatanaAccountArgs {} - fn genesis_value_parser(path: &str) -> Result { let path = PathBuf::from(shellexpand::full(path)?.into_owned()); let genesis = GenesisJson::load(path)?; diff --git a/src/command/deployments/services/mod.rs b/src/command/deployments/services/mod.rs index 62a4317..7d0511b 100644 --- a/src/command/deployments/services/mod.rs +++ b/src/command/deployments/services/mod.rs @@ -1,7 +1,7 @@ use clap::{Subcommand, ValueEnum}; use self::{ - katana::{KatanaAccountArgs, KatanaCreateArgs, KatanaForkArgs, KatanaUpdateArgs}, + katana::{KatanaCreateArgs, KatanaForkArgs, KatanaUpdateArgs}, torii::{ToriiCreateArgs, ToriiUpdateArgs}, madara::MadaraCreateArgs, }; @@ -39,15 +39,9 @@ pub enum ForkServiceCommands { // Torii(ToriiUpdateArgs), } -#[derive(Debug, Subcommand, serde::Serialize)] -#[serde(untagged)] -pub enum KatanaAccountCommands { - #[command(about = "Katana deployment.")] - Katana(KatanaAccountArgs), -} - #[derive(Clone, Debug, ValueEnum, serde::Serialize)] pub enum Service { Katana, Torii, + Madara }