Skip to content
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

feat: start working on new update subscription #40

Merged
merged 6 commits into from
Jul 18, 2024
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
1,707 changes: 830 additions & 877 deletions Cargo.lock

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ version = "1.0.0-alpha.0"
crate-type = ["cdylib", "rlib", "staticlib"]

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


parking_lot = "0.12.1"
starknet = "0.11.0"
starknet-crypto = "0.7.0"

parking_lot = "0.12.1"
tokio = { version = "1.32.0", default-features = false, features = ["rt"] }
url = "2.5.0"
anyhow = "1.0.76"
Expand All @@ -30,6 +31,7 @@ wasm-bindgen = "0.2.92"
stream-cancel = "0.8.2"
cainome = { git = "https://github.com/cartridge-gg/cainome", tag = "v0.3.0" }


# WASM
[target.'cfg(target_arch = "wasm32")'.dependencies]
serde-wasm-bindgen = "0.6.3"
Expand Down
24 changes: 8 additions & 16 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{collections::HashMap, env};
use std::collections::HashMap;
use std::env;

fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
Expand All @@ -11,24 +12,20 @@ fn main() {
config.braces = cbindgen::Braces::SameLine;
config.cpp_compat = true;
config.style = cbindgen::Style::Both;
config.layout = cbindgen::LayoutConfig {
..Default::default()
};
config.layout = cbindgen::LayoutConfig { ..Default::default() };
config.enumeration = cbindgen::EnumConfig {
derive_helper_methods: true,
// prefix_with_name: true,
..Default::default()
};
config.export = cbindgen::ExportConfig {
mangle: cbindgen::MangleConfig {
remove_underscores: true,
..Default::default()
},
mangle: cbindgen::MangleConfig { remove_underscores: true, ..Default::default() },
..Default::default()
};

config.defines = HashMap::new();
// config.defines.insert("target_arch = wasm32".to_string(), "TARGET_WASM32".to_string());
// config.defines.insert("target_arch = wasm32".to_string(),
// "TARGET_WASM32".to_string());
config.defines.insert(
"target_pointer_width = 32".to_string(),
"TARGET_POINTER_WIDTH_32".to_string(),
Expand All @@ -48,19 +45,14 @@ fn main() {
config.language = cbindgen::Language::Cxx;
config.braces = cbindgen::Braces::SameLine;
config.style = cbindgen::Style::Both;
config.layout = cbindgen::LayoutConfig {
..Default::default()
};
config.layout = cbindgen::LayoutConfig { ..Default::default() };
config.enumeration = cbindgen::EnumConfig {
derive_helper_methods: true,
// prefix_with_name: true,
..Default::default()
};
config.export = cbindgen::ExportConfig {
mangle: cbindgen::MangleConfig {
remove_underscores: true,
..Default::default()
},
mangle: cbindgen::MangleConfig { remove_underscores: true, ..Default::default() },
..Default::default()
};

Expand Down
36 changes: 34 additions & 2 deletions dojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ typedef struct Signature {
} Signature;

typedef enum Primitive_Tag {
I8,
I16,
I32,
I64,
I128,
U8,
U16,
U32,
Expand All @@ -115,6 +120,21 @@ typedef enum Primitive_Tag {
typedef struct Primitive {
Primitive_Tag tag;
union {
struct {
int8_t i8;
};
struct {
int16_t i16;
};
struct {
int32_t i32;
};
struct {
int64_t i64;
};
struct {
uint8_t i128[16];
};
struct {
uint8_t u8;
};
Expand Down Expand Up @@ -659,15 +679,27 @@ struct ResultSubscription client_on_sync_model_update(struct ToriiClient *client
void (*callback)(void));

struct ResultSubscription client_on_entity_state_update(struct ToriiClient *client,
const struct EntityKeysClause *clause,
const struct EntityKeysClause *clauses,
uintptr_t clauses_len,
void (*callback)(struct FieldElement,
struct CArrayStruct));

struct Resultbool client_update_entity_subscription(struct ToriiClient *client,
struct Subscription *subscription,
const struct EntityKeysClause *clauses,
uintptr_t clauses_len);

struct ResultSubscription client_on_event_message_update(struct ToriiClient *client,
const struct EntityKeysClause *clause,
const struct EntityKeysClause *clauses,
uintptr_t clauses_len,
void (*callback)(struct FieldElement,
struct CArrayStruct));

struct Resultbool client_update_event_message_subscription(struct ToriiClient *client,
struct Subscription *subscription,
const struct EntityKeysClause *clauses,
uintptr_t clauses_len);

struct Resultbool client_remove_models_to_sync(struct ToriiClient *client,
const struct ModelKeysClause *models,
uintptr_t models_len);
Expand Down
103 changes: 101 additions & 2 deletions dojo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ struct Signature {

struct Primitive {
enum class Tag {
I8,
I16,
I32,
I64,
I128,
U8,
U16,
U32,
Expand All @@ -123,6 +128,26 @@ struct Primitive {
ContractAddress,
};

struct I8_Body {
int8_t _0;
};

struct I16_Body {
int16_t _0;
};

struct I32_Body {
int32_t _0;
};

struct I64_Body {
int64_t _0;
};

struct I128_Body {
uint8_t _0[16];
};

struct U8_Body {
uint8_t _0;
};
Expand Down Expand Up @@ -177,6 +202,11 @@ struct Primitive {

Tag tag;
union {
I8_Body i8;
I16_Body i16;
I32_Body i32;
I64_Body i64;
I128_Body i128;
U8_Body u8;
U16_Body u16;
U32_Body u32;
Expand All @@ -195,6 +225,63 @@ struct Primitive {
ContractAddress_Body contract_address;
};

static Primitive I8(const int8_t &_0) {
Primitive result;
::new (&result.i8._0) (int8_t)(_0);
result.tag = Tag::I8;
return result;
}

bool IsI8() const {
return tag == Tag::I8;
}

static Primitive I16(const int16_t &_0) {
Primitive result;
::new (&result.i16._0) (int16_t)(_0);
result.tag = Tag::I16;
return result;
}

bool IsI16() const {
return tag == Tag::I16;
}

static Primitive I32(const int32_t &_0) {
Primitive result;
::new (&result.i32._0) (int32_t)(_0);
result.tag = Tag::I32;
return result;
}

bool IsI32() const {
return tag == Tag::I32;
}

static Primitive I64(const int64_t &_0) {
Primitive result;
::new (&result.i64._0) (int64_t)(_0);
result.tag = Tag::I64;
return result;
}

bool IsI64() const {
return tag == Tag::I64;
}

static Primitive I128(const uint8_t (&_0)[16]) {
Primitive result;
for (int i = 0; i < 16; i++) {
::new (&result.i128._0[i]) (uint8_t)(_0[i]);
}
result.tag = Tag::I128;
return result;
}

bool IsI128() const {
return tag == Tag::I128;
}

static Primitive U8(const uint8_t &_0) {
Primitive result;
::new (&result.u8._0) (uint8_t)(_0);
Expand Down Expand Up @@ -867,13 +954,25 @@ Result<Subscription*> client_on_sync_model_update(ToriiClient *client,
void (*callback)());

Result<Subscription*> client_on_entity_state_update(ToriiClient *client,
const EntityKeysClause *clause,
const EntityKeysClause *clauses,
uintptr_t clauses_len,
void (*callback)(FieldElement, CArray<Struct>));

Result<bool> client_update_entity_subscription(ToriiClient *client,
Subscription *subscription,
const EntityKeysClause *clauses,
uintptr_t clauses_len);

Result<Subscription*> client_on_event_message_update(ToriiClient *client,
const EntityKeysClause *clause,
const EntityKeysClause *clauses,
uintptr_t clauses_len,
void (*callback)(FieldElement, CArray<Struct>));

Result<bool> client_update_event_message_subscription(ToriiClient *client,
Subscription *subscription,
const EntityKeysClause *clauses,
uintptr_t clauses_len);

Result<bool> client_remove_models_to_sync(ToriiClient *client,
const ModelKeysClause *models,
uintptr_t models_len);
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "1.76.0"
channel = "1.79.0"
28 changes: 28 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
edition = "2021"
max_width = 100
newline_style = "Unix"
use_field_init_shorthand = true
use_small_heuristics = "Max"
use_try_shorthand = true

# Unstable features below
comment_width = 100
format_code_in_doc_comments = true
format_macro_bodies = true
format_macro_matchers = true
format_strings = true
group_imports = "StdExternalCrate"
imports_granularity = "Module"
normalize_comments = true
normalize_doc_attributes = true
unstable_features = true
version = "Two"
wrap_comments = true

# To use these settings in vscode, add the following line to your settings.json file:
#
# "rust-analyzer.rustfmt.extraArgs": [
# "+nightly"
# ],
#
# and run "rustup toolchain install nightly".
Loading
Loading