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(torii/graphql): use borrowed_any instead of owned_any #2689

Merged
merged 9 commits into from
Nov 14, 2024
454 changes: 449 additions & 5 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,17 @@ colored_json = "3.2.0"
console = "0.15.7"
convert_case = "0.6.0"
crypto-bigint = { version = "0.5.3", features = [ "serde" ] }
data-url = "0.3"
derive_more = "0.99.17"
flate2 = "1.0.24"
fluent-uri = "0.3"
futures = "0.3.30"
futures-util = "0.3.30"
hashlink = "0.9.1"
hex = "0.4.3"
hex-literal = "0.4.1"
http = "0.2.9"
image = "0.25.2"
indexmap = "2.2.5"
indoc = "1.0.7"
itertools = "0.12.1"
Expand Down Expand Up @@ -224,6 +227,9 @@ tracing-log = "0.1.3"
tracing-subscriber = { version = "0.3.16", features = [ "env-filter", "json" ] }
url = { version = "2.4.0", features = [ "serde" ] }
walkdir = "2.5.0"
# TODO: see if we still need the git version
ipfs-api-backend-hyper = { git = "https://github.com/ferristseng/rust-ipfs-api", rev = "af2c17f7b19ef5b9898f458d97a90055c3605633", features = [ "with-hyper-rustls", "with-send-sync" ] }
mime_guess = "2.0"

# server
hyper = "0.14.27"
Expand Down
6 changes: 3 additions & 3 deletions bin/torii/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ starknet.workspace = true
tokio-stream = "0.1.11"
tokio-util = "0.7.7"
tokio.workspace = true
toml.workspace = true
torii-cli.workspace = true
torii-core.workspace = true
torii-graphql.workspace = true
torii-grpc = { workspace = true, features = [ "server" ] }
torii-relay.workspace = true
torii-server.workspace = true
tower.workspace = true
toml.workspace = true

clap_config = "0.1.1"
tempfile.workspace = true
tower-http.workspace = true
tracing-subscriber.workspace = true
tracing.workspace = true
url.workspace = true
webbrowser = "0.8"
tempfile.workspace = true
clap_config = "0.1.1"

[dev-dependencies]
assert_matches.workspace = true
Expand Down
31 changes: 26 additions & 5 deletions bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;

use camino::Utf8PathBuf;
use clap::Parser;
use dojo_metrics::exporters::prometheus::PrometheusRecorder;
use dojo_world::contracts::world::WorldContractReader;
Expand All @@ -25,7 +26,7 @@ use sqlx::sqlite::{
use sqlx::SqlitePool;
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::JsonRpcClient;
use tempfile::NamedTempFile;
use tempfile::{NamedTempFile, TempDir};
use tokio::sync::broadcast;
use tokio::sync::broadcast::Sender;
use tokio_stream::StreamExt;
Expand Down Expand Up @@ -109,10 +110,14 @@ 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 (mut executor, sender) = Executor::new(
pool.clone(),
shutdown_tx.clone(),
provider.clone(),
args.indexing.max_concurrent_tasks,
)
.await?;
let executor_handle = tokio::spawn(async move { executor.run().await });

let model_cache = Arc::new(ModelCache::new(pool.clone()));
let db = Sql::new(pool.clone(), sender.clone(), &args.indexing.contracts, model_cache.clone())
Expand Down Expand Up @@ -167,6 +172,16 @@ async fn main() -> anyhow::Result<()> {
)
.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?;

let mut libp2p_relay_server = torii_relay::server::Relay::new(
db,
provider.clone(),
Expand All @@ -179,11 +194,13 @@ async fn main() -> anyhow::Result<()> {
.expect("Failed to start libp2p relay server");

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

let proxy_server = Arc::new(Proxy::new(
addr,
args.server.http_cors_origins.filter(|cors_origins| !cors_origins.is_empty()),
Some(grpc_addr),
None,
Some(artifacts_addr),
));

let graphql_server = spawn_rebuilding_graphql_server(
Expand All @@ -201,6 +218,7 @@ async fn main() -> anyhow::Result<()> {
info!(target: LOG_TARGET, endpoint = %addr, "Starting torii endpoint.");
info!(target: LOG_TARGET, endpoint = %gql_endpoint, "Serving Graphql playground.");
info!(target: LOG_TARGET, url = %explorer_url, "Serving World Explorer.");
info!(target: LOG_TARGET, path = %artifacts_path, "Serving ERC artifacts at path");

if args.explorer {
if let Err(e) = webbrowser::open(&explorer_url) {
Expand All @@ -222,13 +240,16 @@ async fn main() -> anyhow::Result<()> {
let graphql_server_handle = tokio::spawn(graphql_server);
let grpc_server_handle = tokio::spawn(grpc_server);
let libp2p_relay_server_handle = tokio::spawn(async move { libp2p_relay_server.run().await });
let artifacts_server_handle = tokio::spawn(artifacts_server);

tokio::select! {
res = engine_handle => res??,
res = executor_handle => res??,
res = proxy_server_handle => res??,
res = graphql_server_handle => res?,
res = grpc_server_handle => res??,
res = libp2p_relay_server_handle => res?,
res = artifacts_server_handle => res?,
_ = dojo_utils::signal::wait_signals() => {},
};

Expand Down
55 changes: 55 additions & 0 deletions crates/dojo-world/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[package]
description = "Dojo world specification. For example, crates and flags used for compilation."
edition.workspace = true
license-file.workspace = true
name = "dojo-world"
repository.workspace = true
version.workspace = true

[dependencies]
anyhow.workspace = true
async-trait.workspace = true
cairo-lang-filesystem.workspace = true
cairo-lang-project.workspace = true
cairo-lang-starknet-classes.workspace = true
cairo-lang-starknet.workspace = true
camino.workspace = true
convert_case.workspace = true
dojo-utils = { workspace = true, optional = true }
num-traits = { workspace = true, optional = true }
regex.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_with.workspace = true
smol_str.workspace = true
starknet-crypto.workspace = true
starknet.workspace = true
thiserror.workspace = true
topological-sort.workspace = true
tracing.workspace = true

cainome.workspace = true
dojo-types = { path = "../dojo-types", optional = true }
http = { workspace = true, optional = true }
ipfs-api-backend-hyper = { workspace = true, optional = true }
scarb = { workspace = true, optional = true }
tokio = { version = "1.32.0", features = [ "time" ], default-features = false, optional = true }
toml.workspace = true
url = { workspace = true, optional = true }
walkdir.workspace = true

[dev-dependencies]
assert_fs.workspace = true
assert_matches.workspace = true
dojo-lang.workspace = true
dojo-test-utils = { path = "../dojo-test-utils" }
katana-runner.workspace = true
similar-asserts.workspace = true
tempfile.workspace = true
tokio.workspace = true

[features]
contracts = [ "dep:dojo-types", "dep:http", "dep:num-traits" ]
manifest = [ "contracts", "dep:dojo-types", "dep:scarb", "dep:url" ]
metadata = [ "dep:ipfs-api-backend-hyper", "dep:scarb", "dep:url" ]
migration = [ "dep:dojo-utils", "dep:scarb", "dep:tokio", "manifest" ]
8 changes: 4 additions & 4 deletions crates/sozo/ops/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ async-trait.workspace = true
cainome.workspace = true
colored.workspace = true
colored_json.workspace = true
dojo-utils.workspace = true
dojo-types.workspace = true
dojo-utils.workspace = true
dojo-world.workspace = true
futures.workspace = true
num-traits.workspace = true
Expand All @@ -21,8 +21,8 @@ serde_json.workspace = true
serde_with.workspace = true
sozo-walnut = { workspace = true, optional = true }
spinoff.workspace = true
starknet.workspace = true
starknet-crypto.workspace = true
starknet.workspace = true
thiserror.workspace = true
toml.workspace = true
tracing.workspace = true
Expand All @@ -33,11 +33,11 @@ katana-runner = { workspace = true, optional = true }
[dev-dependencies]
assert_fs.workspace = true
dojo-test-utils = { workspace = true, features = [ "build-examples" ] }
ipfs-api-backend-hyper = { git = "https://github.com/ferristseng/rust-ipfs-api", rev = "af2c17f7b19ef5b9898f458d97a90055c3605633", features = [ "with-hyper-rustls" ] }
ipfs-api-backend-hyper.workspace = true
katana-runner.workspace = true
tokio.workspace = true
scarb.workspace = true
sozo-scarbext.workspace = true
tokio.workspace = true

[features]
test-utils = [ "dep:dojo-test-utils", "dep:katana-runner" ]
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
6 changes: 4 additions & 2 deletions crates/torii/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bitflags = "2.6.0"
cainome.workspace = true
chrono.workspace = true
crypto-bigint.workspace = true
data-url.workspace = true
dojo-types.workspace = true
dojo-world.workspace = true
futures-channel = "0.3.0"
Expand All @@ -31,8 +32,9 @@ sqlx.workspace = true
starknet-crypto.workspace = true
starknet.workspace = true
thiserror.workspace = true
tokio = { version = "1.32.0", features = [ "sync", "macros" ], default-features = true }
tokio = { version = "1.32.0", features = [ "macros", "sync" ], default-features = true }
# tokio-stream = "0.1.11"
ipfs-api-backend-hyper.workspace = true
tokio-util.workspace = true
tracing.workspace = true

Expand All @@ -41,5 +43,5 @@ dojo-test-utils.workspace = true
dojo-utils.workspace = true
katana-runner.workspace = true
scarb.workspace = true
tempfile.workspace = true
sozo-scarbext.workspace = true
tempfile.workspace = true
3 changes: 3 additions & 0 deletions crates/torii/core/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub const TOKEN_BALANCE_TABLE: &str = "token_balances";
pub const TOKEN_TRANSFER_TABLE: &str = "token_transfers";
pub const TOKENS_TABLE: &str = "tokens";
Loading
Loading