This commit is contained in:
rigelrozanski 2018-04-22 01:32:47 -04:00
parent d4c2d6fd4c
commit 246e4bdac3
12 changed files with 39 additions and 40 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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