diff --git a/x/evm/handler.go b/x/evm/handler.go index e998e558..867e8dae 100644 --- a/x/evm/handler.go +++ b/x/evm/handler.go @@ -1 +1,41 @@ package evm + +import ( + "fmt" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ethermint/x/evm/types" +) + +// NewHandler returns a handler for Ethermint type messages. +func NewHandler(keeper Keeper) sdk.Handler { + return func(ctx sdk.Context, msg sdk.Msg) sdk.Result { + switch msg := msg.(type) { + case types.EthereumTxMsg: + return handleETHTxMsg(ctx, keeper, msg) + default: + errMsg := fmt.Sprintf("Unrecognized ethermint Msg type: %v", msg.Type()) + return sdk.ErrUnknownRequest(errMsg).Result() + } + } +} + +// Handle an Ethereum specific tx +func handleETHTxMsg(ctx sdk.Context, keeper Keeper, msg types.EthereumTxMsg) sdk.Result { + // TODO: Implement transaction logic + if err := msg.ValidateBasic(); err != nil { + return sdk.ErrUnknownRequest("Basic validation failed").Result() + } + + // If no to address, create contract with evm.Create(...) + + // Else Call contract with evm.Call(...) + + // handle errors + + // Refund remaining gas from tx (Will supply keeper need to be introduced to evm Keeper to do this) + + // add balance for the processor of the tx (determine who rewards are being processed to) + + return sdk.Result{} +} diff --git a/x/evm/module.go b/x/evm/module.go index c6a1e425..ccfeb968 100644 --- a/x/evm/module.go +++ b/x/evm/module.go @@ -2,6 +2,7 @@ package evm import ( "encoding/json" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" @@ -81,7 +82,7 @@ func (am AppModule) Route() string { } func (am AppModule) NewHandler() sdk.Handler { - return nil // NewHandler(am.keeper) + return NewHandler(am.keeper) } func (am AppModule) QuerierRoute() string { return types.ModuleName