@@ -305,8 +305,6 @@ func (h *Handler) isBlockSupported(blockID *BlockID, chainHeight uint64) *jsonrp
305305}
306306
307307func getClassProof (tr core.Trie , classes []felt.Felt ) ([]* HashToNode , error ) {
308- // TODO(maksym): remove after trie2 integration. RPC packages shouldn't
309- // care about which trie implementation is being used and the output format should be the same
310308 switch t := tr .(type ) {
311309 case * trie.Trie :
312310 classProof := trie .NewProofNodeSet ()
@@ -323,7 +321,7 @@ func getClassProof(tr core.Trie, classes []felt.Felt) ([]*HashToNode, error) {
323321 return nil , err
324322 }
325323 }
326- return adaptTrieProofNodes (classProof ), nil
324+ return adaptTrieProofNodes (classProof )
327325 default :
328326 return nil , fmt .Errorf ("unknown trie type: %T" , tr )
329327 }
@@ -334,8 +332,6 @@ func getContractProof(
334332 state core.StateReader ,
335333 contracts []felt.Felt ,
336334) (* ContractProof , error ) {
337- // TODO(maksym): remove after trie2 integration. RPC packages shouldn't
338- // care about which trie implementation is being used and the output format should be the same
339335 switch t := tr .(type ) {
340336 case * trie.Trie :
341337 return getContractProofWithDeprecatedTrie (t , state , contracts )
@@ -386,8 +382,13 @@ func getContractProofWithTrie(
386382 return nil , err
387383 }
388384
385+ nodes , err := adaptTrieProofNodes (contractProof )
386+ if err != nil {
387+ return nil , err
388+ }
389+
389390 return & ContractProof {
390- Nodes : adaptTrieProofNodes ( contractProof ) ,
391+ Nodes : nodes ,
391392 LeavesData : contractLeavesData ,
392393 }, nil
393394}
@@ -399,7 +400,8 @@ func buildContractLeavesData(
399400 contractLeavesData := make ([]* LeafData , len (contracts ))
400401 for i , contract := range contracts {
401402 classHash , err := state .ContractClassHash (& contract )
402- if err != nil { // contract does not exist, skip getting leaf data
403+ if err != nil {
404+ // contract does not exist, skip getting leaf data
403405 if errors .Is (err , db .ErrKeyNotFound ) {
404406 continue
405407 }
@@ -457,7 +459,11 @@ func getContractStorageProof(
457459 return nil , err
458460 }
459461 }
460- contractStorageRes [i ] = adaptTrieProofNodes (contractStorageProof )
462+ nodes , err := adaptTrieProofNodes (contractStorageProof )
463+ if err != nil {
464+ return nil , err
465+ }
466+ contractStorageRes [i ] = nodes
461467 default :
462468 return nil , fmt .Errorf ("unknown trie type: %T" , contractStorageTrie )
463469 }
@@ -496,24 +502,37 @@ func adaptDeprecatedTrieProofNodes(proof *trie.ProofNodeSet) []*HashToNode {
496502 return nodes
497503}
498504
499- func adaptTrieProofNodes (proof * trie2.ProofNodeSet ) []* HashToNode {
505+ func adaptTrieProofNodes (proof * trie2.ProofNodeSet ) ( []* HashToNode , error ) {
500506 nodes := make ([]* HashToNode , proof .Size ())
501507 nodeList := proof .List ()
502508 for i , hash := range proof .Keys () {
503509 var node Node
504510
505511 switch n := nodeList [i ].(type ) {
506512 case * trienode.BinaryNode :
513+ leftChild , err := nodeFelt (n .Children [0 ])
514+ if err != nil {
515+ return nil , err
516+ }
517+ rightChild , err := nodeFelt (n .Children [1 ])
518+ if err != nil {
519+ return nil , err
520+ }
507521 node = & BinaryNode {
508- Left : nodeFelt ( n . Children [ 0 ]) ,
509- Right : nodeFelt ( n . Children [ 1 ]) ,
522+ Left : & leftChild ,
523+ Right : & rightChild ,
510524 }
511525 case * trienode.EdgeNode :
512526 pathFelt := n .Path .Felt ()
527+ child , err := nodeFelt (n .Child )
528+ if err != nil {
529+ return nil , err
530+ }
531+
513532 node = & EdgeNode {
514533 Path : pathFelt .String (),
515534 Length : int (n .Path .Len ()),
516- Child : nodeFelt ( n . Child ) ,
535+ Child : & child ,
517536 }
518537 }
519538
@@ -523,17 +542,17 @@ func adaptTrieProofNodes(proof *trie2.ProofNodeSet) []*HashToNode {
523542 }
524543 }
525544
526- return nodes
545+ return nodes , nil
527546}
528547
529- func nodeFelt (n trienode.Node ) * felt.Felt {
548+ func nodeFelt (n trienode.Node ) ( felt.Felt , error ) {
530549 switch n := n .(type ) {
531550 case * trienode.HashNode :
532- return ( * felt .Felt )( n )
551+ return felt .Felt ( * n ), nil
533552 case * trienode.ValueNode :
534- return ( * felt .Felt )( n )
553+ return felt .Felt ( * n ), nil
535554 default :
536- panic ( fmt .Sprintf ("unknown node type: %T" , n ) )
555+ return felt. Felt {}, fmt .Errorf ("unknown node type: %T" , n )
537556 }
538557}
539558
0 commit comments