laconicd/x/evm/handler.go
Federico Kunze 0c6e44d3d3
evm: remove CommitStateDB, journal and stateObject (#84)
* evm: remove CommitStateDB and stateObject

* imported build fixes

* lint

* rm set nonce

* update account response

* changelog
2021-06-08 13:10:29 -04:00

46 lines
1.1 KiB
Go

package evm
import (
"runtime/debug"
log "github.com/xlab/suplog"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/cosmos/ethermint/x/evm/types"
)
// NewHandler returns a handler for Ethermint type messages.
func NewHandler(server types.MsgServer) sdk.Handler {
return func(ctx sdk.Context, msg sdk.Msg) (result *sdk.Result, err error) {
defer Recover(&err)
ctx = ctx.WithEventManager(sdk.NewEventManager())
switch msg := msg.(type) {
case *types.MsgEthereumTx:
// execute state transition
res, err := server.EthereumTx(sdk.WrapSDKContext(ctx), msg)
return sdk.WrapServiceResult(ctx, res, err)
default:
err := sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unrecognized %s message type: %T", types.ModuleName, msg)
return nil, err
}
}
}
func Recover(err *error) {
if r := recover(); r != nil {
*err = sdkerrors.Wrapf(sdkerrors.ErrPanic, "%v", r)
if e, ok := r.(error); ok {
log.WithError(e).Errorln("evm msg handler panicked with an error")
log.Debugln(string(debug.Stack()))
} else {
log.Errorln(r)
}
}
}