mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-10 14:03:46 +00:00
add log and newAccount hooks
This commit is contained in:
parent
f67ac095a6
commit
84d6432708
2 changed files with 18 additions and 0 deletions
|
|
@ -58,6 +58,8 @@ type StateLogger interface {
|
||||||
OnNonceChange(addr common.Address, prev, new uint64)
|
OnNonceChange(addr common.Address, prev, new uint64)
|
||||||
OnCodeChange(addr common.Address, prevCodeHash common.Hash, prevCode []byte, codeHash common.Hash, code []byte)
|
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)
|
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
|
// 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.TxHash = s.thash
|
||||||
log.TxIndex = uint(s.txIndex)
|
log.TxIndex = uint(s.txIndex)
|
||||||
log.Index = s.logSize
|
log.Index = s.logSize
|
||||||
|
if s.logger != nil {
|
||||||
|
s.logger.OnLog(log)
|
||||||
|
}
|
||||||
s.logs[s.thash] = append(s.logs[s.thash], log)
|
s.logs[s.thash] = append(s.logs[s.thash], log)
|
||||||
s.logSize++
|
s.logSize++
|
||||||
}
|
}
|
||||||
|
|
@ -669,6 +674,11 @@ func (s *StateDB) createObject(addr common.Address) (newobj, prev *stateObject)
|
||||||
prevStorage: storage,
|
prevStorage: storage,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
// TODO: add isPrecompile check
|
||||||
|
// TODO: should we emit on account reset?
|
||||||
|
if s.logger != nil {
|
||||||
|
s.logger.OnNewAccount(addr)
|
||||||
|
}
|
||||||
s.setStateObject(newobj)
|
s.setStateObject(newobj)
|
||||||
if prev != nil && !prev.deleted {
|
if prev != nil && !prev.deleted {
|
||||||
return newobj, prev
|
return newobj, prev
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
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)
|
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)
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue