Skip to content

Commit

Permalink
feat(torii): add config file support for Torii deployments (#122)
Browse files Browse the repository at this point in the history
* feat(torii): add config file support for Torii deployments

Added optional config_file parameter to Torii deployments. New
files read in base64 and included in the deployment request.
Updated corresponding GraphQL schema and dependencies.

* fix(cli): handle missing world config gracefully

Updated the deployment commands to default to "0x0" when the
world configuration is missing. Also simplified the schema definition
of the "world" field to not be nullable.

* fix(cli): simplify world config output

Removed unnecessary unwrap_or pattern in config world output within
describe, create, and update commands. Updated schema to reflect
NON_NULL world type.
  • Loading branch information
steebchen authored Nov 9, 2024
1 parent 47b05cd commit 0e2c6af
Show file tree
Hide file tree
Showing 8 changed files with 2,089 additions and 97 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
torii.toml
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ starknet.workspace = true
shellexpand = "3.1.0"
url.workspace = true
rand.workspace = true
base64 = "0.21.7"

[[bin]]
name = "slot"
Expand Down
54 changes: 37 additions & 17 deletions cli/src/command/deployments/create.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::enum_variant_names)]

use anyhow::Result;
use base64::Engine;
use clap::Args;
use slot::api::Client;
use slot::credential::Credentials;
Expand All @@ -10,9 +11,12 @@ use slot::graphql::deployments::create_deployment::CreateDeploymentCreateDeploym
use slot::graphql::deployments::create_deployment::*;
use slot::graphql::deployments::CreateDeployment;
use slot::graphql::GraphQLQuery;
use std::fs;

use super::{services::CreateServiceCommands, Tier};

use base64::engine::general_purpose;

#[derive(Debug, Args)]
#[command(next_help_heading = "Create options")]
pub struct CreateArgs {
Expand Down Expand Up @@ -61,24 +65,40 @@ impl CreateArgs {
saya: None,
}),
},
CreateServiceCommands::Torii(config) => CreateServiceInput {
type_: DeploymentService::torii,
version: config.version.clone(),
config: Some(CreateServiceConfigInput {
katana: None,
torii: Some(CreateToriiConfigInput {
rpc: Some(config.rpc.clone().unwrap_or("".to_string())),
world: format!("{:#x}", config.world),
contracts: config.contracts.clone(),
start_block: config.start_block,
index_pending: config.index_pending,
polling_interval: config.polling_interval,
index_transactions: config.index_transactions,
index_raw_events: config.index_raw_events,
CreateServiceCommands::Torii(config) => {
// Read the file and convert to base64
let config_file_base64 = match &config.config_file {
Some(file_path) => {
let file_contents = fs::read(file_path)?;
Some(general_purpose::STANDARD.encode(file_contents))
}
None => None,
};

CreateServiceInput {
type_: DeploymentService::torii,
version: config.version.clone(),
config: Some(CreateServiceConfigInput {
katana: None,
torii: Some(CreateToriiConfigInput {
rpc: Some(config.rpc.clone().unwrap_or("".to_string())),
// provide world if provided
world: match &config.world {
Some(world) => format!("{:#x}", world).into(),
None => None,
},
contracts: config.contracts.clone(),
start_block: config.start_block,
index_pending: config.index_pending,
polling_interval: config.polling_interval,
index_transactions: config.index_transactions,
index_raw_events: config.index_raw_events,
config_file: config_file_base64,
}),
saya: None,
}),
saya: None,
}),
},
}
}
CreateServiceCommands::Saya(config) => CreateServiceInput {
type_: DeploymentService::saya,
version: config.version.clone(),
Expand Down
7 changes: 6 additions & 1 deletion cli/src/command/deployments/services/torii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ pub struct ToriiCreateArgs {
#[arg(long)]
#[arg(value_name = "world")]
#[arg(help = "World address.")]
pub world: Felt,
pub world: Option<Felt>,

#[arg(long)]
#[arg(help = "A config file ")]
#[arg(value_name = "config-file")]
pub config_file: Option<String>,

#[arg(short, long)]
#[arg(value_name = "contracts")]
Expand Down
4 changes: 2 additions & 2 deletions scripts/pull_schema.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
# https://github.com/graphql-rust/graphql-client/blob/main/graphql_client_cli/README.md
# cargo install graphql_client_cli

graphql-client introspect-schema --output slot/schema.json https://api.cartridge.gg/query
# graphql-client introspect-schema --output slot/schema.json http://localhost:8000/query
#graphql-client introspect-schema --output slot/schema.json https://api.cartridge.gg/query
graphql-client introspect-schema --output slot/schema.json http://localhost:8000/query
Loading

0 comments on commit 0e2c6af

Please sign in to comment.