Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: git rebase #2685

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Cargo.lock

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

128 changes: 12 additions & 116 deletions bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
use std::sync::Arc;
use std::time::Duration;

use anyhow::Context;
use camino::Utf8PathBuf;
use clap::Parser;
use clap::{ArgAction, Parser};
use dojo_metrics::exporters::prometheus::PrometheusRecorder;
use dojo_world::contracts::world::WorldContractReader;
use sqlx::sqlite::{
Expand Down Expand Up @@ -48,111 +46,6 @@

pub(crate) const LOG_TARGET: &str = "torii::cli";

/// Dojo World Indexer
#[derive(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<Felt>,

/// The sequencer rpc endpoint to index.
#[arg(long, value_name = "URL", default_value = ":5050", value_parser = parse_url)]
rpc: Url,

/// Database filepath (ex: indexer.db). If specified file doesn't exist, it will be
/// created. Defaults to in-memory database
#[arg(short, long, default_value = "")]
database: String,

/// Address to serve api endpoints at.
#[arg(long, value_name = "SOCKET", default_value = "0.0.0.0:8080", value_parser = parse_socket_address)]
addr: SocketAddr,

/// Port to serve Libp2p TCP & UDP Quic transports
#[arg(long, value_name = "PORT", default_value = "9090")]
relay_port: u16,

/// Port to serve Libp2p WebRTC transport
#[arg(long, value_name = "PORT", default_value = "9091")]
relay_webrtc_port: u16,

/// Port to serve Libp2p WebRTC transport
#[arg(long, value_name = "PORT", default_value = "9092")]
relay_websocket_port: u16,

/// Path to a local identity key file. If not specified, a new identity will be generated
#[arg(long, value_name = "PATH")]
relay_local_key_path: Option<String>,

/// Path to a local certificate file. If not specified, a new certificate will be generated
/// for WebRTC connections
#[arg(long, value_name = "PATH")]
relay_cert_path: Option<String>,

/// Specify allowed origins for api endpoints (comma-separated list of allowed origins, or "*"
/// for all)
#[arg(long)]
#[arg(value_delimiter = ',')]
allowed_origins: Option<Vec<String>>,

/// The external url of the server, used for configuring the GraphQL Playground in a hosted
/// environment
#[arg(long, value_parser = parse_url)]
external_url: Option<Url>,

/// Enable Prometheus metrics.
///
/// The metrics will be served at the given interface and port.
#[arg(long, value_name = "SOCKET", value_parser = parse_socket_address, help_heading = "Metrics")]
metrics: Option<SocketAddr>,

/// Open World Explorer on the browser.
#[arg(long)]
explorer: bool,

/// Chunk size of the events page when indexing using events
#[arg(long, default_value = "1024")]
events_chunk_size: u64,

/// Number of blocks to process before commiting to DB
#[arg(long, default_value = "10240")]
blocks_chunk_size: u64,

/// Enable indexing pending blocks
#[arg(long, action = ArgAction::Set, default_value_t = true)]
index_pending: bool,

/// Polling interval in ms
#[arg(long, default_value = "500")]
polling_interval: u64,

/// Max concurrent tasks
#[arg(long, default_value = "100")]
max_concurrent_tasks: usize,

/// Whether or not to index world transactions
#[arg(long, action = ArgAction::Set, default_value_t = false)]
index_transactions: bool,

/// Whether or not to index raw events
#[arg(long, action = ArgAction::Set, default_value_t = true)]
index_raw_events: bool,

/// ERC contract addresses to index
#[arg(long, value_parser = parse_erc_contracts)]
#[arg(conflicts_with = "config")]
contracts: Option<std::vec::Vec<Contract>>,

/// Configuration file
#[arg(long)]
config: Option<PathBuf>,

/// Path to a directory to store ERC artifacts
#[arg(long)]
artifacts_path: Option<Utf8PathBuf>,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let mut args = ToriiArgs::parse().with_config_file()?;
Expand Down Expand Up @@ -217,19 +110,11 @@
// Get world address
let world = WorldContractReader::new(world_address, provider.clone());

// let (mut executor, sender) = Executor::new(pool.clone(), shutdown_tx.clone()).await?;
let contracts = args
.indexing
.contracts
.iter()
.map(|contract| (contract.address, contract.r#type))
.collect();

let (mut executor, sender) = Executor::new(
pool.clone(),
shutdown_tx.clone(),
provider.clone(),
args.max_concurrent_tasks,
args.indexing.max_concurrent_tasks,

Check warning on line 117 in bin/torii/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L117

Added line #L117 was not covered by tests
)
.await?;
let executor_handle = tokio::spawn(async move { executor.run().await });
Expand Down Expand Up @@ -287,6 +172,16 @@
)
.await?;

let temp_dir = TempDir::new()?;
let artifacts_path =
args.artifacts_path.unwrap_or_else(|| Utf8PathBuf::from(temp_dir.path().to_str().unwrap()));

tokio::fs::create_dir_all(&artifacts_path).await?;
let absolute_path = artifacts_path.canonicalize_utf8()?;

let (artifacts_addr, artifacts_server) =
torii_server::artifacts::new(shutdown_tx.subscribe(), &absolute_path, pool.clone()).await?;

Check warning on line 184 in bin/torii/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L175-L184

Added lines #L175 - L184 were not covered by tests
let mut libp2p_relay_server = torii_relay::server::Relay::new(
db,
provider.clone(),
Expand All @@ -299,6 +194,7 @@
.expect("Failed to start libp2p relay server");

let addr = SocketAddr::new(args.server.http_addr, args.server.http_port);

Check warning on line 197 in bin/torii/src/main.rs

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L197

Added line #L197 was not covered by tests
let proxy_server = Arc::new(Proxy::new(
addr,
args.server.http_cors_origins.filter(|cors_origins| !cors_origins.is_empty()),
Expand Down
5 changes: 3 additions & 2 deletions crates/torii/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ version.workspace = true

[dependencies]
anyhow.workspace = true
camino.workspace = true
clap.workspace = true
dojo-utils.workspace = true
serde.workspace = true
starknet.workspace = true
torii-core.workspace = true
toml.workspace = true
torii-core.workspace = true
url.workspace = true

[dev-dependencies]
Expand All @@ -21,4 +22,4 @@ camino.workspace = true

[features]
default = [ "server" ]
server = [ ]
server = [ ]
5 changes: 5 additions & 0 deletions crates/torii/cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;

use anyhow::Result;
use camino::Utf8PathBuf;
use clap::Parser;
use dojo_utils::parse::parse_url;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -47,6 +48,10 @@ pub struct ToriiArgs {
#[arg(long, help = "Configuration file to setup Torii.")]
pub config: Option<PathBuf>,

/// Path to a directory to store ERC artifacts
#[arg(long)]
pub artifacts_path: Option<Utf8PathBuf>,

#[command(flatten)]
pub indexing: IndexingOptions,

Expand Down
1 change: 0 additions & 1 deletion crates/torii/graphql/src/tests/subscription_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ mod tests {
use torii_core::sql::cache::ModelCache;
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 url::Url;

Expand Down
Loading