Fixes requested by Rigel: GenTx, config package name

This commit is contained in:
Greg Szabo 2018-06-13 17:30:16 -07:00
parent bc206c315c
commit 17e88a5e00
6 changed files with 40 additions and 43 deletions

View File

@ -20,8 +20,8 @@ IMPROVEMENTS
* [tests] Application module tests now use a mock application * [tests] Application module tests now use a mock application
* [gaiacli] Fix error message when account isn't found when running gaiacli account * [gaiacli] Fix error message when account isn't found when running gaiacli account
* [lcd] refactored to eliminate use of global variables, and interdependent tests * [lcd] refactored to eliminate use of global variables, and interdependent tests
* Added testnet command to gaiad * [tests] Added testnet command to gaiad
* Added localnet targets to Makefile * [tests] Added localnet targets to Makefile
* [x/stake] More stake tests added to test ByPower index * [x/stake] More stake tests added to test ByPower index
FIXES FIXES

View File

@ -8,13 +8,20 @@ import (
tmtypes "github.com/tendermint/tendermint/types" tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/server" "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" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire" "github.com/cosmos/cosmos-sdk/wire"
"github.com/cosmos/cosmos-sdk/x/auth" "github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/stake" "github.com/cosmos/cosmos-sdk/x/stake"
) )
var (
// bonded tokens given to genesis validators/accounts
freeFermionVal = int64(100)
// ...
freeFermionsAcc = int64(50)
)
// State to Unmarshal // State to Unmarshal
type GenesisState struct { type GenesisState struct {
Accounts []GenesisAccount `json:"accounts"` Accounts []GenesisAccount `json:"accounts"`
@ -75,7 +82,7 @@ type GaiaGenTx struct {
} }
// Generate a gaia genesis transaction with flags // 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) { appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) {
if genTxConfig.Name == "" { if genTxConfig.Name == "" {
return nil, nil, tmtypes.GenesisValidator{}, errors.New("Must specify --name (validator moniker)") 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{ validator = tmtypes.GenesisValidator{
PubKey: pk, PubKey: pk,
Power: server.FreeFermionVal, Power: freeFermionVal,
} }
return return
} }
@ -148,21 +155,21 @@ func GaiaAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (genesisState
accAuth := auth.NewBaseAccountWithAddress(genTx.Address) accAuth := auth.NewBaseAccountWithAddress(genTx.Address)
accAuth.Coins = sdk.Coins{ accAuth.Coins = sdk.Coins{
{genTx.Name + "Token", 1000}, {genTx.Name + "Token", 1000},
{"steak", server.FreeFermionsAcc}, {"steak", freeFermionsAcc},
} }
acc := NewGenesisAccount(&accAuth) acc := NewGenesisAccount(&accAuth)
genaccs[i] = acc genaccs[i] = acc
stakeData.Pool.LooseUnbondedTokens += server.FreeFermionsAcc // increase the supply stakeData.Pool.LooseUnbondedTokens += freeFermionsAcc // increase the supply
// add the validator // add the validator
if len(genTx.Name) > 0 { if len(genTx.Name) > 0 {
desc := stake.NewDescription(genTx.Name, "", "", "") desc := stake.NewDescription(genTx.Name, "", "", "")
validator := stake.NewValidator(genTx.Address, genTx.PubKey, desc) 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) stakeData.Validators = append(stakeData.Validators, validator)
// pool logic // pool logic
stakeData.Pool.BondedTokens += server.FreeFermionVal stakeData.Pool.BondedTokens += freeFermionVal
stakeData.Pool.BondedShares = sdk.NewRat(stakeData.Pool.BondedTokens) stakeData.Pool.BondedShares = sdk.NewRat(stakeData.Pool.BondedTokens)
} }
} }

View File

@ -6,7 +6,7 @@ package config
// For example: init, init gen-tx and testnet commands need similar input and run the same code // 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 // Storage for init gen-tx command input parameters
type GenTxConfig struct { type GenTx struct {
Name string Name string
CliRoot string CliRoot string
Overwrite bool Overwrite bool

View File

@ -26,11 +26,26 @@ import (
dbm "github.com/tendermint/tmlibs/db" dbm "github.com/tendermint/tmlibs/db"
clkeys "github.com/cosmos/cosmos-sdk/client/keys" 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" sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/wire" "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 // genesis piece structure for creating combined genesis
type GenesisTx struct { type GenesisTx struct {
NodeID string `json:"node_id"` NodeID string `json:"node_id"`
@ -39,20 +54,6 @@ type GenesisTx struct {
AppGenTx json.RawMessage `json:"app_gen_tx"` 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 // Storage for init command input parameters
type InitConfig struct { type InitConfig struct {
ChainID string ChainID string
@ -61,17 +62,6 @@ type InitConfig struct {
Overwrite bool 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 // get cmd to initialize all files for tendermint and application
func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command { func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
@ -92,7 +82,7 @@ func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command {
ip = eip ip = eip
} }
genTxConfig := gc.GenTxConfig{ genTxConfig := serverconfig.GenTx{
viper.GetString(FlagName), viper.GetString(FlagName),
viper.GetString(FlagClientHome), viper.GetString(FlagClientHome),
viper.GetBool(FlagOWK), viper.GetBool(FlagOWK),
@ -122,7 +112,7 @@ func GenTxCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command {
return cmd 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) { cliPrint json.RawMessage, genTxFile json.RawMessage, err error) {
nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile()) nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile())
if err != nil { 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") configFilePath := filepath.Join(config.RootDir, "config", "config.toml")
cfg.WriteConfigFile(configFilePath, config) cfg.WriteConfigFile(configFilePath, config)
} else { } else {
genTxConfig := gc.GenTxConfig{ genTxConfig := serverconfig.GenTx{
viper.GetString(FlagName), viper.GetString(FlagName),
viper.GetString(FlagClientHome), viper.GetString(FlagClientHome),
viper.GetBool(FlagOWK), viper.GetBool(FlagOWK),
@ -380,7 +370,7 @@ type AppInit struct {
FlagsAppGenTx *pflag.FlagSet FlagsAppGenTx *pflag.FlagSet
// create the application genesis tx // 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) appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error)
// AppGenState creates the core parameters initialization. It takes in a // AppGenState creates the core parameters initialization. It takes in a
@ -402,7 +392,7 @@ type SimpleGenTx struct {
} }
// Generate a genesis transaction // 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) { appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) {
var addr sdk.Address var addr sdk.Address

View File

@ -125,7 +125,7 @@ func AppGenState(_ *wire.Codec, _ []json.RawMessage) (appState json.RawMessage,
} }
// Return a validator, not much else // 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) { appGenTx, cliPrint json.RawMessage, validator tmtypes.GenesisValidator, err error) {
validator = tmtypes.GenesisValidator{ validator = tmtypes.GenesisValidator{

View File

@ -96,7 +96,7 @@ func testnetWithConfig(config *cfg.Config, ctx *Context, cdc *wire.Codec, appIni
} }
} }
genTxConfig := gc.GenTxConfig{ genTxConfig := gc.GenTx{
nodeDirName, nodeDirName,
clientDir, clientDir,
true, true,