2018-07-19 21:16:48 +00:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
bam "github.com/cosmos/cosmos-sdk/baseapp"
|
2018-08-09 01:06:34 +00:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2018-07-19 21:16:48 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/wire"
|
2018-08-09 01:06:34 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
|
|
|
|
|
|
|
"github.com/cosmos/ethermint/handlers"
|
|
|
|
"github.com/cosmos/ethermint/types"
|
|
|
|
|
|
|
|
ethparams "github.com/ethereum/go-ethereum/params"
|
|
|
|
|
|
|
|
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
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
appName = "Ethermint"
|
|
|
|
)
|
|
|
|
|
2018-08-09 01:06:34 +00:00
|
|
|
type (
|
|
|
|
// EthermintApp implements an extended ABCI application. It is an application
|
|
|
|
// that may process transactions through Ethereum's EVM running atop of
|
|
|
|
// Tendermint consensus.
|
|
|
|
EthermintApp struct {
|
|
|
|
*bam.BaseApp
|
2018-07-19 21:16:48 +00:00
|
|
|
|
2018-08-09 01:06:34 +00:00
|
|
|
codec *wire.Codec
|
|
|
|
sealed bool
|
2018-07-19 21:16:48 +00:00
|
|
|
|
2018-08-09 01:06:34 +00:00
|
|
|
accountKey *sdk.KVStoreKey
|
|
|
|
accountMapper auth.AccountMapper
|
|
|
|
// TODO: keys, stores, mappers, and keepers
|
|
|
|
}
|
2018-07-19 21:16:48 +00:00
|
|
|
|
2018-08-09 01:06:34 +00:00
|
|
|
// Options is a function signature that provides the ability to modify
|
|
|
|
// options of an EthermintApp during initialization.
|
|
|
|
Options func(*EthermintApp)
|
|
|
|
)
|
2018-07-19 21:16:48 +00:00
|
|
|
|
|
|
|
// NewEthermintApp returns a reference to a new initialized Ethermint
|
|
|
|
// application.
|
2018-08-24 15:37:18 +00:00
|
|
|
func NewEthermintApp(logger tmlog.Logger, db dbm.DB, ethChainCfg *ethparams.ChainConfig, opts ...Options,
|
2018-08-09 01:06:34 +00:00
|
|
|
) *EthermintApp {
|
2018-07-19 21:16:48 +00:00
|
|
|
|
2018-08-09 01:06:34 +00:00
|
|
|
codec := CreateCodec()
|
|
|
|
app := &EthermintApp{
|
2018-08-24 15:37:18 +00:00
|
|
|
BaseApp: bam.NewBaseApp(appName, logger, db, types.TxDecoder(codec)),
|
2018-08-09 01:06:34 +00:00
|
|
|
codec: codec,
|
|
|
|
accountKey: sdk.NewKVStoreKey("accounts"),
|
|
|
|
}
|
|
|
|
app.accountMapper = auth.NewAccountMapper(codec, app.accountKey, auth.ProtoBaseAccount)
|
|
|
|
|
|
|
|
app.SetAnteHandler(handlers.AnteHandler(app.accountMapper))
|
|
|
|
app.MountStoresIAVL(app.accountKey)
|
2018-07-19 21:16:48 +00:00
|
|
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
opt(app)
|
|
|
|
}
|
|
|
|
|
2018-08-09 01:06:34 +00:00
|
|
|
err := app.LoadLatestVersion(app.accountKey)
|
|
|
|
if err != nil {
|
|
|
|
tmcmn.Exit(err.Error())
|
|
|
|
}
|
|
|
|
|
2018-07-19 21:16:48 +00:00
|
|
|
app.seal()
|
|
|
|
return app
|
|
|
|
}
|
|
|
|
|
|
|
|
// seal seals the Ethermint application and prohibits any future modifications
|
|
|
|
// that change critical components.
|
|
|
|
func (app *EthermintApp) seal() {
|
|
|
|
app.sealed = true
|
|
|
|
}
|
2018-08-09 01:06:34 +00:00
|
|
|
|
|
|
|
// CreateCodec creates a new amino wire codec and registers all the necessary
|
|
|
|
// structures and interfaces needed for the application.
|
|
|
|
func CreateCodec() *wire.Codec {
|
|
|
|
codec := wire.NewCodec()
|
|
|
|
|
|
|
|
// Register other modules, types, and messages...
|
|
|
|
types.RegisterWire(codec)
|
|
|
|
return codec
|
|
|
|
}
|