@@ -5,7 +5,7 @@ use std::io::{BufWriter, Read, Write};
55use std:: path:: { Path , PathBuf } ;
66use std:: sync:: Arc ;
77
8- use starknet_api:: transaction:: fields:: Proof ;
8+ use starknet_api:: transaction:: fields:: { Proof , ProofFacts } ;
99use starknet_types_core:: felt:: Felt ;
1010use thiserror:: Error ;
1111
@@ -15,9 +15,9 @@ mod proof_storage_test;
1515
1616pub trait ProofStorage : Send + Sync {
1717 type Error : Error ;
18- fn set_proof ( & self , facts_hash : Felt , proof : Proof ) -> Result < ( ) , Self :: Error > ;
19- fn get_proof ( & self , facts_hash : Felt ) -> Result < Option < Proof > , Self :: Error > ;
20- fn contains_proof ( & self , facts_hash : Felt ) -> Result < bool , Self :: Error > ;
18+ fn set_proof ( & self , proof_facts : ProofFacts , proof : Proof ) -> Result < ( ) , Self :: Error > ;
19+ fn get_proof ( & self , proof_facts : ProofFacts ) -> Result < Option < Proof > , Self :: Error > ;
20+ fn contains_proof ( & self , proof_facts : ProofFacts ) -> Result < bool , Self :: Error > ;
2121}
2222
2323#[ derive( Debug , Error ) ]
@@ -150,20 +150,27 @@ impl FsProofStorage {
150150 std:: fs:: rename ( tmp_dir, persistent_dir) ?;
151151 Ok ( ( ) )
152152 }
153+
154+ fn contains_proof_by_hash ( & self , facts_hash : Felt ) -> bool {
155+ self . get_persistent_dir ( facts_hash) . exists ( )
156+ }
153157}
154158
155159impl ProofStorage for FsProofStorage {
156160 type Error = FsProofStorageError ;
157161
158- fn set_proof ( & self , facts_hash : Felt , proof : Proof ) -> Result < ( ) , Self :: Error > {
159- if self . contains_proof ( facts_hash) ? {
162+ fn set_proof ( & self , proof_facts : ProofFacts , proof : Proof ) -> Result < ( ) , Self :: Error > {
163+ let facts_hash = proof_facts. hash ( ) ;
164+
165+ if self . contains_proof_by_hash ( facts_hash) {
160166 return Ok ( ( ) ) ;
161167 }
162168 self . write_proof_atomically ( facts_hash, proof)
163169 }
164170
165- fn get_proof ( & self , facts_hash : Felt ) -> Result < Option < Proof > , Self :: Error > {
166- if !self . contains_proof ( facts_hash) ? {
171+ fn get_proof ( & self , proof_facts : ProofFacts ) -> Result < Option < Proof > , Self :: Error > {
172+ let facts_hash = proof_facts. hash ( ) ;
173+ if !self . contains_proof_by_hash ( facts_hash) {
167174 return Ok ( None ) ;
168175 }
169176
@@ -176,7 +183,7 @@ impl ProofStorage for FsProofStorage {
176183 }
177184 }
178185
179- fn contains_proof ( & self , facts_hash : Felt ) -> Result < bool , Self :: Error > {
180- Ok ( self . get_persistent_dir ( facts_hash ) . exists ( ) )
186+ fn contains_proof ( & self , proof_facts : ProofFacts ) -> Result < bool , Self :: Error > {
187+ Ok ( self . contains_proof_by_hash ( proof_facts . hash ( ) ) )
181188 }
182189}
0 commit comments