Skip to content
This repository was archived by the owner on Nov 30, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@
.glide/
vendor/
build/

# Goland
.idea/
3 changes: 2 additions & 1 deletion app/ethermint.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"github.com/cosmos/ethermint/x/evm"
"os"

bam "github.com/cosmos/cosmos-sdk/baseapp"
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 0 additions & 22 deletions app/genesis.go

This file was deleted.

53 changes: 53 additions & 0 deletions x/evm/genesis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package evm

import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/ethermint/types"
)

type (
// GenesisState defines the application's genesis state. It contains all the
// information required and accounts to initialize the blockchain.
GenesisState struct {
Accounts []GenesisAccount `json:"accounts"`
}

// GenesisAccount defines an account to be initialized in the genesis state.
GenesisAccount struct {
Address sdk.AccAddress `json:"address"`
Coins sdk.Coins `json:"coins"`
Code []byte `json:"code,omitempty"`
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")
}
}
return nil
}

func DefaultGenesisState() GenesisState {
return 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}
//}
51 changes: 51 additions & 0 deletions x/evm/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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
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 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)
}
4 changes: 2 additions & 2 deletions x/evm/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package types

import "github.com/cosmos/cosmos-sdk/codec"

var msgCodec = codec.New()
var ModuleCdc = codec.New()

func init() {
cdc := codec.New()

RegisterCodec(cdc)
codec.RegisterCrypto(cdc)

msgCodec = cdc.Seal()
ModuleCdc = cdc.Seal()
}

// RegisterCodec registers concrete types and interfaces on the given codec.
Expand Down
10 changes: 10 additions & 0 deletions x/evm/types/key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package types

const (
// module name
ModuleName = "ethermint"

// TODO: Use this
// StoreKey to be used when creating the KVStore
StoreKey = ModuleName
)
4 changes: 2 additions & 2 deletions x/evm/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}