From 17e88a5e0029744535ef2c17426825581e1c0f02 Mon Sep 17 00:00:00 2001 From: Greg Szabo Date: Wed, 13 Jun 2018 17:30:16 -0700 Subject: [PATCH] Fixes requested by Rigel: GenTx, config package name --- CHANGELOG.md | 4 ++-- cmd/gaia/app/genesis.go | 21 +++++++++++------ server/config/config.go | 2 +- server/init.go | 52 +++++++++++++++++------------------------ server/mock/app.go | 2 +- server/testnet.go | 2 +- 6 files changed, 40 insertions(+), 43 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ca7ef88e..7e1d20ff2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,8 +20,8 @@ IMPROVEMENTS * [tests] Application module tests now use a mock application * [gaiacli] Fix error message when account isn't found when running gaiacli account * [lcd] refactored to eliminate use of global variables, and interdependent tests -* Added testnet command to gaiad -* Added localnet targets to Makefile +* [tests] Added testnet command to gaiad +* [tests] Added localnet targets to Makefile * [x/stake] More stake tests added to test ByPower index FIXES diff --git a/cmd/gaia/app/genesis.go b/cmd/gaia/app/genesis.go index 3f44a7187..42d0f72e5 100644 --- a/cmd/gaia/app/genesis.go +++ b/cmd/gaia/app/genesis.go @@ -8,13 +8,20 @@ import ( tmtypes "github.com/tendermint/tendermint/types" "github.com/cosmos/cosmos-sdk/server" - gc "github.com/cosmos/cosmos-sdk/server/config" + "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/stake" ) +var ( + // bonded tokens given to genesis validators/accounts + freeFermionVal = int64(100) + // ... + freeFermionsAcc = int64(50) +) + // State to Unmarshal type GenesisState struct { Accounts []GenesisAccount `json:"accounts"` @@ -75,7 +82,7 @@ type GaiaGenTx struct { } // Generate a gaia genesis transaction with flags -func GaiaAppGenTx(cdc *wire.Codec, pk crypto.PubKey, genTxConfig gc.GenTxConfig) ( +func GaiaAppGenTx(cdc *wire.Codec, pk crypto.PubKey, genTxConfig config.GenTx) ( appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) { if genTxConfig.Name == "" { return nil, nil, tmtypes.GenesisValidator{}, errors.New("Must specify --name (validator moniker)") @@ -117,7 +124,7 @@ func GaiaAppGenTxNF(cdc *wire.Codec, pk crypto.PubKey, addr sdk.Address, name st validator = tmtypes.GenesisValidator{ PubKey: pk, - Power: server.FreeFermionVal, + Power: freeFermionVal, } return } @@ -148,21 +155,21 @@ func GaiaAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (genesisState accAuth := auth.NewBaseAccountWithAddress(genTx.Address) accAuth.Coins = sdk.Coins{ {genTx.Name + "Token", 1000}, - {"steak", server.FreeFermionsAcc}, + {"steak", freeFermionsAcc}, } acc := NewGenesisAccount(&accAuth) genaccs[i] = acc - stakeData.Pool.LooseUnbondedTokens += server.FreeFermionsAcc // increase the supply + stakeData.Pool.LooseUnbondedTokens += freeFermionsAcc // increase the supply // add the validator if len(genTx.Name) > 0 { desc := stake.NewDescription(genTx.Name, "", "", "") validator := stake.NewValidator(genTx.Address, genTx.PubKey, desc) - validator.PoolShares = stake.NewBondedShares(sdk.NewRat(server.FreeFermionVal)) + validator.PoolShares = stake.NewBondedShares(sdk.NewRat(freeFermionVal)) stakeData.Validators = append(stakeData.Validators, validator) // pool logic - stakeData.Pool.BondedTokens += server.FreeFermionVal + stakeData.Pool.BondedTokens += freeFermionVal stakeData.Pool.BondedShares = sdk.NewRat(stakeData.Pool.BondedTokens) } } diff --git a/server/config/config.go b/server/config/config.go index 26d038f47..e6fc6a4de 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -6,7 +6,7 @@ package config // For example: init, init gen-tx and testnet commands need similar input and run the same code // Storage for init gen-tx command input parameters -type GenTxConfig struct { +type GenTx struct { Name string CliRoot string Overwrite bool diff --git a/server/init.go b/server/init.go index 9eefda94c..39ac75934 100644 --- a/server/init.go +++ b/server/init.go @@ -26,11 +26,26 @@ import ( dbm "github.com/tendermint/tmlibs/db" clkeys "github.com/cosmos/cosmos-sdk/client/keys" - gc "github.com/cosmos/cosmos-sdk/server/config" + serverconfig "github.com/cosmos/cosmos-sdk/server/config" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/wire" ) +//Parameter names, for init gen-tx command +var ( + FlagName = "name" + FlagClientHome = "home-client" + FlagOWK = "owk" +) + +//parameter names, init command +var ( + FlagOverwrite = "overwrite" + FlagGenTxs = "gen-txs" + FlagIP = "ip" + FlagChainID = "chain-id" +) + // genesis piece structure for creating combined genesis type GenesisTx struct { NodeID string `json:"node_id"` @@ -39,20 +54,6 @@ type GenesisTx struct { AppGenTx json.RawMessage `json:"app_gen_tx"` } -var ( - //--name parameter name, init gen-tx command - FlagName = "name" - //--home-client parameter name, init gen-tx command - FlagClientHome = "home-client" - //--owk parameter name, init gen-tx command - FlagOWK = "owk" - - // bonded tokens given to genesis validators/accounts - FreeFermionVal = int64(100) - // ... - FreeFermionsAcc = int64(50) -) - // Storage for init command input parameters type InitConfig struct { ChainID string @@ -61,17 +62,6 @@ type InitConfig struct { Overwrite bool } -var ( - //--overwrite parameter name, init command - FlagOverwrite = "overwrite" - //--gen-txs parameter name, init command - FlagGenTxs = "gen-txs" - //--ip parameter name, init command - FlagIP = "ip" - //--chain-id parameter name, init command - FlagChainID = "chain-id" -) - // get cmd to initialize all files for tendermint and application func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { cmd := &cobra.Command{ @@ -92,7 +82,7 @@ func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { ip = eip } - genTxConfig := gc.GenTxConfig{ + genTxConfig := serverconfig.GenTx{ viper.GetString(FlagName), viper.GetString(FlagClientHome), viper.GetBool(FlagOWK), @@ -122,7 +112,7 @@ func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { return cmd } -func gentxWithConfig(ctx *Context, cdc *wire.Codec, appInit AppInit, config *cfg.Config, genTxConfig gc.GenTxConfig) ( +func gentxWithConfig(ctx *Context, cdc *wire.Codec, appInit AppInit, config *cfg.Config, genTxConfig serverconfig.GenTx) ( cliPrint json.RawMessage, genTxFile json.RawMessage, err error) { nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile()) if err != nil { @@ -244,7 +234,7 @@ func initWithConfig(ctx *Context, cdc *wire.Codec, appInit AppInit, config *cfg. configFilePath := filepath.Join(config.RootDir, "config", "config.toml") cfg.WriteConfigFile(configFilePath, config) } else { - genTxConfig := gc.GenTxConfig{ + genTxConfig := serverconfig.GenTx{ viper.GetString(FlagName), viper.GetString(FlagClientHome), viper.GetBool(FlagOWK), @@ -380,7 +370,7 @@ type AppInit struct { FlagsAppGenTx *pflag.FlagSet // create the application genesis tx - AppGenTx func(cdc *wire.Codec, pk crypto.PubKey, genTxConfig gc.GenTxConfig) ( + AppGenTx func(cdc *wire.Codec, pk crypto.PubKey, genTxConfig serverconfig.GenTx) ( appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) // AppGenState creates the core parameters initialization. It takes in a @@ -402,7 +392,7 @@ type SimpleGenTx struct { } // Generate a genesis transaction -func SimpleAppGenTx(cdc *wire.Codec, pk crypto.PubKey, genTxConfig gc.GenTxConfig) ( +func SimpleAppGenTx(cdc *wire.Codec, pk crypto.PubKey, genTxConfig serverconfig.GenTx) ( appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) { var addr sdk.Address diff --git a/server/mock/app.go b/server/mock/app.go index 6c553e2be..42e8cf4b5 100644 --- a/server/mock/app.go +++ b/server/mock/app.go @@ -125,7 +125,7 @@ func AppGenState(_ *wire.Codec, _ []json.RawMessage) (appState json.RawMessage, } // Return a validator, not much else -func AppGenTx(_ *wire.Codec, pk crypto.PubKey, genTxConfig gc.GenTxConfig) ( +func AppGenTx(_ *wire.Codec, pk crypto.PubKey, genTxConfig gc.GenTx) ( appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) { validator = tmtypes.GenesisValidator{ diff --git a/server/testnet.go b/server/testnet.go index 2ddf31d98..4d7643750 100644 --- a/server/testnet.go +++ b/server/testnet.go @@ -96,7 +96,7 @@ func testnetWithConfig(config *cfg.Config, ctx *Context, cdc *wire.Codec, appIni } } - genTxConfig := gc.GenTxConfig{ + genTxConfig := gc.GenTx{ nodeDirName, clientDir, true,