2019-07-08 16:02:20 +00:00
|
|
|
package evm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/ethermint/types"
|
2019-07-25 20:38:55 +00:00
|
|
|
ethcmn "github.com/ethereum/go-ethereum/common"
|
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
|
|
|
"math/big"
|
2019-07-08 16:02:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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 {
|
2019-07-25 20:38:55 +00:00
|
|
|
Address ethcmn.Address `json:"address"`
|
|
|
|
Balance *big.Int `json:"balance"`
|
2019-07-08 16:02:20 +00:00
|
|
|
Code []byte `json:"code,omitempty"`
|
|
|
|
Storage types.Storage `json:"storage,omitempty"`
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func ValidateGenesis(data GenesisState) error {
|
|
|
|
for _, acct := range data.Accounts {
|
2019-07-25 20:38:55 +00:00
|
|
|
if len(acct.Address.Bytes()) == 0 {
|
2019-07-08 16:02:20 +00:00
|
|
|
return fmt.Errorf("Invalid GenesisAccount Error: Missing Address")
|
|
|
|
}
|
2019-07-25 20:38:55 +00:00
|
|
|
if acct.Balance == nil {
|
|
|
|
return fmt.Errorf("Invalid GenesisAccount Error: Missing Balance")
|
2019-07-08 16:02:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func DefaultGenesisState() GenesisState {
|
|
|
|
return GenesisState{
|
|
|
|
Accounts: []GenesisAccount{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-25 20:38:55 +00:00
|
|
|
func InitGenesis(ctx sdk.Context, keeper Keeper, data GenesisState) []abci.ValidatorUpdate {
|
|
|
|
for _, record := range data.Accounts {
|
|
|
|
keeper.SetCode(ctx, record.Address, record.Code)
|
|
|
|
keeper.CreateGenesisAccount(ctx, record)
|
|
|
|
}
|
|
|
|
return []abci.ValidatorUpdate{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Implement
|
|
|
|
func ExportGenesis(ctx sdk.Context, k Keeper) GenesisState {
|
|
|
|
return GenesisState{Accounts: nil}
|
|
|
|
}
|