-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(Torii-core): Handle entity deletion events (#1439)
* feat: add store_del_record * feat: Improve fn delete_entity(), add event StoreDelRecordProcessor * Fix: Uncommented database::set * Feat: Improve fn process(), Improve fn delete_entity() * Feat: add fn push_front(),fn build_delete_entity_queries_recursive() * Feat: add fn push_front(),fn build_delete_entity_queries_recursive() * Clean fn delete_entity() * Add tests * Improve current test on model_test, add delete test on model_test * clean * clean code * remove fn delete from spawn-and-move * manifest rollback * enable tests * Clean debug info
- Loading branch information
1 parent
0736cdd
commit 68e2199
Showing
13 changed files
with
265 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
use anyhow::{Error, Ok, Result}; | ||
use async_trait::async_trait; | ||
use dojo_world::contracts::model::ModelReader; | ||
use dojo_world::contracts::world::WorldContractReader; | ||
use starknet::core::types::{BlockWithTxs, Event, InvokeTransactionReceipt}; | ||
use starknet::core::utils::parse_cairo_short_string; | ||
use starknet::providers::Provider; | ||
use tracing::info; | ||
|
||
use super::EventProcessor; | ||
use crate::processors::{MODEL_INDEX, NUM_KEYS_INDEX}; | ||
use crate::sql::Sql; | ||
|
||
#[derive(Default)] | ||
pub struct StoreDelRecordProcessor; | ||
|
||
#[async_trait] | ||
impl<P> EventProcessor<P> for StoreDelRecordProcessor | ||
where | ||
P: Provider + Send + Sync, | ||
{ | ||
fn event_key(&self) -> String { | ||
"StoreDelRecord".to_string() | ||
} | ||
|
||
fn validate(&self, event: &Event) -> bool { | ||
if event.keys.len() > 1 { | ||
info!( | ||
"invalid keys for event {}: {}", | ||
<StoreDelRecordProcessor as EventProcessor<P>>::event_key(self), | ||
<StoreDelRecordProcessor as EventProcessor<P>>::event_keys_as_string(self, event), | ||
); | ||
return false; | ||
} | ||
true | ||
} | ||
|
||
async fn process( | ||
&self, | ||
_world: &WorldContractReader<P>, | ||
db: &mut Sql, | ||
_block: &BlockWithTxs, | ||
_transaction_receipt: &InvokeTransactionReceipt, | ||
_event_id: &str, | ||
event: &Event, | ||
) -> Result<(), Error> { | ||
let name = parse_cairo_short_string(&event.data[MODEL_INDEX])?; | ||
info!("store delete record: {}", name); | ||
|
||
let model = db.model(&name).await?; | ||
|
||
let keys_start = NUM_KEYS_INDEX + 1; | ||
let keys = event.data[keys_start..].to_vec(); | ||
let entity = model.schema().await?; | ||
db.delete_entity(keys, entity).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
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.