forked from starkware-libs/blockifier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add eventmessage for emitting models & start refactoring emit m…
…acro (starkware-libs#1656) * feat: add eventmessage for emitting models & start refactoring emit macro * refactor: emit multiple models event * feat: event message processor * feat: emit_message world func emit event mssage * refactor: catch all event processor * refactor: check model key as name * feat: model name keccak as id & rework model events * fix: storing entities with model hash * refactor: catch all event message and store * feat: emit model evrnt from spawn and move spawn * fix: pass keys as array * feat: fix emit macro and correctly index model events * feat: event messages migrations & set * feat: store events messages and new id system * chore: fmt * fix: keys array * feat: add grpc endpoint for event messages * feat: graphql schema for event messages * cadd comments for moel name hash * revert world.cario changes * fix: graphql entity and model connection * refactor: only test models name ordering * fix: entity/modeldata relation * refactor: remove event testing * fix: cairo code * refactor: add back event rxample * fix: merge * chore: migration * fix: subscription test * fix: tests * fix: subscription test * fix: sql test * chore: format model id correctly in test * fix: model subscription with id * fix: schema for model * chore: revert modelmmeber type * fix: event message query
- Loading branch information
Showing
27 changed files
with
911 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use anyhow::{Error, Result}; | ||
use async_trait::async_trait; | ||
use dojo_world::contracts::model::ModelReader; | ||
use dojo_world::contracts::world::WorldContractReader; | ||
use starknet::core::types::{Event, TransactionReceipt}; | ||
use starknet::providers::Provider; | ||
use tracing::info; | ||
|
||
use super::EventProcessor; | ||
use crate::processors::MODEL_INDEX; | ||
use crate::sql::Sql; | ||
|
||
#[derive(Default)] | ||
pub struct EventMessageProcessor; | ||
|
||
#[async_trait] | ||
impl<P> EventProcessor<P> for EventMessageProcessor | ||
where | ||
P: Provider + Send + Sync, | ||
{ | ||
fn event_key(&self) -> String { | ||
"".to_string() | ||
} | ||
|
||
fn validate(&self, event: &Event) -> bool { | ||
// we expect at least 3 keys | ||
// 1: event selector | ||
// 2: model keys, arbitrary length | ||
// last key: system key | ||
if event.keys.len() < 3 { | ||
return false; | ||
} | ||
|
||
true | ||
} | ||
|
||
async fn process( | ||
&self, | ||
_world: &WorldContractReader<P>, | ||
db: &mut Sql, | ||
_block_number: u64, | ||
_transaction_receipt: &TransactionReceipt, | ||
event_id: &str, | ||
event: &Event, | ||
) -> Result<(), Error> { | ||
// silently ignore if the model is not found | ||
let model = match db.model(&format!("{:#x}", event.keys[MODEL_INDEX])).await { | ||
Ok(model) => model, | ||
Err(_) => return Ok(()), | ||
}; | ||
|
||
info!("store event message: {}", model.name()); | ||
|
||
// skip the first key, as its the event selector | ||
// and dont include last key as its the system key | ||
let mut keys_and_unpacked = | ||
[event.keys[1..event.keys.len() - 1].to_vec(), event.data.clone()].concat(); | ||
|
||
let mut entity = model.schema().await?; | ||
entity.deserialize(&mut keys_and_unpacked)?; | ||
|
||
db.set_event_message(entity, event_id).await?; | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.