Daemon framework (#66)

* Implements daemon framework with basic functionality

* Comment out unused functions for linter
This commit is contained in:
Austin Abell 2019-07-08 15:26:33 -04:00 committed by GitHub
parent 1d490ba4d9
commit d982e0961a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 129 additions and 29 deletions

View File

@ -1,15 +1,19 @@
package app package app
import ( import (
"github.com/cosmos/ethermint/x/evm"
"os" "os"
"github.com/cosmos/ethermint/x/evm"
bam "github.com/cosmos/cosmos-sdk/baseapp" bam "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank" "github.com/cosmos/cosmos-sdk/x/bank"
distr "github.com/cosmos/cosmos-sdk/x/distribution" distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/genaccounts"
"github.com/cosmos/cosmos-sdk/x/genutil"
"github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/gov"
"github.com/cosmos/cosmos-sdk/x/mint" "github.com/cosmos/cosmos-sdk/x/mint"
"github.com/cosmos/cosmos-sdk/x/params" "github.com/cosmos/cosmos-sdk/x/params"
@ -35,6 +39,22 @@ var (
// default home directories for the application CLI // default home directories for the application CLI
DefaultCLIHome = os.ExpandEnv("$HOME/.emintcli") DefaultCLIHome = os.ExpandEnv("$HOME/.emintcli")
// 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{},
)
storeKeyAccount = sdk.NewKVStoreKey("acc") storeKeyAccount = sdk.NewKVStoreKey("acc")
storeKeyStorage = sdk.NewKVStoreKey("contract_storage") storeKeyStorage = sdk.NewKVStoreKey("contract_storage")
storeKeyMain = sdk.NewKVStoreKey("main") storeKeyMain = sdk.NewKVStoreKey("main")
@ -46,34 +66,41 @@ var (
storeKeyTransParams = sdk.NewTransientStoreKey("transient_params") storeKeyTransParams = sdk.NewTransientStoreKey("transient_params")
) )
type ( // MakeCodec generates the necessary codecs for Amino
// EthermintApp implements an extended ABCI application. It is an application func MakeCodec() *codec.Codec {
// that may process transactions through Ethereum's EVM running atop of var cdc = codec.New()
// Tendermint consensus. ModuleBasics.RegisterCodec(cdc)
EthermintApp struct { sdk.RegisterCodec(cdc)
*bam.BaseApp codec.RegisterCrypto(cdc)
return cdc
}
cdc *codec.Codec // 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
accountKey *sdk.KVStoreKey cdc *codec.Codec
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 accountKey *sdk.KVStoreKey
supplyKeeper supply.Keeper storageKey *sdk.KVStoreKey
bankKeeper bank.Keeper mainKey *sdk.KVStoreKey
stakeKeeper staking.Keeper stakeKey *sdk.KVStoreKey
slashingKeeper slashing.Keeper slashingKey *sdk.KVStoreKey
govKeeper gov.Keeper govKey *sdk.KVStoreKey
paramsKeeper params.Keeper 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
}
// NewEthermintApp returns a reference to a new initialized Ethermint // NewEthermintApp returns a reference to a new initialized Ethermint
// application. // application.

View File

@ -1,7 +1,79 @@
package main package main
import (
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/x/genaccounts"
genaccscli "github.com/cosmos/cosmos-sdk/x/genaccounts/client/cli"
"github.com/cosmos/cosmos-sdk/x/staking"
"github.com/spf13/cobra"
"github.com/tendermint/tendermint/libs/cli"
sdk "github.com/cosmos/cosmos-sdk/types"
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
emintapp "github.com/cosmos/ethermint/app"
)
func main() { func main() {
// TODO: Implement daemon command and logic cobra.EnableCommandSorting = false
//
// Ref: https://github.com/cosmos/ethermint/issues/433 cdc := emintapp.MakeCodec()
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(sdk.Bech32PrefixAccAddr, sdk.Bech32PrefixAccPub)
config.SetBech32PrefixForValidator(sdk.Bech32PrefixValAddr, sdk.Bech32PrefixValPub)
config.SetBech32PrefixForConsensusNode(sdk.Bech32PrefixConsAddr, sdk.Bech32PrefixConsPub)
config.Seal()
ctx := server.NewDefaultContext()
rootCmd := &cobra.Command{
Use: "emintd",
Short: "Ethermint App Daemon (server)",
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
}
// CLI commands to initialize the chain
rootCmd.AddCommand(
genutilcli.InitCmd(ctx, cdc, emintapp.ModuleBasics, emintapp.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(ctx, cdc, genaccounts.AppModuleBasic{}, emintapp.DefaultNodeHome),
genutilcli.GenTxCmd(ctx, cdc, emintapp.ModuleBasics, staking.AppModuleBasic{}, genaccounts.AppModuleBasic{}, emintapp.DefaultNodeHome, emintapp.DefaultCLIHome),
genutilcli.ValidateGenesisCmd(ctx, cdc, emintapp.ModuleBasics),
// AddGenesisAccountCmd allows users to add accounts to the genesis file
genaccscli.AddGenesisAccountCmd(ctx, cdc, emintapp.DefaultNodeHome, emintapp.DefaultCLIHome),
)
// TODO: Add export app state and TM validators commands
// server.AddCommands(ctx, cdc, rootCmd, newApp, exportAppStateAndTMValidators)
// prepare and add flags
executor := cli.PrepareBaseCmd(rootCmd, "EM", emintapp.DefaultNodeHome)
err := executor.Execute()
if err != nil {
panic(err)
}
} }
// func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application {
// return emintapp.NewEthermintApp(logger, db)
// }
// func exportAppStateAndTMValidators(
// logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, forZeroHeight bool, jailWhiteList []string,
// ) (json.RawMessage, []tmtypes.GenesisValidator, error) {
// // if height != -1 {
// // emintApp := emintapp.NewEthermintApp(logger, db)
// // err := emintApp.LoadHeight(height)
// // if err != nil {
// // return nil, nil, err
// // }
// // return emintApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
// // }
// // emintApp := emintapp.NewEthermintApp(logger, db)
// // return emintApp.ExportAppStateAndValidators(forZeroHeight, jailWhiteList)
// // TODO: Unstub method
// return json.RawMessage{}, []tmtypes.GenesisValidator{}, nil
// }

1
go.mod
View File

@ -14,6 +14,7 @@ require (
github.com/golangci/golangci-lint v1.17.1 // indirect github.com/golangci/golangci-lint v1.17.1 // indirect
github.com/google/uuid v1.0.0 // indirect github.com/google/uuid v1.0.0 // indirect
github.com/gordonklaus/ineffassign v0.0.0-20190601041439-ed7b1b5ee0f8 // indirect github.com/gordonklaus/ineffassign v0.0.0-20190601041439-ed7b1b5ee0f8 // indirect
github.com/gorilla/mux v1.7.0
github.com/hashicorp/golang-lru v0.5.0 // indirect github.com/hashicorp/golang-lru v0.5.0 // indirect
github.com/huin/goupnp v1.0.0 // indirect github.com/huin/goupnp v1.0.0 // indirect
github.com/influxdata/influxdb v1.7.7 // indirect github.com/influxdata/influxdb v1.7.7 // indirect