mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-15 22:31:21 +00:00
rpc: unsafe_set_config
This commit is contained in:
@ -39,8 +39,3 @@ func UnconfirmedTxs() (*ctypes.ResultUnconfirmedTxs, error) {
|
|||||||
txs := mempoolReactor.Mempool.Reap()
|
txs := mempoolReactor.Mempool.Reap()
|
||||||
return &ctypes.ResultUnconfirmedTxs{len(txs), txs}, nil
|
return &ctypes.ResultUnconfirmedTxs{len(txs), txs}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStartMempool() (*ctypes.ResultTestStartMempool, error) {
|
|
||||||
config.Set("mempool_reap", true)
|
|
||||||
return &ctypes.ResultTestStartMempool{}, nil
|
|
||||||
}
|
|
||||||
|
@ -7,8 +7,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var Routes = map[string]*rpc.RPCFunc{
|
var Routes = map[string]*rpc.RPCFunc{
|
||||||
"subscribe": rpc.NewWSRPCFunc(SubscribeResult, "event"),
|
// subscribe/unsubscribe are reserved for websocket events.
|
||||||
"unsubscribe": rpc.NewWSRPCFunc(UnsubscribeResult, "event"),
|
"subscribe": rpc.NewWSRPCFunc(SubscribeResult, "event"),
|
||||||
|
"unsubscribe": rpc.NewWSRPCFunc(UnsubscribeResult, "event"),
|
||||||
|
|
||||||
"status": rpc.NewRPCFunc(StatusResult, ""),
|
"status": rpc.NewRPCFunc(StatusResult, ""),
|
||||||
"net_info": rpc.NewRPCFunc(NetInfoResult, ""),
|
"net_info": rpc.NewRPCFunc(NetInfoResult, ""),
|
||||||
"dial_seeds": rpc.NewRPCFunc(DialSeedsResult, "seeds"),
|
"dial_seeds": rpc.NewRPCFunc(DialSeedsResult, "seeds"),
|
||||||
@ -20,8 +22,8 @@ var Routes = map[string]*rpc.RPCFunc{
|
|||||||
"broadcast_tx_sync": rpc.NewRPCFunc(BroadcastTxSyncResult, "tx"),
|
"broadcast_tx_sync": rpc.NewRPCFunc(BroadcastTxSyncResult, "tx"),
|
||||||
"broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"),
|
"broadcast_tx_async": rpc.NewRPCFunc(BroadcastTxAsyncResult, "tx"),
|
||||||
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
|
"unconfirmed_txs": rpc.NewRPCFunc(UnconfirmedTxsResult, ""),
|
||||||
"test_start_mempool": rpc.NewRPCFunc(TestStartMempoolResult, ""), // move to test server ?
|
|
||||||
// subscribe/unsubscribe are reserved for websocket events.
|
"unsafe_set_config": rpc.NewRPCFunc(UnsafeSetConfigResult, "type,key,value"),
|
||||||
}
|
}
|
||||||
|
|
||||||
func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
|
func SubscribeResult(wsCtx rpctypes.WSRPCContext, event string) (ctypes.TMResult, error) {
|
||||||
@ -128,8 +130,8 @@ func BroadcastTxAsyncResult(tx []byte) (ctypes.TMResult, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStartMempoolResult() (ctypes.TMResult, error) {
|
func UnsafeSetConfigResult(typ, key, value string) (ctypes.TMResult, error) {
|
||||||
if r, err := TestStartMempool(); err != nil {
|
if r, err := UnsafeSetConfig(typ, key, value); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else {
|
} else {
|
||||||
return r, nil
|
return r, nil
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
ctypes "github.com/tendermint/tendermint/rpc/core/types"
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
@ -28,3 +31,28 @@ func Status() (*ctypes.ResultStatus, error) {
|
|||||||
LatestBlockHeight: latestHeight,
|
LatestBlockHeight: latestHeight,
|
||||||
LatestBlockTime: latestBlockTime}, nil
|
LatestBlockTime: latestBlockTime}, 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
|
||||||
|
}
|
||||||
|
@ -68,7 +68,7 @@ type ResultUnconfirmedTxs struct {
|
|||||||
Txs []types.Tx `json:"txs"`
|
Txs []types.Tx `json:"txs"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResultTestStartMempool struct{}
|
type ResultUnsafeSetConfig struct{}
|
||||||
|
|
||||||
type ResultSubscribe struct {
|
type ResultSubscribe struct {
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ const (
|
|||||||
ResultTypeEvent = byte(0x82)
|
ResultTypeEvent = byte(0x82)
|
||||||
|
|
||||||
// 0xa bytes for testing
|
// 0xa bytes for testing
|
||||||
ResultTypeTestStartMempool = byte(0xa0)
|
ResultTypeUnsafeSetConfig = byte(0xa0)
|
||||||
)
|
)
|
||||||
|
|
||||||
type TMResult interface {
|
type TMResult interface {
|
||||||
@ -132,5 +132,5 @@ var _ = wire.RegisterInterface(
|
|||||||
wire.ConcreteType{&ResultSubscribe{}, ResultTypeSubscribe},
|
wire.ConcreteType{&ResultSubscribe{}, ResultTypeSubscribe},
|
||||||
wire.ConcreteType{&ResultUnsubscribe{}, ResultTypeUnsubscribe},
|
wire.ConcreteType{&ResultUnsubscribe{}, ResultTypeUnsubscribe},
|
||||||
wire.ConcreteType{&ResultEvent{}, ResultTypeEvent},
|
wire.ConcreteType{&ResultEvent{}, ResultTypeEvent},
|
||||||
wire.ConcreteType{&ResultTestStartMempool{}, ResultTypeTestStartMempool},
|
wire.ConcreteType{&ResultUnsafeSetConfig{}, ResultTypeUnsafeSetConfig},
|
||||||
)
|
)
|
||||||
|
@ -11,6 +11,10 @@ import (
|
|||||||
|
|
||||||
//--------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------
|
||||||
// Test the HTTP client
|
// Test the HTTP client
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// status
|
||||||
|
|
||||||
func TestURIStatus(t *testing.T) {
|
func TestURIStatus(t *testing.T) {
|
||||||
tmResult := new(ctypes.TMResult)
|
tmResult := new(ctypes.TMResult)
|
||||||
@ -39,6 +43,63 @@ func testStatus(t *testing.T, statusI interface{}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------
|
||||||
|
// 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 {
|
||||||
|
tmResult := new(ctypes.TMResult)
|
||||||
|
_, err := clientURI.Call("unsafe_set_config", map[string]interface{}{
|
||||||
|
"type": testCase[0],
|
||||||
|
"key": testCase[1],
|
||||||
|
"value": testCase[2],
|
||||||
|
}, tmResult)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
testUnsafeSetConfig(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestJSONUnsafeSetConfig(t *testing.T) {
|
||||||
|
for _, testCase := range testCasesUnsafeSetConfig {
|
||||||
|
tmResult := new(ctypes.TMResult)
|
||||||
|
_, err := clientJSON.Call("unsafe_set_config", []interface{}{testCase[0], testCase[1], testCase[2]}, tmResult)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
testUnsafeSetConfig(t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testUnsafeSetConfig(t *testing.T) {
|
||||||
|
s := config.GetString("key1")
|
||||||
|
if s != stringVal {
|
||||||
|
t.Fatalf("got %v, expected %v", s, stringVal)
|
||||||
|
}
|
||||||
|
|
||||||
|
i := config.GetInt("key2")
|
||||||
|
if i != intVal {
|
||||||
|
t.Fatalf("got %v, expected %v", i, intVal)
|
||||||
|
}
|
||||||
|
|
||||||
|
b := config.GetBool("key3")
|
||||||
|
if b != boolVal {
|
||||||
|
t.Fatalf("got %v, expected %v", b, boolVal)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*func TestURIBroadcastTx(t *testing.T) {
|
/*func TestURIBroadcastTx(t *testing.T) {
|
||||||
testBroadcastTx(t, "HTTP")
|
testBroadcastTx(t, "HTTP")
|
||||||
}*/
|
}*/
|
||||||
|
Reference in New Issue
Block a user