laconicd-deprecated/x/evm/genesis.go
Federico Kunze 261f86fdf2
bump SDK to v0.39.1 (#386)
* bump sdk version to v0.39.0 candidate

* updates

* update evm

* bump commit

* more changes

* build

* genesis

* fix tests

* fix tests

* bump commit

* bump commit

* bump commit

* add keygen func

* bump version to 0.39.0-rc0

* update AnteHandler

* fix TxDecoder

* lint

* fix test

* update statedb

* changelog

* fixes

* remove extra files

* update make test-import

* rename test

* bump SDK version to final release

* update to 0.39.1-rc1

* fix evm tests

* update RPC

* minor fixes

* update to rc2

* bump to v0.39.1

* fix personal API

* fix string type cast ambiguity (#449)

* init

* fix estimate gas test

* minor genesis change

* remove comments from unstable commit (stargate release)

Co-authored-by: Alessio Treglia <quadrispro@ubuntu.com>
2020-08-23 17:41:54 -04:00

82 lines
1.9 KiB
Go

package evm
import (
sdk "github.com/cosmos/cosmos-sdk/types"
emint "github.com/cosmos/ethermint/types"
"github.com/cosmos/ethermint/x/evm/types"
abci "github.com/tendermint/tendermint/abci/types"
)
// InitGenesis initializes genesis state based on exported genesis
func InitGenesis(ctx sdk.Context, k Keeper, data GenesisState) []abci.ValidatorUpdate {
for _, account := range data.Accounts {
// FIXME: this will override bank InitGenesis balance!
k.SetBalance(ctx, account.Address, account.Balance)
k.SetCode(ctx, account.Address, account.Code)
for _, storage := range account.Storage {
k.SetState(ctx, account.Address, storage.Key, storage.Value)
}
}
var err error
for _, txLog := range data.TxsLogs {
err = k.SetLogs(ctx, txLog.Hash, txLog.Logs)
if err != nil {
panic(err)
}
}
// set state objects and code to store
_, err = k.Commit(ctx, false)
if err != nil {
panic(err)
}
// set storage to store
// NOTE: don't delete empty object to prevent import-export simulation failure
err = k.Finalise(ctx, false)
if err != nil {
panic(err)
}
return []abci.ValidatorUpdate{}
}
// ExportGenesis exports genesis state of the EVM module
func ExportGenesis(ctx sdk.Context, k Keeper, ak types.AccountKeeper) GenesisState {
// nolint: prealloc
var ethGenAccounts []types.GenesisAccount
accounts := ak.GetAllAccounts(ctx)
for _, account := range accounts {
ethAccount, ok := account.(*emint.EthAccount)
if !ok {
continue
}
addr := ethAccount.EthAddress()
storage, err := k.GetAccountStorage(ctx, addr)
if err != nil {
panic(err)
}
genAccount := types.GenesisAccount{
Address: addr,
Balance: k.GetBalance(ctx, addr),
Code: k.GetCode(ctx, addr),
Storage: storage,
}
ethGenAccounts = append(ethGenAccounts, genAccount)
}
return GenesisState{
Accounts: ethGenAccounts,
TxsLogs: k.GetAllTxLogs(ctx),
}
}