mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-17 07:01:20 +00:00
remove "rpc" prefix from package imports
This commit is contained in:
@ -11,8 +11,7 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
// cmn "github.com/tendermint/go-common"
|
types "github.com/tendermint/go-rpc/types"
|
||||||
rpctypes "github.com/tendermint/go-rpc/types"
|
|
||||||
wire "github.com/tendermint/go-wire"
|
wire "github.com/tendermint/go-wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -28,7 +27,7 @@ func makeHTTPDialer(remoteAddr string) (string, func(string, string) (net.Conn,
|
|||||||
var protocol, address string
|
var protocol, address string
|
||||||
if len(parts) != 2 {
|
if len(parts) != 2 {
|
||||||
log.Warn("WARNING (go-rpc): Please use fully formed listening addresses, including the tcp:// or unix:// prefix")
|
log.Warn("WARNING (go-rpc): Please use fully formed listening addresses, including the tcp:// or unix:// prefix")
|
||||||
protocol = rpctypes.SocketType(remoteAddr)
|
protocol = types.SocketType(remoteAddr)
|
||||||
address = remoteAddr
|
address = remoteAddr
|
||||||
} else {
|
} else {
|
||||||
protocol, address = parts[0], parts[1]
|
protocol, address = parts[0], parts[1]
|
||||||
@ -73,7 +72,7 @@ func (c *ClientJSONRPC) Call(method string, params map[string]interface{}, resul
|
|||||||
|
|
||||||
func (c *ClientJSONRPC) call(method string, params map[string]interface{}, result interface{}) (interface{}, error) {
|
func (c *ClientJSONRPC) call(method string, params map[string]interface{}, result interface{}) (interface{}, error) {
|
||||||
// Make request and get responseBytes
|
// Make request and get responseBytes
|
||||||
request := rpctypes.RPCRequest{
|
request := types.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: method,
|
Method: method,
|
||||||
Params: params,
|
Params: params,
|
||||||
@ -144,7 +143,7 @@ func unmarshalResponseBytes(responseBytes []byte, result interface{}) (interface
|
|||||||
// into the correct type
|
// into the correct type
|
||||||
// log.Notice("response", "response", string(responseBytes))
|
// log.Notice("response", "response", string(responseBytes))
|
||||||
var err error
|
var err error
|
||||||
response := &rpctypes.RPCResponse{}
|
response := &types.RPCResponse{}
|
||||||
err = json.Unmarshal(responseBytes, response)
|
err = json.Unmarshal(responseBytes, response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error unmarshalling rpc response: %v", err)
|
return nil, fmt.Errorf("Error unmarshalling rpc response: %v", err)
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
cmn "github.com/tendermint/go-common"
|
cmn "github.com/tendermint/go-common"
|
||||||
rpctypes "github.com/tendermint/go-rpc/types"
|
types "github.com/tendermint/go-rpc/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -96,7 +96,7 @@ func (wsc *WSClient) receiveEventsRoutine() {
|
|||||||
wsc.Stop()
|
wsc.Stop()
|
||||||
break
|
break
|
||||||
} else {
|
} else {
|
||||||
var response rpctypes.RPCResponse
|
var response types.RPCResponse
|
||||||
err := json.Unmarshal(data, &response)
|
err := json.Unmarshal(data, &response)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("WSClient failed to parse message", "error", err, "data", string(data))
|
log.Info("WSClient failed to parse message", "error", err, "data", string(data))
|
||||||
@ -118,7 +118,7 @@ func (wsc *WSClient) receiveEventsRoutine() {
|
|||||||
|
|
||||||
// subscribe to an event
|
// subscribe to an event
|
||||||
func (wsc *WSClient) Subscribe(eventid string) error {
|
func (wsc *WSClient) Subscribe(eventid string) error {
|
||||||
err := wsc.WriteJSON(rpctypes.RPCRequest{
|
err := wsc.WriteJSON(types.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
ID: "",
|
ID: "",
|
||||||
Method: "subscribe",
|
Method: "subscribe",
|
||||||
@ -129,7 +129,7 @@ func (wsc *WSClient) Subscribe(eventid string) error {
|
|||||||
|
|
||||||
// unsubscribe from an event
|
// unsubscribe from an event
|
||||||
func (wsc *WSClient) Unsubscribe(eventid string) error {
|
func (wsc *WSClient) Unsubscribe(eventid string) error {
|
||||||
err := wsc.WriteJSON(rpctypes.RPCRequest{
|
err := wsc.WriteJSON(types.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
ID: "",
|
ID: "",
|
||||||
Method: "unsubscribe",
|
Method: "unsubscribe",
|
||||||
|
49
rpc_test.go
49
rpc_test.go
@ -5,14 +5,14 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
rpcclient "github.com/tendermint/go-rpc/client"
|
client "github.com/tendermint/go-rpc/client"
|
||||||
rpcserver "github.com/tendermint/go-rpc/server"
|
server "github.com/tendermint/go-rpc/server"
|
||||||
rpctypes "github.com/tendermint/go-rpc/types"
|
types "github.com/tendermint/go-rpc/types"
|
||||||
wire "github.com/tendermint/go-wire"
|
wire "github.com/tendermint/go-wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Client and Server should work over tcp or unix sockets
|
// Client and Server should work over tcp or unix sockets
|
||||||
var (
|
const (
|
||||||
tcpAddr = "tcp://0.0.0.0:46657"
|
tcpAddr = "tcp://0.0.0.0:46657"
|
||||||
unixAddr = "unix:///tmp/go-rpc.sock" // NOTE: must remove file for test to run again
|
unixAddr = "unix:///tmp/go-rpc.sock" // NOTE: must remove file for test to run again
|
||||||
|
|
||||||
@ -32,8 +32,8 @@ var _ = wire.RegisterInterface(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Define some routes
|
// Define some routes
|
||||||
var Routes = map[string]*rpcserver.RPCFunc{
|
var Routes = map[string]*server.RPCFunc{
|
||||||
"status": rpcserver.NewRPCFunc(StatusResult, "arg"),
|
"status": server.NewRPCFunc(StatusResult, "arg"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// an rpc function
|
// an rpc function
|
||||||
@ -43,23 +43,24 @@ func StatusResult(v string) (Result, error) {
|
|||||||
|
|
||||||
// launch unix and tcp servers
|
// launch unix and tcp servers
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
rpcserver.RegisterRPCFuncs(mux, Routes)
|
server.RegisterRPCFuncs(mux, Routes)
|
||||||
wm := rpcserver.NewWebsocketManager(Routes, nil)
|
wm := server.NewWebsocketManager(Routes, nil)
|
||||||
mux.HandleFunc(websocketEndpoint, wm.WebsocketHandler)
|
mux.HandleFunc(websocketEndpoint, wm.WebsocketHandler)
|
||||||
go func() {
|
go func() {
|
||||||
_, err := rpcserver.StartHTTPServer(tcpAddr, mux)
|
_, err := server.StartHTTPServer(tcpAddr, mux)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
mux2 := http.NewServeMux()
|
mux2 := http.NewServeMux()
|
||||||
rpcserver.RegisterRPCFuncs(mux2, Routes)
|
server.RegisterRPCFuncs(mux2, Routes)
|
||||||
wm = rpcserver.NewWebsocketManager(Routes, nil)
|
wm = server.NewWebsocketManager(Routes, nil)
|
||||||
mux2.HandleFunc(websocketEndpoint, wm.WebsocketHandler)
|
mux2.HandleFunc(websocketEndpoint, wm.WebsocketHandler)
|
||||||
go func() {
|
go func() {
|
||||||
_, err := rpcserver.StartHTTPServer(unixAddr, mux2)
|
_, err := server.StartHTTPServer(unixAddr, mux2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
@ -70,7 +71,7 @@ func init() {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testURI(t *testing.T, cl *rpcclient.ClientURI) {
|
func testURI(t *testing.T, cl *client.ClientURI) {
|
||||||
val := "acbd"
|
val := "acbd"
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"arg": val,
|
"arg": val,
|
||||||
@ -86,7 +87,7 @@ func testURI(t *testing.T, cl *rpcclient.ClientURI) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testJSONRPC(t *testing.T, cl *rpcclient.ClientJSONRPC) {
|
func testJSONRPC(t *testing.T, cl *client.ClientJSONRPC) {
|
||||||
val := "acbd"
|
val := "acbd"
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"arg": val,
|
"arg": val,
|
||||||
@ -102,12 +103,12 @@ func testJSONRPC(t *testing.T, cl *rpcclient.ClientJSONRPC) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func testWS(t *testing.T, cl *rpcclient.WSClient) {
|
func testWS(t *testing.T, cl *client.WSClient) {
|
||||||
val := "acbd"
|
val := "acbd"
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
"arg": val,
|
"arg": val,
|
||||||
}
|
}
|
||||||
err := cl.WriteJSON(rpctypes.RPCRequest{
|
err := cl.WriteJSON(types.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
ID: "",
|
ID: "",
|
||||||
Method: "status",
|
Method: "status",
|
||||||
@ -132,27 +133,27 @@ func testWS(t *testing.T, cl *rpcclient.WSClient) {
|
|||||||
//-------------
|
//-------------
|
||||||
|
|
||||||
func TestURI_TCP(t *testing.T) {
|
func TestURI_TCP(t *testing.T) {
|
||||||
cl := rpcclient.NewClientURI(tcpAddr)
|
cl := client.NewClientURI(tcpAddr)
|
||||||
testURI(t, cl)
|
testURI(t, cl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestURI_UNIX(t *testing.T) {
|
func TestURI_UNIX(t *testing.T) {
|
||||||
cl := rpcclient.NewClientURI(unixAddr)
|
cl := client.NewClientURI(unixAddr)
|
||||||
testURI(t, cl)
|
testURI(t, cl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJSONRPC_TCP(t *testing.T) {
|
func TestJSONRPC_TCP(t *testing.T) {
|
||||||
cl := rpcclient.NewClientJSONRPC(tcpAddr)
|
cl := client.NewClientJSONRPC(tcpAddr)
|
||||||
testJSONRPC(t, cl)
|
testJSONRPC(t, cl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestJSONRPC_UNIX(t *testing.T) {
|
func TestJSONRPC_UNIX(t *testing.T) {
|
||||||
cl := rpcclient.NewClientJSONRPC(unixAddr)
|
cl := client.NewClientJSONRPC(unixAddr)
|
||||||
testJSONRPC(t, cl)
|
testJSONRPC(t, cl)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWS_TCP(t *testing.T) {
|
func TestWS_TCP(t *testing.T) {
|
||||||
cl := rpcclient.NewWSClient(tcpAddr, websocketEndpoint)
|
cl := client.NewWSClient(tcpAddr, websocketEndpoint)
|
||||||
_, err := cl.Start()
|
_, err := cl.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -161,7 +162,7 @@ func TestWS_TCP(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWS_UNIX(t *testing.T) {
|
func TestWS_UNIX(t *testing.T) {
|
||||||
cl := rpcclient.NewWSClient(unixAddr, websocketEndpoint)
|
cl := client.NewWSClient(unixAddr, websocketEndpoint)
|
||||||
_, err := cl.Start()
|
_, err := cl.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
@ -170,7 +171,7 @@ func TestWS_UNIX(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHexStringArg(t *testing.T) {
|
func TestHexStringArg(t *testing.T) {
|
||||||
cl := rpcclient.NewClientURI(tcpAddr)
|
cl := client.NewClientURI(tcpAddr)
|
||||||
// should NOT be handled as hex
|
// should NOT be handled as hex
|
||||||
val := "0xabc"
|
val := "0xabc"
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
@ -188,7 +189,7 @@ func TestHexStringArg(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestQuotedStringArg(t *testing.T) {
|
func TestQuotedStringArg(t *testing.T) {
|
||||||
cl := rpcclient.NewClientURI(tcpAddr)
|
cl := client.NewClientURI(tcpAddr)
|
||||||
// should NOT be unquoted
|
// should NOT be unquoted
|
||||||
val := "\"abc\""
|
val := "\"abc\""
|
||||||
params := map[string]interface{}{
|
params := map[string]interface{}{
|
||||||
|
@ -11,9 +11,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "github.com/tendermint/go-common"
|
types "github.com/tendermint/go-rpc/types"
|
||||||
. "github.com/tendermint/go-rpc/types"
|
|
||||||
//"github.com/tendermint/go-wire"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func StartHTTPServer(listenAddr string, handler http.Handler) (listener net.Listener, err error) {
|
func StartHTTPServer(listenAddr string, handler http.Handler) (listener net.Listener, err error) {
|
||||||
@ -24,14 +22,14 @@ func StartHTTPServer(listenAddr string, handler http.Handler) (listener net.List
|
|||||||
log.Warn("WARNING (go-rpc): Please use fully formed listening addresses, including the tcp:// or unix:// prefix")
|
log.Warn("WARNING (go-rpc): Please use fully formed listening addresses, including the tcp:// or unix:// prefix")
|
||||||
// we used to allow addrs without tcp/unix prefix by checking for a colon
|
// we used to allow addrs without tcp/unix prefix by checking for a colon
|
||||||
// TODO: Deprecate
|
// TODO: Deprecate
|
||||||
proto = SocketType(listenAddr)
|
proto = types.SocketType(listenAddr)
|
||||||
addr = listenAddr
|
addr = listenAddr
|
||||||
// return nil, fmt.Errorf("Invalid listener address %s", lisenAddr)
|
// return nil, fmt.Errorf("Invalid listener address %s", lisenAddr)
|
||||||
} else {
|
} else {
|
||||||
proto, addr = parts[0], parts[1]
|
proto, addr = parts[0], parts[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Notice(Fmt("Starting RPC HTTP server on %s socket %v", proto, addr))
|
log.Notice(fmt.Sprintf("Starting RPC HTTP server on %s socket %v", proto, addr))
|
||||||
listener, err = net.Listen(proto, addr)
|
listener, err = net.Listen(proto, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Failed to listen to %v: %v", listenAddr, err)
|
return nil, fmt.Errorf("Failed to listen to %v: %v", listenAddr, err)
|
||||||
@ -47,7 +45,7 @@ func StartHTTPServer(listenAddr string, handler http.Handler) (listener net.List
|
|||||||
return listener, nil
|
return listener, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteRPCResponseHTTP(w http.ResponseWriter, res RPCResponse) {
|
func WriteRPCResponseHTTP(w http.ResponseWriter, res types.RPCResponse) {
|
||||||
// jsonBytes := wire.JSONBytesPretty(res)
|
// jsonBytes := wire.JSONBytesPretty(res)
|
||||||
jsonBytes, err := json.Marshal(res)
|
jsonBytes, err := json.Marshal(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -83,13 +81,13 @@ func RecoverAndLogHandler(handler http.Handler) http.Handler {
|
|||||||
if e := recover(); e != nil {
|
if e := recover(); e != nil {
|
||||||
|
|
||||||
// If RPCResponse
|
// If RPCResponse
|
||||||
if res, ok := e.(RPCResponse); ok {
|
if res, ok := e.(types.RPCResponse); ok {
|
||||||
WriteRPCResponseHTTP(rww, res)
|
WriteRPCResponseHTTP(rww, res)
|
||||||
} else {
|
} else {
|
||||||
// For the rest,
|
// For the rest,
|
||||||
log.Error("Panic in RPC HTTP handler", "error", e, "stack", string(debug.Stack()))
|
log.Error("Panic in RPC HTTP handler", "error", e, "stack", string(debug.Stack()))
|
||||||
rww.WriteHeader(http.StatusInternalServerError)
|
rww.WriteHeader(http.StatusInternalServerError)
|
||||||
WriteRPCResponseHTTP(rww, NewRPCResponse("", nil, Fmt("Internal Server Error: %v", e)))
|
WriteRPCResponseHTTP(rww, types.NewRPCResponse("", nil, fmt.Sprintf("Internal Server Error: %v", e)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user