Skip to content

Commit 23734d3

Browse files
authored
chore: c header (#97)
1 parent 77a7c72 commit 23734d3

File tree

5 files changed

+21
-70
lines changed

5 files changed

+21
-70
lines changed

dojo.h

+2-11
Original file line numberDiff line numberDiff line change
@@ -503,10 +503,7 @@ typedef enum Primitive_Tag {
503503
U32,
504504
U64,
505505
U128,
506-
U256,
507-
#if defined(TARGET_POINTER_WIDTH_32)
508-
U256,
509-
#endif
506+
U256_,
510507
Bool,
511508
Felt252,
512509
ClassHash,
@@ -548,13 +545,8 @@ typedef struct Primitive {
548545
uint8_t u128[16];
549546
};
550547
struct {
551-
uint64_t u256[4];
548+
struct U256 u256;
552549
};
553-
#if defined(TARGET_POINTER_WIDTH_32)
554-
struct {
555-
uint32_t u256[8];
556-
};
557-
#endif
558550
struct {
559551
bool bool_;
560552
};
@@ -798,7 +790,6 @@ extern "C" {
798790
*
799791
* # Parameters
800792
* * `torii_url` - URL of the Torii server
801-
* * `rpc_url` - URL of the Starknet RPC endpoint
802793
* * `libp2p_relay_url` - URL of the libp2p relay server
803794
* * `world` - World address as a FieldElement
804795
*

dojo.hpp

+13-43
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ struct Entity {
128128
CArray<Struct> models;
129129
};
130130

131+
struct U256 {
132+
uint8_t data[32];
133+
};
134+
131135
struct Primitive {
132136
enum class Tag {
133137
I8,
@@ -140,10 +144,7 @@ struct Primitive {
140144
U32,
141145
U64,
142146
U128,
143-
U256,
144-
#if defined(TARGET_POINTER_WIDTH_32)
145-
U256,
146-
#endif
147+
U256_,
147148
Bool,
148149
Felt252,
149150
ClassHash,
@@ -191,16 +192,10 @@ struct Primitive {
191192
uint8_t _0[16];
192193
};
193194

194-
struct U256_Body {
195-
uint64_t _0[4];
195+
struct U256__Body {
196+
U256 _0;
196197
};
197198

198-
#if defined(TARGET_POINTER_WIDTH_32)
199-
struct U256_Body {
200-
uint32_t _0[8];
201-
};
202-
#endif
203-
204199
struct Bool_Body {
205200
bool _0;
206201
};
@@ -233,10 +228,7 @@ struct Primitive {
233228
U32_Body u32;
234229
U64_Body u64;
235230
U128_Body u128;
236-
U256_Body u256;
237-
#if defined(TARGET_POINTER_WIDTH_32)
238-
U256_Body u256;
239-
#endif
231+
U256__Body u256;
240232
Bool_Body bool_;
241233
Felt252_Body felt252;
242234
ClassHash_Body class_hash;
@@ -358,33 +350,16 @@ struct Primitive {
358350
return tag == Tag::U128;
359351
}
360352

361-
static Primitive U256(const uint64_t (&_0)[4]) {
362-
Primitive result;
363-
for (int i = 0; i < 4; i++) {
364-
::new (&result.u256._0[i]) (uint64_t)(_0[i]);
365-
}
366-
result.tag = Tag::U256;
367-
return result;
368-
}
369-
370-
bool IsU256() const {
371-
return tag == Tag::U256;
372-
}
373-
374-
#if defined(TARGET_POINTER_WIDTH_32)
375-
static Primitive U256(const uint32_t (&_0)[8]) {
353+
static Primitive U256_(const U256 &_0) {
376354
Primitive result;
377-
for (int i = 0; i < 8; i++) {
378-
::new (&result.u256._0[i]) (uint32_t)(_0[i]);
379-
}
380-
result.tag = Tag::U256;
355+
::new (&result.u256._0) (U256)(_0);
356+
result.tag = Tag::U256_;
381357
return result;
382358
}
383359

384-
bool IsU256() const {
385-
return tag == Tag::U256;
360+
bool IsU256_() const {
361+
return tag == Tag::U256_;
386362
}
387-
#endif
388363

389364
static Primitive Bool(const bool &_0) {
390365
Primitive result;
@@ -592,10 +567,6 @@ struct Event {
592567
FieldElement transaction_hash;
593568
};
594569

595-
struct U256 {
596-
uint8_t data[32];
597-
};
598-
599570
struct Token {
600571
FieldElement contract_address;
601572
U256 token_id;
@@ -940,7 +911,6 @@ extern "C" {
940911
///
941912
/// # Parameters
942913
/// * `torii_url` - URL of the Torii server
943-
/// * `rpc_url` - URL of the Starknet RPC endpoint
944914
/// * `libp2p_relay_url` - URL of the libp2p relay server
945915
/// * `world` - World address as a FieldElement
946916
///

dojo.pyx

+2-5
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,7 @@ cdef extern from *:
322322
U32,
323323
U64,
324324
U128,
325-
U256,
326-
U256,
325+
U256_,
327326
Bool,
328327
Felt252,
329328
ClassHash,
@@ -342,8 +341,7 @@ cdef extern from *:
342341
uint32_t u32;
343342
uint64_t u64;
344343
uint8_t u128[16];
345-
uint64_t u256[4];
346-
uint32_t u256[8];
344+
U256 u256;
347345
bool bool_;
348346
FieldElement felt252;
349347
FieldElement class_hash;
@@ -498,7 +496,6 @@ cdef extern from *:
498496
#
499497
# # Parameters
500498
# * `torii_url` - URL of the Torii server
501-
# * `rpc_url` - URL of the Starknet RPC endpoint
502499
# * `libp2p_relay_url` - URL of the libp2p relay server
503500
# * `world` - World address as a FieldElement
504501
#

src/c/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ lazy_static! {
7373
///
7474
/// # Parameters
7575
/// * `torii_url` - URL of the Torii server
76-
/// * `rpc_url` - URL of the Starknet RPC endpoint
7776
/// * `libp2p_relay_url` - URL of the libp2p relay server
7877
/// * `world` - World address as a FieldElement
7978
///

src/c/types.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -854,10 +854,7 @@ pub enum Primitive {
854854
U64(u64),
855855
// TODO: better way?
856856
U128([u8; 16]),
857-
#[cfg(target_pointer_width = "64")]
858-
U256([u64; 4]),
859-
#[cfg(target_pointer_width = "32")]
860-
U256([u32; 8]),
857+
U256_(U256),
861858
Bool(bool),
862859
Felt252(FieldElement),
863860
ClassHash(FieldElement),
@@ -882,7 +879,7 @@ impl From<&Primitive> for dojo_types::primitive::Primitive {
882879
Primitive::U128(v) => {
883880
dojo_types::primitive::Primitive::U128(Some(u128::from_be_bytes(*v)))
884881
}
885-
Primitive::U256(v) => dojo_types::primitive::Primitive::U256(Some((*v).into())),
882+
Primitive::U256_(v) => dojo_types::primitive::Primitive::U256(Some(v.into())),
886883
Primitive::Bool(v) => dojo_types::primitive::Primitive::Bool(Some(*v)),
887884
Primitive::Felt252(v) => {
888885
dojo_types::primitive::Primitive::Felt252(Some((&v.clone()).into()))
@@ -927,12 +924,9 @@ impl From<&dojo_types::primitive::Primitive> for Primitive {
927924
}
928925
dojo_types::primitive::Primitive::U256(v) => {
929926
if let Some(v) = v {
930-
Primitive::U256(v.to_words())
927+
Primitive::U256_(v.into())
931928
} else {
932-
#[cfg(target_pointer_width = "64")]
933-
return Primitive::U256([0; 4]);
934-
#[cfg(target_pointer_width = "32")]
935-
return Primitive::U256([0; 8]);
929+
Primitive::U256_(U256 { data: [0; 32] })
936930
}
937931
}
938932
dojo_types::primitive::Primitive::Bool(v) => Primitive::Bool(v.unwrap_or(false)),

0 commit comments

Comments
 (0)