Skip to content

Commit

Permalink
Merge pull request #22 from b-harvest/feat/precompiled-events
Browse files Browse the repository at this point in the history
feat: add precompiled contract logs using cosmos event converter
  • Loading branch information
jasonsong0 authored Sep 11, 2024
2 parents 324e8d8 + 67de448 commit 0f22ad8
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion x/evm/statedb/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/ethereum/go-ethereum/crypto"
)

type EventConverter = func(sdk.Event) (*ethtypes.Log, error)

// revision is the identifier of a version of state.
// it consists of an auto-increment id and a journal index.
// it's safer to use than using journal index alone.
Expand Down Expand Up @@ -318,7 +320,24 @@ func (s *StateDB) RevertWithMultiStoreSnapshot(snapshot sdk.MultiStore) {

// If revert is occurred, the snapshot of journal is overwrited to MultiStore of ctx.
// The events is just for debug.
func (s *StateDB) PostPrecompileProcessing(snapshot sdk.MultiStore, events sdk.Events) {
func (s *StateDB) PostPrecompileProcessing(snapshot sdk.MultiStore, events sdk.Events, contract common.Address, converter EventConverter) {
// convert native events to evm logs
if converter != nil && len(events) > 0 {
for _, event := range events {
log, err := converter(event)
if err != nil {
s.ctx.Logger().Error("failed to convert event", "err", err)
continue
}
if log == nil {
continue
}

log.Address = contract
s.AddLog(log)
}
}

s.journal.append(precompileChange{snapshot, events})
}

Expand Down

0 comments on commit 0f22ad8

Please sign in to comment.