From 860330b3fc1e33b1b2f09e668132142bda807df9 Mon Sep 17 00:00:00 2001 From: Nasr Date: Fri, 5 Sep 2025 15:55:41 +0100 Subject: [PATCH] refactor(c): update callback entity --- dojo.h | 22 ++++++++++------------ dojo.hpp | 4 ++-- dojo.pyx | 18 +++++++++--------- src/c/mod.rs | 14 ++++---------- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/dojo.h b/dojo.h index 5fe0a87..b1bcee3 100644 --- a/dojo.h +++ b/dojo.h @@ -600,6 +600,14 @@ typedef struct CArrayStruct { uintptr_t data_len; } CArrayStruct; +typedef struct Entity { + struct FieldElement hashed_keys; + struct CArrayStruct models; + uint64_t created_at; + uint64_t updated_at; + uint64_t executed_at; +} Entity; + typedef struct Event { struct CArrayFieldElement keys; struct CArrayFieldElement data; @@ -869,14 +877,6 @@ typedef struct OrderBy { enum OrderDirection direction; } OrderBy; -typedef struct Entity { - struct FieldElement hashed_keys; - struct CArrayStruct models; - uint64_t created_at; - uint64_t updated_at; - uint64_t executed_at; -} Entity; - typedef enum COptionFieldElement_Tag { SomeFieldElement, NoneFieldElement, @@ -1294,8 +1294,7 @@ struct ResultSubscription client_on_transaction(struct ToriiClient *client, */ struct ResultSubscription client_on_entity_state_update(struct ToriiClient *client, struct COptionClause clause, - void (*callback)(struct FieldElement, - struct CArrayStruct)); + void (*callback)(struct Entity)); /** * Updates an existing entity subscription with new clauses @@ -1327,8 +1326,7 @@ struct Resultbool client_update_entity_subscription(struct ToriiClient *client, */ struct ResultSubscription client_on_event_message_update(struct ToriiClient *client, struct COptionClause clause, - void (*callback)(struct FieldElement, - struct CArrayStruct)); + void (*callback)(struct Entity)); /** * Updates an existing event message subscription diff --git a/dojo.hpp b/dojo.hpp index 9b58733..4697ccc 100644 --- a/dojo.hpp +++ b/dojo.hpp @@ -1244,7 +1244,7 @@ Result client_on_transaction(ToriiClient *client, /// Result containing pointer to Subscription or error Result client_on_entity_state_update(ToriiClient *client, COption clause, - void (*callback)(FieldElement, CArray)); + void (*callback)(Entity)); /// Updates an existing entity subscription with new clauses /// @@ -1272,7 +1272,7 @@ Result client_update_entity_subscription(ToriiClient *client, /// Result containing pointer to Subscription or error Result client_on_event_message_update(ToriiClient *client, COption clause, - void (*callback)(FieldElement, CArray)); + void (*callback)(Entity)); /// Updates an existing event message subscription /// diff --git a/dojo.pyx b/dojo.pyx index 3f4c437..0be60ce 100644 --- a/dojo.pyx +++ b/dojo.pyx @@ -388,6 +388,13 @@ cdef extern from *: Struct *data; uintptr_t data_len; + cdef struct Entity: + FieldElement hashed_keys; + CArrayStruct models; + uint64_t created_at; + uint64_t updated_at; + uint64_t executed_at; + cdef struct Event: CArrayFieldElement keys; CArrayFieldElement data; @@ -561,13 +568,6 @@ cdef extern from *: const char *field; OrderDirection direction; - cdef struct Entity: - FieldElement hashed_keys; - CArrayStruct models; - uint64_t created_at; - uint64_t updated_at; - uint64_t executed_at; - cdef enum COptionFieldElement_Tag: SomeFieldElement, NoneFieldElement, @@ -903,7 +903,7 @@ cdef extern from *: # Result containing pointer to Subscription or error ResultSubscription client_on_entity_state_update(ToriiClient *client, COptionClause clause, - void (*callback)(FieldElement, CArrayStruct)); + void (*callback)(Entity)); # Updates an existing entity subscription with new clauses # @@ -931,7 +931,7 @@ cdef extern from *: # Result containing pointer to Subscription or error ResultSubscription client_on_event_message_update(ToriiClient *client, COptionClause clause, - void (*callback)(FieldElement, CArrayStruct)); + void (*callback)(Entity)); # Updates an existing event message subscription # diff --git a/src/c/mod.rs b/src/c/mod.rs index f73cd36..f29e572 100644 --- a/src/c/mod.rs +++ b/src/c/mod.rs @@ -925,7 +925,7 @@ pub unsafe extern "C" fn client_on_transaction( pub unsafe extern "C" fn client_on_entity_state_update( client: *mut ToriiClient, clause: COption, - callback: unsafe extern "C" fn(types::FieldElement, CArray), + callback: unsafe extern "C" fn(Entity), ) -> Result<*mut Subscription> { let client = Arc::new(unsafe { &*client }); let (trigger, tripwire) = Tripwire::new(); @@ -952,10 +952,7 @@ pub unsafe extern "C" fn client_on_entity_state_update( if let Some(tx) = sub_id_tx.take() { tx.send(id).expect("Failed to send subscription ID"); } else { - let key: types::FieldElement = entity.hashed_keys.into(); - let models: Vec = - entity.models.into_iter().map(|e| e.into()).collect(); - callback(key, models.into()); + callback(entity.into()); } } } @@ -1023,7 +1020,7 @@ pub unsafe extern "C" fn client_update_entity_subscription( pub unsafe extern "C" fn client_on_event_message_update( client: *mut ToriiClient, clause: COption, - callback: unsafe extern "C" fn(types::FieldElement, CArray), + callback: unsafe extern "C" fn(Entity), ) -> Result<*mut Subscription> { let client = Arc::new(unsafe { &*client }); let clause: Option = clause.map(|c| c.into()).into(); @@ -1049,10 +1046,7 @@ pub unsafe extern "C" fn client_on_event_message_update( if let Some(tx) = sub_id_tx.take() { tx.send(id).expect("Failed to send subscription ID"); } else { - let key: types::FieldElement = entity.hashed_keys.into(); - let models: Vec = - entity.models.into_iter().map(|e| e.into()).collect(); - callback(key, models.into()); + callback(entity.into()); } } }