diff --git a/dojo.h b/dojo.h index 64e20d2..63c00b1 100644 --- a/dojo.h +++ b/dojo.h @@ -503,10 +503,7 @@ typedef enum Primitive_Tag { U32, U64, U128, - U256, -#if defined(TARGET_POINTER_WIDTH_32) - U256, -#endif + U256_, Bool, Felt252, ClassHash, @@ -548,13 +545,8 @@ typedef struct Primitive { uint8_t u128[16]; }; struct { - uint64_t u256[4]; + struct U256 u256; }; -#if defined(TARGET_POINTER_WIDTH_32) - struct { - uint32_t u256[8]; - }; -#endif struct { bool bool_; }; @@ -798,7 +790,6 @@ extern "C" { * * # Parameters * * `torii_url` - URL of the Torii server - * * `rpc_url` - URL of the Starknet RPC endpoint * * `libp2p_relay_url` - URL of the libp2p relay server * * `world` - World address as a FieldElement * diff --git a/dojo.hpp b/dojo.hpp index 0331a02..8f2bfae 100644 --- a/dojo.hpp +++ b/dojo.hpp @@ -128,6 +128,10 @@ struct Entity { CArray models; }; +struct U256 { + uint8_t data[32]; +}; + struct Primitive { enum class Tag { I8, @@ -140,10 +144,7 @@ struct Primitive { U32, U64, U128, - U256, -#if defined(TARGET_POINTER_WIDTH_32) - U256, -#endif + U256_, Bool, Felt252, ClassHash, @@ -191,16 +192,10 @@ struct Primitive { uint8_t _0[16]; }; - struct U256_Body { - uint64_t _0[4]; + struct U256__Body { + U256 _0; }; -#if defined(TARGET_POINTER_WIDTH_32) - struct U256_Body { - uint32_t _0[8]; - }; -#endif - struct Bool_Body { bool _0; }; @@ -233,10 +228,7 @@ struct Primitive { U32_Body u32; U64_Body u64; U128_Body u128; - U256_Body u256; -#if defined(TARGET_POINTER_WIDTH_32) - U256_Body u256; -#endif + U256__Body u256; Bool_Body bool_; Felt252_Body felt252; ClassHash_Body class_hash; @@ -358,33 +350,16 @@ struct Primitive { return tag == Tag::U128; } - static Primitive U256(const uint64_t (&_0)[4]) { - Primitive result; - for (int i = 0; i < 4; i++) { - ::new (&result.u256._0[i]) (uint64_t)(_0[i]); - } - result.tag = Tag::U256; - return result; - } - - bool IsU256() const { - return tag == Tag::U256; - } - -#if defined(TARGET_POINTER_WIDTH_32) - static Primitive U256(const uint32_t (&_0)[8]) { + static Primitive U256_(const U256 &_0) { Primitive result; - for (int i = 0; i < 8; i++) { - ::new (&result.u256._0[i]) (uint32_t)(_0[i]); - } - result.tag = Tag::U256; + ::new (&result.u256._0) (U256)(_0); + result.tag = Tag::U256_; return result; } - bool IsU256() const { - return tag == Tag::U256; + bool IsU256_() const { + return tag == Tag::U256_; } -#endif static Primitive Bool(const bool &_0) { Primitive result; @@ -592,10 +567,6 @@ struct Event { FieldElement transaction_hash; }; -struct U256 { - uint8_t data[32]; -}; - struct Token { FieldElement contract_address; U256 token_id; @@ -940,7 +911,6 @@ extern "C" { /// /// # Parameters /// * `torii_url` - URL of the Torii server -/// * `rpc_url` - URL of the Starknet RPC endpoint /// * `libp2p_relay_url` - URL of the libp2p relay server /// * `world` - World address as a FieldElement /// diff --git a/dojo.pyx b/dojo.pyx index a645a44..433ceb1 100644 --- a/dojo.pyx +++ b/dojo.pyx @@ -322,8 +322,7 @@ cdef extern from *: U32, U64, U128, - U256, - U256, + U256_, Bool, Felt252, ClassHash, @@ -342,8 +341,7 @@ cdef extern from *: uint32_t u32; uint64_t u64; uint8_t u128[16]; - uint64_t u256[4]; - uint32_t u256[8]; + U256 u256; bool bool_; FieldElement felt252; FieldElement class_hash; @@ -498,7 +496,6 @@ cdef extern from *: # # # Parameters # * `torii_url` - URL of the Torii server - # * `rpc_url` - URL of the Starknet RPC endpoint # * `libp2p_relay_url` - URL of the libp2p relay server # * `world` - World address as a FieldElement # diff --git a/src/c/mod.rs b/src/c/mod.rs index 38d7f2d..8ba738c 100644 --- a/src/c/mod.rs +++ b/src/c/mod.rs @@ -73,7 +73,6 @@ lazy_static! { /// /// # Parameters /// * `torii_url` - URL of the Torii server -/// * `rpc_url` - URL of the Starknet RPC endpoint /// * `libp2p_relay_url` - URL of the libp2p relay server /// * `world` - World address as a FieldElement /// diff --git a/src/c/types.rs b/src/c/types.rs index 2386730..4aec7f1 100644 --- a/src/c/types.rs +++ b/src/c/types.rs @@ -854,10 +854,7 @@ pub enum Primitive { U64(u64), // TODO: better way? U128([u8; 16]), - #[cfg(target_pointer_width = "64")] - U256([u64; 4]), - #[cfg(target_pointer_width = "32")] - U256([u32; 8]), + U256_(U256), Bool(bool), Felt252(FieldElement), ClassHash(FieldElement), @@ -882,7 +879,7 @@ impl From<&Primitive> for dojo_types::primitive::Primitive { Primitive::U128(v) => { dojo_types::primitive::Primitive::U128(Some(u128::from_be_bytes(*v))) } - Primitive::U256(v) => dojo_types::primitive::Primitive::U256(Some((*v).into())), + Primitive::U256_(v) => dojo_types::primitive::Primitive::U256(Some(v.into())), Primitive::Bool(v) => dojo_types::primitive::Primitive::Bool(Some(*v)), Primitive::Felt252(v) => { dojo_types::primitive::Primitive::Felt252(Some((&v.clone()).into())) @@ -927,12 +924,9 @@ impl From<&dojo_types::primitive::Primitive> for Primitive { } dojo_types::primitive::Primitive::U256(v) => { if let Some(v) = v { - Primitive::U256(v.to_words()) + Primitive::U256_(v.into()) } else { - #[cfg(target_pointer_width = "64")] - return Primitive::U256([0; 4]); - #[cfg(target_pointer_width = "32")] - return Primitive::U256([0; 8]); + Primitive::U256_(U256 { data: [0; 32] }) } } dojo_types::primitive::Primitive::Bool(v) => Primitive::Bool(v.unwrap_or(false)),