remove viper from rpc except test

This commit is contained in:
Ethan Buchman 2017-04-29 00:07:50 -04:00
parent 1fcc9dc654
commit f0e7f0acf8
6 changed files with 9 additions and 92 deletions

View File

@ -293,7 +293,6 @@ func (n *Node) AddListener(l p2p.Listener) {
// ConfigureRPC sets all variables in rpccore so they will serve
// rpc calls from this node
func (n *Node) ConfigureRPC() {
rpccore.SetConfig(n.config)
rpccore.SetEventSwitch(n.evsw)
rpccore.SetBlockStore(n.blockStore)
rpccore.SetConsensusState(n.consensusState)

View File

@ -1,10 +1,8 @@
package core
import (
"fmt"
"os"
"runtime/pprof"
"strconv"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
)
@ -14,31 +12,6 @@ func UnsafeFlushMempool() (*ctypes.ResultUnsafeFlushMempool, error) {
return &ctypes.ResultUnsafeFlushMempool{}, nil
}
func UnsafeSetConfig(typ, key, value string) (*ctypes.ResultUnsafeSetConfig, error) {
switch typ {
case "string":
config.Set(key, value)
case "int":
val, err := strconv.Atoi(value)
if err != nil {
return nil, fmt.Errorf("non-integer value found. key:%s; value:%s; err:%v", key, value, err)
}
config.Set(key, val)
case "bool":
switch value {
case "true":
config.Set(key, true)
case "false":
config.Set(key, false)
default:
return nil, fmt.Errorf("bool value must be true or false. got %s", value)
}
default:
return nil, fmt.Errorf("Unknown type %s", typ)
}
return &ctypes.ResultUnsafeSetConfig{}, nil
}
var profFile *os.File
func UnsafeStartCPUProfiler(filename string) (*ctypes.ResultUnsafeProfile, error) {

View File

@ -1,8 +1,6 @@
package core
import (
"github.com/spf13/viper"
crypto "github.com/tendermint/go-crypto"
"github.com/tendermint/tendermint/consensus"
p2p "github.com/tendermint/tendermint/p2p"
@ -34,7 +32,6 @@ var (
// external, thread safe interfaces
eventSwitch types.EventSwitch
proxyAppQuery proxy.AppConnQuery
config *viper.Viper
// interfaces defined in types and above
blockStore types.BlockStore
@ -49,10 +46,6 @@ var (
txIndexer txindex.TxIndexer
)
func SetConfig(c *viper.Viper) {
config = c
}
func SetEventSwitch(evsw types.EventSwitch) {
eventSwitch = evsw
}

View File

@ -2,6 +2,12 @@ package core
import (
rpc "github.com/tendermint/tendermint/rpc/lib/server"
data "github.com/tendermint/go-wire/data"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpc "github.com/tendermint/tendermint/rpc/lib/server"
"github.com/tendermint/tendermint/rpc/lib/types"
"github.com/tendermint/tendermint/types"
)
// TODO: better system than "unsafe" prefix
@ -36,9 +42,6 @@ var Routes = map[string]*rpc.RPCFunc{
"dial_seeds": rpc.NewRPCFunc(UnsafeDialSeeds, "seeds"),
"unsafe_flush_mempool": rpc.NewRPCFunc(UnsafeFlushMempool, ""),
// config is not in general thread safe. expose specifics if you need em
// "unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfig, "type,key,value"),
// profiler API
"unsafe_start_cpu_profiler": rpc.NewRPCFunc(UnsafeStartCPUProfiler, "filename"),
"unsafe_stop_cpu_profiler": rpc.NewRPCFunc(UnsafeStopCPUProfiler, ""),

View File

@ -6,6 +6,7 @@ import (
abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-wire/data"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/types"
)
@ -116,8 +117,6 @@ type ResultABCIQuery struct {
type ResultUnsafeFlushMempool struct{}
type ResultUnsafeSetConfig struct{}
type ResultUnsafeProfile struct{}
type ResultSubscribe struct{}

View File

@ -13,12 +13,13 @@ import (
abci "github.com/tendermint/abci/types"
"github.com/tendermint/go-wire/data"
. "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tendermint/rpc/core"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpc "github.com/tendermint/tendermint/rpc/lib/client"
"github.com/tendermint/tendermint/state/txindex/null"
"github.com/tendermint/tendermint/types"
. "github.com/tendermint/tmlibs/common"
)
//--------------------------------------------------------------------------------
@ -349,54 +350,3 @@ func TestWSDoubleFire(t *testing.T) {
return nil
})
}*/
//--------------------------------------------------------------------------------
//TODO needs to be refactored so we don't use a mutable config but rather update specific values we're interested in
// unsafe_set_config
//var stringVal = "my string"
//var intVal = 987654321
//var boolVal = true
//
//// don't change these
//var testCasesUnsafeSetConfig = [][]string{
// []string{"string", "key1", stringVal},
// []string{"int", "key2", fmt.Sprintf("%v", intVal)},
// []string{"bool", "key3", fmt.Sprintf("%v", boolVal)},
//}
//
//func TestURIUnsafeSetConfig(t *testing.T) {
// for _, testCase := range testCasesUnsafeSetConfig {
// result := new(ctypes.TMResult)
// _, err := GetURIClient().Call("unsafe_set_config", map[string]interface{}{
// "type": testCase[0],
// "key": testCase[1],
// "value": testCase[2],
// }, result)
// require.Nil(t, err)
// }
// testUnsafeSetConfig(t)
//}
//
//func TestJSONUnsafeSetConfig(t *testing.T) {
// for _, testCase := range testCasesUnsafeSetConfig {
// result := new(ctypes.TMResult)
// _, err := GetJSONClient().Call("unsafe_set_config",
// map[string]interface{}{"type": testCase[0], "key": testCase[1], "value": testCase[2]},
// result)
// require.Nil(t, err)
// }
// testUnsafeSetConfig(t)
//}
//
//func testUnsafeSetConfig(t *testing.T) {
// require := require.New(t)
// s := config.GetString("key1")
// require.Equal(stringVal, s)
//
// i := config.GetInt("key2")
// require.Equal(intVal, i)
//
// b := config.GetBool("key3")
// require.Equal(boolVal, b)
//}