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
* [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

View File

@ -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)
}
}

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
// Storage for init gen-tx command input parameters
type GenTxConfig struct {
type GenTx struct {
Name string
CliRoot string
Overwrite bool

View File

@ -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

View File

@ -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{

View File

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