1
1
use crate :: trace:: types:: { ContractName , Selector } ;
2
+ use cairo_lang_sierra:: program:: ProgramArtifact ;
3
+ use cairo_lang_starknet_classes:: contract_class:: ContractClass ;
2
4
use cheatnet:: forking:: data:: ForkData ;
3
5
use cheatnet:: runtime_extensions:: forge_runtime_extension:: contracts_data:: ContractsData ;
4
6
use rayon:: iter:: IntoParallelRefIterator ;
@@ -8,11 +10,12 @@ use starknet_api::core::{ClassHash, EntryPointSelector};
8
10
use std:: collections:: HashMap ;
9
11
10
12
/// Data structure containing information about contracts,
11
- /// including their ABI, names, and selectors that will be used to create a [`Trace`](crate::Trace).
13
+ /// including their ABI, names, selectors and programs that will be used to create a [`Trace`](crate::Trace).
12
14
pub struct ContractsDataStore {
13
15
abi : HashMap < ClassHash , Vec < AbiEntry > > ,
14
16
contract_names : HashMap < ClassHash , ContractName > ,
15
17
selectors : HashMap < EntryPointSelector , Selector > ,
18
+ programs : HashMap < ClassHash , ProgramArtifact > ,
16
19
}
17
20
18
21
impl ContractsDataStore {
@@ -43,10 +46,34 @@ impl ContractsDataStore {
43
46
. chain ( fork_data. abi . clone ( ) )
44
47
. collect ( ) ;
45
48
49
+ let programs = contracts_data
50
+ . contracts
51
+ . par_iter ( )
52
+ . map ( |( _, contract_data) | {
53
+ let contract_class =
54
+ serde_json:: from_str :: < ContractClass > ( & contract_data. artifacts . sierra )
55
+ . expect ( "this should be valid `ContractClass`" ) ;
56
+
57
+ let program = contract_class
58
+ . extract_sierra_program ( )
59
+ . expect ( "extraction should succeed" ) ;
60
+
61
+ let debug_info = contract_class. sierra_program_debug_info ;
62
+
63
+ let program_artifact = ProgramArtifact {
64
+ program,
65
+ debug_info,
66
+ } ;
67
+
68
+ ( contract_data. class_hash , program_artifact)
69
+ } )
70
+ . collect ( ) ;
71
+
46
72
Self {
47
73
abi,
48
74
contract_names,
49
75
selectors,
76
+ programs,
50
77
}
51
78
}
52
79
@@ -66,4 +93,10 @@ impl ContractsDataStore {
66
93
pub fn get_selector ( & self , entry_point_selector : & EntryPointSelector ) -> Option < & Selector > {
67
94
self . selectors . get ( entry_point_selector)
68
95
}
96
+
97
+ /// Gets the [`ProgramArtifact`] for a given contract [`ClassHash`].
98
+ #[ must_use]
99
+ pub fn get_program_artifact ( & self , class_hash : & ClassHash ) -> Option < & ProgramArtifact > {
100
+ self . programs . get ( class_hash)
101
+ }
69
102
}
0 commit comments