From 64478acef72211a0ef6c151e45ec065fcb5c1ed8 Mon Sep 17 00:00:00 2001 From: David Ansermino Date: Fri, 5 Jul 2019 16:51:21 -0400 Subject: [PATCH 1/6] Adds AppModuleBasic implementation and genesis functions --- {app => x/evm}/genesis.go | 20 +++++++++++++++- x/evm/module.go | 48 +++++++++++++++++++++++++++++++++++++++ x/evm/types/codec.go | 5 ++-- x/evm/types/key.go | 10 ++++++++ 4 files changed, 80 insertions(+), 3 deletions(-) rename {app => x/evm}/genesis.go (59%) create mode 100644 x/evm/module.go create mode 100644 x/evm/types/key.go diff --git a/app/genesis.go b/x/evm/genesis.go similarity index 59% rename from app/genesis.go rename to x/evm/genesis.go index 0b59fe14e..9f8c08aa5 100644 --- a/app/genesis.go +++ b/x/evm/genesis.go @@ -1,6 +1,7 @@ -package app +package evm import ( + "fmt" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/ethermint/types" ) @@ -20,3 +21,20 @@ type ( Storage types.Storage `json:"storage,omitempty"` } ) + +func ValidateGenesis(data GenesisState) error { + for _, acct := range data.Accounts { + if acct.Address == nil { + return fmt.Errorf("Invalid GenesisAccount Error: Missing Address") + } + if acct.Coins == nil { + return fmt.Errorf("Invalid GenesisAccount Error: Missing Coins") + } + } +} + +func DefaultGenesisState() GenesisState { + return GenesisState{ + Accounts: []GenesisAccount{}, + } +} diff --git a/x/evm/module.go b/x/evm/module.go new file mode 100644 index 000000000..ff85b7e3e --- /dev/null +++ b/x/evm/module.go @@ -0,0 +1,48 @@ +package evm + +import ( + "encoding/json" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/ethermint/x/evm/types" +) + +// app module Basics object +type AppModuleBasic struct{} + +func (AppModuleBasic) Name() string { + return types.ModuleName +} + +func (AppModuleBasic) RegisterCodec(cdc *codec.Codec) { + types.RegisterCodec(cdc) +} + +func (AppModuleBasic) DefaultGenesis() json.RawMessage { + return types.ModuleCdc.MustMarshalJSON(DefaultGenesisState()) +} + +// Validation check of the Genesis +func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { + var data GenesisState + err := types.ModuleCdc.UnmarshalJSON(bz, &data) + if err != nil { + return err + } + // Once json successfully marshalled, passes along to genesis.go + return ValidateGenesis(data) +} + +// Register rest routes +//func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { +// rpc.RegisterRoutes(ctx, rtr, StoreKey) +//} + +//// Get the root query command of this module +//func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { +// return cli.GetQueryCmd(StoreKey, cdc) +//} +// +//// Get the root tx command of this module +//func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { +// return cli.GetTxCmd(StoreKey, cdc) +//} diff --git a/x/evm/types/codec.go b/x/evm/types/codec.go index c30ae1e97..536d385e6 100644 --- a/x/evm/types/codec.go +++ b/x/evm/types/codec.go @@ -2,7 +2,8 @@ package types import "github.com/cosmos/cosmos-sdk/codec" -var msgCodec = codec.New() +// TODO: Is this the MAIN codec? or should it only be applied to eth specific messages (originally `MsgCodec`) +var ModuleCdc = codec.New() func init() { cdc := codec.New() @@ -10,7 +11,7 @@ func init() { RegisterCodec(cdc) codec.RegisterCrypto(cdc) - msgCodec = cdc.Seal() + ModuleCdc = cdc.Seal() } // RegisterCodec registers concrete types and interfaces on the given codec. diff --git a/x/evm/types/key.go b/x/evm/types/key.go new file mode 100644 index 000000000..afc45877c --- /dev/null +++ b/x/evm/types/key.go @@ -0,0 +1,10 @@ +package types + +const ( + // module name + ModuleName = "ethermint" + + // TODO: Use this + // StoreKey to be used when creating the KVStore + StoreKey = ModuleName +) \ No newline at end of file From de9506fa2808ba0474d0b2130944130b314e99d8 Mon Sep 17 00:00:00 2001 From: David Ansermino Date: Fri, 5 Jul 2019 17:00:14 -0400 Subject: [PATCH 2/6] Fixes broken links --- app/ethermint.go | 3 ++- x/evm/genesis.go | 1 + x/evm/types/msg_test.go | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/ethermint.go b/app/ethermint.go index 84df14cef..7231ae0ea 100644 --- a/app/ethermint.go +++ b/app/ethermint.go @@ -1,6 +1,7 @@ package app import ( + "github.com/cosmos/ethermint/x/evm" "os" bam "github.com/cosmos/cosmos-sdk/baseapp" @@ -164,7 +165,7 @@ func (app *EthermintApp) initChainer( _ sdk.Context, req abci.RequestInitChain, ) abci.ResponseInitChain { - var genesisState GenesisState + var genesisState evm.GenesisState stateJSON := req.AppStateBytes err := app.cdc.UnmarshalJSON(stateJSON, &genesisState) diff --git a/x/evm/genesis.go b/x/evm/genesis.go index 9f8c08aa5..83b8291b8 100644 --- a/x/evm/genesis.go +++ b/x/evm/genesis.go @@ -31,6 +31,7 @@ func ValidateGenesis(data GenesisState) error { return fmt.Errorf("Invalid GenesisAccount Error: Missing Coins") } } + return nil } func DefaultGenesisState() GenesisState { diff --git a/x/evm/types/msg_test.go b/x/evm/types/msg_test.go index 3fe43838e..161b49dba 100644 --- a/x/evm/types/msg_test.go +++ b/x/evm/types/msg_test.go @@ -124,12 +124,12 @@ func TestMsgEthereumTxAmino(t *testing.T) { addr := GenerateEthAddress() msg := NewEthereumTxMsg(0, addr, nil, 100000, nil, []byte("test")) - raw, err := msgCodec.MarshalBinaryBare(msg) + raw, err := ModuleCdc.MarshalBinaryBare(msg) require.NoError(t, err) var msg2 EthereumTxMsg - err = msgCodec.UnmarshalBinaryBare(raw, &msg2) + err = ModuleCdc.UnmarshalBinaryBare(raw, &msg2) require.NoError(t, err) require.Equal(t, msg.Data, msg2.Data) } From 31fa7778414ffa6826df8cd516153570c7e1f353 Mon Sep 17 00:00:00 2001 From: David Ansermino Date: Fri, 5 Jul 2019 17:01:22 -0400 Subject: [PATCH 3/6] Adds .idea/ --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 17cffba80..bb3a3e0e3 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ .glide/ vendor/ build/ + +# Goland +.idea/ \ No newline at end of file From d12893f7dff6fe97610560bc735331c8f3a3f535 Mon Sep 17 00:00:00 2001 From: David Ansermino Date: Sat, 6 Jul 2019 11:47:26 -0400 Subject: [PATCH 4/6] Adds starter for missing genesis funcs --- x/evm/genesis.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/x/evm/genesis.go b/x/evm/genesis.go index 83b8291b8..6b0cee023 100644 --- a/x/evm/genesis.go +++ b/x/evm/genesis.go @@ -39,3 +39,15 @@ func DefaultGenesisState() GenesisState { Accounts: []GenesisAccount{}, } } + +// TODO: Implement these once keeper is established +//func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) []abci.ValidatorUpdate { +// for _, record := range data.Accounts { +// // TODO: Add to keeper +// } +// return []abci.ValidatorUpdate{} +//} +// +//func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState { +// return GenesisState{Accounts: nil} +//} From 18202088d12672eca505b750c37ebfeda868b76f Mon Sep 17 00:00:00 2001 From: David Ansermino Date: Sat, 6 Jul 2019 11:48:53 -0400 Subject: [PATCH 5/6] Completes AppModuleBasic interface --- x/evm/module.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/x/evm/module.go b/x/evm/module.go index ff85b7e3e..c2c0141f9 100644 --- a/x/evm/module.go +++ b/x/evm/module.go @@ -2,8 +2,11 @@ package evm import ( "encoding/json" + "github.com/cosmos/cosmos-sdk/client/context" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/ethermint/x/evm/types" + "github.com/gorilla/mux" + "github.com/spf13/cobra" ) // app module Basics object @@ -33,16 +36,16 @@ func (AppModuleBasic) ValidateGenesis(bz json.RawMessage) error { } // Register rest routes -//func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { -// rpc.RegisterRoutes(ctx, rtr, StoreKey) -//} - -//// Get the root query command of this module -//func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { -// return cli.GetQueryCmd(StoreKey, cdc) -//} -// -//// Get the root tx command of this module -//func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { -// return cli.GetTxCmd(StoreKey, cdc) -//} +func (AppModuleBasic) RegisterRESTRoutes(ctx context.CLIContext, rtr *mux.Router) { + //rpc.RegisterRoutes(ctx, rtr, StoreKey) +} + +// Get the root query command of this module +func (AppModuleBasic) GetQueryCmd(cdc *codec.Codec) *cobra.Command { + return nil // cli.GetQueryCmd(StoreKey, cdc) +} + +// Get the root tx command of this module +func (AppModuleBasic) GetTxCmd(cdc *codec.Codec) *cobra.Command { + return nil // cli.GetTxCmd(StoreKey, cdc) +} From d61b7b19f644e8a487ba55321a24dd7af4827d62 Mon Sep 17 00:00:00 2001 From: David Ansermino Date: Sat, 6 Jul 2019 11:57:01 -0400 Subject: [PATCH 6/6] Removes comment --- x/evm/types/codec.go | 1 - 1 file changed, 1 deletion(-) diff --git a/x/evm/types/codec.go b/x/evm/types/codec.go index 536d385e6..985e4def6 100644 --- a/x/evm/types/codec.go +++ b/x/evm/types/codec.go @@ -2,7 +2,6 @@ package types import "github.com/cosmos/cosmos-sdk/codec" -// TODO: Is this the MAIN codec? or should it only be applied to eth specific messages (originally `MsgCodec`) var ModuleCdc = codec.New() func init() {