From 246e4bdac3432e3f730ead6219bf2cc480c10bfb Mon Sep 17 00:00:00 2001 From: rigelrozanski Date: Sun, 22 Apr 2018 01:32:47 -0400 Subject: [PATCH] renames --- CHANGELOG.md | 2 +- cmd/gaia/app/app.go | 15 +++++++++++---- cmd/gaia/cmd/gaiad/main.go | 22 +++++++++++----------- examples/democoin/cmd/democoind/main.go | 8 ++++---- mock/app.go | 4 ++-- mock/app_test.go | 2 +- server/init.go | 2 +- server/init_test.go | 2 +- server/start_test.go | 4 ++-- server/test_helpers.go | 2 +- server/tm_cmds.go | 4 ++++ server/wire.go | 12 ------------ 12 files changed, 39 insertions(+), 40 deletions(-) delete mode 100644 server/wire.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 076129dbc1..618db746aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,7 +74,7 @@ BREAKING CHANGES to allow mounting multiple stores with their own DB until they can share one * [x/staking] Renamed to `simplestake` * [builder] Functions don't take `passphrase` as argument -* [server] GenAppState returns generated seed and address +* [server] GenAppParams returns generated seed and address * [basecoind] `init` command outputs JSON of everything necessary for testnet * [basecoind] `basecoin.db -> data/basecoin.db` * [basecli] `data/keys.db -> keys/keys.db` diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index b09bd7159a..1ab0c7c19d 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -180,9 +180,16 @@ func (ga *GenesisAccount) ToAccount() (acc *auth.BaseAccount) { } } -// GaiaGenAppState expects two args: an account address -// and a coin denomination, and gives lots of coins to that address. -func GaiaGenAppState(cdc *wire.Codec, pubKey crypto.PubKey) (chainID string, validators []tmtypes.GenesisValidator, appState, message json.RawMessage, err error) { +// XXX func GeneratePiece +// XXX func AddPiece + +// Create the core parameters for genesis initialization for gaia +func GaiaGenAppParams(cdc *wire.Codec, pubKey crypto.PubKey) (chainID string, validators []tmtypes.GenesisValidator, appState, cliPrint json.RawMessage, err error) { + + // XXX what's the best way to pass around this information? have special flagset defined here? + // add keys to accounts (flag) + // generate X accounts each with X money + // generate X number of validators each bonded with X amount of token var addr sdk.Address var secret string @@ -193,7 +200,7 @@ func GaiaGenAppState(cdc *wire.Codec, pubKey crypto.PubKey) (chainID string, val mm := map[string]string{"secret": secret} bz, err := cdc.MarshalJSON(mm) - message = json.RawMessage(bz) + cliPrint = json.RawMessage(bz) chainID = cmn.Fmt("test-chain-%v", cmn.RandStr(6)) diff --git a/cmd/gaia/cmd/gaiad/main.go b/cmd/gaia/cmd/gaiad/main.go index 8231c4d428..1637a80852 100644 --- a/cmd/gaia/cmd/gaiad/main.go +++ b/cmd/gaia/cmd/gaiad/main.go @@ -15,16 +15,6 @@ import ( "github.com/cosmos/cosmos-sdk/server" ) -func generateApp(rootDir string, logger log.Logger) (abci.Application, error) { - dataDir := filepath.Join(rootDir, "data") - db, err := dbm.NewGoLevelDB("gaia", dataDir) - if err != nil { - return nil, err - } - bapp := app.NewGaiaApp(logger, db) - return bapp, nil -} - func main() { cdc := app.MakeCodec() ctx := server.NewDefaultContext() @@ -34,10 +24,20 @@ func main() { PersistentPreRunE: server.PersistentPreRunEFn(ctx), } - server.AddCommands(ctx, cdc, rootCmd, app.GaiaGenAppState, generateApp) + server.AddCommands(ctx, cdc, rootCmd, app.GaiaGenAppParams, generateApp) // prepare and add flags rootDir := os.ExpandEnv("$HOME/.gaiad") executor := cli.PrepareBaseCmd(rootCmd, "GA", rootDir) executor.Execute() } + +func generateApp(rootDir string, logger log.Logger) (abci.Application, error) { + dataDir := filepath.Join(rootDir, "data") + db, err := dbm.NewGoLevelDB("gaia", dataDir) + if err != nil { + return nil, err + } + bapp := app.NewGaiaApp(logger, db) + return bapp, nil +} diff --git a/examples/democoin/cmd/democoind/main.go b/examples/democoin/cmd/democoind/main.go index 93602023a1..7cfd55e916 100644 --- a/examples/democoin/cmd/democoind/main.go +++ b/examples/democoin/cmd/democoind/main.go @@ -19,9 +19,9 @@ import ( "github.com/cosmos/cosmos-sdk/wire" ) -// coolGenAppState sets up the app_state and appends the cool app state -func CoolGenAppState(cdc *wire.Codec, pubKey crypto.PubKey) (chainID string, validators []tmtypes.GenesisValidator, appState, message json.RawMessage, err error) { - chainID, validators, appState, message, err = server.SimpleGenAppParams(cdc, pubKey) +// coolGenAppParams sets up the app_state and appends the cool app state +func CoolGenAppParams(cdc *wire.Codec, pubKey crypto.PubKey) (chainID string, validators []tmtypes.GenesisValidator, appState, cliPrint json.RawMessage, err error) { + chainID, validators, appState, cliPrint, err = server.SimpleGenAppParams(cdc, pubKey) if err != nil { return } @@ -52,7 +52,7 @@ func main() { PersistentPreRunE: server.PersistentPreRunEFn(ctx), } - server.AddCommands(ctx, cdc, rootCmd, CoolGenAppState, generateApp) + server.AddCommands(ctx, cdc, rootCmd, CoolGenAppParams, generateApp) // prepare and add flags rootDir := os.ExpandEnv("$HOME/.democoind") diff --git a/mock/app.go b/mock/app.go index c687d6d4b4..09f09b830c 100644 --- a/mock/app.go +++ b/mock/app.go @@ -106,9 +106,9 @@ func InitChainer(key sdk.StoreKey) func(sdk.Context, abci.RequestInitChain) abci } } -// GenAppState can be passed into InitCmd, returns a static string of a few +// GenAppParams can be passed into InitCmd, returns a static string of a few // key-values that can be parsed by InitChainer -func GenAppState(_ *wire.Codec, pubKey crypto.PubKey) (chainID string, validators []tmtypes.GenesisValidator, appState, message json.RawMessage, err error) { +func GenAppParams(_ *wire.Codec, pubKey crypto.PubKey) (chainID string, validators []tmtypes.GenesisValidator, appState, cliPrint json.RawMessage, err error) { chainID = fmt.Sprintf("test-chain-%v", cmn.RandStr(6)) diff --git a/mock/app_test.go b/mock/app_test.go index 099808ee2d..fe0948a84c 100644 --- a/mock/app_test.go +++ b/mock/app_test.go @@ -23,7 +23,7 @@ func TestInitApp(t *testing.T) { // initialize it future-way pubKey := crypto.GenPrivKeyEd25519().PubKey() - _, _, appState, _, err := GenAppState(nil, pubKey) + _, _, appState, _, err := GenAppParams(nil, pubKey) require.NoError(t, err) //TODO test validators in the init chain? req := abci.RequestInitChain{ diff --git a/server/init.go b/server/init.go index fc80b495fd..14635a9410 100644 --- a/server/init.go +++ b/server/init.go @@ -122,7 +122,7 @@ func addAppStateToGenesis(cdc *wire.Codec, genesisConfigPath string, appState js // GenAppParams creates the core parameters initialization. It takes in a // pubkey meant to represent the pubkey of the validator of this machine. -type GenAppParams func(*wire.Codec, crypto.PubKey) (chainID string, validators []tmtypes.GenesisValidator, appState, message json.RawMessage, err error) +type GenAppParams func(*wire.Codec, crypto.PubKey) (chainID string, validators []tmtypes.GenesisValidator, appState, cliPrint json.RawMessage, err error) // Create one account with a whole bunch of mycoin in it func SimpleGenAppParams(cdc *wire.Codec, pubKey crypto.PubKey) (chainID string, validators []tmtypes.GenesisValidator, appState, cliPrint json.RawMessage, err error) { diff --git a/server/init_test.go b/server/init_test.go index a035a3077d..e4bf8c0169 100644 --- a/server/init_test.go +++ b/server/init_test.go @@ -18,7 +18,7 @@ func TestInit(t *testing.T) { cfg, err := tcmd.ParseConfig() require.Nil(t, err) ctx := NewContext(cfg, logger) - cmd := InitCmd(ctx, cdc, mock.GenAppState) + cmd := InitCmd(ctx, cdc, mock.GenAppParams) err = cmd.RunE(nil, nil) require.NoError(t, err) } diff --git a/server/start_test.go b/server/start_test.go index f8ac5f709e..9cbd456616 100644 --- a/server/start_test.go +++ b/server/start_test.go @@ -25,7 +25,7 @@ func TestStartStandAlone(t *testing.T) { cfg, err := tcmd.ParseConfig() require.Nil(t, err) ctx := NewContext(cfg, logger) - initCmd := InitCmd(ctx, cdc, mock.GenAppState) + initCmd := InitCmd(ctx, cdc, mock.GenAppParams) err = initCmd.RunE(nil, nil) require.NoError(t, err) @@ -51,7 +51,7 @@ func TestStartWithTendermint(t *testing.T) { cfg, err := tcmd.ParseConfig() require.Nil(t, err) ctx := NewContext(cfg, logger) - initCmd := InitCmd(ctx, cdc, mock.GenAppState) + initCmd := InitCmd(ctx, cdc, mock.GenAppParams) err = initCmd.RunE(nil, nil) require.NoError(t, err) diff --git a/server/test_helpers.go b/server/test_helpers.go index 6855f0e927..55b6caf43b 100644 --- a/server/test_helpers.go +++ b/server/test_helpers.go @@ -47,7 +47,7 @@ func setupViper(t *testing.T) func() { //// init server //ctx := NewContext(cfg, log.NewNopLogger()) -//initCmd := InitCmd(ctx, cdc, mock.GenAppState) +//initCmd := InitCmd(ctx, cdc, mock.GenAppParams) //err = initCmd.RunE(nil, nil) //require.NoError(t, err) diff --git a/server/tm_cmds.go b/server/tm_cmds.go index 73dca6651e..a876d1bcd3 100644 --- a/server/tm_cmds.go +++ b/server/tm_cmds.go @@ -5,6 +5,7 @@ import ( "fmt" "strings" + "github.com/cosmos/cosmos-sdk/wire" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -43,6 +44,9 @@ func ShowValidatorCmd(ctx *Context) *cobra.Command { pubKey := privValidator.PubKey if viper.GetBool(flagJSON) { + + cdc := wire.NewCodec() + wire.RegisterCrypto(cdc) pubKeyJSONBytes, err := cdc.MarshalJSON(pubKey) if err != nil { return err diff --git a/server/wire.go b/server/wire.go deleted file mode 100644 index 261e7cfe1e..0000000000 --- a/server/wire.go +++ /dev/null @@ -1,12 +0,0 @@ -package server - -import ( - "github.com/cosmos/cosmos-sdk/wire" -) - -var cdc *wire.Codec - -func init() { - cdc = wire.NewCodec() - wire.RegisterCrypto(cdc) -}