@@ -89,6 +89,10 @@ pub enum AbiEntry {
89
89
Event ( AbiEvent ) ,
90
90
Struct ( AbiStruct ) ,
91
91
Enum ( AbiEnum ) ,
92
+ Constructor ( AbiConstructor ) ,
93
+ Impl ( AbiImpl ) ,
94
+ Interface ( AbiInterface ) ,
95
+ L1Handler ( AbiFunction ) ,
92
96
}
93
97
94
98
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -126,18 +130,71 @@ pub struct AbiFunction {
126
130
127
131
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
128
132
#[ cfg_attr( feature = "no_unknown_fields" , serde( deny_unknown_fields) ) ]
129
- pub struct AbiEvent {
133
+ #[ serde( untagged) ]
134
+ pub enum AbiEvent {
135
+ /// Cairo 2.x ABI event entry
136
+ Typed ( TypedAbiEvent ) ,
137
+ /// Cairo 1.x ABI event entry
138
+ Untyped ( UntypedAbiEvent ) ,
139
+ }
140
+
141
+ #[ derive( Debug , Clone , Deserialize ) ]
142
+ #[ serde( tag = "kind" , rename_all = "snake_case" ) ]
143
+ #[ cfg_attr( feature = "no_unknown_fields" , serde( deny_unknown_fields) ) ]
144
+ pub enum TypedAbiEvent {
145
+ Struct ( AbiEventStruct ) ,
146
+ Enum ( AbiEventEnum ) ,
147
+ }
148
+
149
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
150
+ #[ cfg_attr( feature = "no_unknown_fields" , serde( deny_unknown_fields) ) ]
151
+ pub struct UntypedAbiEvent {
130
152
pub name : String ,
131
153
pub inputs : Vec < AbiNamedMember > ,
132
154
}
133
155
156
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
157
+ #[ cfg_attr( feature = "no_unknown_fields" , serde( deny_unknown_fields) ) ]
158
+ pub struct AbiEventStruct {
159
+ pub name : String ,
160
+ pub members : Vec < EventField > ,
161
+ }
162
+
163
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
164
+ #[ cfg_attr( feature = "no_unknown_fields" , serde( deny_unknown_fields) ) ]
165
+ pub struct AbiEventEnum {
166
+ pub name : String ,
167
+ pub variants : Vec < EventField > ,
168
+ }
169
+
134
170
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
135
171
#[ cfg_attr( feature = "no_unknown_fields" , serde( deny_unknown_fields) ) ]
136
172
pub struct AbiStruct {
137
173
pub name : String ,
138
174
pub members : Vec < AbiNamedMember > ,
139
175
}
140
176
177
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
178
+ #[ cfg_attr( feature = "no_unknown_fields" , serde( deny_unknown_fields) ) ]
179
+ pub struct AbiConstructor {
180
+ pub name : String ,
181
+ pub inputs : Vec < AbiNamedMember > ,
182
+ }
183
+
184
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
185
+ #[ cfg_attr( feature = "no_unknown_fields" , serde( deny_unknown_fields) ) ]
186
+ pub struct AbiImpl {
187
+ pub name : String ,
188
+ pub interface_name : String ,
189
+ }
190
+
191
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
192
+ #[ cfg_attr( feature = "no_unknown_fields" , serde( deny_unknown_fields) ) ]
193
+ pub struct AbiInterface {
194
+ pub name : String ,
195
+ pub items : Vec < AbiEntry > ,
196
+ }
197
+
141
198
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
142
199
#[ cfg_attr( feature = "no_unknown_fields" , serde( deny_unknown_fields) ) ]
143
200
pub struct AbiEnum {
@@ -158,13 +215,29 @@ pub struct AbiOutput {
158
215
pub r#type : String ,
159
216
}
160
217
218
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
219
+ #[ cfg_attr( feature = "no_unknown_fields" , serde( deny_unknown_fields) ) ]
220
+ pub struct EventField {
221
+ pub name : String ,
222
+ pub r#type : String ,
223
+ pub kind : EventFieldKind ,
224
+ }
225
+
161
226
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
162
227
#[ serde( rename_all = "snake_case" ) ]
163
228
pub enum StateMutability {
164
229
External ,
165
230
View ,
166
231
}
167
232
233
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
234
+ #[ serde( rename_all = "snake_case" ) ]
235
+ pub enum EventFieldKind {
236
+ Key ,
237
+ Data ,
238
+ Nested ,
239
+ }
240
+
168
241
#[ derive( Debug , thiserror:: Error ) ]
169
242
pub enum ComputeClassHashError {
170
243
#[ error( "invalid builtin name" ) ]
@@ -370,6 +443,47 @@ impl<'de> Deserialize<'de> for PythonicHint {
370
443
}
371
444
}
372
445
446
+ // Manually implementing this so we can put `kind` in the middle:
447
+ impl Serialize for TypedAbiEvent {
448
+ fn serialize < S > ( & self , serializer : S ) -> Result < S :: Ok , S :: Error >
449
+ where
450
+ S : Serializer ,
451
+ {
452
+ #[ derive( Serialize ) ]
453
+ struct StructRef < ' a > {
454
+ name : & ' a str ,
455
+ kind : & ' static str ,
456
+ members : & ' a [ EventField ] ,
457
+ }
458
+
459
+ #[ derive( Serialize ) ]
460
+ struct EnumRef < ' a > {
461
+ name : & ' a str ,
462
+ kind : & ' static str ,
463
+ variants : & ' a [ EventField ] ,
464
+ }
465
+
466
+ match self {
467
+ TypedAbiEvent :: Struct ( inner) => StructRef :: serialize (
468
+ & StructRef {
469
+ name : & inner. name ,
470
+ kind : "struct" ,
471
+ members : & inner. members ,
472
+ } ,
473
+ serializer,
474
+ ) ,
475
+ TypedAbiEvent :: Enum ( inner) => EnumRef :: serialize (
476
+ & EnumRef {
477
+ name : & inner. name ,
478
+ kind : "enum" ,
479
+ variants : & inner. variants ,
480
+ } ,
481
+ serializer,
482
+ ) ,
483
+ }
484
+ }
485
+ }
486
+
373
487
fn hash_sierra_entrypoints ( entrypoints : & [ SierraEntryPoint ] ) -> FieldElement {
374
488
let mut hasher = PoseidonHasher :: new ( ) ;
375
489
@@ -394,10 +508,11 @@ mod tests {
394
508
#[ test]
395
509
#[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test:: wasm_bindgen_test) ]
396
510
fn test_sierra_class_deser ( ) {
397
- // Artifacts generated from cairo v1.0.0-rc0
398
511
for raw_artifact in [
399
512
include_str ! ( "../../../test-data/contracts/cairo1/artifacts/abi_types_sierra.txt" ) ,
400
513
include_str ! ( "../../../test-data/contracts/cairo1/artifacts/erc20_sierra.txt" ) ,
514
+ include_str ! ( "../../../test-data/contracts/cairo2/artifacts/abi_types_sierra.txt" ) ,
515
+ include_str ! ( "../../../test-data/contracts/cairo2/artifacts/erc20_sierra.txt" ) ,
401
516
]
402
517
. into_iter ( )
403
518
{
@@ -411,10 +526,11 @@ mod tests {
411
526
#[ test]
412
527
#[ cfg_attr( target_arch = "wasm32" , wasm_bindgen_test:: wasm_bindgen_test) ]
413
528
fn test_compiled_class_deser ( ) {
414
- // Artifacts generated from cairo v1.0.0-rc0
415
529
for raw_artifact in [
416
530
include_str ! ( "../../../test-data/contracts/cairo1/artifacts/abi_types_compiled.txt" ) ,
417
531
include_str ! ( "../../../test-data/contracts/cairo1/artifacts/erc20_compiled.txt" ) ,
532
+ include_str ! ( "../../../test-data/contracts/cairo2/artifacts/abi_types_compiled.txt" ) ,
533
+ include_str ! ( "../../../test-data/contracts/cairo2/artifacts/erc20_compiled.txt" ) ,
418
534
]
419
535
. into_iter ( )
420
536
{
@@ -448,6 +564,14 @@ mod tests {
448
564
include_str ! ( "../../../test-data/contracts/cairo1/artifacts/abi_types_sierra.txt" ) ,
449
565
include_str ! ( "../../../test-data/contracts/cairo1/artifacts/abi_types.hashes.json" ) ,
450
566
) ,
567
+ (
568
+ include_str ! ( "../../../test-data/contracts/cairo2/artifacts/erc20_sierra.txt" ) ,
569
+ include_str ! ( "../../../test-data/contracts/cairo2/artifacts/erc20.hashes.json" ) ,
570
+ ) ,
571
+ (
572
+ include_str ! ( "../../../test-data/contracts/cairo2/artifacts/abi_types_sierra.txt" ) ,
573
+ include_str ! ( "../../../test-data/contracts/cairo2/artifacts/abi_types.hashes.json" ) ,
574
+ ) ,
451
575
]
452
576
. into_iter ( )
453
577
{
@@ -475,6 +599,16 @@ mod tests {
475
599
) ,
476
600
include_str ! ( "../../../test-data/contracts/cairo1/artifacts/abi_types.hashes.json" ) ,
477
601
) ,
602
+ (
603
+ include_str ! ( "../../../test-data/contracts/cairo2/artifacts/erc20_compiled.txt" ) ,
604
+ include_str ! ( "../../../test-data/contracts/cairo2/artifacts/erc20.hashes.json" ) ,
605
+ ) ,
606
+ (
607
+ include_str ! (
608
+ "../../../test-data/contracts/cairo2/artifacts/abi_types_compiled.txt"
609
+ ) ,
610
+ include_str ! ( "../../../test-data/contracts/cairo2/artifacts/abi_types.hashes.json" ) ,
611
+ ) ,
478
612
]
479
613
. into_iter ( )
480
614
{
0 commit comments