Skip to content

Commit

Permalink
feat(torii): fetch and process erc721 metadata and image
Browse files Browse the repository at this point in the history
commit-id:274aaa3a
  • Loading branch information
lambda-0x committed Oct 20, 2024
1 parent a5d7c4a commit 48c880f
Show file tree
Hide file tree
Showing 19 changed files with 1,279 additions and 165 deletions.
490 changes: 485 additions & 5 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,16 @@ clap_complete = "4.3"
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"
http = "0.2.9"
image = "0.25.2"
indexmap = "2.2.5"
indoc = "1.0.7"
itertools = "0.12.1"
Expand Down
35 changes: 29 additions & 6 deletions bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use std::sync::Arc;
use std::time::Duration;

use anyhow::Context;
use camino::Utf8PathBuf;
use clap::{ArgAction, Parser};
use dojo_metrics::exporters::prometheus::PrometheusRecorder;
use dojo_utils::parse::{parse_socket_address, parse_url};
Expand Down Expand Up @@ -146,6 +147,10 @@ struct Args {
/// Configuration file
#[arg(long)]
config: Option<PathBuf>,

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

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

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L153

Added line #L153 was not covered by tests
}

#[tokio::main]
Expand Down Expand Up @@ -213,7 +218,8 @@ async fn main() -> anyhow::Result<()> {
let contracts =
config.contracts.iter().map(|contract| (contract.address, contract.r#type)).collect();

let (mut executor, sender) = Executor::new(pool.clone(), shutdown_tx.clone()).await?;
let (mut executor, sender) =
Executor::new(pool.clone(), shutdown_tx.clone(), args.artifacts_path.clone()).await?;

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

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L221-L222

Added lines #L221 - L222 were not covered by tests
tokio::spawn(async move {
executor.run().await.unwrap();
});
Expand Down Expand Up @@ -254,10 +260,19 @@ async fn main() -> anyhow::Result<()> {
Arc::new(contracts),
);

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))
.await?;
let (grpc_addr, grpc_server) = torii_grpc::server::new(
shutdown_tx.subscribe(),
&pool,
block_rx,
world_address,
Arc::clone(&provider),
)
.await?;

tokio::fs::create_dir_all(args.artifacts_path.clone()).await?;
let absolute_path = args.artifacts_path.canonicalize()?;
let (artifacts_addr, artifacts_server) =
torii_server::artifacts::new(shutdown_tx.subscribe(), absolute_path).await?;

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

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L263-L275

Added lines #L263 - L275 were not covered by tests

let mut libp2p_relay_server = torii_relay::server::Relay::new(
db,
Expand All @@ -270,7 +285,13 @@ 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,
args.allowed_origins,
Some(grpc_addr),
None,
Some(artifacts_addr),
));

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

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L288-L294

Added lines #L288 - L294 were not covered by tests

let graphql_server = spawn_rebuilding_graphql_server(
shutdown_tx.clone(),
Expand Down Expand Up @@ -308,13 +329,15 @@ 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);

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

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L332

Added line #L332 was not covered by tests

tokio::select! {
res = engine_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?,

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

View check run for this annotation

Codecov / codecov/patch

bin/torii/src/main.rs#L340

Added line #L340 was not covered by tests
_ = dojo_utils::signal::wait_signals() => {},
};

Expand Down
4 changes: 4 additions & 0 deletions crates/torii/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ async-trait.workspace = true
base64.workspace = true
bitflags = "2.6.0"
cainome.workspace = true
camino.workspace = true
chrono.workspace = true
crypto-bigint.workspace = true
data-url.workspace = true
dojo-types.workspace = true
dojo-world = { workspace = true, features = [ "contracts", "manifest" ] }
fluent-uri.workspace = true
futures-channel = "0.3.0"
futures-util.workspace = true
hashlink.workspace = true
image.workspace = true
num-traits.workspace = true
once_cell.workspace = true
reqwest.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/torii/core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ impl<P: Provider + Send + Sync + std::fmt::Debug + 'static> Engine<P> {

match self.process(fetch_result).await {
Ok(_) => {
self.db.execute().await?;
self.db.flush().await?;
self.db.apply_cache_diff().await?;
self.db.execute().await?;
},
Err(e) => {
error!(target: LOG_TARGET, error = %e, "Processing fetched data.");
Expand Down
Loading

0 comments on commit 48c880f

Please sign in to comment.