Skip to content

Commit

Permalink
Merge pull request #57 from dojoengine/alpha-12
Browse files Browse the repository at this point in the history
feat: update for alpha 12
  • Loading branch information
Larkooo authored Sep 17, 2024
2 parents 9944e8b + 8396f57 commit c9578c5
Show file tree
Hide file tree
Showing 9 changed files with 319 additions and 146 deletions.
311 changes: 188 additions & 123 deletions Cargo.lock

Large diffs are not rendered by default.

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

[dependencies]
dojo-types = { git = "https://github.com/dojoengine/dojo", branch = "Larkooo-patch-1" }
torii-client = { git = "https://github.com/dojoengine/dojo", branch = "Larkooo-patch-1" }
dojo-types = { git = "https://github.com/dojoengine/dojo", rev = "91a0fd0eecf02227528a74df4eae3e9e0458338e" }
torii-client = { git = "https://github.com/dojoengine/dojo", rev = "91a0fd0eecf02227528a74df4eae3e9e0458338e" }
torii-grpc = { git = "https://github.com/dojoengine/dojo", features = [
"client",
], branch = "Larkooo-patch-1" }
torii-relay = { git = "https://github.com/dojoengine/dojo", branch = "Larkooo-patch-1" }
dojo-world = { git = "https://github.com/dojoengine/dojo", branch = "Larkooo-patch-1" }
], rev = "91a0fd0eecf02227528a74df4eae3e9e0458338e" }
torii-relay = { git = "https://github.com/dojoengine/dojo", rev = "91a0fd0eecf02227528a74df4eae3e9e0458338e" }
dojo-world = { git = "https://github.com/dojoengine/dojo", rev = "91a0fd0eecf02227528a74df4eae3e9e0458338e" }


starknet = "0.11.0"
starknet-crypto = "0.7.0"
starknet-crypto = "0.7.1"

parking_lot = "0.12.1"
tokio = { version = "1.39.2", default-features = false, features = ["rt"] }
Expand Down Expand Up @@ -53,9 +53,5 @@ gloo-timers = { version = "0.3.0", features = ["futures"] }
cbindgen = "0.26.0"

[patch.crates-io]
# Remove this patch once the following PR is merged: <https://github.com/xJonathanLEI/starknet-rs/pull/615>
#
# To enable std feature on `starknet-types-core`.
# To re-export the entire `felt` module from `starknet-types-core`.
starknet-core = { git = "https://github.com/kariy/starknet-rs", branch = "dojo-patch" }
starknet-types-core = { git = "https://github.com/dojoengine/types-rs", rev = "289e2f0" }
# Matching the same rev that `cainome` is using. Mainly because `starknet-rs` hasn't create a new release yet.
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "2ddc694" }
19 changes: 18 additions & 1 deletion dojo.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,28 @@ typedef struct KeysClause {
struct CArrayc_char models;
} KeysClause;

typedef enum MemberValue_Tag {
Primitive,
String,
} MemberValue_Tag;

typedef struct MemberValue {
MemberValue_Tag tag;
union {
struct {
struct Primitive primitive;
};
struct {
const char *string;
};
};
} MemberValue;

typedef struct MemberClause {
const char *model;
const char *member;
enum ComparisonOperator operator_;
struct Primitive value;
struct MemberValue value;
} MemberClause;

typedef struct CArrayClause {
Expand Down
45 changes: 44 additions & 1 deletion dojo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,54 @@ struct KeysClause {
CArray<const char*> models;
};

struct MemberValue {
enum class Tag {
Primitive,
String,
};

struct Primitive_Body {
Primitive _0;
};

struct String_Body {
const char *_0;
};

Tag tag;
union {
Primitive_Body primitive;
String_Body string;
};

static MemberValue Primitive(const Primitive &_0) {
MemberValue result;
::new (&result.primitive._0) (Primitive)(_0);
result.tag = Tag::Primitive;
return result;
}

bool IsPrimitive() const {
return tag == Tag::Primitive;
}

static MemberValue String(const char *const &_0) {
MemberValue result;
::new (&result.string._0) (const char*)(_0);
result.tag = Tag::String;
return result;
}

bool IsString() const {
return tag == Tag::String;
}
};

struct MemberClause {
const char *model;
const char *member;
ComparisonOperator operator_;
Primitive value;
MemberValue value;
};

struct CompositeClause {
Expand Down
11 changes: 10 additions & 1 deletion dojo.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,20 @@ cdef extern from *:
PatternMatching pattern_matching;
CArrayc_char models;

cdef enum MemberValue_Tag:
Primitive,
String,

cdef struct MemberValue:
MemberValue_Tag tag;
Primitive primitive;
const char *string;

cdef struct MemberClause:
const char *model;
const char *member;
ComparisonOperator operator_;
Primitive value;
MemberValue value;

cdef struct CArrayClause:
Clause *data;
Expand Down
4 changes: 2 additions & 2 deletions src/c/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ pub unsafe extern "C" fn account_deploy_burner(
);

// deploy the burner
let exec = (*master_account).0.execute_v1(vec![starknet::accounts::Call {
let exec = (*master_account).0.execute_v1(vec![starknet::core::types::Call {
to: constants::UDC_ADDRESS,
calldata: vec![
constants::KATANA_ACCOUNT_CLASS_HASH, // class_hash
Expand Down Expand Up @@ -698,7 +698,7 @@ pub unsafe extern "C" fn account_execute_raw(
) -> Result<types::FieldElement> {
let calldata = unsafe { std::slice::from_raw_parts(calldata, calldata_len).to_vec() };
let calldata =
calldata.into_iter().map(|c| (&c).into()).collect::<Vec<starknet::accounts::Call>>();
calldata.into_iter().map(|c| (&c).into()).collect::<Vec<starknet::core::types::Call>>();
let call = (*account).0.execute_v1(calldata);

match tokio::runtime::Runtime::new() {
Expand Down
33 changes: 30 additions & 3 deletions src/c/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,15 @@ impl From<&BlockTag> for starknet::core::types::BlockTag {
}
}

impl From<&Call> for starknet::accounts::Call {
impl From<&Call> for starknet::core::types::Call {
fn from(val: &Call) -> Self {
let selector = unsafe { CStr::from_ptr(val.selector).to_string_lossy().to_string() };

let calldata: Vec<FieldElement> = (&val.calldata).into();
let calldata = std::mem::ManuallyDrop::new(calldata);
let calldata = calldata.iter().map(|c| (&c.clone()).into()).collect();

starknet::accounts::Call {
starknet::core::types::Call {
to: (&val.to).into(),
selector: get_selector_from_name(&selector).unwrap(),
calldata,
Expand Down Expand Up @@ -261,13 +261,40 @@ pub struct ModelKeysClause {
pub model: *const c_char,
}

#[derive(Clone, Debug)]
#[repr(C)]
pub enum MemberValue {
Primitive(Primitive),
String(*const c_char),
}

impl From<&MemberValue> for torii_grpc::types::MemberValue {
fn from(val: &MemberValue) -> Self {
match val {
MemberValue::Primitive(primitive) => torii_grpc::types::MemberValue::Primitive((&primitive.clone()).into()),
MemberValue::String(string) => torii_grpc::types::MemberValue::String(unsafe { CStr::from_ptr(*string).to_string_lossy().to_string() }),
}
}
}

impl From<&torii_grpc::types::MemberValue> for MemberValue {
fn from(val: &torii_grpc::types::MemberValue) -> Self {
match val {
torii_grpc::types::MemberValue::Primitive(primitive) => MemberValue::Primitive((&primitive.clone()).into()),
torii_grpc::types::MemberValue::String(string) => MemberValue::String(CString::new(string.clone()).unwrap().into_raw()),
}
}
}



#[derive(Clone, Debug)]
#[repr(C)]
pub struct MemberClause {
pub model: *const c_char,
pub member: *const c_char,
pub operator: ComparisonOperator,
pub value: Primitive,
pub value: MemberValue,
}

#[derive(Clone, Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl Account {
SingleOwnerAccount::new(provider, signer, address, chain_id, ExecutionEncoding::New);

// deploy the burner
let exec = self.0.execute_v1(vec![starknet::accounts::Call {
let exec = self.0.execute_v1(vec![starknet::core::types::Call {
to: constants::UDC_ADDRESS,
calldata: vec![
constants::KATANA_ACCOUNT_CLASS_HASH, // class_hash
Expand Down
20 changes: 18 additions & 2 deletions src/wasm/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub struct Call {
pub calldata: Vec<String>,
}

impl From<&Call> for starknet::accounts::Call {
impl From<&Call> for starknet::core::types::Call {
fn from(value: &Call) -> Self {
Self {
to: Felt::from_str(value.to.as_str()).unwrap(),
Expand Down Expand Up @@ -252,13 +252,29 @@ pub struct KeysClause {
pub models: Vec<String>,
}

#[derive(Tsify, Serialize, Deserialize, Debug)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub enum MemberValue {
Primitive(Primitive),
String(String),
}

impl From<&MemberValue> for torii_grpc::types::MemberValue {
fn from(value: &MemberValue) -> Self {
match value {
MemberValue::Primitive(primitive) => torii_grpc::types::MemberValue::Primitive(primitive.into()),
MemberValue::String(string) => torii_grpc::types::MemberValue::String(string.clone()),
}
}
}

#[derive(Tsify, Serialize, Deserialize, Debug)]
#[tsify(into_wasm_abi, from_wasm_abi)]
pub struct MemberClause {
pub model: String,
pub member: String,
pub operator: ComparisonOperator,
pub value: Primitive,
pub value: MemberValue,
}

#[derive(Tsify, Serialize, Deserialize, Debug)]
Expand Down

0 comments on commit c9578c5

Please sign in to comment.