remove some more viper

This commit is contained in:
Ethan Buchman
2017-04-29 00:18:30 -04:00
parent f0e7f0acf8
commit 95c74b2ccd
4 changed files with 18 additions and 24 deletions

View File

@ -4,7 +4,6 @@ import (
"os" "os"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/tendermint/log15" "github.com/tendermint/log15"
"github.com/tendermint/tendermint/types" "github.com/tendermint/tendermint/types"
@ -30,36 +29,34 @@ func init() {
// XXX: this is totally unsafe. // XXX: this is totally unsafe.
// it's only suitable for testnets. // it's only suitable for testnets.
func resetAll(cmd *cobra.Command, args []string) { func resetAll(cmd *cobra.Command, args []string) {
ResetAll(config, log) ResetAll(config.GetString("db_dir"), config.GetString("priv_validator_file"), log)
} }
// XXX: this is totally unsafe. // XXX: this is totally unsafe.
// it's only suitable for testnets. // it's only suitable for testnets.
func resetPrivValidator(cmd *cobra.Command, args []string) { func resetPrivValidator(cmd *cobra.Command, args []string) {
resetPrivValidatorLocal(config, log) resetPrivValidatorLocal(config.GetString("priv_validator_file"), log)
} }
// Exported so other CLI tools can use it // Exported so other CLI tools can use it
func ResetAll(c *viper.Viper, l log15.Logger) { func ResetAll(dbDir, privValFile string, l log15.Logger) {
resetPrivValidatorLocal(c, l) resetPrivValidatorLocal(privValFile, l)
dataDir := c.GetString("db_dir") os.RemoveAll(dbDir)
os.RemoveAll(dataDir) l.Notice("Removed all data", "dir", dbDir)
l.Notice("Removed all data", "dir", dataDir)
} }
func resetPrivValidatorLocal(c *viper.Viper, l log15.Logger) { func resetPrivValidatorLocal(privValFile string, l log15.Logger) {
// Get PrivValidator // Get PrivValidator
var privValidator *types.PrivValidator var privValidator *types.PrivValidator
privValidatorFile := c.GetString("priv_validator_file") if _, err := os.Stat(privValFile); err == nil {
if _, err := os.Stat(privValidatorFile); err == nil { privValidator = types.LoadPrivValidator(privValFile)
privValidator = types.LoadPrivValidator(privValidatorFile)
privValidator.Reset() privValidator.Reset()
l.Notice("Reset PrivValidator", "file", privValidatorFile) l.Notice("Reset PrivValidator", "file", privValFile)
} else { } else {
privValidator = types.GenPrivValidator() privValidator = types.GenPrivValidator()
privValidator.SetFile(privValidatorFile) privValidator.SetFile(privValFile)
privValidator.Save() privValidator.Save()
l.Notice("Generated PrivValidator", "file", privValidatorFile) l.Notice("Generated PrivValidator", "file", privValFile)
} }
} }

View File

@ -10,8 +10,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/spf13/viper"
abci "github.com/tendermint/abci/types" abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-wire" "github.com/tendermint/go-wire"
auto "github.com/tendermint/tmlibs/autofile" auto "github.com/tendermint/tmlibs/autofile"
@ -200,15 +198,14 @@ func makeHeightSearchFunc(height int) auto.SearchFunc {
// we were last and using the WAL to recover there // we were last and using the WAL to recover there
type Handshaker struct { type Handshaker struct {
config *viper.Viper state *sm.State
state *sm.State store types.BlockStore
store types.BlockStore
nBlocks int // number of blocks applied to the state nBlocks int // number of blocks applied to the state
} }
func NewHandshaker(config *viper.Viper, state *sm.State, store types.BlockStore) *Handshaker { func NewHandshaker(state *sm.State, store types.BlockStore) *Handshaker {
return &Handshaker{config, state, store, 0} return &Handshaker{state, store, 0}
} }
func (h *Handshaker) NBlocks() int { func (h *Handshaker) NBlocks() int {

View File

@ -247,7 +247,7 @@ func newConsensusStateForReplay(config *viper.Viper) *ConsensusState {
// Create proxyAppConn connection (consensus, mempool, query) // Create proxyAppConn connection (consensus, mempool, query)
clientCreator := proxy.DefaultClientCreator(config.GetString("proxy_app"), config.GetString("abci"), config.GetString("db_dir")) clientCreator := proxy.DefaultClientCreator(config.GetString("proxy_app"), config.GetString("abci"), config.GetString("db_dir"))
proxyApp := proxy.NewAppConns(clientCreator, NewHandshaker(config, state, blockStore)) proxyApp := proxy.NewAppConns(clientCreator, NewHandshaker(state, blockStore))
_, err := proxyApp.Start() _, err := proxyApp.Start()
if err != nil { if err != nil {
cmn.Exit(cmn.Fmt("Error starting proxy app conns: %v", err)) cmn.Exit(cmn.Fmt("Error starting proxy app conns: %v", err))

View File

@ -85,7 +85,7 @@ func NewNode(config *viper.Viper, privValidator *types.PrivValidator, clientCrea
// Create the proxyApp, which manages connections (consensus, mempool, query) // Create the proxyApp, which manages connections (consensus, mempool, query)
// and sync tendermint and the app by replaying any necessary blocks // and sync tendermint and the app by replaying any necessary blocks
proxyApp := proxy.NewAppConns(clientCreator, consensus.NewHandshaker(config, state, blockStore)) proxyApp := proxy.NewAppConns(clientCreator, consensus.NewHandshaker(state, blockStore))
if _, err := proxyApp.Start(); err != nil { if _, err := proxyApp.Start(); err != nil {
cmn.Exit(cmn.Fmt("Error starting proxy app connections: %v", err)) cmn.Exit(cmn.Fmt("Error starting proxy app connections: %v", err))
} }