Skip to content

Commit

Permalink
feat(torii): add config file support for Torii deployments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
steebchen committed Nov 8, 2024
1 parent 47b05cd commit e0a0cfa
Show file tree
Hide file tree
Showing 8 changed files with 2,087 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
52 changes: 35 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::encode;

Check failure on line 4 in cli/src/command/deployments/create.rs

View workflow job for this annotation

GitHub Actions / ensure-windows

use of deprecated function `base64::encode`: Use Engine::encode

Check failure on line 4 in cli/src/command/deployments/create.rs

View workflow job for this annotation

GitHub Actions / test

use of deprecated function `base64::encode`: Use Engine::encode

Check failure on line 4 in cli/src/command/deployments/create.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated function `base64::encode`: Use Engine::encode
use clap::Args;
use slot::api::Client;
use slot::credential::Credentials;
Expand All @@ -10,6 +11,7 @@ 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};

Expand Down Expand Up @@ -61,24 +63,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(encode(&file_contents))

Check failure on line 71 in cli/src/command/deployments/create.rs

View workflow job for this annotation

GitHub Actions / ensure-windows

use of deprecated function `base64::encode`: Use Engine::encode

Check failure on line 71 in cli/src/command/deployments/create.rs

View workflow job for this annotation

GitHub Actions / test

use of deprecated function `base64::encode`: Use Engine::encode

Check failure on line 71 in cli/src/command/deployments/create.rs

View workflow job for this annotation

GitHub Actions / clippy

use of deprecated function `base64::encode`: Use Engine::encode

Check failure on line 71 in cli/src/command/deployments/create.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits
}
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 e0a0cfa

Please sign in to comment.