Skip to content

Commit

Permalink
cover crc20 callbacks as well
Browse files Browse the repository at this point in the history
  • Loading branch information
yihuang committed Nov 1, 2023
1 parent 59f0a53 commit 24750f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 9 additions & 0 deletions x/cronos/keeper/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/ethereum/go-ethereum/common"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/crypto"
evmtypes "github.com/evmos/ethermint/x/evm/types"

Expand Down Expand Up @@ -35,6 +36,14 @@ func (k Keeper) CallEVM(ctx sdk.Context, to *common.Address, data []byte, value
if err != nil {
return nil, nil, err
}

// if the call originally comes from an ibc-in precompiled message, re-emit the logs into the original stateDB.
if stateDB, ok := ctx.Value(types.StateDBContextKey).(vm.StateDB); ok {
for _, l := range ret.Logs {
stateDB.AddLog(l.ToEthereum())
}
}

return &msg, ret, nil
}

Expand Down
8 changes: 1 addition & 7 deletions x/cronos/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
cronosprecompiles "github.com/crypto-org-chain/cronos/v2/x/cronos/keeper/precompiles"
"github.com/crypto-org-chain/cronos/v2/x/cronos/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm"
// this line is used by starport scaffolding # ibc/keeper/import
)

Expand Down Expand Up @@ -299,16 +298,11 @@ func (k Keeper) onPacketResult(
return err
}
gasLimit := k.GetParams(ctx).MaxCallbackGas
_, rsp, err := k.CallEVM(ctx, &contractAddr, data, big.NewInt(0), gasLimit)
_, _, err = k.CallEVM(ctx, &contractAddr, data, big.NewInt(0), gasLimit)
if err != nil {
return err
}

if stateDB, ok := ctx.Value(types.StateDBContextKey).(vm.StateDB); ok {
for _, l := range rsp.Logs {
stateDB.AddLog(l.ToEthereum())
}
}
return nil
}

Expand Down

0 comments on commit 24750f1

Please sign in to comment.