Skip to content

Commit

Permalink
fix(torii): only parse events from world address
Browse files Browse the repository at this point in the history
  • Loading branch information
broody committed Jul 28, 2023
1 parent 0b870e1 commit aeae78c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
5 changes: 3 additions & 2 deletions crates/torii/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mod tests;
#[command(author, version, about, long_about = None)]
struct Args {
/// The world to index
#[arg(short, long, default_value = "0x420")]
#[arg(short, long)]
world_address: FieldElement,
/// The rpc endpoint to use
#[arg(long, default_value = "http://localhost:5050")]
Expand Down Expand Up @@ -95,7 +95,8 @@ async fn main() -> anyhow::Result<()> {
..Processors::default()
};

let indexer = Indexer::new(&state, &provider, processors, manifest, args.start_block);
let indexer =
Indexer::new(&state, &provider, processors, manifest, args.world_address, args.start_block);
let graphql = start_graphql(&pool);

tokio::select! {
Expand Down
10 changes: 9 additions & 1 deletion crates/torii/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use starknet::core::types::{
use starknet::core::utils::get_selector_from_name;
use starknet::providers::jsonrpc::{JsonRpcClient, JsonRpcTransport};
use starknet::providers::Provider;
use starknet_crypto::FieldElement;
use tokio::time::sleep;
use tracing::{error, info, warn};

Expand Down Expand Up @@ -42,6 +43,7 @@ pub struct Engine<'a, S: State + Executable, T: JsonRpcTransport + Sync + Send>
storage: &'a S,
provider: &'a JsonRpcClient<T>,
processors: Processors<S, T>,
world_address: FieldElement,
start_block: Option<u64>,
config: EngineConfig,
}
Expand All @@ -51,10 +53,11 @@ impl<'a, S: State + Executable, T: JsonRpcTransport + Sync + Send> Engine<'a, S,
storage: &'a S,
provider: &'a JsonRpcClient<T>,
processors: Processors<S, T>,
world_address: FieldElement,
start_block: Option<u64>,
config: EngineConfig,
) -> Self {
Self { storage, provider, processors, start_block, config }
Self { storage, provider, processors, world_address, start_block, config }
}

pub async fn start(&self) -> Result<(), Box<dyn Error>> {
Expand Down Expand Up @@ -155,6 +158,11 @@ impl<'a, S: State + Executable, T: JsonRpcTransport + Sync + Send> Engine<'a, S,

if let TransactionReceipt::Invoke(invoke_receipt) = receipt.clone() {
for event in &invoke_receipt.events {
if event.from_address != self.world_address {
info!("event not from world address, skipping");
continue;
}

process_event(
self.storage,
self.provider,
Expand Down
12 changes: 10 additions & 2 deletions crates/torii/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::error::Error;

use dojo_world::manifest::Manifest;
use starknet::providers::jsonrpc::{JsonRpcClient, JsonRpcTransport};
use starknet_crypto::FieldElement;
use tracing::info;

use crate::engine::{Engine, EngineConfig, Processors};
Expand All @@ -22,10 +23,17 @@ impl<'a, S: State + Executable, T: JsonRpcTransport + Sync + Send> Indexer<'a, S
provider: &'a JsonRpcClient<T>,
processors: Processors<S, T>,
manifest: Manifest,
world_address: FieldElement,
start_block: Option<u64>,
) -> Self {
let engine =
Engine::new(storage, provider, processors, start_block, EngineConfig::default());
let engine = Engine::new(
storage,
provider,
processors,
world_address,
start_block,
EngineConfig::default(),
);
Self { storage, provider, engine, manifest }
}

Expand Down

0 comments on commit aeae78c

Please sign in to comment.