Skip to content

Commit

Permalink
change table schema and core implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lambda-0x committed Aug 18, 2024
1 parent 705b55a commit 62a4f34
Show file tree
Hide file tree
Showing 7 changed files with 263 additions and 95 deletions.
13 changes: 7 additions & 6 deletions bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,14 @@ async fn main() -> anyhow::Result<()> {
// Get world address
let world = WorldContractReader::new(args.world_address, &provider);

let erc_contracts = config
.erc_contracts
.iter()
.map(|contract| (contract.contract_address, contract.clone()))
.collect();
let class_hash =
provider.get_class_hash_at(BlockId::Tag(BlockTag::Pending), args.world_address).await?;
let db = Sql::new(pool.clone(), args.world_address, class_hash).await?;
let db = Sql::new(pool.clone(), args.world_address, class_hash, &erc_contracts).await?;
let processors = Processors {
event: vec![
Box::new(RegisterModelProcessor),
Expand Down Expand Up @@ -229,11 +234,7 @@ async fn main() -> anyhow::Result<()> {
},
shutdown_tx.clone(),
Some(block_tx),
config
.erc_contracts
.iter()
.map(|contract| (contract.contract_address, contract.clone()))
.collect(),
erc_contracts,
);

let shutdown_rx = shutdown_tx.subscribe();
Expand Down
4 changes: 2 additions & 2 deletions crates/torii/core/src/processors/erc20_legacy_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where

async fn process(
&self,
_world: &WorldContractReader<P>,
world: &WorldContractReader<P>,
db: &mut Sql,
_block_number: u64,
_block_timestamp: u64,
Expand All @@ -50,7 +50,7 @@ where
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).await?;
db.handle_erc20_transfer(token_address, from, to, value, world.provider()).await?;
info!(target: LOG_TARGET,from = ?from, to = ?to, value = ?value, "Legacy ERC20 Transfer");

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions crates/torii/core/src/processors/erc20_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ where

async fn process(
&self,
_world: &WorldContractReader<P>,
world: &WorldContractReader<P>,
db: &mut Sql,
_block_number: u64,
_block_timestamp: u64,
Expand All @@ -50,7 +50,7 @@ where
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).await?;
db.handle_erc20_transfer(token_address, from, to, value, world.provider()).await?;
info!(target: LOG_TARGET,from = ?from, to = ?to, value = ?value, "ERC20 Transfer");

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions crates/torii/core/src/processors/erc721_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where

async fn process(
&self,
_world: &WorldContractReader<P>,
world: &WorldContractReader<P>,
db: &mut Sql,
_block_number: u64,
_block_timestamp: u64,
Expand All @@ -51,7 +51,7 @@ where
let token_id = U256Cainome::cairo_deserialize(&event.keys, 3)?;
let token_id = U256::from_words(token_id.low, token_id.high);

db.handle_erc721_transfer(token_address, from, to, token_id).await?;
db.handle_erc721_transfer(token_address, from, to, token_id, world.provider()).await?;
info!(target: LOG_TARGET, from = ?from, to = ?to, token_id = ?token_id, "ERC721 Transfer");

Ok(())
Expand Down
Loading

0 comments on commit 62a4f34

Please sign in to comment.