Skip to content
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
22 changes: 10 additions & 12 deletions dojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions dojo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ Result<Subscription*> client_on_transaction(ToriiClient *client,
/// Result containing pointer to Subscription or error
Result<Subscription*> client_on_entity_state_update(ToriiClient *client,
COption<Clause> clause,
void (*callback)(FieldElement, CArray<Struct>));
void (*callback)(Entity));

/// Updates an existing entity subscription with new clauses
///
Expand Down Expand Up @@ -1272,7 +1272,7 @@ Result<bool> client_update_entity_subscription(ToriiClient *client,
/// Result containing pointer to Subscription or error
Result<Subscription*> client_on_event_message_update(ToriiClient *client,
COption<Clause> clause,
void (*callback)(FieldElement, CArray<Struct>));
void (*callback)(Entity));

/// Updates an existing event message subscription
///
Expand Down
18 changes: 9 additions & 9 deletions dojo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
#
Expand Down Expand Up @@ -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
#
Expand Down
14 changes: 4 additions & 10 deletions src/c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Clause>,
callback: unsafe extern "C" fn(types::FieldElement, CArray<Struct>),
callback: unsafe extern "C" fn(Entity),
) -> Result<*mut Subscription> {
let client = Arc::new(unsafe { &*client });
let (trigger, tripwire) = Tripwire::new();
Expand All @@ -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<Struct> =
entity.models.into_iter().map(|e| e.into()).collect();
callback(key, models.into());
callback(entity.into());
}
}
}
Expand Down Expand Up @@ -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<Clause>,
callback: unsafe extern "C" fn(types::FieldElement, CArray<Struct>),
callback: unsafe extern "C" fn(Entity),
) -> Result<*mut Subscription> {
let client = Arc::new(unsafe { &*client });
let clause: Option<torii_proto::Clause> = clause.map(|c| c.into()).into();
Expand All @@ -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<Struct> =
entity.models.into_iter().map(|e| e.into()).collect();
callback(key, models.into());
callback(entity.into());
}
}
}
Expand Down