Browse Source

remove viper from rpc except test

pull/484/head
Ethan Buchman 8 years ago
parent
commit
f0e7f0acf8
6 changed files with 9 additions and 92 deletions
  1. +0
    -1
      node/node.go
  2. +0
    -27
      rpc/core/dev.go
  3. +0
    -7
      rpc/core/pipe.go
  4. +6
    -3
      rpc/core/routes.go
  5. +1
    -2
      rpc/core/types/responses.go
  6. +2
    -52
      rpc/test/client_test.go

+ 0
- 1
node/node.go 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)


+ 0
- 27
rpc/core/dev.go 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) {


+ 0
- 7
rpc/core/pipe.go 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
}


+ 6
- 3
rpc/core/routes.go 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, ""),


+ 1
- 2
rpc/core/types/responses.go 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{}


+ 2
- 52
rpc/test/client_test.go 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)
//}

Loading…
Cancel
Save