Browse Source

consolidate counter/dummy into the binary, #95

pull/1780/head
Zach Ramsay 7 years ago
parent
commit
df5d9ac1bb
3 changed files with 99 additions and 91 deletions
  1. +99
    -0
      cmd/abci-cli/abci-cli.go
  2. +0
    -41
      cmd/counter/main.go
  3. +0
    -50
      cmd/dummy/main.go

+ 99
- 0
cmd/abci-cli/abci-cli.go View File

@ -11,8 +11,12 @@ import (
"strings"
abcicli "github.com/tendermint/abci/client"
"github.com/tendermint/abci/example/counter"
"github.com/tendermint/abci/example/dummy"
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
//"github.com/tendermint/abci/version"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"
"github.com/spf13/cobra"
@ -42,13 +46,23 @@ var logger log.Logger
// flags
var (
// global
address string
abci string
verbose bool
// query
path string
height int
prove bool
// counter
addrC string
serial bool
// dummy
addrD string
persist string
)
var RootCmd = &cobra.Command{
@ -93,6 +107,15 @@ func addQueryFlags() {
queryCmd.PersistentFlags().BoolVarP(&prove, "prove", "", false, "Whether or not to return a merkle proof of the query result")
}
func addCounterFlags() {
counterCmd.PersistentFlags().StringVarP(&addrC, "addr", "", "tcp://0.0.0.0:46658", "Listen address")
counterCmd.PersistentFlags().BoolVarP(&serial, "serial", "", false, "Enforce incrementing (serial) transactions")
}
func addDummyFlags() {
dummyCmd.PersistentFlags().StringVarP(&addrD, "addr", "", "tcp://0.0.0.0:46658", "Listen address")
dummyCmd.PersistentFlags().StringVarP(&persist, "persist", "", "", "Directory to use for a database")
}
func addCommands() {
RootCmd.AddCommand(batchCmd)
RootCmd.AddCommand(consoleCmd)
@ -104,6 +127,12 @@ func addCommands() {
RootCmd.AddCommand(commitCmd)
addQueryFlags()
RootCmd.AddCommand(queryCmd)
// examples
addCounterFlags()
RootCmd.AddCommand(counterCmd)
addDummyFlags()
RootCmd.AddCommand(dummyCmd)
}
var batchCmd = &cobra.Command{
@ -168,6 +197,20 @@ var queryCmd = &cobra.Command{
Run: cmdQuery,
}
var counterCmd = &cobra.Command{
Use: "counter",
Short: "ABCI demo example",
Long: "",
Run: cmdCounter,
}
var dummyCmd = &cobra.Command{
Use: "dummy",
Short: "ABCI demo example",
Long: "",
Run: cmdDummy,
}
// Generates new Args array based off of previous call args to maintain flag persistence
func persistentArgs(line []byte) []string {
@ -341,6 +384,62 @@ func cmdQuery(cmd *cobra.Command, args []string) {
})
}
func cmdCounter(cmd *cobra.Command, args []string) {
app := counter.NewCounterApplication(serial)
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
// Start the listener
srv, err := server.NewServer(addrC, abci, app)
if err != nil {
logger.Error(err.Error())
os.Exit(1)
}
srv.SetLogger(logger.With("module", "abci-server"))
if _, err := srv.Start(); err != nil {
logger.Error(err.Error())
os.Exit(1)
}
// Wait forever
cmn.TrapSignal(func() {
// Cleanup
srv.Stop()
})
}
func cmdDummy(cmd *cobra.Command, args []string) {
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
// Create the application - in memory or persisted to disk
var app types.Application
if persist == "" {
app = dummy.NewDummyApplication()
} else {
app = dummy.NewPersistentDummyApplication(persist)
app.(*dummy.PersistentDummyApplication).SetLogger(logger.With("module", "dummy"))
}
// Start the listener
srv, err := server.NewServer(addrD, abci, app)
if err != nil {
logger.Error(err.Error())
os.Exit(1)
}
srv.SetLogger(logger.With("module", "abci-server"))
if _, err := srv.Start(); err != nil {
logger.Error(err.Error())
os.Exit(1)
}
// Wait forever
cmn.TrapSignal(func() {
// Cleanup
srv.Stop()
})
}
//--------------------------------------------------------------------------------
func printResponse(cmd *cobra.Command, args []string, rsp response) {


+ 0
- 41
cmd/counter/main.go View File

@ -1,41 +0,0 @@
package main
import (
"flag"
"os"
"github.com/tendermint/abci/example/counter"
"github.com/tendermint/abci/server"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"
)
func main() {
addrPtr := flag.String("addr", "tcp://0.0.0.0:46658", "Listen address")
abciPtr := flag.String("abci", "socket", "ABCI server: socket | grpc")
serialPtr := flag.Bool("serial", false, "Enforce incrementing (serial) txs")
flag.Parse()
app := counter.NewCounterApplication(*serialPtr)
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
// Start the listener
srv, err := server.NewServer(*addrPtr, *abciPtr, app)
if err != nil {
logger.Error(err.Error())
os.Exit(1)
}
srv.SetLogger(logger.With("module", "abci-server"))
if _, err := srv.Start(); err != nil {
logger.Error(err.Error())
os.Exit(1)
}
// Wait forever
cmn.TrapSignal(func() {
// Cleanup
srv.Stop()
})
}

+ 0
- 50
cmd/dummy/main.go View File

@ -1,50 +0,0 @@
package main
import (
"flag"
"os"
"github.com/tendermint/abci/example/dummy"
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"
)
func main() {
addrPtr := flag.String("addr", "tcp://0.0.0.0:46658", "Listen address")
abciPtr := flag.String("abci", "socket", "socket | grpc")
persistencePtr := flag.String("persist", "", "directory to use for a database")
flag.Parse()
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
// Create the application - in memory or persisted to disk
var app types.Application
if *persistencePtr == "" {
app = dummy.NewDummyApplication()
} else {
app = dummy.NewPersistentDummyApplication(*persistencePtr)
app.(*dummy.PersistentDummyApplication).SetLogger(logger.With("module", "dummy"))
}
// Start the listener
srv, err := server.NewServer(*addrPtr, *abciPtr, app)
if err != nil {
logger.Error(err.Error())
os.Exit(1)
}
srv.SetLogger(logger.With("module", "abci-server"))
if _, err := srv.Start(); err != nil {
logger.Error(err.Error())
os.Exit(1)
}
// Wait forever
cmn.TrapSignal(func() {
// Cleanup
srv.Stop()
})
}

Loading…
Cancel
Save