Skip to content

Commit

Permalink
Fixes requested by Rigel: GenTx, config package name
Browse files Browse the repository at this point in the history
  • Loading branch information
greg-szabo committed Jun 14, 2018
1 parent bc206c3 commit 17e88a5
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 43 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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)")
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 21 additions & 31 deletions server/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand All @@ -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{
Expand All @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion server/mock/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion server/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func testnetWithConfig(config *cfg.Config, ctx *Context, cdc *wire.Codec, appIni
}
}

genTxConfig := gc.GenTxConfig{
genTxConfig := gc.GenTx{
nodeDirName,
clientDir,
true,
Expand Down

0 comments on commit 17e88a5

Please sign in to comment.