d068f5b331
* Problem: verbose logs display with FATAL option (fix #320) add my script increase amount for metamask add run amount ok hide log show info my logger hook log revive eth log tidy up use suplog log replace ok removed suplog tidy up tidy up fix compile remove sh tidy up tidy up * logger handler * fix * fix eth log override (#371) remove redundant log tidy up * log test * c++ Co-authored-by: jongwhan lee <jonghwan@crypto.com> Co-authored-by: Jongwhan Lee <51560997+leejw51crypto@users.noreply.github.com>
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package evm
|
|
|
|
import (
|
|
"fmt"
|
|
"runtime/debug"
|
|
|
|
tmlog "github.com/tendermint/tendermint/libs/log"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
|
|
|
"github.com/tharsis/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(ctx.Logger(), &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(logger tmlog.Logger, err *error) {
|
|
if r := recover(); r != nil {
|
|
*err = sdkerrors.Wrapf(sdkerrors.ErrPanic, "%v", r)
|
|
|
|
if e, ok := r.(error); ok {
|
|
logger.Error(
|
|
"message handler panicked",
|
|
"error", e,
|
|
"stack trace", string(debug.Stack()),
|
|
)
|
|
} else {
|
|
logger.Error(
|
|
"message handler panicked",
|
|
"recover", fmt.Sprintf("%v", r),
|
|
)
|
|
}
|
|
}
|
|
}
|