diff --git a/app/app.go b/app/app.go index d0ef500da2..e20f97f2c7 100644 --- a/app/app.go +++ b/app/app.go @@ -28,12 +28,16 @@ type Basecoin struct { state *Store handler sdk.Handler + tick Ticker pending []*abci.Validator height uint64 logger log.Logger } +// Ticker - tick function +type Ticker func(sm.SimpleDB) ([]*abci.Validator, error) + var _ abci.Application = &Basecoin{} // NewBasecoin - create a new instance of the basecoin application @@ -46,6 +50,17 @@ func NewBasecoin(handler sdk.Handler, store *Store, logger log.Logger) *Basecoin } } +// NewBasecoinTick - create a new instance of the basecoin application with tick functionality +func NewBasecoinTick(handler sdk.Handler, store *Store, logger log.Logger, tick Ticker) *Basecoin { + return &Basecoin{ + handler: handler, + info: sm.NewChainState(), + state: store, + logger: logger, + tick: tick, + } +} + // GetChainID returns the currently stored chain func (app *Basecoin) GetChainID() string { return app.info.GetChainID(app.state.Committed()) @@ -168,9 +183,18 @@ func (app *Basecoin) InitChain(req abci.RequestInitChain) { // BeginBlock - ABCI func (app *Basecoin) BeginBlock(req abci.RequestBeginBlock) { app.height++ + // for _, plugin := range app.plugins.GetList() { // plugin.BeginBlock(app.state, hash, header) // } + + if app.tick != nil { + diff, err := app.tick(app.state.Append()) + if err != nil { + panic(err) + } + app.addValChange(diff) + } } // EndBlock - ABCI diff --git a/examples/eyes/cmd/eyes/init.go b/examples/eyes/cmd/eyes/init.go index 0fbe5f51ca..29e682193b 100644 --- a/examples/eyes/cmd/eyes/init.go +++ b/examples/eyes/cmd/eyes/init.go @@ -35,7 +35,7 @@ func initCmd(cmd *cobra.Command, args []string) error { } genesis := getGenesisJSON(viper.GetString(commands.FlagChainID)) - return commands.CreateGenesisValidatorFiles(cfg, genesis, cmd.Root().Name()) + return commands.CreateGenesisValidatorFiles(cfg, genesis, commands.StaticPrivValJSON, cmd.Root().Name()) } // TODO: better, auto-generate validator... diff --git a/server/commands/init.go b/server/commands/init.go index f913798d39..0935463ecd 100644 --- a/server/commands/init.go +++ b/server/commands/init.go @@ -2,6 +2,7 @@ package commands import ( "encoding/hex" + "encoding/json" "fmt" "io/ioutil" "os" @@ -13,25 +14,33 @@ import ( tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands" "github.com/tendermint/tendermint/config" + "github.com/tendermint/tendermint/types" cmn "github.com/tendermint/tmlibs/common" ) -// InitCmd - node initialization command -var InitCmd = &cobra.Command{ - Use: "init [address]", - Short: "Initialize genesis files for a blockchain", - RunE: initCmd, -} - -//nolint - flags var ( + // InitCmd - node initialization command + InitCmd = GetInitCmd("mycoin") + + //nolint - flags FlagChainID = "chain-id" //TODO group with other flags or remove? is this already a flag here? + FlagDenom = "denom" //TODO group with other flags or remove? is this already a flag here? FlagOption = "option" + FlagStatic = "static" ) -func init() { - InitCmd.Flags().String(FlagChainID, "test_chain_id", "Chain ID") - InitCmd.Flags().StringSliceP(FlagOption, "p", []string{}, "Genesis option in the format /