From d6c77c0c49e850e2c59cdca561a9aa3c8f956d51 Mon Sep 17 00:00:00 2001 From: Nasr Date: Wed, 6 Nov 2024 10:49:34 -0500 Subject: [PATCH 1/8] feat(torii): configutation file for all torii cli options --- Cargo.lock | 1 + bin/torii/Cargo.toml | 1 + bin/torii/src/main.rs | 47 ++++++++++++---------------------- crates/torii/core/src/types.rs | 15 ----------- 4 files changed, 18 insertions(+), 46 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 294f2dd455..1d0ecfd2c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14897,6 +14897,7 @@ dependencies = [ "tokio", "tokio-stream", "tokio-util", + "toml 0.8.19", "torii-core", "torii-graphql", "torii-grpc", diff --git a/bin/torii/Cargo.toml b/bin/torii/Cargo.toml index aadbd390cd..1da76bfd19 100644 --- a/bin/torii/Cargo.toml +++ b/bin/torii/Cargo.toml @@ -40,6 +40,7 @@ torii-grpc = { workspace = true, features = [ "server" ] } torii-relay.workspace = true torii-server.workspace = true tower.workspace = true +toml.workspace = true tower-http.workspace = true tracing-subscriber.workspace = true diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index c55da2f464..a3f865c471 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -23,6 +23,7 @@ use clap::{ArgAction, Parser}; use dojo_metrics::exporters::prometheus::PrometheusRecorder; use dojo_utils::parse::{parse_socket_address, parse_url}; use dojo_world::contracts::world::WorldContractReader; +use serde::{Deserialize, Serialize}; use sqlx::sqlite::{ SqliteAutoVacuum, SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous, }; @@ -39,7 +40,7 @@ use torii_core::executor::Executor; use torii_core::processors::store_transaction::StoreTransactionProcessor; use torii_core::simple_broker::SimpleBroker; use torii_core::sql::Sql; -use torii_core::types::{Contract, ContractType, Model, ToriiConfig}; +use torii_core::types::{Contract, ContractType, Model}; use torii_server::proxy::Proxy; use tracing::{error, info}; use tracing_subscriber::{fmt, EnvFilter}; @@ -48,7 +49,7 @@ use url::{form_urlencoded, Url}; pub(crate) const LOG_TARGET: &str = "torii::cli"; /// Dojo World Indexer -#[derive(Parser, Debug)] +#[derive(Parser, Debug, Serialize, Deserialize)] #[command(name = "torii", author, version, about, long_about = None)] struct Args { /// The world to index @@ -148,20 +149,24 @@ struct Args { config: Option, } +impl Args { + fn from_file(path: &PathBuf) -> anyhow::Result { + let content = std::fs::read_to_string(path) + .with_context(|| format!("Failed to read config file: {}", path.display()))?; + + toml::from_str(&content) + .with_context(|| "Failed to parse TOML config") + } +} + #[tokio::main] async fn main() -> anyhow::Result<()> { let args = Args::parse(); - let mut config = if let Some(path) = args.config { - ToriiConfig::load_from_path(&path)? + let args = if let Some(path) = args.config { + Args::from_file(&path)? } else { - let mut config = ToriiConfig::default(); - - if let Some(contracts) = args.contracts { - config.contracts = VecDeque::from(contracts); - } - - config + args }; let world_address = verify_single_world_address(args.world_address, &mut config)?; @@ -321,26 +326,6 @@ async fn main() -> anyhow::Result<()> { Ok(()) } -// Verifies that the world address is defined at most once -// and returns the world address -fn verify_single_world_address( - world_address: Option, - config: &mut ToriiConfig, -) -> anyhow::Result { - let world_from_config = - config.contracts.iter().find(|c| c.r#type == ContractType::WORLD).map(|c| c.address); - - match (world_address, world_from_config) { - (Some(_), Some(_)) => Err(anyhow::anyhow!("World address specified multiple times")), - (Some(addr), _) => { - config.contracts.push_front(Contract { address: addr, r#type: ContractType::WORLD }); - Ok(addr) - } - (_, Some(addr)) => Ok(addr), - (None, None) => Err(anyhow::anyhow!("World address not specified")), - } -} - async fn spawn_rebuilding_graphql_server( shutdown_tx: Sender<()>, pool: Arc, diff --git a/crates/torii/core/src/types.rs b/crates/torii/core/src/types.rs index a9ecf79a0d..9b1895455d 100644 --- a/crates/torii/core/src/types.rs +++ b/crates/torii/core/src/types.rs @@ -123,21 +123,6 @@ pub struct Event { pub executed_at: DateTime, pub created_at: DateTime, } - -#[derive(Default, Deserialize, Debug, Clone)] -pub struct ToriiConfig { - /// contract addresses to index - pub contracts: VecDeque, -} - -impl ToriiConfig { - pub fn load_from_path(path: &PathBuf) -> Result { - let config = std::fs::read_to_string(path)?; - let config: Self = toml::from_str(&config)?; - Ok(config) - } -} - #[derive(Deserialize, Debug, Clone, Copy)] pub struct Contract { pub address: Felt, From 310803991f4005f166d86c66272630befdce51ed Mon Sep 17 00:00:00 2001 From: Nasr Date: Fri, 8 Nov 2024 14:01:17 -0500 Subject: [PATCH 2/8] fix: config --- Cargo.lock | 26 ++++++++++++++++ bin/torii/Cargo.toml | 1 + bin/torii/src/main.rs | 57 +++++++++++++--------------------- crates/torii/core/src/types.rs | 6 ++-- 4 files changed, 51 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1d0ecfd2c0..ff6929e84d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3589,6 +3589,7 @@ dependencies = [ "anstyle", "clap_lex", "strsim 0.11.1", + "terminal_size", ] [[package]] @@ -3600,6 +3601,20 @@ dependencies = [ "clap", ] +[[package]] +name = "clap_config" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46efb9cbf691f5505d0b7b2c8055aec0c9a770eaac8a06834b6d84b5be93279a" +dependencies = [ + "clap", + "heck 0.5.0", + "proc-macro2", + "quote", + "serde", + "syn 2.0.77", +] + [[package]] name = "clap_derive" version = "4.5.18" @@ -14384,6 +14399,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "terminal_size" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +dependencies = [ + "rustix 0.38.37", + "windows-sys 0.48.0", +] + [[package]] name = "termtree" version = "0.4.1" @@ -14874,6 +14899,7 @@ dependencies = [ "camino", "chrono", "clap", + "clap_config", "ctrlc", "dojo-metrics", "dojo-types 1.0.0-rc.1", diff --git a/bin/torii/Cargo.toml b/bin/torii/Cargo.toml index 1da76bfd19..71ff5ec916 100644 --- a/bin/torii/Cargo.toml +++ b/bin/torii/Cargo.toml @@ -48,6 +48,7 @@ tracing.workspace = true url.workspace = true webbrowser = "0.8" tempfile.workspace = true +clap_config = "0.1.1" [dev-dependencies] camino.workspace = true diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index a3f865c471..8527b9e16d 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -11,7 +11,6 @@ //! for more info. use std::cmp; -use std::collections::VecDeque; use std::net::SocketAddr; use std::path::PathBuf; use std::str::FromStr; @@ -19,11 +18,11 @@ use std::sync::Arc; use std::time::Duration; use anyhow::Context; -use clap::{ArgAction, Parser}; +use clap::{ArgAction, CommandFactory, FromArgMatches, Parser}; +use clap_config::ClapConfig; use dojo_metrics::exporters::prometheus::PrometheusRecorder; use dojo_utils::parse::{parse_socket_address, parse_url}; use dojo_world::contracts::world::WorldContractReader; -use serde::{Deserialize, Serialize}; use sqlx::sqlite::{ SqliteAutoVacuum, SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous, }; @@ -49,12 +48,12 @@ use url::{form_urlencoded, Url}; pub(crate) const LOG_TARGET: &str = "torii::cli"; /// Dojo World Indexer -#[derive(Parser, Debug, Serialize, Deserialize)] +#[derive(ClapConfig, Parser, Debug)] #[command(name = "torii", author, version, about, long_about = None)] struct Args { /// The world to index #[arg(short, long = "world", env = "DOJO_WORLD_ADDRESS")] - world_address: Option, + world_address: Felt, /// The sequencer rpc endpoint to index. #[arg(long, value_name = "URL", default_value = ":5050", value_parser = parse_url)] @@ -140,37 +139,24 @@ struct Args { index_raw_events: bool, /// ERC contract addresses to index - #[arg(long, value_parser = parse_erc_contracts)] - #[arg(conflicts_with = "config")] - contracts: Option>, + #[arg(long, value_parser = parse_erc_contracts, default_value = "")] + contracts: Vec, /// Configuration file #[arg(long)] config: Option, } -impl Args { - fn from_file(path: &PathBuf) -> anyhow::Result { - let content = std::fs::read_to_string(path) - .with_context(|| format!("Failed to read config file: {}", path.display()))?; - - toml::from_str(&content) - .with_context(|| "Failed to parse TOML config") - } -} - #[tokio::main] async fn main() -> anyhow::Result<()> { - let args = Args::parse(); - - let args = if let Some(path) = args.config { - Args::from_file(&path)? + let matches = ::command().get_matches(); + let args = if let Some(path) = matches.get_one::("config") { + let config: ArgsConfig = toml::from_str(&std::fs::read_to_string(path)?)?; + Args::from_merged(matches, Some(config)) } else { - args + Args::from_arg_matches(&matches)? }; - let world_address = verify_single_world_address(args.world_address, &mut config)?; - let filter_layer = EnvFilter::try_from_default_env() .unwrap_or_else(|_| EnvFilter::new("info,hyper_reverse_proxy=off")); @@ -213,10 +199,9 @@ async fn main() -> anyhow::Result<()> { let provider: Arc<_> = JsonRpcClient::new(HttpTransport::new(args.rpc)).into(); // Get world address - let world = WorldContractReader::new(world_address, provider.clone()); + let world = WorldContractReader::new(args.world_address, provider.clone()); - let contracts = - config.contracts.iter().map(|contract| (contract.address, contract.r#type)).collect(); + let contracts = args.contracts.iter().map(|contract| (contract.address, contract.r#type)).collect(); let (mut executor, sender) = Executor::new(pool.clone(), shutdown_tx.clone()).await?; tokio::spawn(async move { @@ -261,7 +246,7 @@ async fn main() -> anyhow::Result<()> { let shutdown_rx = shutdown_tx.subscribe(); let (grpc_addr, grpc_server) = - torii_grpc::server::new(shutdown_rx, &pool, block_rx, world_address, Arc::clone(&provider)) + torii_grpc::server::new(shutdown_rx, &pool, block_rx, args.world_address, Arc::clone(&provider)) .await?; let mut libp2p_relay_server = torii_relay::server::Relay::new( @@ -354,18 +339,20 @@ async fn spawn_rebuilding_graphql_server( // - erc_type:address:start_block // - address:start_block (erc_type defaults to ERC20) fn parse_erc_contracts(s: &str) -> anyhow::Result> { + if s.is_empty() { + return Ok(Vec::new()); + } + let parts: Vec<&str> = s.split(',').collect(); let mut contracts = Vec::new(); for part in parts { match part.split(':').collect::>().as_slice() { [r#type, address] => { let r#type = r#type.parse::()?; - let address = Felt::from_str(address) - .with_context(|| format!("Expected address, found {}", address))?; - contracts.push(Contract { address, r#type }); - } - [address] => { - let r#type = ContractType::WORLD; + if r#type == ContractType::WORLD { + return Err(anyhow::anyhow!("World address cannot be specified as an ERC contract")); + } + let address = Felt::from_str(address) .with_context(|| format!("Expected address, found {}", address))?; contracts.push(Contract { address, r#type }); diff --git a/crates/torii/core/src/types.rs b/crates/torii/core/src/types.rs index 9b1895455d..96d2f68ca4 100644 --- a/crates/torii/core/src/types.rs +++ b/crates/torii/core/src/types.rs @@ -1,6 +1,4 @@ use core::fmt; -use std::collections::VecDeque; -use std::path::PathBuf; use std::str::FromStr; use chrono::{DateTime, Utc}; @@ -123,13 +121,13 @@ pub struct Event { pub executed_at: DateTime, pub created_at: DateTime, } -#[derive(Deserialize, Debug, Clone, Copy)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy)] pub struct Contract { pub address: Felt, pub r#type: ContractType, } -#[derive(Deserialize, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub enum ContractType { WORLD, ERC20, From aa985f72ce9e278d631f0e217992daf9b303b52a Mon Sep 17 00:00:00 2001 From: Nasr Date: Fri, 8 Nov 2024 14:02:43 -0500 Subject: [PATCH 3/8] skip config --- bin/torii/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index 8527b9e16d..108e283bf8 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -144,6 +144,7 @@ struct Args { /// Configuration file #[arg(long)] + #[clap_config(skip)] config: Option, } From 7c19061f66593a9e1b8543a8e437e049a5098a2d Mon Sep 17 00:00:00 2001 From: Nasr Date: Fri, 8 Nov 2024 14:36:53 -0500 Subject: [PATCH 4/8] wrap up config --- bin/torii/src/main.rs | 10 ++++++---- crates/torii/core/src/engine.rs | 6 ++++-- crates/torii/core/src/sql/mod.rs | 10 +++++----- crates/torii/core/src/sql/test.rs | 10 +++++----- crates/torii/graphql/src/tests/metadata_test.rs | 8 +++----- crates/torii/graphql/src/tests/mod.rs | 6 +++--- crates/torii/graphql/src/tests/subscription_test.rs | 13 ++++++------- crates/torii/grpc/src/server/tests/entities_test.rs | 6 +++--- crates/torii/libp2p/src/tests.rs | 5 ++--- 9 files changed, 37 insertions(+), 37 deletions(-) diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index 108e283bf8..46ad959d13 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -139,8 +139,8 @@ struct Args { index_raw_events: bool, /// ERC contract addresses to index - #[arg(long, value_parser = parse_erc_contracts, default_value = "")] - contracts: Vec, + #[arg(long, default_value = "")] + contracts: String, /// Configuration file #[arg(long)] @@ -158,6 +158,9 @@ async fn main() -> anyhow::Result<()> { Args::from_arg_matches(&matches)? }; + let mut contracts = parse_erc_contracts(&args.contracts)?; + contracts.push(Contract { address: args.world_address, r#type: ContractType::WORLD }); + let filter_layer = EnvFilter::try_from_default_env() .unwrap_or_else(|_| EnvFilter::new("info,hyper_reverse_proxy=off")); @@ -202,7 +205,6 @@ async fn main() -> anyhow::Result<()> { // Get world address let world = WorldContractReader::new(args.world_address, provider.clone()); - let contracts = args.contracts.iter().map(|contract| (contract.address, contract.r#type)).collect(); let (mut executor, sender) = Executor::new(pool.clone(), shutdown_tx.clone()).await?; tokio::spawn(async move { @@ -242,7 +244,7 @@ async fn main() -> anyhow::Result<()> { }, shutdown_tx.clone(), Some(block_tx), - Arc::new(contracts), + &contracts, ); let shutdown_rx = shutdown_tx.subscribe(); diff --git a/crates/torii/core/src/engine.rs b/crates/torii/core/src/engine.rs index f060500f89..5ddce943a1 100644 --- a/crates/torii/core/src/engine.rs +++ b/crates/torii/core/src/engine.rs @@ -39,7 +39,7 @@ use crate::processors::store_update_member::StoreUpdateMemberProcessor; use crate::processors::store_update_record::StoreUpdateRecordProcessor; use crate::processors::{BlockProcessor, EventProcessor, TransactionProcessor}; use crate::sql::{Cursors, Sql}; -use crate::types::ContractType; +use crate::types::{Contract, ContractType}; type EventProcessorMap

= HashMap>>>; @@ -217,8 +217,10 @@ impl Engine

{ config: EngineConfig, shutdown_tx: Sender<()>, block_tx: Option>, - contracts: Arc>, + contracts: &Vec, ) -> Self { + let contracts = Arc::new(contracts.iter().map(|contract| (contract.address, contract.r#type)).collect()); + Self { world: Arc::new(world), db, diff --git a/crates/torii/core/src/sql/mod.rs b/crates/torii/core/src/sql/mod.rs index 3c20222a9a..ae72371039 100644 --- a/crates/torii/core/src/sql/mod.rs +++ b/crates/torii/core/src/sql/mod.rs @@ -20,7 +20,7 @@ use crate::executor::{ Argument, DeleteEntityQuery, EventMessageQuery, QueryMessage, QueryType, ResetCursorsQuery, SetHeadQuery, UpdateCursorsQuery, }; -use crate::types::ContractType; +use crate::types::Contract; use crate::utils::utc_dt_string_from_timestamp; type IsEventMessage = bool; @@ -59,7 +59,7 @@ impl Sql { pub async fn new( pool: Pool, executor: UnboundedSender, - contracts: &HashMap, + contracts: &Vec, ) -> Result { for contract in contracts { executor.send(QueryMessage::other( @@ -67,9 +67,9 @@ impl Sql { ?, ?)" .to_string(), vec![ - Argument::FieldElement(*contract.0), - Argument::FieldElement(*contract.0), - Argument::String(contract.1.to_string()), + Argument::FieldElement(contract.address), + Argument::FieldElement(contract.address), + Argument::String(contract.r#type.to_string()), ], ))?; } diff --git a/crates/torii/core/src/sql/test.rs b/crates/torii/core/src/sql/test.rs index fd1539b49c..9bab88ec0c 100644 --- a/crates/torii/core/src/sql/test.rs +++ b/crates/torii/core/src/sql/test.rs @@ -24,7 +24,7 @@ use tokio::sync::broadcast; use crate::engine::{Engine, EngineConfig, Processors}; use crate::executor::Executor; use crate::sql::Sql; -use crate::types::ContractType; +use crate::types::{Contract, ContractType}; pub async fn bootstrap_engine

( world: WorldContractReader

, @@ -45,7 +45,7 @@ where EngineConfig::default(), shutdown_tx, None, - Arc::new(HashMap::from([(world_address, ContractType::WORLD)])), + &vec![Contract { address: world_address, r#type: ContractType::WORLD }], ); let data = engine.fetch_range(0, to, &HashMap::new()).await.unwrap(); @@ -127,7 +127,7 @@ async fn test_load_from_remote(sequencer: &RunnerCtx) { let db = Sql::new( pool.clone(), sender.clone(), - &HashMap::from([(world_reader.address, ContractType::WORLD)]), + &vec![Contract { address: world_reader.address, r#type: ContractType::WORLD }], ) .await .unwrap(); @@ -285,7 +285,7 @@ async fn test_load_from_remote_del(sequencer: &RunnerCtx) { let db = Sql::new( pool.clone(), sender.clone(), - &HashMap::from([(world_reader.address, ContractType::WORLD)]), + &vec![Contract { address: world_reader.address, r#type: ContractType::WORLD }], ) .await .unwrap(); @@ -371,7 +371,7 @@ async fn test_update_with_set_record(sequencer: &RunnerCtx) { let db = Sql::new( pool.clone(), sender.clone(), - &HashMap::from([(world_reader.address, ContractType::WORLD)]), + &vec![Contract { address: world_reader.address, r#type: ContractType::WORLD }], ) .await .unwrap(); diff --git a/crates/torii/graphql/src/tests/metadata_test.rs b/crates/torii/graphql/src/tests/metadata_test.rs index d92cca5854..3f0d6ec11e 100644 --- a/crates/torii/graphql/src/tests/metadata_test.rs +++ b/crates/torii/graphql/src/tests/metadata_test.rs @@ -1,14 +1,12 @@ #[cfg(test)] mod tests { - use std::collections::HashMap; - use dojo_world::config::{ProfileConfig, WorldMetadata}; use sqlx::SqlitePool; use starknet::core::types::Felt; use tokio::sync::broadcast; use torii_core::executor::Executor; use torii_core::sql::Sql; - use torii_core::types::ContractType; + use torii_core::types::{Contract, ContractType}; use crate::schema::build_schema; use crate::tests::{run_graphql_query, Connection, Content, Metadata as SqlMetadata, Social}; @@ -59,7 +57,7 @@ mod tests { executor.run().await.unwrap(); }); let mut db = - Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)])) + Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) .await .unwrap(); let schema = build_schema(&pool).await.unwrap(); @@ -120,7 +118,7 @@ mod tests { executor.run().await.unwrap(); }); let mut db = - Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)])) + Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) .await .unwrap(); let schema = build_schema(&pool).await.unwrap(); diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index 7a54dcce72..a003b7ea01 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -30,7 +30,7 @@ use tokio_stream::StreamExt; use torii_core::engine::{Engine, EngineConfig, Processors}; use torii_core::executor::Executor; use torii_core::sql::Sql; -use torii_core::types::ContractType; +use torii_core::types::{Contract, ContractType}; mod entities_test; mod events_test; @@ -345,7 +345,7 @@ pub async fn spinup_types_test(path: &str) -> Result { tokio::spawn(async move { executor.run().await.unwrap(); }); - let db = Sql::new(pool.clone(), sender, &HashMap::from([(world_address, ContractType::WORLD)])) + let db = Sql::new(pool.clone(), sender, &vec![Contract { address: world_address, r#type: ContractType::WORLD }]) .await .unwrap(); @@ -358,7 +358,7 @@ pub async fn spinup_types_test(path: &str) -> Result { EngineConfig::default(), shutdown_tx, None, - Arc::new(HashMap::from([(world_address, ContractType::WORLD)])), + &vec![Contract { address: world_address, r#type: ContractType::WORLD }], ); let to = account.provider().block_hash_and_number().await?.block_number; diff --git a/crates/torii/graphql/src/tests/subscription_test.rs b/crates/torii/graphql/src/tests/subscription_test.rs index 11ef4585eb..5a79ea9c08 100644 --- a/crates/torii/graphql/src/tests/subscription_test.rs +++ b/crates/torii/graphql/src/tests/subscription_test.rs @@ -1,6 +1,5 @@ #[cfg(test)] mod tests { - use std::collections::HashMap; use std::str::FromStr; use std::time::Duration; @@ -17,7 +16,7 @@ mod tests { use torii_core::executor::Executor; use torii_core::sql::utils::felts_to_sql_string; use torii_core::sql::Sql; - use torii_core::types::ContractType; + use torii_core::types::{Contract, ContractType}; use crate::tests::{model_fixtures, run_graphql_subscription}; use crate::utils; @@ -32,7 +31,7 @@ mod tests { executor.run().await.unwrap(); }); let mut db = - Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)])) + Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) .await .unwrap(); @@ -176,7 +175,7 @@ mod tests { executor.run().await.unwrap(); }); let mut db = - Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)])) + Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) .await .unwrap(); @@ -300,7 +299,7 @@ mod tests { executor.run().await.unwrap(); }); let mut db = - Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)])) + Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) .await .unwrap(); // 0. Preprocess model value @@ -374,7 +373,7 @@ mod tests { executor.run().await.unwrap(); }); let mut db = - Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)])) + Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) .await .unwrap(); // 0. Preprocess model value @@ -449,7 +448,7 @@ mod tests { executor.run().await.unwrap(); }); let mut db = - Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)])) + Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) .await .unwrap(); let block_timestamp: u64 = 1710754478_u64; diff --git a/crates/torii/grpc/src/server/tests/entities_test.rs b/crates/torii/grpc/src/server/tests/entities_test.rs index e7996092e9..5214575d96 100644 --- a/crates/torii/grpc/src/server/tests/entities_test.rs +++ b/crates/torii/grpc/src/server/tests/entities_test.rs @@ -25,7 +25,7 @@ use tokio::sync::broadcast; use torii_core::engine::{Engine, EngineConfig, Processors}; use torii_core::executor::Executor; use torii_core::sql::Sql; -use torii_core::types::ContractType; +use torii_core::types::{Contract, ContractType}; use crate::proto::types::KeysClause; use crate::server::DojoWorld; @@ -92,7 +92,7 @@ async fn test_entities_queries(sequencer: &RunnerCtx) { tokio::spawn(async move { executor.run().await.unwrap(); }); - let db = Sql::new(pool.clone(), sender, &HashMap::from([(world_address, ContractType::WORLD)])) + let db = Sql::new(pool.clone(), sender, &vec![Contract { address: world_address, r#type: ContractType::WORLD }]) .await .unwrap(); @@ -105,7 +105,7 @@ async fn test_entities_queries(sequencer: &RunnerCtx) { EngineConfig::default(), shutdown_tx, None, - Arc::new(HashMap::from([(world_address, ContractType::WORLD)])), + &vec![Contract { address: world_address, r#type: ContractType::WORLD }], ); let to = provider.block_hash_and_number().await.unwrap().block_number; diff --git a/crates/torii/libp2p/src/tests.rs b/crates/torii/libp2p/src/tests.rs index e033d6c5fb..7c94fa04c5 100644 --- a/crates/torii/libp2p/src/tests.rs +++ b/crates/torii/libp2p/src/tests.rs @@ -524,7 +524,6 @@ mod test { #[cfg(not(target_arch = "wasm32"))] #[tokio::test] async fn test_client_messaging() -> Result<(), Box> { - use std::collections::HashMap; use std::time::Duration; use dojo_types::schema::{Member, Struct, Ty}; @@ -541,7 +540,7 @@ mod test { use tokio::time::sleep; use torii_core::executor::Executor; use torii_core::sql::Sql; - use torii_core::types::ContractType; + use torii_core::types::{Contract, ContractType}; use crate::server::Relay; use crate::typed_data::{Domain, Field, SimpleField, TypedData}; @@ -579,7 +578,7 @@ mod test { executor.run().await.unwrap(); }); let mut db = - Sql::new(pool.clone(), sender, &HashMap::from([(Felt::ZERO, ContractType::WORLD)])) + Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) .await .unwrap(); From cf20035960399018867f129a33cba0e5d000f159 Mon Sep 17 00:00:00 2001 From: Nasr Date: Fri, 8 Nov 2024 15:12:36 -0500 Subject: [PATCH 5/8] optional world address --- bin/torii/src/main.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index 46ad959d13..ebeca4dd36 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -53,7 +53,7 @@ pub(crate) const LOG_TARGET: &str = "torii::cli"; struct Args { /// The world to index #[arg(short, long = "world", env = "DOJO_WORLD_ADDRESS")] - world_address: Felt, + world_address: Option, /// The sequencer rpc endpoint to index. #[arg(long, value_name = "URL", default_value = ":5050", value_parser = parse_url)] @@ -91,8 +91,7 @@ struct Args { /// Specify allowed origins for api endpoints (comma-separated list of allowed origins, or "*" /// for all) - #[arg(long)] - #[arg(value_delimiter = ',')] + #[arg(long, value_delimiter = ',')] allowed_origins: Option>, /// The external url of the server, used for configuring the GraphQL Playground in a hosted @@ -158,8 +157,14 @@ async fn main() -> anyhow::Result<()> { Args::from_arg_matches(&matches)? }; + let world_address = if let Some(world_address) = args.world_address { + world_address + } else { + return Err(anyhow::anyhow!("Please specify a world address.")); + }; + let mut contracts = parse_erc_contracts(&args.contracts)?; - contracts.push(Contract { address: args.world_address, r#type: ContractType::WORLD }); + contracts.push(Contract { address: world_address, r#type: ContractType::WORLD }); let filter_layer = EnvFilter::try_from_default_env() .unwrap_or_else(|_| EnvFilter::new("info,hyper_reverse_proxy=off")); @@ -203,7 +208,7 @@ async fn main() -> anyhow::Result<()> { let provider: Arc<_> = JsonRpcClient::new(HttpTransport::new(args.rpc)).into(); // Get world address - let world = WorldContractReader::new(args.world_address, provider.clone()); + let world = WorldContractReader::new(world_address, provider.clone()); let (mut executor, sender) = Executor::new(pool.clone(), shutdown_tx.clone()).await?; @@ -249,7 +254,7 @@ async fn main() -> anyhow::Result<()> { let shutdown_rx = shutdown_tx.subscribe(); let (grpc_addr, grpc_server) = - torii_grpc::server::new(shutdown_rx, &pool, block_rx, args.world_address, Arc::clone(&provider)) + torii_grpc::server::new(shutdown_rx, &pool, block_rx, world_address, Arc::clone(&provider)) .await?; let mut libp2p_relay_server = torii_relay::server::Relay::new( From f6715439433fb73f3f376f942524fe9157ac224d Mon Sep 17 00:00:00 2001 From: Nasr Date: Fri, 8 Nov 2024 15:45:58 -0500 Subject: [PATCH 6/8] hisotrical event message sconfig --- Cargo.lock | 1 - bin/torii/src/main.rs | 66 +++++----- crates/torii/core/Cargo.toml | 1 - crates/torii/core/src/engine.rs | 9 +- .../src/processors/erc20_legacy_transfer.rs | 3 +- .../core/src/processors/erc20_transfer.rs | 3 +- .../src/processors/erc721_legacy_transfer.rs | 3 +- .../core/src/processors/erc721_transfer.rs | 3 +- .../core/src/processors/event_message.rs | 5 +- .../core/src/processors/metadata_update.rs | 3 +- crates/torii/core/src/processors/mod.rs | 6 + crates/torii/core/src/processors/raw_event.rs | 3 +- .../core/src/processors/register_event.rs | 3 +- .../core/src/processors/register_model.rs | 3 +- .../core/src/processors/store_del_record.rs | 3 +- .../core/src/processors/store_set_record.rs | 3 +- .../src/processors/store_update_member.rs | 3 +- .../src/processors/store_update_record.rs | 3 +- .../core/src/processors/upgrade_event.rs | 114 ++++++++++++++++++ .../core/src/processors/upgrade_model.rs | 111 +++++++++++++++++ 20 files changed, 301 insertions(+), 48 deletions(-) create mode 100644 crates/torii/core/src/processors/upgrade_event.rs create mode 100644 crates/torii/core/src/processors/upgrade_model.rs diff --git a/Cargo.lock b/Cargo.lock index ff6929e84d..1da6cf97a1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14999,7 +14999,6 @@ dependencies = [ "thiserror", "tokio", "tokio-util", - "toml 0.8.19", "tracing", ] diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index ebeca4dd36..56d10b9380 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -37,6 +37,7 @@ use tokio_stream::StreamExt; use torii_core::engine::{Engine, EngineConfig, IndexingFlags, Processors}; use torii_core::executor::Executor; use torii_core::processors::store_transaction::StoreTransactionProcessor; +use torii_core::processors::EventProcessorConfig; use torii_core::simple_broker::SimpleBroker; use torii_core::sql::Sql; use torii_core::types::{Contract, ContractType, Model}; @@ -92,7 +93,7 @@ struct Args { /// Specify allowed origins for api endpoints (comma-separated list of allowed origins, or "*" /// for all) #[arg(long, value_delimiter = ',')] - allowed_origins: Option>, + allowed_origins: Vec, /// The external url of the server, used for configuring the GraphQL Playground in a hosted /// environment @@ -138,8 +139,13 @@ struct Args { index_raw_events: bool, /// ERC contract addresses to index - #[arg(long, default_value = "")] - contracts: String, + #[arg(long, value_delimiter = ',', value_parser = parse_erc_contract)] + contracts: Vec, + + /// Event messages that are going to be treated as historical + /// A list of the model tags (namespace-name) + #[arg(long, value_delimiter = ',')] + historical_events: Vec, /// Configuration file #[arg(long)] @@ -150,7 +156,7 @@ struct Args { #[tokio::main] async fn main() -> anyhow::Result<()> { let matches = ::command().get_matches(); - let args = if let Some(path) = matches.get_one::("config") { + let mut args = if let Some(path) = matches.get_one::("config") { let config: ArgsConfig = toml::from_str(&std::fs::read_to_string(path)?)?; Args::from_merged(matches, Some(config)) } else { @@ -163,8 +169,8 @@ async fn main() -> anyhow::Result<()> { return Err(anyhow::anyhow!("Please specify a world address.")); }; - let mut contracts = parse_erc_contracts(&args.contracts)?; - contracts.push(Contract { address: world_address, r#type: ContractType::WORLD }); + // let mut contracts = parse_erc_contracts(&args.contracts)?; + args.contracts.push(Contract { address: world_address, r#type: ContractType::WORLD }); let filter_layer = EnvFilter::try_from_default_env() .unwrap_or_else(|_| EnvFilter::new("info,hyper_reverse_proxy=off")); @@ -210,13 +216,12 @@ async fn main() -> anyhow::Result<()> { // Get world address let world = WorldContractReader::new(world_address, provider.clone()); - let (mut executor, sender) = Executor::new(pool.clone(), shutdown_tx.clone()).await?; tokio::spawn(async move { executor.run().await.unwrap(); }); - let db = Sql::new(pool.clone(), sender.clone(), &contracts).await?; + let db = Sql::new(pool.clone(), sender.clone(), &args.contracts).await?; let processors = Processors { transaction: vec![Box::new(StoreTransactionProcessor)], @@ -246,10 +251,13 @@ async fn main() -> anyhow::Result<()> { index_pending: args.index_pending, polling_interval: Duration::from_millis(args.polling_interval), flags, + event_processor_config: EventProcessorConfig { + historical_events: args.historical_events, + }, }, shutdown_tx.clone(), Some(block_tx), - &contracts, + &args.contracts, ); let shutdown_rx = shutdown_tx.subscribe(); @@ -268,7 +276,12 @@ async fn main() -> anyhow::Result<()> { ) .expect("Failed to start libp2p relay server"); - let proxy_server = Arc::new(Proxy::new(args.addr, args.allowed_origins, Some(grpc_addr), None)); + let proxy_server = Arc::new(Proxy::new( + args.addr, + if args.allowed_origins.is_empty() { None } else { Some(args.allowed_origins) }, + Some(grpc_addr), + None, + )); let graphql_server = spawn_rebuilding_graphql_server( shutdown_tx.clone(), @@ -346,27 +359,20 @@ async fn spawn_rebuilding_graphql_server( // Parses clap cli argument which is expected to be in the format: // - erc_type:address:start_block // - address:start_block (erc_type defaults to ERC20) -fn parse_erc_contracts(s: &str) -> anyhow::Result> { - if s.is_empty() { - return Ok(Vec::new()); - } - - let parts: Vec<&str> = s.split(',').collect(); - let mut contracts = Vec::new(); - for part in parts { - match part.split(':').collect::>().as_slice() { - [r#type, address] => { - let r#type = r#type.parse::()?; - if r#type == ContractType::WORLD { - return Err(anyhow::anyhow!("World address cannot be specified as an ERC contract")); - } - - let address = Felt::from_str(address) - .with_context(|| format!("Expected address, found {}", address))?; - contracts.push(Contract { address, r#type }); +fn parse_erc_contract(part: &str) -> anyhow::Result { + match part.split(':').collect::>().as_slice() { + [r#type, address] => { + let r#type = r#type.parse::()?; + if r#type == ContractType::WORLD { + return Err(anyhow::anyhow!( + "World address cannot be specified as an ERC contract" + )); } - _ => return Err(anyhow::anyhow!("Invalid contract format")), + + let address = Felt::from_str(address) + .with_context(|| format!("Expected address, found {}", address))?; + Ok(Contract { address, r#type }) } + _ => Err(anyhow::anyhow!("Invalid contract format")), } - Ok(contracts) } diff --git a/crates/torii/core/Cargo.toml b/crates/torii/core/Cargo.toml index 345ded02e9..aac4d9010f 100644 --- a/crates/torii/core/Cargo.toml +++ b/crates/torii/core/Cargo.toml @@ -34,7 +34,6 @@ thiserror.workspace = true tokio = { version = "1.32.0", features = [ "sync", "macros" ], default-features = true } # tokio-stream = "0.1.11" tokio-util.workspace = true -toml.workspace = true tracing.workspace = true [dev-dependencies] diff --git a/crates/torii/core/src/engine.rs b/crates/torii/core/src/engine.rs index 5ddce943a1..7b3c4d883e 100644 --- a/crates/torii/core/src/engine.rs +++ b/crates/torii/core/src/engine.rs @@ -37,7 +37,7 @@ use crate::processors::store_del_record::StoreDelRecordProcessor; use crate::processors::store_set_record::StoreSetRecordProcessor; use crate::processors::store_update_member::StoreUpdateMemberProcessor; use crate::processors::store_update_record::StoreUpdateRecordProcessor; -use crate::processors::{BlockProcessor, EventProcessor, TransactionProcessor}; +use crate::processors::{BlockProcessor, EventProcessor, EventProcessorConfig, TransactionProcessor}; use crate::sql::{Cursors, Sql}; use crate::types::{Contract, ContractType}; @@ -142,6 +142,7 @@ pub struct EngineConfig { pub index_pending: bool, pub max_concurrent_tasks: usize, pub flags: IndexingFlags, + pub event_processor_config: EventProcessorConfig, } impl Default for EngineConfig { @@ -154,6 +155,7 @@ impl Default for EngineConfig { index_pending: true, max_concurrent_tasks: 100, flags: IndexingFlags::empty(), + event_processor_config: EventProcessorConfig::default(), } } } @@ -576,6 +578,7 @@ impl Engine

{ let semaphore = semaphore.clone(); let processors = self.processors.clone(); + let event_processor_config = self.config.event_processor_config.clone(); handles.push(tokio::spawn(async move { let _permit = semaphore.acquire().await?; let mut local_db = db.clone(); @@ -588,7 +591,7 @@ impl Engine

{ debug!(target: LOG_TARGET, event_name = processor.event_key(), task_id = %task_id, "Processing parallelized event."); if let Err(e) = processor - .process(&world, &mut local_db, block_number, block_timestamp, &event_id, &event) + .process(&world, &mut local_db, block_number, block_timestamp, &event_id, &event, &event_processor_config) .await { error!(target: LOG_TARGET, event_name = processor.event_key(), error = %e, task_id = %task_id, "Processing parallelized event."); @@ -798,6 +801,7 @@ impl Engine

{ block_timestamp, event_id, event, + &self.config.event_processor_config, ) .await { @@ -857,6 +861,7 @@ impl Engine

{ block_timestamp, event_id, event, + &self.config.event_processor_config, ) .await { diff --git a/crates/torii/core/src/processors/erc20_legacy_transfer.rs b/crates/torii/core/src/processors/erc20_legacy_transfer.rs index bf4fd33e49..4ed17416bc 100644 --- a/crates/torii/core/src/processors/erc20_legacy_transfer.rs +++ b/crates/torii/core/src/processors/erc20_legacy_transfer.rs @@ -6,7 +6,7 @@ use starknet::core::types::{Event, U256}; use starknet::providers::Provider; use tracing::debug; -use super::EventProcessor; +use super::{EventProcessor, EventProcessorConfig}; use crate::sql::Sql; pub(crate) const LOG_TARGET: &str = "torii_core::processors::erc20_legacy_transfer"; @@ -42,6 +42,7 @@ where block_timestamp: u64, event_id: &str, event: &Event, + _config: &EventProcessorConfig, ) -> Result<(), Error> { let token_address = event.from_address; let from = event.data[0]; diff --git a/crates/torii/core/src/processors/erc20_transfer.rs b/crates/torii/core/src/processors/erc20_transfer.rs index 7ed1620503..64f50d13a2 100644 --- a/crates/torii/core/src/processors/erc20_transfer.rs +++ b/crates/torii/core/src/processors/erc20_transfer.rs @@ -6,7 +6,7 @@ use starknet::core::types::{Event, U256}; use starknet::providers::Provider; use tracing::debug; -use super::EventProcessor; +use super::{EventProcessor, EventProcessorConfig}; use crate::sql::Sql; pub(crate) const LOG_TARGET: &str = "torii_core::processors::erc20_transfer"; @@ -42,6 +42,7 @@ where block_timestamp: u64, event_id: &str, event: &Event, + _config: &EventProcessorConfig, ) -> Result<(), Error> { let token_address = event.from_address; let from = event.keys[1]; diff --git a/crates/torii/core/src/processors/erc721_legacy_transfer.rs b/crates/torii/core/src/processors/erc721_legacy_transfer.rs index 198a1ebbd9..b3fdcbbfe8 100644 --- a/crates/torii/core/src/processors/erc721_legacy_transfer.rs +++ b/crates/torii/core/src/processors/erc721_legacy_transfer.rs @@ -6,7 +6,7 @@ use starknet::core::types::{Event, U256}; use starknet::providers::Provider; use tracing::debug; -use super::EventProcessor; +use super::{EventProcessor, EventProcessorConfig}; use crate::sql::Sql; pub(crate) const LOG_TARGET: &str = "torii_core::processors::erc721_legacy_transfer"; @@ -42,6 +42,7 @@ where block_timestamp: u64, event_id: &str, event: &Event, + _config: &EventProcessorConfig, ) -> Result<(), Error> { let token_address = event.from_address; let from = event.data[0]; diff --git a/crates/torii/core/src/processors/erc721_transfer.rs b/crates/torii/core/src/processors/erc721_transfer.rs index 349bdbea24..266ea18e51 100644 --- a/crates/torii/core/src/processors/erc721_transfer.rs +++ b/crates/torii/core/src/processors/erc721_transfer.rs @@ -6,7 +6,7 @@ use starknet::core::types::{Event, U256}; use starknet::providers::Provider; use tracing::debug; -use super::EventProcessor; +use super::{EventProcessor, EventProcessorConfig}; use crate::sql::Sql; pub(crate) const LOG_TARGET: &str = "torii_core::processors::erc721_transfer"; @@ -42,6 +42,7 @@ where block_timestamp: u64, event_id: &str, event: &Event, + _config: &EventProcessorConfig, ) -> Result<(), Error> { let token_address = event.from_address; let from = event.keys[1]; diff --git a/crates/torii/core/src/processors/event_message.rs b/crates/torii/core/src/processors/event_message.rs index 6236cda856..2f9dcb78cd 100644 --- a/crates/torii/core/src/processors/event_message.rs +++ b/crates/torii/core/src/processors/event_message.rs @@ -6,7 +6,7 @@ use starknet::core::types::{Event, Felt}; use starknet::providers::Provider; use tracing::info; -use super::EventProcessor; +use super::{EventProcessor, EventProcessorConfig}; use crate::sql::Sql; pub(crate) const LOG_TARGET: &str = "torii_core::processors::event_message"; @@ -35,6 +35,7 @@ where block_timestamp: u64, event_id: &str, event: &Event, + config: &EventProcessorConfig, ) -> Result<(), Error> { // Torii version is coupled to the world version, so we can expect the event to be well // formed. @@ -72,7 +73,7 @@ where entity.deserialize(&mut keys_and_unpacked)?; // TODO: this must come from some torii's configuration. - let historical = false; + let historical = config.historical_events.contains(&format!("{}-{}", model.namespace, model.name)); db.set_event_message(entity, event_id, block_timestamp, historical).await?; Ok(()) } diff --git a/crates/torii/core/src/processors/metadata_update.rs b/crates/torii/core/src/processors/metadata_update.rs index 8a1b68f7c2..76a9f37c12 100644 --- a/crates/torii/core/src/processors/metadata_update.rs +++ b/crates/torii/core/src/processors/metadata_update.rs @@ -15,7 +15,7 @@ use starknet::providers::Provider; use tokio_util::bytes::Bytes; use tracing::{error, info}; -use super::EventProcessor; +use super::{EventProcessor, EventProcessorConfig}; use crate::sql::Sql; const IPFS_URL: &str = "https://cartridge.infura-ipfs.io/ipfs/"; @@ -47,6 +47,7 @@ where block_timestamp: u64, _event_id: &str, event: &Event, + _config: &EventProcessorConfig, ) -> Result<(), Error> { // Torii version is coupled to the world version, so we can expect the event to be well // formed. diff --git a/crates/torii/core/src/processors/mod.rs b/crates/torii/core/src/processors/mod.rs index 58dad65928..9ea8ccf74c 100644 --- a/crates/torii/core/src/processors/mod.rs +++ b/crates/torii/core/src/processors/mod.rs @@ -24,6 +24,11 @@ pub mod store_update_record; const MODEL_INDEX: usize = 0; const ENTITY_ID_INDEX: usize = 1; +#[derive(Clone, Debug, Default)] +pub struct EventProcessorConfig { + pub historical_events: Vec, +} + #[async_trait] pub trait EventProcessor

: Send + Sync where @@ -46,6 +51,7 @@ where block_timestamp: u64, event_id: &str, event: &Event, + _config: &EventProcessorConfig, ) -> Result<(), Error>; } diff --git a/crates/torii/core/src/processors/raw_event.rs b/crates/torii/core/src/processors/raw_event.rs index 079247dc54..ff496ef74b 100644 --- a/crates/torii/core/src/processors/raw_event.rs +++ b/crates/torii/core/src/processors/raw_event.rs @@ -4,7 +4,7 @@ use dojo_world::contracts::world::WorldContractReader; use starknet::core::types::Event; use starknet::providers::Provider; -use super::EventProcessor; +use super::{EventProcessor, EventProcessorConfig}; use crate::sql::Sql; #[derive(Default, Debug)] @@ -31,6 +31,7 @@ where _block_timestamp: u64, _event_id: &str, _event: &Event, + _config: &EventProcessorConfig, ) -> Result<(), Error> { // We can choose to consider them, or not. diff --git a/crates/torii/core/src/processors/register_event.rs b/crates/torii/core/src/processors/register_event.rs index 79ab0067f0..6b5f0af9a0 100644 --- a/crates/torii/core/src/processors/register_event.rs +++ b/crates/torii/core/src/processors/register_event.rs @@ -7,7 +7,7 @@ use starknet::core::types::Event; use starknet::providers::Provider; use tracing::{debug, info}; -use super::EventProcessor; +use super::{EventProcessor, EventProcessorConfig}; use crate::sql::Sql; pub(crate) const LOG_TARGET: &str = "torii_core::processors::register_event"; @@ -38,6 +38,7 @@ where block_timestamp: u64, _event_id: &str, event: &Event, + _config: &EventProcessorConfig, ) -> Result<(), Error> { // Torii version is coupled to the world version, so we can expect the event to be well // formed. diff --git a/crates/torii/core/src/processors/register_model.rs b/crates/torii/core/src/processors/register_model.rs index 6f25230b39..58c7333a2f 100644 --- a/crates/torii/core/src/processors/register_model.rs +++ b/crates/torii/core/src/processors/register_model.rs @@ -7,7 +7,7 @@ use starknet::core::types::Event; use starknet::providers::Provider; use tracing::{debug, info}; -use super::EventProcessor; +use super::{EventProcessor, EventProcessorConfig}; use crate::sql::Sql; pub(crate) const LOG_TARGET: &str = "torii_core::processors::register_model"; @@ -38,6 +38,7 @@ where block_timestamp: u64, _event_id: &str, event: &Event, + _config: &EventProcessorConfig, ) -> Result<(), Error> { // Torii version is coupled to the world version, so we can expect the event to be well // formed. diff --git a/crates/torii/core/src/processors/store_del_record.rs b/crates/torii/core/src/processors/store_del_record.rs index 99f8ba579d..ad380885e1 100644 --- a/crates/torii/core/src/processors/store_del_record.rs +++ b/crates/torii/core/src/processors/store_del_record.rs @@ -6,7 +6,7 @@ use starknet::core::types::Event; use starknet::providers::Provider; use tracing::info; -use super::EventProcessor; +use super::{EventProcessor, EventProcessorConfig}; use crate::sql::Sql; pub(crate) const LOG_TARGET: &str = "torii_core::processors::store_del_record"; @@ -35,6 +35,7 @@ where block_timestamp: u64, event_id: &str, event: &Event, + _config: &EventProcessorConfig, ) -> Result<(), Error> { // Torii version is coupled to the world version, so we can expect the event to be well // formed. diff --git a/crates/torii/core/src/processors/store_set_record.rs b/crates/torii/core/src/processors/store_set_record.rs index 5faebc9855..fdbdd14646 100644 --- a/crates/torii/core/src/processors/store_set_record.rs +++ b/crates/torii/core/src/processors/store_set_record.rs @@ -6,7 +6,7 @@ use starknet::core::types::Event; use starknet::providers::Provider; use tracing::info; -use super::EventProcessor; +use super::{EventProcessor, EventProcessorConfig}; use crate::sql::utils::felts_to_sql_string; use crate::sql::Sql; @@ -36,6 +36,7 @@ where block_timestamp: u64, event_id: &str, event: &Event, + _config: &EventProcessorConfig, ) -> Result<(), Error> { // Torii version is coupled to the world version, so we can expect the event to be well // formed. diff --git a/crates/torii/core/src/processors/store_update_member.rs b/crates/torii/core/src/processors/store_update_member.rs index 567e9e18d0..632d5999c6 100644 --- a/crates/torii/core/src/processors/store_update_member.rs +++ b/crates/torii/core/src/processors/store_update_member.rs @@ -9,7 +9,7 @@ use starknet::core::utils::get_selector_from_name; use starknet::providers::Provider; use tracing::{info, warn}; -use super::EventProcessor; +use super::{EventProcessor, EventProcessorConfig}; use crate::processors::{ENTITY_ID_INDEX, MODEL_INDEX}; use crate::sql::Sql; @@ -50,6 +50,7 @@ where block_timestamp: u64, event_id: &str, event: &Event, + _config: &EventProcessorConfig, ) -> Result<(), Error> { let model_id = event.data[MODEL_INDEX]; let entity_id = event.data[ENTITY_ID_INDEX]; diff --git a/crates/torii/core/src/processors/store_update_record.rs b/crates/torii/core/src/processors/store_update_record.rs index ae4bfdac91..4cde69dc68 100644 --- a/crates/torii/core/src/processors/store_update_record.rs +++ b/crates/torii/core/src/processors/store_update_record.rs @@ -7,7 +7,7 @@ use starknet::core::types::Event; use starknet::providers::Provider; use tracing::info; -use super::EventProcessor; +use super::{EventProcessor, EventProcessorConfig}; use crate::sql::Sql; pub(crate) const LOG_TARGET: &str = "torii_core::processors::store_update_record"; @@ -36,6 +36,7 @@ where block_timestamp: u64, event_id: &str, event: &Event, + _config: &EventProcessorConfig, ) -> Result<(), Error> { // Torii version is coupled to the world version, so we can expect the event to be well // formed. diff --git a/crates/torii/core/src/processors/upgrade_event.rs b/crates/torii/core/src/processors/upgrade_event.rs new file mode 100644 index 0000000000..8479d9ab05 --- /dev/null +++ b/crates/torii/core/src/processors/upgrade_event.rs @@ -0,0 +1,114 @@ +use anyhow::{Error, Ok, Result}; +use async_trait::async_trait; +use dojo_world::contracts::abigen::world::Event as WorldEvent; +use dojo_world::contracts::model::ModelReader; +use dojo_world::contracts::world::WorldContractReader; +use starknet::core::types::Event; +use starknet::providers::Provider; +use tracing::{debug, info}; + +use super::{EventProcessor, EventProcessorConfig}; +use crate::sql::Sql; + +pub(crate) const LOG_TARGET: &str = "torii_core::processors::upgrade_event"; + +#[derive(Default, Debug)] +pub struct UpgradeEventProcessor; + +#[async_trait] +impl

EventProcessor

for UpgradeEventProcessor +where + P: Provider + Send + Sync + std::fmt::Debug, +{ + fn event_key(&self) -> String { + "EventUpgraded".to_string() + } + + // We might not need this anymore, since we don't have fallback and all world events must + // be handled. + fn validate(&self, _event: &Event) -> bool { + true + } + + async fn process( + &self, + world: &WorldContractReader

, + db: &mut Sql, + _block_number: u64, + block_timestamp: u64, + _event_id: &str, + event: &Event, + _config: &EventProcessorConfig, + ) -> Result<(), Error> { + // Torii version is coupled to the world version, so we can expect the event to be well + // formed. + let event = match WorldEvent::try_from(event).unwrap_or_else(|_| { + panic!( + "Expected {} event to be well formed.", + >::event_key(self) + ) + }) { + WorldEvent::EventUpgraded(e) => e, + _ => { + unreachable!() + } + }; + + // Called model here by language, but it's an event. Torii rework will make clear + // distinction. + let model = db.model(event.selector).await?; + let name = model.name; + let namespace = model.namespace; + let prev_schema = model.schema; + + let model = world.model_reader(&namespace, &name).await?; + let new_schema = model.schema().await?; + let schema_diff = new_schema.diff(&prev_schema); + // No changes to the schema. This can happen if torii is re-run with a fresh database. + // As the register model fetches the latest schema from the chain. + if schema_diff.is_none() { + return Ok(()); + } + + let schema_diff = schema_diff.unwrap(); + let layout = model.layout().await?; + + // Events are never stored onchain, hence no packing or unpacking. + let unpacked_size: u32 = 0; + let packed_size: u32 = 0; + + info!( + target: LOG_TARGET, + namespace = %namespace, + name = %name, + "Upgraded event." + ); + + debug!( + target: LOG_TARGET, + name, + diff = ?schema_diff, + layout = ?layout, + class_hash = ?event.class_hash, + contract_address = ?event.address, + packed_size = %packed_size, + unpacked_size = %unpacked_size, + "Upgraded event content." + ); + + db.register_model( + &namespace, + &new_schema, + layout, + event.class_hash.into(), + event.address.into(), + packed_size, + unpacked_size, + block_timestamp, + Some(&schema_diff), + ) + .await?; + + Ok(()) + } +} diff --git a/crates/torii/core/src/processors/upgrade_model.rs b/crates/torii/core/src/processors/upgrade_model.rs new file mode 100644 index 0000000000..403e1e17fd --- /dev/null +++ b/crates/torii/core/src/processors/upgrade_model.rs @@ -0,0 +1,111 @@ +use anyhow::{Error, Ok, Result}; +use async_trait::async_trait; +use dojo_world::contracts::abigen::world::Event as WorldEvent; +use dojo_world::contracts::model::ModelReader; +use dojo_world::contracts::world::WorldContractReader; +use starknet::core::types::Event; +use starknet::providers::Provider; +use tracing::{debug, info}; + +use super::{EventProcessor, EventProcessorConfig}; +use crate::sql::Sql; + +pub(crate) const LOG_TARGET: &str = "torii_core::processors::upgrade_model"; + +#[derive(Default, Debug)] +pub struct UpgradeModelProcessor; + +#[async_trait] +impl

EventProcessor

for UpgradeModelProcessor +where + P: Provider + Send + Sync + std::fmt::Debug, +{ + fn event_key(&self) -> String { + "ModelUpgraded".to_string() + } + + // We might not need this anymore, since we don't have fallback and all world events must + // be handled. + fn validate(&self, _event: &Event) -> bool { + true + } + + async fn process( + &self, + world: &WorldContractReader

, + db: &mut Sql, + _block_number: u64, + block_timestamp: u64, + _event_id: &str, + event: &Event, + _config: &EventProcessorConfig, + ) -> Result<(), Error> { + // Torii version is coupled to the world version, so we can expect the event to be well + // formed. + let event = match WorldEvent::try_from(event).unwrap_or_else(|_| { + panic!( + "Expected {} event to be well formed.", + >::event_key(self) + ) + }) { + WorldEvent::ModelUpgraded(e) => e, + _ => { + unreachable!() + } + }; + + let model = db.model(event.selector).await?; + let name = model.name; + let namespace = model.namespace; + let prev_schema = model.schema; + + let model = world.model_reader(&namespace, &name).await?; + let new_schema = model.schema().await?; + let schema_diff = new_schema.diff(&prev_schema); + // No changes to the schema. This can happen if torii is re-run with a fresh database. + // As the register model fetches the latest schema from the chain. + if schema_diff.is_none() { + return Ok(()); + } + + let schema_diff = schema_diff.unwrap(); + let layout = model.layout().await?; + + let unpacked_size: u32 = model.unpacked_size().await?; + let packed_size: u32 = model.packed_size().await?; + + info!( + target: LOG_TARGET, + namespace = %namespace, + name = %name, + "Upgraded model." + ); + + debug!( + target: LOG_TARGET, + name = %name, + diff = ?schema_diff, + layout = ?layout, + class_hash = ?event.class_hash, + contract_address = ?event.address, + packed_size = %packed_size, + unpacked_size = %unpacked_size, + "Upgraded model content." + ); + + db.register_model( + &namespace, + &new_schema, + layout, + event.class_hash.into(), + event.address.into(), + packed_size, + unpacked_size, + block_timestamp, + Some(&schema_diff), + ) + .await?; + + Ok(()) + } +} From 8b41cf24f5b0cb8c4999b6424bf7287a5104d0a5 Mon Sep 17 00:00:00 2001 From: Nasr Date: Fri, 8 Nov 2024 15:46:25 -0500 Subject: [PATCH 7/8] remove upgrade --- .../core/src/processors/upgrade_event.rs | 114 ------------------ .../core/src/processors/upgrade_model.rs | 111 ----------------- 2 files changed, 225 deletions(-) delete mode 100644 crates/torii/core/src/processors/upgrade_event.rs delete mode 100644 crates/torii/core/src/processors/upgrade_model.rs diff --git a/crates/torii/core/src/processors/upgrade_event.rs b/crates/torii/core/src/processors/upgrade_event.rs deleted file mode 100644 index 8479d9ab05..0000000000 --- a/crates/torii/core/src/processors/upgrade_event.rs +++ /dev/null @@ -1,114 +0,0 @@ -use anyhow::{Error, Ok, Result}; -use async_trait::async_trait; -use dojo_world::contracts::abigen::world::Event as WorldEvent; -use dojo_world::contracts::model::ModelReader; -use dojo_world::contracts::world::WorldContractReader; -use starknet::core::types::Event; -use starknet::providers::Provider; -use tracing::{debug, info}; - -use super::{EventProcessor, EventProcessorConfig}; -use crate::sql::Sql; - -pub(crate) const LOG_TARGET: &str = "torii_core::processors::upgrade_event"; - -#[derive(Default, Debug)] -pub struct UpgradeEventProcessor; - -#[async_trait] -impl

EventProcessor

for UpgradeEventProcessor -where - P: Provider + Send + Sync + std::fmt::Debug, -{ - fn event_key(&self) -> String { - "EventUpgraded".to_string() - } - - // We might not need this anymore, since we don't have fallback and all world events must - // be handled. - fn validate(&self, _event: &Event) -> bool { - true - } - - async fn process( - &self, - world: &WorldContractReader

, - db: &mut Sql, - _block_number: u64, - block_timestamp: u64, - _event_id: &str, - event: &Event, - _config: &EventProcessorConfig, - ) -> Result<(), Error> { - // Torii version is coupled to the world version, so we can expect the event to be well - // formed. - let event = match WorldEvent::try_from(event).unwrap_or_else(|_| { - panic!( - "Expected {} event to be well formed.", - >::event_key(self) - ) - }) { - WorldEvent::EventUpgraded(e) => e, - _ => { - unreachable!() - } - }; - - // Called model here by language, but it's an event. Torii rework will make clear - // distinction. - let model = db.model(event.selector).await?; - let name = model.name; - let namespace = model.namespace; - let prev_schema = model.schema; - - let model = world.model_reader(&namespace, &name).await?; - let new_schema = model.schema().await?; - let schema_diff = new_schema.diff(&prev_schema); - // No changes to the schema. This can happen if torii is re-run with a fresh database. - // As the register model fetches the latest schema from the chain. - if schema_diff.is_none() { - return Ok(()); - } - - let schema_diff = schema_diff.unwrap(); - let layout = model.layout().await?; - - // Events are never stored onchain, hence no packing or unpacking. - let unpacked_size: u32 = 0; - let packed_size: u32 = 0; - - info!( - target: LOG_TARGET, - namespace = %namespace, - name = %name, - "Upgraded event." - ); - - debug!( - target: LOG_TARGET, - name, - diff = ?schema_diff, - layout = ?layout, - class_hash = ?event.class_hash, - contract_address = ?event.address, - packed_size = %packed_size, - unpacked_size = %unpacked_size, - "Upgraded event content." - ); - - db.register_model( - &namespace, - &new_schema, - layout, - event.class_hash.into(), - event.address.into(), - packed_size, - unpacked_size, - block_timestamp, - Some(&schema_diff), - ) - .await?; - - Ok(()) - } -} diff --git a/crates/torii/core/src/processors/upgrade_model.rs b/crates/torii/core/src/processors/upgrade_model.rs deleted file mode 100644 index 403e1e17fd..0000000000 --- a/crates/torii/core/src/processors/upgrade_model.rs +++ /dev/null @@ -1,111 +0,0 @@ -use anyhow::{Error, Ok, Result}; -use async_trait::async_trait; -use dojo_world::contracts::abigen::world::Event as WorldEvent; -use dojo_world::contracts::model::ModelReader; -use dojo_world::contracts::world::WorldContractReader; -use starknet::core::types::Event; -use starknet::providers::Provider; -use tracing::{debug, info}; - -use super::{EventProcessor, EventProcessorConfig}; -use crate::sql::Sql; - -pub(crate) const LOG_TARGET: &str = "torii_core::processors::upgrade_model"; - -#[derive(Default, Debug)] -pub struct UpgradeModelProcessor; - -#[async_trait] -impl

EventProcessor

for UpgradeModelProcessor -where - P: Provider + Send + Sync + std::fmt::Debug, -{ - fn event_key(&self) -> String { - "ModelUpgraded".to_string() - } - - // We might not need this anymore, since we don't have fallback and all world events must - // be handled. - fn validate(&self, _event: &Event) -> bool { - true - } - - async fn process( - &self, - world: &WorldContractReader

, - db: &mut Sql, - _block_number: u64, - block_timestamp: u64, - _event_id: &str, - event: &Event, - _config: &EventProcessorConfig, - ) -> Result<(), Error> { - // Torii version is coupled to the world version, so we can expect the event to be well - // formed. - let event = match WorldEvent::try_from(event).unwrap_or_else(|_| { - panic!( - "Expected {} event to be well formed.", - >::event_key(self) - ) - }) { - WorldEvent::ModelUpgraded(e) => e, - _ => { - unreachable!() - } - }; - - let model = db.model(event.selector).await?; - let name = model.name; - let namespace = model.namespace; - let prev_schema = model.schema; - - let model = world.model_reader(&namespace, &name).await?; - let new_schema = model.schema().await?; - let schema_diff = new_schema.diff(&prev_schema); - // No changes to the schema. This can happen if torii is re-run with a fresh database. - // As the register model fetches the latest schema from the chain. - if schema_diff.is_none() { - return Ok(()); - } - - let schema_diff = schema_diff.unwrap(); - let layout = model.layout().await?; - - let unpacked_size: u32 = model.unpacked_size().await?; - let packed_size: u32 = model.packed_size().await?; - - info!( - target: LOG_TARGET, - namespace = %namespace, - name = %name, - "Upgraded model." - ); - - debug!( - target: LOG_TARGET, - name = %name, - diff = ?schema_diff, - layout = ?layout, - class_hash = ?event.class_hash, - contract_address = ?event.address, - packed_size = %packed_size, - unpacked_size = %unpacked_size, - "Upgraded model content." - ); - - db.register_model( - &namespace, - &new_schema, - layout, - event.class_hash.into(), - event.address.into(), - packed_size, - unpacked_size, - block_timestamp, - Some(&schema_diff), - ) - .await?; - - Ok(()) - } -} From a2c064e61a54d00c9b67d90be06c54721054687e Mon Sep 17 00:00:00 2001 From: Nasr Date: Fri, 8 Nov 2024 15:57:13 -0500 Subject: [PATCH 8/8] fmt clippy --- bin/torii/src/main.rs | 4 +- bin/torii/torii.toml | 18 ++++-- crates/torii/core/src/engine.rs | 10 +++- .../core/src/processors/event_message.rs | 3 +- crates/torii/core/src/processors/mod.rs | 4 +- crates/torii/core/src/sql/test.rs | 2 +- .../torii/graphql/src/tests/metadata_test.rs | 22 +++++--- crates/torii/graphql/src/tests/mod.rs | 12 ++-- .../graphql/src/tests/subscription_test.rs | 55 ++++++++++++------- .../grpc/src/server/tests/entities_test.rs | 12 ++-- crates/torii/libp2p/src/tests.rs | 11 ++-- 11 files changed, 100 insertions(+), 53 deletions(-) diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index 56d10b9380..a6dc11c24f 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -143,7 +143,7 @@ struct Args { contracts: Vec, /// Event messages that are going to be treated as historical - /// A list of the model tags (namespace-name) + /// A list of the model tags (namespace-name) #[arg(long, value_delimiter = ',')] historical_events: Vec, @@ -252,7 +252,7 @@ async fn main() -> anyhow::Result<()> { polling_interval: Duration::from_millis(args.polling_interval), flags, event_processor_config: EventProcessorConfig { - historical_events: args.historical_events, + historical_events: args.historical_events.into_iter().collect(), }, }, shutdown_tx.clone(), diff --git a/bin/torii/torii.toml b/bin/torii/torii.toml index 93a444170f..ee843ea651 100644 --- a/bin/torii/torii.toml +++ b/bin/torii/torii.toml @@ -1,6 +1,14 @@ # Example configuration file for Torii -# contracts = [ -# { type = "WORLD", address = "" }, -# { type = "ERC20", address = "" }, -# { type = "ERC721", address = "" }, -# ] \ No newline at end of file +world_address="0x054d0f13bf3fb5f15a8674c5204aad35e3022af96bcc23bdbd16b7e297ffd399" +addr="0.0.0.0:8080" +rpc="http://0.0.0.0:5050" + +historical_events=["ns-Moved", "ns-Spawned"] + +[[contracts]] +type="ERC20" +address="0x0" + +[[contracts]] +type="ERC721" +address="0x123" \ No newline at end of file diff --git a/crates/torii/core/src/engine.rs b/crates/torii/core/src/engine.rs index 7b3c4d883e..b73b66bcf9 100644 --- a/crates/torii/core/src/engine.rs +++ b/crates/torii/core/src/engine.rs @@ -37,7 +37,9 @@ use crate::processors::store_del_record::StoreDelRecordProcessor; use crate::processors::store_set_record::StoreSetRecordProcessor; use crate::processors::store_update_member::StoreUpdateMemberProcessor; use crate::processors::store_update_record::StoreUpdateRecordProcessor; -use crate::processors::{BlockProcessor, EventProcessor, EventProcessorConfig, TransactionProcessor}; +use crate::processors::{ + BlockProcessor, EventProcessor, EventProcessorConfig, TransactionProcessor, +}; use crate::sql::{Cursors, Sql}; use crate::types::{Contract, ContractType}; @@ -219,9 +221,11 @@ impl Engine

{ config: EngineConfig, shutdown_tx: Sender<()>, block_tx: Option>, - contracts: &Vec, + contracts: &[Contract], ) -> Self { - let contracts = Arc::new(contracts.iter().map(|contract| (contract.address, contract.r#type)).collect()); + let contracts = Arc::new( + contracts.iter().map(|contract| (contract.address, contract.r#type)).collect(), + ); Self { world: Arc::new(world), diff --git a/crates/torii/core/src/processors/event_message.rs b/crates/torii/core/src/processors/event_message.rs index 2f9dcb78cd..2fbb982284 100644 --- a/crates/torii/core/src/processors/event_message.rs +++ b/crates/torii/core/src/processors/event_message.rs @@ -73,7 +73,8 @@ where entity.deserialize(&mut keys_and_unpacked)?; // TODO: this must come from some torii's configuration. - let historical = config.historical_events.contains(&format!("{}-{}", model.namespace, model.name)); + let historical = + config.historical_events.contains(&format!("{}-{}", model.namespace, model.name)); db.set_event_message(entity, event_id, block_timestamp, historical).await?; Ok(()) } diff --git a/crates/torii/core/src/processors/mod.rs b/crates/torii/core/src/processors/mod.rs index 9ea8ccf74c..fa24de5e9b 100644 --- a/crates/torii/core/src/processors/mod.rs +++ b/crates/torii/core/src/processors/mod.rs @@ -1,3 +1,5 @@ +use std::collections::HashSet; + use anyhow::{Error, Result}; use async_trait::async_trait; use dojo_world::contracts::world::WorldContractReader; @@ -26,7 +28,7 @@ const ENTITY_ID_INDEX: usize = 1; #[derive(Clone, Debug, Default)] pub struct EventProcessorConfig { - pub historical_events: Vec, + pub historical_events: HashSet, } #[async_trait] diff --git a/crates/torii/core/src/sql/test.rs b/crates/torii/core/src/sql/test.rs index 9bab88ec0c..65076fffa3 100644 --- a/crates/torii/core/src/sql/test.rs +++ b/crates/torii/core/src/sql/test.rs @@ -45,7 +45,7 @@ where EngineConfig::default(), shutdown_tx, None, - &vec![Contract { address: world_address, r#type: ContractType::WORLD }], + &[Contract { address: world_address, r#type: ContractType::WORLD }], ); let data = engine.fetch_range(0, to, &HashMap::new()).await.unwrap(); diff --git a/crates/torii/graphql/src/tests/metadata_test.rs b/crates/torii/graphql/src/tests/metadata_test.rs index 3f0d6ec11e..d6b00ea72b 100644 --- a/crates/torii/graphql/src/tests/metadata_test.rs +++ b/crates/torii/graphql/src/tests/metadata_test.rs @@ -56,10 +56,13 @@ mod tests { tokio::spawn(async move { executor.run().await.unwrap(); }); - let mut db = - Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) - .await - .unwrap(); + let mut db = Sql::new( + pool.clone(), + sender, + &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }], + ) + .await + .unwrap(); let schema = build_schema(&pool).await.unwrap(); let cover_img = "QWxsIHlvdXIgYmFzZSBiZWxvbmcgdG8gdXM="; @@ -117,10 +120,13 @@ mod tests { tokio::spawn(async move { executor.run().await.unwrap(); }); - let mut db = - Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) - .await - .unwrap(); + let mut db = Sql::new( + pool.clone(), + sender, + &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }], + ) + .await + .unwrap(); let schema = build_schema(&pool).await.unwrap(); db.set_metadata(&RESOURCE, URI, BLOCK_TIMESTAMP).unwrap(); diff --git a/crates/torii/graphql/src/tests/mod.rs b/crates/torii/graphql/src/tests/mod.rs index a003b7ea01..c21419bbba 100644 --- a/crates/torii/graphql/src/tests/mod.rs +++ b/crates/torii/graphql/src/tests/mod.rs @@ -345,9 +345,13 @@ pub async fn spinup_types_test(path: &str) -> Result { tokio::spawn(async move { executor.run().await.unwrap(); }); - let db = Sql::new(pool.clone(), sender, &vec![Contract { address: world_address, r#type: ContractType::WORLD }]) - .await - .unwrap(); + let db = Sql::new( + pool.clone(), + sender, + &vec![Contract { address: world_address, r#type: ContractType::WORLD }], + ) + .await + .unwrap(); let (shutdown_tx, _) = broadcast::channel(1); let mut engine = Engine::new( @@ -358,7 +362,7 @@ pub async fn spinup_types_test(path: &str) -> Result { EngineConfig::default(), shutdown_tx, None, - &vec![Contract { address: world_address, r#type: ContractType::WORLD }], + &[Contract { address: world_address, r#type: ContractType::WORLD }], ); let to = account.provider().block_hash_and_number().await?.block_number; diff --git a/crates/torii/graphql/src/tests/subscription_test.rs b/crates/torii/graphql/src/tests/subscription_test.rs index 5a79ea9c08..583779c97d 100644 --- a/crates/torii/graphql/src/tests/subscription_test.rs +++ b/crates/torii/graphql/src/tests/subscription_test.rs @@ -30,10 +30,13 @@ mod tests { tokio::spawn(async move { executor.run().await.unwrap(); }); - let mut db = - Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) - .await - .unwrap(); + let mut db = Sql::new( + pool.clone(), + sender, + &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }], + ) + .await + .unwrap(); model_fixtures(&mut db).await; // 0. Preprocess expected entity value @@ -174,10 +177,13 @@ mod tests { tokio::spawn(async move { executor.run().await.unwrap(); }); - let mut db = - Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) - .await - .unwrap(); + let mut db = Sql::new( + pool.clone(), + sender, + &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }], + ) + .await + .unwrap(); model_fixtures(&mut db).await; // 0. Preprocess expected entity value @@ -298,10 +304,13 @@ mod tests { tokio::spawn(async move { executor.run().await.unwrap(); }); - let mut db = - Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) - .await - .unwrap(); + let mut db = Sql::new( + pool.clone(), + sender, + &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }], + ) + .await + .unwrap(); // 0. Preprocess model value let namespace = "types_test".to_string(); let model_name = "Subrecord".to_string(); @@ -372,10 +381,13 @@ mod tests { tokio::spawn(async move { executor.run().await.unwrap(); }); - let mut db = - Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) - .await - .unwrap(); + let mut db = Sql::new( + pool.clone(), + sender, + &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }], + ) + .await + .unwrap(); // 0. Preprocess model value let namespace = "types_test".to_string(); let model_name = "Subrecord".to_string(); @@ -447,10 +459,13 @@ mod tests { tokio::spawn(async move { executor.run().await.unwrap(); }); - let mut db = - Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) - .await - .unwrap(); + let mut db = Sql::new( + pool.clone(), + sender, + &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }], + ) + .await + .unwrap(); let block_timestamp: u64 = 1710754478_u64; let (tx, mut rx) = mpsc::channel(7); tokio::spawn(async move { diff --git a/crates/torii/grpc/src/server/tests/entities_test.rs b/crates/torii/grpc/src/server/tests/entities_test.rs index 5214575d96..9a0bb39f31 100644 --- a/crates/torii/grpc/src/server/tests/entities_test.rs +++ b/crates/torii/grpc/src/server/tests/entities_test.rs @@ -92,9 +92,13 @@ async fn test_entities_queries(sequencer: &RunnerCtx) { tokio::spawn(async move { executor.run().await.unwrap(); }); - let db = Sql::new(pool.clone(), sender, &vec![Contract { address: world_address, r#type: ContractType::WORLD }]) - .await - .unwrap(); + let db = Sql::new( + pool.clone(), + sender, + &vec![Contract { address: world_address, r#type: ContractType::WORLD }], + ) + .await + .unwrap(); let (shutdown_tx, _) = broadcast::channel(1); let mut engine = Engine::new( @@ -105,7 +109,7 @@ async fn test_entities_queries(sequencer: &RunnerCtx) { EngineConfig::default(), shutdown_tx, None, - &vec![Contract { address: world_address, r#type: ContractType::WORLD }], + &[Contract { address: world_address, r#type: ContractType::WORLD }], ); let to = provider.block_hash_and_number().await.unwrap().block_number; diff --git a/crates/torii/libp2p/src/tests.rs b/crates/torii/libp2p/src/tests.rs index 7c94fa04c5..0156093935 100644 --- a/crates/torii/libp2p/src/tests.rs +++ b/crates/torii/libp2p/src/tests.rs @@ -577,10 +577,13 @@ mod test { tokio::spawn(async move { executor.run().await.unwrap(); }); - let mut db = - Sql::new(pool.clone(), sender, &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }]) - .await - .unwrap(); + let mut db = Sql::new( + pool.clone(), + sender, + &vec![Contract { address: Felt::ZERO, r#type: ContractType::WORLD }], + ) + .await + .unwrap(); // Register the model of our Message db.register_model(