@@ -710,45 +710,52 @@ type ExecutionResult struct {
710
710
// StructLogRes stores a structured log emitted by the EVM while replaying a
711
711
// transaction in debug mode
712
712
type StructLogRes struct {
713
- Pc uint64 `json:"pc"`
714
- Op string `json:"op"`
715
- Gas uint64 `json:"gas"`
716
- GasCost uint64 `json:"gasCost"`
717
- Depth int `json:"depth"`
718
- Error error `json:"error"`
719
- Stack []string `json:"stack"`
720
- Memory []string `json:"memory"`
721
- Storage map [string ]string `json:"storage"`
713
+ Pc uint64 `json:"pc"`
714
+ Op string `json:"op"`
715
+ Gas uint64 `json:"gas"`
716
+ GasCost uint64 `json:"gasCost"`
717
+ Depth int `json:"depth"`
718
+ Error error `json:"error,omitempty "`
719
+ Stack * []string `json:"stack,omitempty "`
720
+ Memory * []string `json:"memory,omitempty "`
721
+ Storage * map [string ]string `json:"storage,omitempty "`
722
722
}
723
723
724
724
// formatLogs formats EVM returned structured logs for json output
725
- func FormatLogs (structLogs []vm.StructLog ) []StructLogRes {
726
- formattedStructLogs := make ([]StructLogRes , len (structLogs ))
727
- for index , trace := range structLogs {
728
- formattedStructLogs [index ] = StructLogRes {
725
+ func FormatLogs (logs []vm.StructLog ) []StructLogRes {
726
+ formatted := make ([]StructLogRes , len (logs ))
727
+ for index , trace := range logs {
728
+ formatted [index ] = StructLogRes {
729
729
Pc : trace .Pc ,
730
730
Op : trace .Op .String (),
731
731
Gas : trace .Gas ,
732
732
GasCost : trace .GasCost ,
733
733
Depth : trace .Depth ,
734
734
Error : trace .Err ,
735
- Stack : make ([]string , len (trace .Stack )),
736
- Storage : make (map [string ]string ),
737
735
}
738
-
739
- for i , stackValue := range trace .Stack {
740
- formattedStructLogs [index ].Stack [i ] = fmt .Sprintf ("%x" , math .PaddedBigBytes (stackValue , 32 ))
736
+ if trace .Stack != nil {
737
+ stack := make ([]string , len (trace .Stack ))
738
+ for i , stackValue := range trace .Stack {
739
+ stack [i ] = fmt .Sprintf ("%x" , math .PaddedBigBytes (stackValue , 32 ))
740
+ }
741
+ formatted [index ].Stack = & stack
741
742
}
742
-
743
- for i := 0 ; i + 32 <= len (trace .Memory ); i += 32 {
744
- formattedStructLogs [index ].Memory = append (formattedStructLogs [index ].Memory , fmt .Sprintf ("%x" , trace .Memory [i :i + 32 ]))
743
+ if trace .Memory != nil {
744
+ memory := make ([]string , 0 , (len (trace .Memory )+ 31 )/ 32 )
745
+ for i := 0 ; i + 32 <= len (trace .Memory ); i += 32 {
746
+ memory = append (memory , fmt .Sprintf ("%x" , trace .Memory [i :i + 32 ]))
747
+ }
748
+ formatted [index ].Memory = & memory
745
749
}
746
-
747
- for i , storageValue := range trace .Storage {
748
- formattedStructLogs [index ].Storage [fmt .Sprintf ("%x" , i )] = fmt .Sprintf ("%x" , storageValue )
750
+ if trace .Storage != nil {
751
+ storage := make (map [string ]string )
752
+ for i , storageValue := range trace .Storage {
753
+ storage [fmt .Sprintf ("%x" , i )] = fmt .Sprintf ("%x" , storageValue )
754
+ }
755
+ formatted [index ].Storage = & storage
749
756
}
750
757
}
751
- return formattedStructLogs
758
+ return formatted
752
759
}
753
760
754
761
// rpcOutputBlock converts the given block to the RPC output which depends on fullTx. If inclTx is true transactions are
0 commit comments