Skip to content

Commit

Permalink
Add cli to basecoind, fix compatability issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanfrey authored and rigelrozanski committed Mar 1, 2018
1 parent c0f9a6f commit 4e91a0d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 20 deletions.
57 changes: 50 additions & 7 deletions examples/basecoin/cmd/basecoind/main.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,70 @@
package main

import (
"encoding/json"
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/tendermint/tmlibs/cli"
dbm "github.com/tendermint/tmlibs/db"
"github.com/tendermint/tmlibs/log"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/examples/basecoin/app"
"github.com/cosmos/cosmos-sdk/server"
"github.com/cosmos/cosmos-sdk/version"
)

func main() {
fmt.Println("This is temporary, for unblocking our build process.")
return
// gaiadCmd is the entry point for this binary
var (
gaiadCmd = &cobra.Command{
Use: "gaiad",
Short: "Gaia Daemon (server)",
}
)

// defaultOptions sets up the app_options for the
// default genesis file
func defaultOptions(args []string) (json.RawMessage, error) {
addr, secret, err := server.GenerateCoinKey()
if err != nil {
return nil, err
}
fmt.Println("Secret phrase to access coins:")
fmt.Println(secret)

opts := fmt.Sprintf(`{
"accounts": [{
"address": "%s",
"coins": [
{
"denom": "mycoin",
"amount": 9007199254740992
}
]
}]
}`, addr)
return json.RawMessage(opts), nil
}

// TODO CREATE CLI
func main() {
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)).With("module", "main")
db, err := dbm.NewGoLevelDB("basecoind", "data")
db, err := dbm.NewGoLevelDB("/tmp/basecoind", "data")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
bapp := app.NewBasecoinApp(logger, db)
baseapp.RunForever(bapp)

gaiadCmd.AddCommand(
server.InitCmd(defaultOptions),
server.StartCmd(bapp, bapp.Logger),
server.UnsafeResetAllCmd(bapp.Logger),
version.VersionCmd,
)

// prepare and add flags
executor := cli.PrepareBaseCmd(gaiadCmd, "GA", os.ExpandEnv("$HOME/.gaiad"))
executor.Execute()
}
2 changes: 1 addition & 1 deletion examples/gaia/gaiad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func main() {

gaiadCmd.AddCommand(
server.InitCmd(defaultOptions),
server.StartCmd(app),
server.StartCmd(app, app.Logger),
server.UnsafeResetAllCmd(app.Logger),
version.VersionCmd,
)
Expand Down
23 changes: 11 additions & 12 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"github.com/spf13/viper"

"github.com/tendermint/abci/server"
abci "github.com/tendermint/abci/types"

tcmd "github.com/tendermint/tendermint/cmd/tendermint/commands"
"github.com/tendermint/tendermint/node"
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"
cmn "github.com/tendermint/tmlibs/common"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/tendermint/tmlibs/log"
)

const (
Expand All @@ -23,9 +23,10 @@ const (

// StartCmd runs the service passed in, either
// stand-alone, or in-process with tendermint
func StartCmd(app *baseapp.BaseApp) *cobra.Command {
func StartCmd(app abci.Application, logger log.Logger) *cobra.Command {
start := startCmd{
app: app,
app: app,
logger: logger,
}
cmd := &cobra.Command{
Use: "start",
Expand All @@ -46,28 +47,27 @@ type startCmd struct {
// do this in main:
// rootDir := viper.GetString(cli.HomeFlag)
// node.Logger = ....
app *baseapp.BaseApp
app abci.Application
logger log.Logger
}

func (s startCmd) run(cmd *cobra.Command, args []string) error {
logger := s.app.Logger
if !viper.GetBool(flagWithTendermint) {
logger.Info("Starting ABCI without Tendermint")
s.logger.Info("Starting ABCI without Tendermint")
return s.startStandAlone()
}
logger.Info("Starting ABCI with Tendermint")
s.logger.Info("Starting ABCI with Tendermint")
return s.startInProcess()
}

func (s startCmd) startStandAlone() error {
logger := s.app.Logger
// Start the ABCI listener
addr := viper.GetString(flagAddress)
svr, err := server.NewServer(addr, "socket", s.app)
if err != nil {
return errors.Errorf("Error creating listener: %v\n", err)
}
svr.SetLogger(logger.With("module", "abci-server"))
svr.SetLogger(s.logger.With("module", "abci-server"))
svr.Start()

// Wait forever
Expand All @@ -79,7 +79,6 @@ func (s startCmd) startStandAlone() error {
}

func (s startCmd) startInProcess() error {
logger := s.app.Logger
cfg, err := tcmd.ParseConfig()
if err != nil {
return err
Expand All @@ -91,7 +90,7 @@ func (s startCmd) startInProcess() error {
proxy.NewLocalClientCreator(s.app),
node.DefaultGenesisDocProviderFunc(cfg),
node.DefaultDBProvider,
logger.With("module", "node"))
s.logger.With("module", "node"))
if err != nil {
return err
}
Expand Down

0 comments on commit 4e91a0d

Please sign in to comment.