@@ -42,6 +42,7 @@ type LogConfig struct {
4242 DisableStack bool // disable stack capture
4343 DisableStorage bool // disable storage capture
4444 FullStorage bool // show full storage (slow)
45+ Limit int // maximum length of output, but zero means unlimited
4546}
4647
4748// StructLog is emitted to the Environment each cycle and lists information about the current internal state
@@ -64,7 +65,7 @@ type StructLog struct {
6465// Note that reference types are actual VM data structures; make copies
6566// if you need to retain them beyond the current call.
6667type Tracer interface {
67- CaptureState (env Environment , pc uint64 , op OpCode , gas , cost * big.Int , memory * Memory , stack * Stack , contract * Contract , depth int , err error )
68+ CaptureState (env Environment , pc uint64 , op OpCode , gas , cost * big.Int , memory * Memory , stack * Stack , contract * Contract , depth int , err error ) error
6869}
6970
7071// StructLogger is an EVM state logger and implements Tracer.
@@ -93,7 +94,12 @@ func NewStructLogger(cfg *LogConfig) *StructLogger {
9394// captureState logs a new structured log message and pushes it out to the environment
9495//
9596// captureState also tracks SSTORE ops to track dirty values.
96- func (l * StructLogger ) CaptureState (env Environment , pc uint64 , op OpCode , gas , cost * big.Int , memory * Memory , stack * Stack , contract * Contract , depth int , err error ) {
97+ func (l * StructLogger ) CaptureState (env Environment , pc uint64 , op OpCode , gas , cost * big.Int , memory * Memory , stack * Stack , contract * Contract , depth int , err error ) error {
98+ // check if already accumulated the specified number of logs
99+ if l .cfg .Limit != 0 && l .cfg .Limit <= len (l .logs ) {
100+ return TraceLimitReachedError
101+ }
102+
97103 // initialise new changed values storage container for this contract
98104 // if not present.
99105 if l .changedValues [contract .Address ()] == nil {
@@ -152,6 +158,7 @@ func (l *StructLogger) CaptureState(env Environment, pc uint64, op OpCode, gas,
152158 log := StructLog {pc , op , new (big.Int ).Set (gas ), cost , mem , stck , storage , env .Depth (), err }
153159
154160 l .logs = append (l .logs , log )
161+ return nil
155162}
156163
157164// StructLogs returns a list of captured log entries
0 commit comments