Skip to content

Commit

Permalink
cwgoes comments, bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
rigelrozanski committed Apr 26, 2018
1 parent 525a852 commit 4049c5d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 34 deletions.
21 changes: 13 additions & 8 deletions server/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ import (
dbm "github.com/tendermint/tmlibs/db"
)

// TODO flag to retrieve genesis file / config file from a URL?
// get cmd to initialize all files for tendermint and application
func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command {
flagOverwrite, flagPieceFile := "overwrite", "piece-file"
flagOverwrite, flagPieceFile, flagIP := "overwrite", "piece-file", "ip"
cmd := &cobra.Command{
Use: "init",
Short: "Initialize genesis config, priv-validator file, and p2p-node file",
Expand Down Expand Up @@ -79,9 +78,12 @@ func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command {
// write the piece file is path specified
if viper.GetBool(flagPieceFile) {
//create the piece
ip, err := externalIP()
if err != nil {
return err
ip := viper.GetString(flagIP)
if len(ip) == 0 {
ip, err = externalIP()
if err != nil {
return err
}
}
piece := GenesisPiece{
ChainID: chainID,
Expand All @@ -90,7 +92,7 @@ func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command {
AppState: appState,
Validators: validators,
}
bz, err := cdc.MarshalJSON(piece)
bz, err := wire.MarshalJSONIndent(cdc, piece)
if err != nil {
return err
}
Expand All @@ -107,6 +109,7 @@ func InitCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Command {
cmd.Flags().BoolP(flagPieceFile, "a", false, "create an append file (under [--home]/[nodeID]piece.json) for others to import")
}
cmd.Flags().BoolP(flagOverwrite, "o", false, "overwrite the config file")
cmd.Flags().String(flagIP, "", "external facing IP to use if left blank IP will be retrieved from this machine")
cmd.Flags().AddFlagSet(appInit.Flags)
return cmd
}
Expand Down Expand Up @@ -158,6 +161,7 @@ func FromPiecesCmd(ctx *Context, cdc *wire.Codec, appInit AppInit) *cobra.Comman
// append a genesis-piece
func appendPiece(ctx *Context, cdc *wire.Codec, appInit AppInit, nodeKeyFile, genFile string) filepath.WalkFunc {
return func(pieceFile string, _ os.FileInfo, err error) error {
fmt.Printf("debug pieceFile: %v\n", pieceFile)
if err != nil {
return err
}
Expand Down Expand Up @@ -202,7 +206,7 @@ func appendPiece(ctx *Context, cdc *wire.Codec, appInit AppInit, nodeKeyFile, ge
return err
}
if piece.ChainID != genChainID {
return fmt.Errorf("piece chain id's are mismatched, %s != %s", piece.ChainID, genMap["chain_id"])
return fmt.Errorf("piece chain id's are mismatched, %s != %s", piece.ChainID, genChainID)
}

// combine the validator set
Expand Down Expand Up @@ -237,7 +241,8 @@ func appendPiece(ctx *Context, cdc *wire.Codec, appInit AppInit, nodeKeyFile, ge
if len(ctx.Config.P2P.PersistentPeers) == 0 {
comma = ""
}
ctx.Config.P2P.PersistentPeers += fmt.Sprintf("%s%s@%s", comma, piece.NodeID, piece.IP)
//newPeer := fmt.Sprintf("%s%s@%s:46656", comma, piece.NodeID, piece.IP)
ctx.Config.P2P.PersistentPeers += fmt.Sprintf("%s%s@%s:46656", comma, piece.NodeID, piece.IP)
configFilePath := filepath.Join(viper.GetString("home"), "config", "config.toml") //TODO this is annoying should be easier to get
cfg.WriteConfigFile(configFilePath, ctx.Config)

Expand Down
24 changes: 0 additions & 24 deletions server/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,6 @@ func setupViper(t *testing.T) func() {
}
}

// Begin the server pass up the channel to close
// NOTE pass up the channel so it can be closed at the end of the process
//func StartServer(t *testing.T, cdc *wire.Codec) chan error {
//defer setupViper(t)()

//cfg, err := tcmd.ParseConfig()
//require.Nil(t, err)

//// init server
//ctx := NewContext(cfg, log.NewNopLogger())
//initCmd := InitCmd(ctx, cdc, mock.GenAppParams)
//err = initCmd.RunE(nil, nil)
//require.NoError(t, err)

//// start server
//viper.Set(flagWithTendermint, true)
//startCmd := StartCmd(mock.NewApp, ctx)
//startCmd.Flags().Set(flagAddress, FreeTCPAddr(t)) // set to a new free address
//startCmd.Flags().Set("rpc.laddr", FreeTCPAddr(t)) // set to a new free address
//timeout := time.Duration(3) * time.Second

//return RunOrTimeout(startCmd, timeout, t)
//}

// Run or Timout RunE of command passed in
func RunOrTimeout(cmd *cobra.Command, timeout time.Duration, t *testing.T) chan error {
done := make(chan error)
Expand Down
2 changes: 0 additions & 2 deletions server/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/stretchr/testify/require"
)

//func AppendJSON(cdc *wire.Codec, baseJSON []byte, key string, value json.RawMessage) (appended []byte, err error) {

func TestAppendJSON(t *testing.T) {
cdc := wire.NewCodec()

Expand Down

0 comments on commit 4049c5d

Please sign in to comment.