emit onNewAccount when reseting account

This commit is contained in:
Sina Mahmoodi 2024-01-30 16:36:14 +01:00
parent ae522d6fb6
commit 56862cf07f
4 changed files with 14 additions and 12 deletions

View File

@ -61,7 +61,9 @@ type StateLogger interface {
OnStorageChange(addr common.Address, slot common.Hash, prev, new common.Hash)
OnLog(log *types.Log)
// OnNewAccount is called when a new account is created.
OnNewAccount(addr common.Address)
// Reset indicates an account existed at that address
// which will be replaced.
OnNewAccount(addr common.Address, reset bool)
}
// StateDB structs within the ethereum protocol are used to store anything
@ -665,15 +667,15 @@ func (s *StateDB) getOrNewStateObject(addr common.Address) *stateObject {
func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject) {
prev = s.getDeletedStateObject(addr) // Note, prev might have been deleted, we need that!
newobj = newObject(s, addr, nil)
if s.logger != nil {
// Precompiled contracts are touched during a call.
// Make sure we avoid emitting a new account event for them.
if _, ok := s.precompiles[addr]; !ok {
s.logger.OnNewAccount(addr, prev != nil)
}
}
if prev == nil {
s.journal.append(createObjectChange{account: &addr})
if s.logger != nil {
// Precompiled contracts are touched during a call.
// Make sure we avoid emitting a new account event for them.
if _, ok := s.precompiles[addr]; !ok {
s.logger.OnNewAccount(addr)
}
}
} else {
// The original account should be marked as destructed and all cached
// account and storage data should be cleared as well. Note, it must

View File

@ -86,7 +86,7 @@ func (*NoopTracer) OnStorageChange(a common.Address, k, prev, new common.Hash) {
func (*NoopTracer) OnLog(log *types.Log) {}
func (*NoopTracer) OnNewAccount(a common.Address) {}
func (*NoopTracer) OnNewAccount(a common.Address, reset bool) {}
// GetResult returns an empty json object.
func (t *NoopTracer) GetResult() (json.RawMessage, error) {

View File

@ -125,7 +125,7 @@ func (p *Printer) OnLog(l *types.Log) {
fmt.Printf("OnLog: l=%s\n", buf)
}
func (p *Printer) OnNewAccount(a common.Address) {
func (p *Printer) OnNewAccount(a common.Address, reset bool) {
fmt.Printf("OnNewAccount: a=%v\n", a)
}

View File

@ -159,9 +159,9 @@ func (t *muxTracer) OnLog(log *types.Log) {
}
}
func (t *muxTracer) OnNewAccount(a common.Address) {
func (t *muxTracer) OnNewAccount(a common.Address, reset bool) {
for _, t := range t.tracers {
t.OnNewAccount(a)
t.OnNewAccount(a, reset)
}
}