Skip to content

Commit

Permalink
refactor(api): use new simple gql api
Browse files Browse the repository at this point in the history
  • Loading branch information
steebchen committed Dec 9, 2024
1 parent 6f489c1 commit 06cbd52
Show file tree
Hide file tree
Showing 11 changed files with 759 additions and 2,156 deletions.
94 changes: 40 additions & 54 deletions cli/src/command/deployments/accounts.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
#![allow(clippy::enum_variant_names)]

use std::str::FromStr;

use anyhow::Result;
use clap::Args;
use katana_primitives::contract::ContractAddress;
use katana_primitives::genesis::allocation::{DevAllocationsGenerator, GenesisAccountAlloc};
use katana_primitives::genesis::allocation::{DevGenesisAccount, GenesisAccount};
use katana_primitives::genesis::Genesis;
use slot::graphql::deployments::katana_accounts::KatanaAccountsDeploymentConfig::KatanaConfig;
use slot::graphql::deployments::{katana_accounts::*, KatanaAccounts};
use slot::graphql::GraphQLQuery;
use starknet::core::types::Felt;

use slot::api::Client;
use slot::credential::Credentials;
Expand All @@ -37,55 +32,46 @@ impl AccountsArgs {
let user = Credentials::load()?;
let client = Client::new_with_token(user.access_token);

let data: ResponseData = client.query(&request_body).await?;

if let Some(deployment) = data.deployment {
if let KatanaConfig(config) = deployment.config {
match config.accounts {
Some(accounts) => {
let mut accounts_vec = Vec::new();
for account in accounts {
let address =
ContractAddress::new(Felt::from_str(&account.address).unwrap());

let public_key = Felt::from_str(&account.public_key).unwrap();
let private_key = Felt::from_str(&account.private_key).unwrap();

let genesis_account = GenesisAccount {
public_key,
..GenesisAccount::default()
};

accounts_vec.push((
address,
GenesisAccountAlloc::DevAccount(DevGenesisAccount {
private_key,
inner: genesis_account,
}),
));
}
print_genesis_accounts(accounts_vec.iter().map(|(a, b)| (a, b)), None);
}
None => {
// NOTICE: This is implementation assume that the Katana instance is configured with the default seed and total number of accounts. If not, the
// generated addresses will be different from the ones in the Katana instance. This is rather a hack until `slot` can return the addresses directly (or
// at least the exact configurations of the instance).

let seed = "0";
let total_accounts = 10;

let accounts = DevAllocationsGenerator::new(total_accounts)
.with_seed(parse_seed(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 _data: ResponseData = client.query(&request_body).await?;

// TODO use data.deployment.config and parse `accounts`
// let mut accounts_vec = Vec::new();
// for account in accounts {
// let address =
// ContractAddress::new(Felt::from_str(&account.address).unwrap());
//
// let public_key = Felt::from_str(&account.public_key).unwrap();
// let private_key = Felt::from_str(&account.private_key).unwrap();
//
// let genesis_account = GenesisAccount {
// public_key,
// ..GenesisAccount::default()
// };
//
// accounts_vec.push((
// address,
// GenesisAccountAlloc::DevAccount(DevGenesisAccount {
// private_key,
// inner: genesis_account,
// }),
// ));
// }
// print_genesis_accounts(accounts_vec.iter().map(|(a, b)| (a, b)), None);

// NOTICE: This is implementation assume that the Katana instance is configured with the default seed and total number of accounts. If not, the
// generated addresses will be different from the ones in the Katana instance. This is rather a hack until `slot` can return the addresses directly (or
// at least the exact configurations of the instance).

let seed = "0";
let total_accounts = 10;

let accounts = DevAllocationsGenerator::new(total_accounts)
.with_seed(parse_seed(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(&seed));

Check failure on line 74 in cli/src/command/deployments/accounts.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler

Ok(())
}
Expand Down
57 changes: 3 additions & 54 deletions cli/src/command/deployments/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,7 @@ impl CreateArgs {
CreateServiceInput {
type_: DeploymentService::katana,
version: config.version.clone(),
config: Some(CreateServiceConfigInput {
katana: Some(CreateKatanaConfigInput {
config_file: Some(slot::read::base64_encode_string(&service_config)),
// TODO: those must be changed on the server side to pull the schema correctly from the infra.
block_time: None,
accounts: None,
dev: None,
fork_rpc_url: None,
fork_block_number: None,
seed: None,
invoke_max_steps: None,
validate_max_steps: None,
disable_fee: None,
gas_price: None,
genesis: None,
}),
torii: None,
saya: None,
}),
config: slot::read::base64_encode_string(&service_config),
}
}
CreateServiceCommands::Torii(config) => {
Expand All @@ -90,46 +72,13 @@ impl CreateArgs {
CreateServiceInput {
type_: DeploymentService::torii,
version: config.version.clone(),
config: Some(CreateServiceConfigInput {
katana: None,
torii: Some(CreateToriiConfigInput {
config_file: Some(slot::read::base64_encode_string(&service_config)),
// TODO: those must be changed on the server side to pull the schema correctly from the infra.
rpc: None,
world: None,
contracts: None,
start_block: None,
index_pending: None,
polling_interval: None,
index_transactions: None,
index_raw_events: None,
}),
saya: None,
}),
config: slot::read::base64_encode_string(&service_config),
}
}
CreateServiceCommands::Saya(config) => CreateServiceInput {
type_: DeploymentService::saya,
version: config.version.clone(),
config: Some(CreateServiceConfigInput {
katana: None,
torii: None,
saya: Some(CreateSayaConfigInput {
mode: config.mode.clone(),
rpc_url: config.rpc_url.clone(),
registry: config.registry.clone(),
settlement_contract: config.settlement_contract.clone(),
world: config.world.clone().to_string(),
prover_url: config.prover_url.clone(),
store_proofs: config.store_proofs.unwrap_or(false),
starknet_url: config.starknet_url.clone(),
signer_key: config.signer_key.clone(),
signer_address: config.signer_address.clone(),
private_key: config.private_key.clone(),
batch_size: config.batch_size.unwrap_or(1),
start_block: config.start_block.unwrap_or(0),
}),
}),
config: "TODO".to_string(),
},
};

Expand Down
23 changes: 2 additions & 21 deletions cli/src/command/deployments/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ use crate::command::deployments::print_config_file;
use super::services::Service;
use anyhow::Result;
use clap::Args;
use slot::graphql::deployments::describe_deployment::DescribeDeploymentDeploymentConfig::{
KatanaConfig, SayaConfig, ToriiConfig,
};
use slot::graphql::deployments::{describe_deployment::*, DescribeDeployment};
use slot::graphql::GraphQLQuery;
use slot::{api::Client, credential::Credentials};
Expand Down Expand Up @@ -53,24 +50,8 @@ impl DescribeArgs {
super::service_url(&deployment.project, &self.service.to_string())
);

match deployment.config {
ToriiConfig(config) => {
println!("Version: {}", config.version);
if let Some(config_file) = config.config_file {
print_config_file(&config_file);
}
}
KatanaConfig(config) => {
println!("Version: {}", config.version);
if let Some(config_file) = config.config_file {
print_config_file(&config_file);
}
}
SayaConfig(config) => {
println!("\nEndpoints:");
println!(" RPC URL: {}", config.rpc_url);
}
}
// convert config of type String to &str
print_config_file(&deployment.config.config)
}

Ok(())
Expand Down
28 changes: 4 additions & 24 deletions cli/src/command/deployments/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use katana_cli::file::NodeArgsConfig;
use slot::api::Client;
use slot::credential::Credentials;
use slot::graphql::deployments::update_deployment::{
self, UpdateKatanaConfigInput, UpdateServiceConfigInput, UpdateServiceInput,
UpdateToriiConfigInput,
self, UpdateServiceInput,
};
use slot::graphql::deployments::{update_deployment::*, UpdateDeployment};
use slot::graphql::GraphQLQuery;
Expand Down Expand Up @@ -40,18 +39,7 @@ impl UpdateArgs {
UpdateServiceInput {
type_: DeploymentService::katana,
version: config.version.clone(),
config: Some(UpdateServiceConfigInput {
torii: None,
katana: Some(UpdateKatanaConfigInput {
config_file: Some(slot::read::base64_encode_string(&service_config)),
block_time: None,
invoke_max_steps: None,
validate_max_steps: None,
disable_fee: None,
gas_price: None,
dev: None,
}),
}),
config: Some(slot::read::base64_encode_string(&service_config)),
}
}
UpdateServiceCommands::Torii(config) => {
Expand All @@ -75,21 +63,13 @@ impl UpdateArgs {
UpdateServiceInput {
type_: DeploymentService::torii,
version: config.version.clone(),
config: Some(UpdateServiceConfigInput {
katana: None,
torii: Some(UpdateToriiConfigInput {
config_file: Some(slot::read::base64_encode_string(&service_config)),
}),
}),
config: Some(slot::read::base64_encode_string(&service_config)),
}
}
UpdateServiceCommands::Saya(config) => UpdateServiceInput {
type_: DeploymentService::saya,
version: config.version.clone(),
config: Some(UpdateServiceConfigInput {
katana: None,
torii: None,
}),
config: None, // TODO
},
};

Expand Down
Loading

0 comments on commit 06cbd52

Please sign in to comment.