Skip to content

Commit 2d8c316

Browse files
authored
Add ProgramArtifact for ContractsDataStore (#3612)
commit-id:98159d1a
1 parent 861e543 commit 2d8c316

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/debugging/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ paste.workspace = true
1111
console.workspace = true
1212
starknet-types-core.workspace = true
1313
starknet.workspace = true
14+
cairo-lang-sierra.workspace = true
15+
cairo-lang-starknet-classes.workspace = true
1416
cheatnet = { path = "../cheatnet" }
1517
data-transformer = { path = "../data-transformer" }
1618
serde_json.workspace = true

crates/debugging/src/contracts_data_store.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
use crate::trace::types::{ContractName, Selector};
2+
use cairo_lang_sierra::program::ProgramArtifact;
3+
use cairo_lang_starknet_classes::contract_class::ContractClass;
24
use cheatnet::forking::data::ForkData;
35
use cheatnet::runtime_extensions::forge_runtime_extension::contracts_data::ContractsData;
46
use rayon::iter::IntoParallelRefIterator;
@@ -8,11 +10,12 @@ use starknet_api::core::{ClassHash, EntryPointSelector};
810
use std::collections::HashMap;
911

1012
/// 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).
1214
pub struct ContractsDataStore {
1315
abi: HashMap<ClassHash, Vec<AbiEntry>>,
1416
contract_names: HashMap<ClassHash, ContractName>,
1517
selectors: HashMap<EntryPointSelector, Selector>,
18+
programs: HashMap<ClassHash, ProgramArtifact>,
1619
}
1720

1821
impl ContractsDataStore {
@@ -43,10 +46,34 @@ impl ContractsDataStore {
4346
.chain(fork_data.abi.clone())
4447
.collect();
4548

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+
4672
Self {
4773
abi,
4874
contract_names,
4975
selectors,
76+
programs,
5077
}
5178
}
5279

@@ -66,4 +93,10 @@ impl ContractsDataStore {
6693
pub fn get_selector(&self, entry_point_selector: &EntryPointSelector) -> Option<&Selector> {
6794
self.selectors.get(entry_point_selector)
6895
}
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+
}
69102
}

0 commit comments

Comments
 (0)