2018-07-19 21:16:48 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2019-07-05 16:46:13 +00:00
|
|
|
"os"
|
|
|
|
|
2019-07-08 19:26:33 +00:00
|
|
|
"github.com/cosmos/ethermint/x/evm"
|
|
|
|
|
2018-07-19 21:16:48 +00:00
|
|
|
bam "github.com/cosmos/cosmos-sdk/baseapp"
|
2018-10-24 14:49:37 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2018-08-09 01:06:34 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2019-07-08 19:26:33 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
2018-08-09 01:06:34 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
2019-07-04 19:46:54 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
|
|
|
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
2019-07-08 19:26:33 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/genaccounts"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/genutil"
|
2018-08-24 18:56:43 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
2019-07-04 19:46:54 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/mint"
|
2018-08-24 18:56:43 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/params"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing"
|
2019-07-04 19:46:54 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/supply"
|
2018-08-09 01:06:34 +00:00
|
|
|
|
2018-12-18 16:10:04 +00:00
|
|
|
"github.com/cosmos/ethermint/crypto"
|
2018-11-28 22:19:22 +00:00
|
|
|
evmtypes "github.com/cosmos/ethermint/x/evm/types"
|
2018-08-09 01:06:34 +00:00
|
|
|
|
2018-11-28 22:19:22 +00:00
|
|
|
"github.com/pkg/errors"
|
2018-08-09 01:06:34 +00:00
|
|
|
|
2018-08-24 18:56:43 +00:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2018-08-09 01:06:34 +00:00
|
|
|
tmcmn "github.com/tendermint/tendermint/libs/common"
|
|
|
|
dbm "github.com/tendermint/tendermint/libs/db"
|
|
|
|
tmlog "github.com/tendermint/tendermint/libs/log"
|
2018-07-19 21:16:48 +00:00
|
|
|
)
|
|
|
|
|
2018-11-28 22:19:22 +00:00
|
|
|
const appName = "Ethermint"
|
|
|
|
|
|
|
|
// application multi-store keys
|
|
|
|
var (
|
2019-07-05 16:46:13 +00:00
|
|
|
// default home directories for the application CLI
|
|
|
|
DefaultCLIHome = os.ExpandEnv("$HOME/.emintcli")
|
|
|
|
|
2019-07-08 19:26:33 +00:00
|
|
|
// DefaultNodeHome sets the folder where the applcation data and configuration will be stored
|
|
|
|
DefaultNodeHome = os.ExpandEnv("$HOME/.emintd")
|
|
|
|
|
|
|
|
// ModuleBasics is in charge of setting up basic module elements
|
|
|
|
ModuleBasics = module.NewBasicManager(
|
|
|
|
genaccounts.AppModuleBasic{},
|
|
|
|
genutil.AppModuleBasic{},
|
|
|
|
auth.AppModuleBasic{},
|
|
|
|
bank.AppModuleBasic{},
|
|
|
|
params.AppModuleBasic{},
|
|
|
|
evm.AppModuleBasic{},
|
|
|
|
staking.AppModuleBasic{},
|
|
|
|
distr.AppModuleBasic{},
|
|
|
|
slashing.AppModuleBasic{},
|
|
|
|
)
|
|
|
|
|
2018-11-28 22:19:22 +00:00
|
|
|
storeKeyAccount = sdk.NewKVStoreKey("acc")
|
|
|
|
storeKeyStorage = sdk.NewKVStoreKey("contract_storage")
|
|
|
|
storeKeyMain = sdk.NewKVStoreKey("main")
|
|
|
|
storeKeyStake = sdk.NewKVStoreKey("stake")
|
|
|
|
storeKeySlashing = sdk.NewKVStoreKey("slashing")
|
|
|
|
storeKeyGov = sdk.NewKVStoreKey("gov")
|
2019-07-04 19:46:54 +00:00
|
|
|
storeKeySupply = sdk.NewKVStoreKey("supply")
|
2018-11-28 22:19:22 +00:00
|
|
|
storeKeyParams = sdk.NewKVStoreKey("params")
|
|
|
|
storeKeyTransParams = sdk.NewTransientStoreKey("transient_params")
|
2018-07-19 21:16:48 +00:00
|
|
|
)
|
|
|
|
|
2019-07-08 19:26:33 +00:00
|
|
|
// MakeCodec generates the necessary codecs for Amino
|
|
|
|
func MakeCodec() *codec.Codec {
|
|
|
|
var cdc = codec.New()
|
|
|
|
ModuleBasics.RegisterCodec(cdc)
|
|
|
|
sdk.RegisterCodec(cdc)
|
|
|
|
codec.RegisterCrypto(cdc)
|
|
|
|
return cdc
|
|
|
|
}
|
|
|
|
|
|
|
|
// EthermintApp implements an extended ABCI application. It is an application
|
|
|
|
// that may process transactions through Ethereum's EVM running atop of
|
|
|
|
// Tendermint consensus.
|
|
|
|
type EthermintApp struct {
|
|
|
|
*bam.BaseApp
|
|
|
|
|
|
|
|
cdc *codec.Codec
|
|
|
|
|
|
|
|
accountKey *sdk.KVStoreKey
|
|
|
|
storageKey *sdk.KVStoreKey
|
|
|
|
mainKey *sdk.KVStoreKey
|
|
|
|
stakeKey *sdk.KVStoreKey
|
|
|
|
slashingKey *sdk.KVStoreKey
|
|
|
|
govKey *sdk.KVStoreKey
|
|
|
|
supplyKey *sdk.KVStoreKey
|
|
|
|
paramsKey *sdk.KVStoreKey
|
|
|
|
tParamsKey *sdk.TransientStoreKey
|
|
|
|
|
|
|
|
accountKeeper auth.AccountKeeper
|
|
|
|
supplyKeeper supply.Keeper
|
|
|
|
bankKeeper bank.Keeper
|
|
|
|
stakeKeeper staking.Keeper
|
|
|
|
slashingKeeper slashing.Keeper
|
|
|
|
govKeeper gov.Keeper
|
|
|
|
paramsKeeper params.Keeper
|
|
|
|
}
|
2018-07-19 21:16:48 +00:00
|
|
|
|
|
|
|
// NewEthermintApp returns a reference to a new initialized Ethermint
|
|
|
|
// application.
|
2018-11-28 22:19:22 +00:00
|
|
|
//
|
|
|
|
// TODO: Ethermint needs to support being bootstrapped as an application running
|
|
|
|
// in a sovereign zone and as an application running with a shared security model.
|
|
|
|
// For now, it will support only running as a sovereign application.
|
|
|
|
func NewEthermintApp(logger tmlog.Logger, db dbm.DB, baseAppOpts ...func(*bam.BaseApp)) *EthermintApp {
|
2018-10-24 14:49:37 +00:00
|
|
|
cdc := CreateCodec()
|
2018-09-07 17:34:29 +00:00
|
|
|
|
2018-12-18 16:10:04 +00:00
|
|
|
baseApp := bam.NewBaseApp(appName, logger, db, evmtypes.TxDecoder(cdc), baseAppOpts...)
|
2018-08-09 01:06:34 +00:00
|
|
|
app := &EthermintApp{
|
2018-09-07 17:34:29 +00:00
|
|
|
BaseApp: baseApp,
|
2018-10-24 14:49:37 +00:00
|
|
|
cdc: cdc,
|
2018-11-28 22:19:22 +00:00
|
|
|
accountKey: storeKeyAccount,
|
|
|
|
storageKey: storeKeyStorage,
|
|
|
|
mainKey: storeKeyMain,
|
|
|
|
stakeKey: storeKeyStake,
|
|
|
|
slashingKey: storeKeySlashing,
|
|
|
|
govKey: storeKeyGov,
|
2019-07-04 19:46:54 +00:00
|
|
|
supplyKey: storeKeySupply,
|
2018-11-28 22:19:22 +00:00
|
|
|
paramsKey: storeKeyParams,
|
|
|
|
tParamsKey: storeKeyTransParams,
|
2018-08-09 01:06:34 +00:00
|
|
|
}
|
2018-08-24 18:56:43 +00:00
|
|
|
|
2019-07-04 19:46:54 +00:00
|
|
|
// Set params keeper and subspaces
|
|
|
|
app.paramsKeeper = params.NewKeeper(app.cdc, app.paramsKey, app.tParamsKey, params.DefaultCodespace)
|
|
|
|
authSubspace := app.paramsKeeper.Subspace(auth.DefaultParamspace)
|
|
|
|
bankSubspace := app.paramsKeeper.Subspace(bank.DefaultParamspace)
|
|
|
|
|
|
|
|
// account permissions
|
|
|
|
basicModuleAccs := []string{auth.FeeCollectorName, distr.ModuleName}
|
|
|
|
minterModuleAccs := []string{mint.ModuleName}
|
|
|
|
burnerModuleAccs := []string{staking.BondedPoolName, staking.NotBondedPoolName, gov.ModuleName}
|
|
|
|
|
|
|
|
// Add keepers
|
|
|
|
app.accountKeeper = auth.NewAccountKeeper(app.cdc, app.accountKey, authSubspace, auth.ProtoBaseAccount)
|
|
|
|
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper, bankSubspace, bank.DefaultCodespace)
|
|
|
|
app.supplyKeeper = supply.NewKeeper(cdc, app.supplyKey, app.accountKeeper, app.bankKeeper, supply.DefaultCodespace, basicModuleAccs, minterModuleAccs, burnerModuleAccs)
|
2018-08-24 18:56:43 +00:00
|
|
|
|
|
|
|
// register message handlers
|
|
|
|
app.Router().
|
2018-11-28 22:19:22 +00:00
|
|
|
// TODO: add remaining routes
|
2019-07-04 19:46:54 +00:00
|
|
|
AddRoute("stake", staking.NewHandler(app.stakeKeeper)).
|
2018-08-24 18:56:43 +00:00
|
|
|
AddRoute("slashing", slashing.NewHandler(app.slashingKeeper)).
|
|
|
|
AddRoute("gov", gov.NewHandler(app.govKeeper))
|
|
|
|
|
|
|
|
// initialize the underlying ABCI BaseApp
|
|
|
|
app.SetInitChainer(app.initChainer)
|
|
|
|
app.SetBeginBlocker(app.BeginBlocker)
|
|
|
|
app.SetEndBlocker(app.EndBlocker)
|
2019-07-04 19:46:54 +00:00
|
|
|
app.SetAnteHandler(NewAnteHandler(app.accountKeeper, app.supplyKeeper))
|
2018-08-24 18:56:43 +00:00
|
|
|
|
2018-12-18 16:10:04 +00:00
|
|
|
app.MountStores(
|
2018-08-24 18:56:43 +00:00
|
|
|
app.mainKey, app.accountKey, app.stakeKey, app.slashingKey,
|
2019-07-04 19:46:54 +00:00
|
|
|
app.govKey, app.supplyKey, app.paramsKey, app.storageKey,
|
2018-08-24 18:56:43 +00:00
|
|
|
)
|
|
|
|
app.MountStore(app.tParamsKey, sdk.StoreTypeTransient)
|
|
|
|
|
|
|
|
if err := app.LoadLatestVersion(app.accountKey); err != nil {
|
|
|
|
tmcmn.Exit(err.Error())
|
|
|
|
}
|
2018-08-09 01:06:34 +00:00
|
|
|
|
2018-08-24 18:56:43 +00:00
|
|
|
app.BaseApp.Seal()
|
|
|
|
return app
|
|
|
|
}
|
2018-07-19 21:16:48 +00:00
|
|
|
|
2018-08-24 18:56:43 +00:00
|
|
|
// BeginBlocker signals the beginning of a block. It performs application
|
|
|
|
// updates on the start of every block.
|
2018-11-28 22:19:22 +00:00
|
|
|
func (app *EthermintApp) BeginBlocker(
|
|
|
|
_ sdk.Context, _ abci.RequestBeginBlock,
|
|
|
|
) abci.ResponseBeginBlock {
|
|
|
|
|
2018-10-24 14:21:51 +00:00
|
|
|
return abci.ResponseBeginBlock{}
|
2018-08-24 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EndBlocker signals the end of a block. It performs application updates on
|
|
|
|
// the end of every block.
|
2018-11-28 22:19:22 +00:00
|
|
|
func (app *EthermintApp) EndBlocker(
|
|
|
|
_ sdk.Context, _ abci.RequestEndBlock,
|
|
|
|
) abci.ResponseEndBlock {
|
|
|
|
|
2018-10-24 14:21:51 +00:00
|
|
|
return abci.ResponseEndBlock{}
|
2018-08-24 18:56:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// initChainer initializes the application blockchain with validators and other
|
|
|
|
// state data from TendermintCore.
|
2018-11-28 22:19:22 +00:00
|
|
|
func (app *EthermintApp) initChainer(
|
|
|
|
_ sdk.Context, req abci.RequestInitChain,
|
|
|
|
) abci.ResponseInitChain {
|
|
|
|
|
2019-07-08 16:02:20 +00:00
|
|
|
var genesisState evm.GenesisState
|
2018-08-24 18:56:43 +00:00
|
|
|
stateJSON := req.AppStateBytes
|
|
|
|
|
2018-10-24 14:49:37 +00:00
|
|
|
err := app.cdc.UnmarshalJSON(stateJSON, &genesisState)
|
2018-08-09 01:06:34 +00:00
|
|
|
if err != nil {
|
2018-08-24 18:56:43 +00:00
|
|
|
panic(errors.Wrap(err, "failed to parse application genesis state"))
|
2018-08-09 01:06:34 +00:00
|
|
|
}
|
|
|
|
|
2018-10-24 14:21:51 +00:00
|
|
|
// TODO: load the genesis accounts
|
2018-07-19 21:16:48 +00:00
|
|
|
|
2018-10-24 14:21:51 +00:00
|
|
|
return abci.ResponseInitChain{}
|
2018-07-19 21:16:48 +00:00
|
|
|
}
|
2018-08-09 01:06:34 +00:00
|
|
|
|
|
|
|
// CreateCodec creates a new amino wire codec and registers all the necessary
|
2018-08-30 18:32:32 +00:00
|
|
|
// concrete types and interfaces needed for the application.
|
2018-10-24 14:49:37 +00:00
|
|
|
func CreateCodec() *codec.Codec {
|
|
|
|
cdc := codec.New()
|
2018-08-09 01:06:34 +00:00
|
|
|
|
2018-11-28 22:19:22 +00:00
|
|
|
// TODO: Add remaining codec registrations:
|
|
|
|
// bank, staking, distribution, slashing, and gov
|
|
|
|
|
2018-12-18 16:10:04 +00:00
|
|
|
crypto.RegisterCodec(cdc)
|
2018-11-28 22:19:22 +00:00
|
|
|
evmtypes.RegisterCodec(cdc)
|
2018-10-24 14:49:37 +00:00
|
|
|
auth.RegisterCodec(cdc)
|
2018-11-28 22:19:22 +00:00
|
|
|
sdk.RegisterCodec(cdc)
|
2018-10-24 14:49:37 +00:00
|
|
|
codec.RegisterCrypto(cdc)
|
2018-08-24 18:56:43 +00:00
|
|
|
|
2018-10-24 14:49:37 +00:00
|
|
|
return cdc
|
2018-08-09 01:06:34 +00:00
|
|
|
}
|