Skip to content

feat: update types for entity metadata #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
32 changes: 18 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ crate-type = ["cdylib", "rlib", "staticlib"]
[dependencies]
dojo-world = { git = "https://github.com/dojoengine/dojo", rev = "4145801" }
dojo-types = { git = "https://github.com/dojoengine/dojo", rev = "4145801" }
torii-proto = { git = "https://github.com/dojoengine/torii", rev = "3ae9b23" }
torii-client = { git = "https://github.com/dojoengine/torii", rev = "3ae9b23" }
torii-grpc-client = { git = "https://github.com/dojoengine/torii", rev = "3ae9b23" }
torii-typed-data = { git = "https://github.com/dojoengine/torii", rev = "3ae9b23" }
torii-libp2p-types = { git = "https://github.com/dojoengine/torii", rev = "3ae9b23" }
torii-proto = { git = "https://github.com/dojoengine/torii", rev = "ae0420b" }
torii-client = { git = "https://github.com/dojoengine/torii", rev = "ae0420b" }
torii-grpc-client = { git = "https://github.com/dojoengine/torii", rev = "ae0420b" }
torii-typed-data = { git = "https://github.com/dojoengine/torii", rev = "ae0420b" }
torii-libp2p-types = { git = "https://github.com/dojoengine/torii", rev = "ae0420b" }

starknet = "0.13.0"
starknet-crypto = "0.7.2"
Expand Down Expand Up @@ -50,6 +50,7 @@ instant = { version = "0.1.13", features = ["wasm-bindgen"] }
gloo-timers = { version = "0.3.0", features = ["futures"] }
num-bigint = "0.4.6"
num-traits = "0.2.19"
chrono = "0.4.41"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
axum = "0.8.1"
Expand All @@ -71,4 +72,4 @@ base64 = "0.22.1"
cbindgen = { git = "https://github.com/masnagam/cbindgen", branch = "fix-issue-43" }

[patch.crates-io]
crunchy = { git = "https://github.com/nmathewson/crunchy", branch = "cross-compilation-fix" }
crunchy = { git = "https://github.com/nmathewson/crunchy", branch = "cross-compilation-fix" }
5 changes: 5 additions & 0 deletions dojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,11 @@ typedef struct Controller {
typedef struct Entity {
struct FieldElement hashed_keys;
struct CArrayStruct models;
const char *event_id;
uint64_t executed_at_timestamp;
uint64_t created_at_timestamp;
uint64_t updated_at_timestamp;
bool is_deleted;
} Entity;

typedef struct OrderBy {
Expand Down
5 changes: 5 additions & 0 deletions dojo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ struct Struct {
struct Entity {
FieldElement hashed_keys;
CArray<Struct> models;
const char *event_id;
uint64_t executed_at_timestamp;
uint64_t created_at_timestamp;
uint64_t updated_at_timestamp;
bool is_deleted;
};

template<typename T>
Expand Down
5 changes: 5 additions & 0 deletions dojo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,11 @@ cdef extern from *:
cdef struct Entity:
FieldElement hashed_keys;
CArrayStruct models;
const char *event_id;
uint64_t executed_at_timestamp;
uint64_t created_at_timestamp;
uint64_t updated_at_timestamp;
bool is_deleted;

cdef struct OrderBy:
const char *model;
Expand Down
27 changes: 24 additions & 3 deletions src/c/types.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::ffi::{c_char, CStr, CString};
use std::ffi::{CStr, CString, c_char};

use crypto_bigint::Encoding;
use starknet::core::utils::get_selector_from_name;
Expand Down Expand Up @@ -678,22 +678,43 @@ pub enum ValueType {
pub struct Entity {
pub hashed_keys: FieldElement,
pub models: CArray<Struct>,
pub event_id: *const c_char,
pub executed_at_timestamp: u64,
pub created_at_timestamp: u64,
pub updated_at_timestamp: u64,
pub is_deleted: bool,
}

impl From<Entity> for torii_proto::schema::Entity {
fn from(val: Entity) -> Self {
let models: Vec<Struct> = val.models.into();
let models = models.into_iter().map(|m| m.into()).collect();

torii_proto::schema::Entity { hashed_keys: val.hashed_keys.into(), models }
torii_proto::schema::Entity {
hashed_keys: val.hashed_keys.into(),
models,
event_id: unsafe { CStr::from_ptr(val.event_id).to_string_lossy().to_string() },
executed_at: val.executed_at_timestamp,
created_at: val.created_at_timestamp,
updated_at: val.updated_at_timestamp,
is_deleted: val.is_deleted,
}
}
}

impl From<torii_proto::schema::Entity> for Entity {
fn from(val: torii_proto::schema::Entity) -> Self {
let models = val.models.into_iter().map(|m| m.into()).collect::<Vec<Struct>>();

Entity { hashed_keys: val.hashed_keys.into(), models: models.into() }
Entity {
hashed_keys: val.hashed_keys.into(),
models: models.into(),
event_id: CString::new(val.event_id.clone()).unwrap().into_raw(),
executed_at_timestamp: val.executed_at.timestamp() as u64,
created_at_timestamp: val.created_at.timestamp() as u64,
updated_at_timestamp: val.updated_at.timestamp() as u64,
is_deleted: val.is_deleted,
}
}
}

Expand Down
Loading