Handler Framework (#80)
* Implement base handler framework * Add comments for the missing state transition logic components for a tx * Fix typo * Remove TODO checks done by anteHandler
This commit is contained in:
parent
64b63f33f1
commit
5777ead349
@ -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{}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user