@@ -20,7 +20,7 @@ use cairo_vm::serde::deserialize_program::{
2020} ;
2121use cairo_vm:: types:: builtin_name:: BuiltinName ;
2222use cairo_vm:: types:: errors:: program_errors:: ProgramError ;
23- use cairo_vm:: types:: program:: Program ;
23+ use cairo_vm:: types:: program:: { HintsCollection , Program } ;
2424use cairo_vm:: types:: relocatable:: MaybeRelocatable ;
2525use cairo_vm:: vm:: runners:: cairo_runner:: ExecutionResources ;
2626use itertools:: Itertools ;
@@ -709,6 +709,29 @@ fn hint_to_hint_params(hint: &Hint) -> Result<HintParams, ProgramError> {
709709 } )
710710}
711711
712+ /// Converts `HintParams` back to `Hint` by deserializing the JSON code.
713+ /// This is the reverse of `hint_to_hint_params`.
714+ fn hint_params_to_hint ( hint_params : & HintParams ) -> Result < Hint , ProgramError > {
715+ Ok ( serde_json:: from_str ( & hint_params. code ) ?)
716+ }
717+
718+ /// Converts `BTreeMap<usize, Vec<HintParams>>` back to `Vec<(usize, Vec<Hint>)>`.
719+ /// This is the reverse of the conversion done in `TryFrom<VersionedCasm> for CompiledClassV1`.
720+ pub fn program_hints_to_casm_hints (
721+ program_hints : & HintsCollection ,
722+ ) -> Result < Vec < ( usize , Vec < Hint > ) > , ProgramError > {
723+ let program_hints: BTreeMap < usize , Vec < HintParams > > = program_hints. into ( ) ;
724+ let mut casm_hints: Vec < ( usize , Vec < Hint > ) > = Vec :: new ( ) ;
725+ for ( i, hint_params_list) in program_hints. iter ( ) {
726+ let hints: Vec < Hint > = hint_params_list
727+ . iter ( )
728+ . map ( hint_params_to_hint)
729+ . collect :: < Result < Vec < Hint > , ProgramError > > ( ) ?;
730+ casm_hints. push ( ( * i, hints) ) ;
731+ }
732+ Ok ( casm_hints)
733+ }
734+
712735fn convert_entry_points_v1 ( external : & [ CasmContractEntryPoint ] ) -> Vec < EntryPointV1 > {
713736 external
714737 . iter ( )
0 commit comments