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
32 changes: 16 additions & 16 deletions Cargo.lock

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

8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ version = "0.7.0"
crate-type = ["cdylib", "rlib", "staticlib"]

[dependencies]
dojo-types = { git = "https://github.com/dojoengine/dojo", rev = "2ea37a177fcfeedfebf6be8a55a462a752bbe4ec" }
torii-client = { git = "https://github.com/dojoengine/dojo", rev = "2ea37a177fcfeedfebf6be8a55a462a752bbe4ec" }
dojo-types = { git = "https://github.com/dojoengine/dojo", rev = "e8539d5b199efbd51c89c75da32f6592de5d9262" }
torii-client = { git = "https://github.com/dojoengine/dojo", rev = "e8539d5b199efbd51c89c75da32f6592de5d9262" }
torii-grpc = { git = "https://github.com/dojoengine/dojo", features = [
"client",
], rev = "2ea37a177fcfeedfebf6be8a55a462a752bbe4ec" }
torii-relay = { git = "https://github.com/dojoengine/dojo", rev = "2ea37a177fcfeedfebf6be8a55a462a752bbe4ec" }
], rev = "e8539d5b199efbd51c89c75da32f6592de5d9262" }
torii-relay = { git = "https://github.com/dojoengine/dojo", rev = "e8539d5b199efbd51c89c75da32f6592de5d9262" }

parking_lot = "0.12.1"
starknet = "0.10.0"
Expand Down
53 changes: 15 additions & 38 deletions dojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,42 +228,33 @@ typedef struct Ty {
};
} Ty;

typedef enum COptionTy_Tag {
SomeTy,
NoneTy,
} COptionTy_Tag;
typedef enum ResultTy_Tag {
OkTy,
ErrTy,
} ResultTy_Tag;

typedef struct COptionTy {
COptionTy_Tag tag;
typedef struct ResultTy {
ResultTy_Tag tag;
union {
struct {
struct Ty *some;
};
};
} COptionTy;

typedef enum ResultCOptionTy_Tag {
OkCOptionTy,
ErrCOptionTy,
} ResultCOptionTy_Tag;

typedef struct ResultCOptionTy {
ResultCOptionTy_Tag tag;
union {
struct {
struct COptionTy ok;
struct Ty *ok;
};
struct {
struct Error err;
};
};
} ResultCOptionTy;
} ResultTy;

typedef struct CArrayFieldElement {
struct FieldElement *data;
uintptr_t data_len;
} CArrayFieldElement;

typedef struct CArrayFieldElement {
struct FieldElement **data;
uintptr_t data_len;
} CArrayFieldElement;

typedef struct ModelKeysClause {
struct CArrayFieldElement keys;
const char *model;
Expand Down Expand Up @@ -390,24 +381,10 @@ typedef struct Clause {
};
} Clause;

typedef enum COptionClause_Tag {
SomeClause,
NoneClause,
} COptionClause_Tag;

typedef struct COptionClause {
COptionClause_Tag tag;
union {
struct {
struct Clause some;
};
};
} COptionClause;

typedef struct Query {
uint32_t limit;
uint32_t offset;
struct COptionClause clause;
struct Clause *clause;
} Query;

typedef struct CArrayModelKeysClause {
Expand Down Expand Up @@ -637,7 +614,7 @@ struct ResultCArrayu8 client_publish_message(struct ToriiClient *client,
const char *message,
struct Signature signature);

struct ResultCOptionTy client_model(struct ToriiClient *client, const struct ModelKeysClause *keys);
struct ResultTy client_model(struct ToriiClient *client, const struct ModelKeysClause *keys);

struct ResultCArrayEntity client_entities(struct ToriiClient *client, const struct Query *query);

Expand Down
44 changes: 3 additions & 41 deletions dojo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,44 +471,6 @@ struct Ty {
}
};

template<typename T>
struct COption {
enum class Tag {
Some,
None,
};

struct Some_Body {
T _0;
};

Tag tag;
union {
Some_Body some;
};

static COption Some(const T &_0) {
COption result;
::new (&result.some._0) (T)(_0);
result.tag = Tag::Some;
return result;
}

bool IsSome() const {
return tag == Tag::Some;
}

static COption None() {
COption result;
result.tag = Tag::None;
return result;
}

bool IsNone() const {
return tag == Tag::None;
}
};

struct ModelKeysClause {
CArray<FieldElement> keys;
const char *model;
Expand All @@ -525,7 +487,7 @@ struct Entity {
};

struct KeysClause {
CArray<FieldElement> keys;
CArray<FieldElement*> keys;
PatternMatching pattern_matching;
CArray<const char*> models;
};
Expand Down Expand Up @@ -705,7 +667,7 @@ struct Clause {
struct Query {
uint32_t limit;
uint32_t offset;
COption<Clause> clause;
Clause *clause;
};

struct ModelMetadata {
Expand Down Expand Up @@ -851,7 +813,7 @@ Result<CArray<uint8_t>> client_publish_message(ToriiClient *client,
const char *message,
Signature signature);

Result<COption<Ty*>> client_model(ToriiClient *client, const ModelKeysClause *keys);
Result<Ty*> client_model(ToriiClient *client, const ModelKeysClause *keys);

Result<CArray<Entity>> client_entities(ToriiClient *client, const Query *query);

Expand Down
10 changes: 5 additions & 5 deletions src/c/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod types;

use self::types::{
BlockId, CArray, COption, Call, Entity, Error, Model, Query, Result, Signature, ToriiClient,
Ty, WorldMetadata,
BlockId, CArray, Call, Entity, Error, Model, Query, Result, Signature, ToriiClient, Ty,
WorldMetadata,
};
use crate::constants;
use crate::types::{Account, Provider, Subscription};
Expand Down Expand Up @@ -105,16 +105,16 @@ pub unsafe extern "C" fn client_publish_message(
pub unsafe extern "C" fn client_model(
client: *mut ToriiClient,
keys: &ModelKeysClause,
) -> Result<COption<*mut Ty>> {
) -> Result<*mut Ty> {
let keys = (&keys.clone()).into();
let entity_future = unsafe { (*client).inner.model(&keys) };

match (*client).runtime.block_on(entity_future) {
Ok(ty) => {
if let Some(ty) = ty {
Result::Ok(COption::Some(Box::into_raw(Box::new((&ty).into()))))
Result::Ok(Box::into_raw(Box::new((&ty).into())))
} else {
Result::Ok(COption::None)
Result::Ok(std::ptr::null_mut())
}
}
Err(e) => Result::Err(e.into()),
Expand Down
Loading