@@ -250,28 +250,24 @@ func getContractProof(
250250 }
251251}
252252
253- func getContractProofWithDeprecatedTrie (
254- tr * trie.Trie ,
253+ func buildContractLeavesData (
255254 state core.CommonStateReader ,
256255 contracts []felt.Felt ,
257- ) (* ContractProof , error ) {
258- contractProof := trie .NewProofNodeSet ()
256+ getRoot func () (felt.Felt , error ),
257+ contractNotFoundErr error ,
258+ ) ([]* LeafData , error ) {
259259 contractLeavesData := make ([]* LeafData , len (contracts ))
260260
261261 for i , contract := range contracts {
262- if err := tr .Prove (& contract , contractProof ); err != nil {
263- return nil , err
264- }
265-
266- root , err := tr .Hash ()
262+ root , err := getRoot ()
267263 if err != nil {
268264 return nil , err
269265 }
270266
271267 nonce , err := state .ContractNonce (& contract )
272268 if err != nil {
273269 // contract does not exist, skip getting leaf data
274- if errors .Is (err , db . ErrKeyNotFound ) {
270+ if errors .Is (err , contractNotFoundErr ) {
275271 continue
276272 }
277273 return nil , err
@@ -289,6 +285,27 @@ func getContractProofWithDeprecatedTrie(
289285 }
290286 }
291287
288+ return contractLeavesData , nil
289+ }
290+
291+ func getContractProofWithDeprecatedTrie (
292+ tr * trie.Trie ,
293+ state core.CommonStateReader ,
294+ contracts []felt.Felt ,
295+ ) (* ContractProof , error ) {
296+ contractProof := trie .NewProofNodeSet ()
297+
298+ for _ , contract := range contracts {
299+ if err := tr .Prove (& contract , contractProof ); err != nil {
300+ return nil , err
301+ }
302+ }
303+
304+ contractLeavesData , err := buildContractLeavesData (state , contracts , tr .Hash , db .ErrKeyNotFound )
305+ if err != nil {
306+ return nil , err
307+ }
308+
292309 return & ContractProof {
293310 Nodes : adaptDeprecatedTrieProofNodes (contractProof ),
294311 LeavesData : contractLeavesData ,
@@ -301,36 +318,16 @@ func getContractProofWithTrie(
301318 contracts []felt.Felt ,
302319) (* ContractProof , error ) {
303320 contractProof := trie2 .NewProofNodeSet ()
304- contractLeavesData := make ([]* LeafData , len (contracts ))
305- for i , contract := range contracts {
306- if err := tr .Prove (& contract , contractProof ); err != nil {
307- return nil , err
308- }
309321
310- root , err := tr .Hash ()
311- if err != nil {
312- return nil , err
313- }
314-
315- nonce , err := st .ContractNonce (& contract )
316- if err != nil {
317- // contract does not exist, skip getting leaf data
318- if errors .Is (err , state .ErrContractNotDeployed ) {
319- continue
320- }
321- return nil , err
322- }
323-
324- classHash , err := st .ContractClassHash (& contract )
325- if err != nil {
322+ for _ , contract := range contracts {
323+ if err := tr .Prove (& contract , contractProof ); err != nil {
326324 return nil , err
327325 }
326+ }
328327
329- contractLeavesData [i ] = & LeafData {
330- Nonce : & nonce ,
331- ClassHash : & classHash ,
332- StorageRoot : & root ,
333- }
328+ contractLeavesData , err := buildContractLeavesData (st , contracts , tr .Hash , state .ErrContractNotDeployed )
329+ if err != nil {
330+ return nil , err
334331 }
335332
336333 return & ContractProof {
0 commit comments