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"
|
|
|
|
|
|
|
|
ethcmn "github.com/ethereum/go-ethereum/common"
|
|
|
|
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-09 01:06:34 +00:00
|
|
|
func NewEthermintApp(
|
|
|
|
logger tmlog.Logger, db dbm.DB, ethChainCfg *ethparams.ChainConfig,
|
|
|
|
sdkAddr ethcmn.Address, opts ...Options,
|
|
|
|
) *EthermintApp {
|
2018-07-19 21:16:48 +00:00
|
|
|
|
2018-08-09 01:06:34 +00:00
|
|
|
codec := CreateCodec()
|
|
|
|
app := &EthermintApp{
|
|
|
|
BaseApp: bam.NewBaseApp(appName, codec, logger, db),
|
|
|
|
codec: codec,
|
|
|
|
accountKey: sdk.NewKVStoreKey("accounts"),
|
|
|
|
}
|
|
|
|
app.accountMapper = auth.NewAccountMapper(codec, app.accountKey, auth.ProtoBaseAccount)
|
|
|
|
|
|
|
|
app.SetTxDecoder(types.TxDecoder(codec, sdkAddr))
|
|
|
|
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
|
|
|
|
}
|