From 84d643270889f1a0ee4e11325bd6a4a3f987aa6d Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Thu, 22 Jun 2023 13:10:05 +0200 Subject: [PATCH] add log and newAccount hooks --- core/state/statedb.go | 10 ++++++++++ eth/tracers/printer.go | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/core/state/statedb.go b/core/state/statedb.go index 0ef6e6e344..a7f1310b98 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -58,6 +58,8 @@ type StateLogger interface { OnNonceChange(addr common.Address, prev, new uint64) OnCodeChange(addr common.Address, prevCodeHash common.Hash, prevCode []byte, codeHash common.Hash, code []byte) OnStorageChange(addr common.Address, slot common.Hash, prev, new common.Hash) + OnLog(log *types.Log) + OnNewAccount(addr common.Address) } // StateDB structs within the ethereum protocol are used to store anything @@ -214,6 +216,9 @@ func (s *StateDB) AddLog(log *types.Log) { log.TxHash = s.thash log.TxIndex = uint(s.txIndex) log.Index = s.logSize + if s.logger != nil { + s.logger.OnLog(log) + } s.logs[s.thash] = append(s.logs[s.thash], log) s.logSize++ } @@ -669,6 +674,11 @@ func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject) prevStorage: storage, }) } + // TODO: add isPrecompile check + // TODO: should we emit on account reset? + if s.logger != nil { + s.logger.OnNewAccount(addr) + } s.setStateObject(newobj) if prev != nil && !prev.deleted { return newobj, prev diff --git a/eth/tracers/printer.go b/eth/tracers/printer.go index 94e7b10b45..e77df83365 100644 --- a/eth/tracers/printer.go +++ b/eth/tracers/printer.go @@ -85,3 +85,11 @@ func (p *Printer) OnCodeChange(a common.Address, prevCodeHash common.Hash, prev func (p *Printer) OnStorageChange(a common.Address, k, prev, new common.Hash) { fmt.Printf("OnStorageChange: a=%v, k=%v, prev=%v, new=%v\n", a, k, prev, new) } + +func (p *Printer) OnLog(l *types.Log) { + fmt.Printf("OnLog: l=%v\n", l) +} + +func (p *Printer) OnNewAccount(a common.Address) { + fmt.Printf("OnNewAccount: a=%v\n", a) +}