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

refactor(torii): clean up ercs branch and few fixes #2491

Merged
merged 5 commits into from
Oct 2, 2024
Merged
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
9 changes: 2 additions & 7 deletions crates/torii/core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
use crate::processors::store_update_member::StoreUpdateMemberProcessor;
use crate::processors::store_update_record::StoreUpdateRecordProcessor;
use crate::processors::{BlockProcessor, EventProcessor, TransactionProcessor};
use crate::sql::utils::I256;
use crate::sql::{Cursors, Sql};
use crate::types::ContractType;

Expand Down Expand Up @@ -193,7 +192,6 @@
block_tx: Option<BoundedSender<u64>>,
tasks: HashMap<u64, Vec<(ContractType, ParallelizedEvent)>>,
contracts: Arc<HashMap<Felt, ContractType>>,
cache: HashMap<String, I256>,
}

struct UnprocessedEvent {
Expand Down Expand Up @@ -223,7 +221,6 @@
block_tx,
contracts,
tasks: HashMap::new(),
cache: HashMap::new(),
}
}

Expand Down Expand Up @@ -458,7 +455,7 @@
}
FetchDataResult::None => {}
}
self.db.apply_cache_diff(&mut self.cache).await?;
self.db.apply_cache_diff().await?;

Check warning on line 458 in crates/torii/core/src/engine.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/core/src/engine.rs#L458

Added line #L458 was not covered by tests

Ok(())
}
Expand Down Expand Up @@ -577,7 +574,7 @@
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, None, block_number, block_timestamp, &event_id, &event)
.process(&world, &mut local_db, block_number, block_timestamp, &event_id, &event)
.await
{
error!(target: LOG_TARGET, event_name = processor.event_key(), error = %e, task_id = %task_id, "Processing parallelized event.");
Expand Down Expand Up @@ -765,7 +762,6 @@
.process(
&self.world,
&mut self.db,
None,
block_number,
block_timestamp,
event_id,
Expand Down Expand Up @@ -825,7 +821,6 @@
.process(
&self.world,
&mut self.db,
Some(&mut self.cache),
block_number,
block_timestamp,
event_id,
Expand Down
1 change: 0 additions & 1 deletion crates/torii/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub mod cache;
pub mod engine;
pub mod error;
pub mod model;
Expand Down
16 changes: 2 additions & 14 deletions crates/torii/core/src/processors/erc20_legacy_transfer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use anyhow::Error;
use async_trait::async_trait;
use cainome::cairo_serde::{CairoSerde, U256 as U256Cainome};
Expand All @@ -9,7 +7,6 @@
use tracing::debug;

use super::EventProcessor;
use crate::sql::utils::I256;
use crate::sql::Sql;

pub(crate) const LOG_TARGET: &str = "torii_core::processors::erc20_legacy_transfer";
Expand Down Expand Up @@ -41,7 +38,6 @@
&self,
world: &WorldContractReader<P>,
db: &mut Sql,
cache: Option<&mut HashMap<String, I256>>,
_block_number: u64,
block_timestamp: u64,
_event_id: &str,
Expand All @@ -54,16 +50,8 @@
let value = U256Cainome::cairo_deserialize(&event.data, 2)?;
let value = U256::from_words(value.low, value.high);

db.handle_erc20_transfer(
token_address,
from,
to,
value,
world.provider(),
block_timestamp,
cache.expect("cache is required"),
)
.await?;
db.handle_erc20_transfer(token_address, from, to, value, world.provider(), block_timestamp)
.await?;

Check warning on line 54 in crates/torii/core/src/processors/erc20_legacy_transfer.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/core/src/processors/erc20_legacy_transfer.rs#L53-L54

Added lines #L53 - L54 were not covered by tests
debug!(target: LOG_TARGET,from = ?from, to = ?to, value = ?value, "Legacy ERC20 Transfer");

Ok(())
Expand Down
16 changes: 2 additions & 14 deletions crates/torii/core/src/processors/erc20_transfer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use anyhow::Error;
use async_trait::async_trait;
use cainome::cairo_serde::{CairoSerde, U256 as U256Cainome};
Expand All @@ -9,7 +7,6 @@
use tracing::debug;

use super::EventProcessor;
use crate::sql::utils::I256;
use crate::sql::Sql;

pub(crate) const LOG_TARGET: &str = "torii_core::processors::erc20_transfer";
Expand Down Expand Up @@ -41,7 +38,6 @@
&self,
world: &WorldContractReader<P>,
db: &mut Sql,
cache: Option<&mut HashMap<String, I256>>,
_block_number: u64,
block_timestamp: u64,
_event_id: &str,
Expand All @@ -54,16 +50,8 @@
let value = U256Cainome::cairo_deserialize(&event.data, 0)?;
let value = U256::from_words(value.low, value.high);

db.handle_erc20_transfer(
token_address,
from,
to,
value,
world.provider(),
block_timestamp,
cache.expect("cache is required"),
)
.await?;
db.handle_erc20_transfer(token_address, from, to, value, world.provider(), block_timestamp)
.await?;

Check warning on line 54 in crates/torii/core/src/processors/erc20_transfer.rs

View check run for this annotation

Codecov / codecov/patch

crates/torii/core/src/processors/erc20_transfer.rs#L53-L54

Added lines #L53 - L54 were not covered by tests
debug!(target: LOG_TARGET,from = ?from, to = ?to, value = ?value, "ERC20 Transfer");

Ok(())
Expand Down
5 changes: 0 additions & 5 deletions crates/torii/core/src/processors/erc721_legacy_transfer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use anyhow::Error;
use async_trait::async_trait;
use cainome::cairo_serde::{CairoSerde, U256 as U256Cainome};
Expand All @@ -9,7 +7,6 @@ use starknet::providers::Provider;
use tracing::debug;

use super::EventProcessor;
use crate::sql::utils::I256;
use crate::sql::Sql;

pub(crate) const LOG_TARGET: &str = "torii_core::processors::erc721_legacy_transfer";
Expand Down Expand Up @@ -41,7 +38,6 @@ where
&self,
world: &WorldContractReader<P>,
db: &mut Sql,
cache: Option<&mut HashMap<String, I256>>,
_block_number: u64,
block_timestamp: u64,
_event_id: &str,
Expand All @@ -61,7 +57,6 @@ where
token_id,
world.provider(),
block_timestamp,
cache.expect("cache is required"),
)
.await?;
debug!(target: LOG_TARGET, from = ?from, to = ?to, token_id = ?token_id, "ERC721 Transfer");
Expand Down
5 changes: 0 additions & 5 deletions crates/torii/core/src/processors/erc721_transfer.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use anyhow::Error;
use async_trait::async_trait;
use cainome::cairo_serde::{CairoSerde, U256 as U256Cainome};
Expand All @@ -9,7 +7,6 @@ use starknet::providers::Provider;
use tracing::debug;

use super::EventProcessor;
use crate::sql::utils::I256;
use crate::sql::Sql;

pub(crate) const LOG_TARGET: &str = "torii_core::processors::erc721_transfer";
Expand Down Expand Up @@ -41,7 +38,6 @@ where
&self,
world: &WorldContractReader<P>,
db: &mut Sql,
cache: Option<&mut HashMap<String, I256>>,
_block_number: u64,
block_timestamp: u64,
_event_id: &str,
Expand All @@ -61,7 +57,6 @@ where
token_id,
world.provider(),
block_timestamp,
cache.expect("cache is required"),
)
.await?;
debug!(target: LOG_TARGET, from = ?from, to = ?to, token_id = ?token_id, "ERC721 Transfer");
Expand Down
4 changes: 0 additions & 4 deletions crates/torii/core/src/processors/event_message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use anyhow::{Error, Result};
use async_trait::async_trait;
use dojo_world::contracts::world::WorldContractReader;
Expand All @@ -9,7 +7,6 @@ use tracing::info;

use super::EventProcessor;
use crate::processors::MODEL_INDEX;
use crate::sql::utils::I256;
use crate::sql::Sql;

pub(crate) const LOG_TARGET: &str = "torii_core::processors::event_message";
Expand Down Expand Up @@ -42,7 +39,6 @@ where
&self,
_world: &WorldContractReader<P>,
db: &mut Sql,
_cache: Option<&mut HashMap<String, I256>>,
_block_number: u64,
block_timestamp: u64,
event_id: &str,
Expand Down
3 changes: 0 additions & 3 deletions crates/torii/core/src/processors/metadata_update.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::time::Duration;

use anyhow::{Error, Result};
Expand All @@ -16,7 +15,6 @@ use tokio_util::bytes::Bytes;
use tracing::{error, info};

use super::EventProcessor;
use crate::sql::utils::I256;
use crate::sql::Sql;

const IPFS_URL: &str = "https://cartridge.infura-ipfs.io/ipfs/";
Expand Down Expand Up @@ -53,7 +51,6 @@ where
&self,
_world: &WorldContractReader<P>,
db: &mut Sql,
_cache: Option<&mut HashMap<String, I256>>,
_block_number: u64,
block_timestamp: u64,
_event_id: &str,
Expand Down
4 changes: 0 additions & 4 deletions crates/torii/core/src/processors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use std::collections::HashMap;

use anyhow::{Error, Result};
use async_trait::async_trait;
use dojo_world::contracts::world::WorldContractReader;
use starknet::core::types::{Event, Felt, Transaction};
use starknet::providers::Provider;

use crate::sql::utils::I256;
use crate::sql::Sql;

pub mod erc20_legacy_transfer;
Expand Down Expand Up @@ -44,7 +41,6 @@ where
&self,
world: &WorldContractReader<P>,
db: &mut Sql,
cache: Option<&mut HashMap<String, I256>>,
block_number: u64,
block_timestamp: u64,
event_id: &str,
Expand Down
4 changes: 0 additions & 4 deletions crates/torii/core/src/processors/register_model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use anyhow::{Error, Ok, Result};
use async_trait::async_trait;
use cainome::cairo_serde::{ByteArray, CairoSerde};
Expand All @@ -10,7 +8,6 @@ use starknet::providers::Provider;
use tracing::{debug, info};

use super::EventProcessor;
use crate::sql::utils::I256;
use crate::sql::Sql;

pub(crate) const LOG_TARGET: &str = "torii_core::processors::register_model";
Expand Down Expand Up @@ -44,7 +41,6 @@ where
&self,
world: &WorldContractReader<P>,
db: &mut Sql,
_cache: Option<&mut HashMap<String, I256>>,
_block_number: u64,
block_timestamp: u64,
_event_id: &str,
Expand Down
4 changes: 0 additions & 4 deletions crates/torii/core/src/processors/store_del_record.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use anyhow::{Error, Ok, Result};
use async_trait::async_trait;
use dojo_world::contracts::world::WorldContractReader;
Expand All @@ -9,7 +7,6 @@ use tracing::info;

use super::EventProcessor;
use crate::processors::{ENTITY_ID_INDEX, MODEL_INDEX};
use crate::sql::utils::I256;
use crate::sql::Sql;

pub(crate) const LOG_TARGET: &str = "torii_core::processors::store_del_record";
Expand Down Expand Up @@ -43,7 +40,6 @@ where
&self,
_world: &WorldContractReader<P>,
db: &mut Sql,
_cache: Option<&mut HashMap<String, I256>>,
_block_number: u64,
block_timestamp: u64,
event_id: &str,
Expand Down
5 changes: 1 addition & 4 deletions crates/torii/core/src/processors/store_set_record.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use anyhow::{Context, Error, Ok, Result};
use async_trait::async_trait;
use dojo_world::contracts::world::WorldContractReader;
Expand All @@ -10,7 +8,7 @@ use tracing::info;

use super::EventProcessor;
use crate::processors::{ENTITY_ID_INDEX, MODEL_INDEX, NUM_KEYS_INDEX};
use crate::sql::utils::{felts_to_sql_string, I256};
use crate::sql::utils::felts_to_sql_string;
use crate::sql::Sql;

pub(crate) const LOG_TARGET: &str = "torii_core::processors::store_set_record";
Expand Down Expand Up @@ -44,7 +42,6 @@ where
&self,
_world: &WorldContractReader<P>,
db: &mut Sql,
_cache: Option<&mut HashMap<String, I256>>,
_block_number: u64,
block_timestamp: u64,
event_id: &str,
Expand Down
4 changes: 0 additions & 4 deletions crates/torii/core/src/processors/store_update_member.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use anyhow::{Context, Error, Result};
use async_trait::async_trait;
use dojo_types::schema::{Struct, Ty};
Expand All @@ -13,7 +11,6 @@ use tracing::{info, warn};

use super::EventProcessor;
use crate::processors::{ENTITY_ID_INDEX, MODEL_INDEX};
use crate::sql::utils::I256;
use crate::sql::Sql;

pub(crate) const LOG_TARGET: &str = "torii_core::processors::store_update_member";
Expand Down Expand Up @@ -49,7 +46,6 @@ where
&self,
_world: &WorldContractReader<P>,
db: &mut Sql,
_cache: Option<&mut HashMap<String, I256>>,
_block_number: u64,
block_timestamp: u64,
event_id: &str,
Expand Down
4 changes: 0 additions & 4 deletions crates/torii/core/src/processors/store_update_record.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::collections::HashMap;

use anyhow::{Context, Error, Ok, Result};
use async_trait::async_trait;
use dojo_types::schema::Ty;
Expand All @@ -11,7 +9,6 @@ use tracing::info;

use super::EventProcessor;
use crate::processors::{ENTITY_ID_INDEX, MODEL_INDEX};
use crate::sql::utils::I256;
use crate::sql::Sql;

pub(crate) const LOG_TARGET: &str = "torii_core::processors::store_update_record";
Expand Down Expand Up @@ -45,7 +42,6 @@ where
&self,
_world: &WorldContractReader<P>,
db: &mut Sql,
_cache: Option<&mut HashMap<String, I256>>,
_block_number: u64,
block_timestamp: u64,
event_id: &str,
Expand Down
Loading
Loading