1
+ use alloc:: { boxed:: Box , collections:: BTreeMap , format, string:: String , vec:: Vec } ;
2
+
1
3
use crate :: {
2
4
crypto:: compute_hash_on_elements,
3
5
serde:: { num_hex:: u64 as u64_hex, unsigned_field_element:: UfeHex } ,
4
6
types:: {
5
- contract:: { CompressProgramError , ComputeClassHashError , JsonError } ,
6
- CompressedLegacyContractClass , FieldElement , FunctionStateMutability ,
7
- LegacyContractAbiEntry , LegacyContractEntryPoint , LegacyEntryPointsByType ,
8
- LegacyEventAbiEntry , LegacyEventAbiType , LegacyFunctionAbiEntry , LegacyFunctionAbiType ,
9
- LegacyStructAbiEntry , LegacyStructAbiType , LegacyStructMember , LegacyTypedParameter ,
7
+ contract:: { ComputeClassHashError , JsonError } ,
8
+ FieldElement , FunctionStateMutability , LegacyContractAbiEntry , LegacyContractEntryPoint ,
9
+ LegacyEntryPointsByType , LegacyEventAbiEntry , LegacyEventAbiType , LegacyFunctionAbiEntry ,
10
+ LegacyFunctionAbiType , LegacyStructAbiEntry , LegacyStructAbiType , LegacyStructMember ,
11
+ LegacyTypedParameter ,
10
12
} ,
11
13
utils:: { cairo_short_string_to_felt, starknet_keccak} ,
12
14
} ;
13
15
14
- use flate2:: { write:: GzEncoder , Compression } ;
15
16
use serde:: {
16
17
de:: Error as DeError , ser:: SerializeSeq , Deserialize , Deserializer , Serialize , Serializer ,
17
18
} ;
18
19
use serde_json_pythonic:: to_string_pythonic;
19
20
use serde_with:: { serde_as, SerializeAs } ;
20
- use std:: { collections:: BTreeMap , io:: Write } ;
21
+
22
+ #[ cfg( feature = "std" ) ]
23
+ use crate :: types:: { contract:: CompressProgramError , CompressedLegacyContractClass } ;
24
+ #[ cfg( feature = "std" ) ]
25
+ use flate2:: { write:: GzEncoder , Compression } ;
21
26
22
27
const API_VERSION : FieldElement = FieldElement :: ZERO ;
23
28
@@ -396,13 +401,13 @@ impl<'de> Deserialize<'de> for RawLegacyAbiEntry {
396
401
397
402
impl LegacyContractClass {
398
403
pub fn class_hash ( & self ) -> Result < FieldElement , ComputeClassHashError > {
399
- let mut elements = vec ! [ ] ;
404
+ let mut elements = Vec :: new ( ) ;
400
405
401
406
elements. push ( API_VERSION ) ;
402
407
403
408
// Hashes external entry points
404
409
elements. push ( {
405
- let mut buffer = vec ! [ ] ;
410
+ let mut buffer = Vec :: new ( ) ;
406
411
for entrypoint in self . entry_points_by_type . external . iter ( ) {
407
412
buffer. push ( entrypoint. selector ) ;
408
413
buffer. push ( entrypoint. offset . into ( ) ) ;
@@ -412,7 +417,7 @@ impl LegacyContractClass {
412
417
413
418
// Hashes L1 handler entry points
414
419
elements. push ( {
415
- let mut buffer = vec ! [ ] ;
420
+ let mut buffer = Vec :: new ( ) ;
416
421
for entrypoint in self . entry_points_by_type . l1_handler . iter ( ) {
417
422
buffer. push ( entrypoint. selector ) ;
418
423
buffer. push ( entrypoint. offset . into ( ) ) ;
@@ -422,7 +427,7 @@ impl LegacyContractClass {
422
427
423
428
// Hashes constructor entry points
424
429
elements. push ( {
425
- let mut buffer = vec ! [ ] ;
430
+ let mut buffer = Vec :: new ( ) ;
426
431
for entrypoint in self . entry_points_by_type . constructor . iter ( ) {
427
432
buffer. push ( entrypoint. selector ) ;
428
433
buffer. push ( entrypoint. offset . into ( ) ) ;
@@ -474,6 +479,7 @@ impl LegacyContractClass {
474
479
Ok ( starknet_keccak ( serialized. as_bytes ( ) ) )
475
480
}
476
481
482
+ #[ cfg( feature = "std" ) ]
477
483
pub fn compress ( & self ) -> Result < CompressedLegacyContractClass , CompressProgramError > {
478
484
Ok ( CompressedLegacyContractClass {
479
485
program : self . program . compress ( ) ?,
@@ -490,7 +496,10 @@ impl LegacyContractClass {
490
496
}
491
497
492
498
impl LegacyProgram {
499
+ #[ cfg( feature = "std" ) ]
493
500
pub fn compress ( & self ) -> Result < Vec < u8 > , CompressProgramError > {
501
+ use std:: io:: Write ;
502
+
494
503
#[ serde_as]
495
504
#[ derive( Serialize ) ]
496
505
pub struct ProgramWithoutDebugInfo < ' a > {
0 commit comments