mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-31 04:01:55 +00:00
some cleanup from review
This commit is contained in:
@@ -59,25 +59,17 @@ though this is configurable when starting the server.
|
||||
Define some types and routes:
|
||||
|
||||
```
|
||||
// Define a type for results and register concrete versions with go-wire
|
||||
type Result interface{}
|
||||
|
||||
type ResultStatus struct {
|
||||
Value string
|
||||
}
|
||||
|
||||
var _ = wire.RegisterInterface(
|
||||
struct{ Result }{},
|
||||
wire.ConcreteType{&ResultStatus{}, 0x1},
|
||||
)
|
||||
|
||||
// Define some routes
|
||||
var Routes = map[string]*rpcserver.RPCFunc{
|
||||
"status": rpcserver.NewRPCFunc(StatusResult, "arg"),
|
||||
"status": rpcserver.NewRPCFunc(Status, "arg"),
|
||||
}
|
||||
|
||||
// an rpc function
|
||||
func StatusResult(v string) (Result, error) {
|
||||
func Status(v string) (*ResultStatus, error) {
|
||||
return &ResultStatus{v}, nil
|
||||
}
|
||||
|
||||
|
@@ -67,13 +67,6 @@ func NewJSONRPCClient(remote string) *JSONRPCClient {
|
||||
}
|
||||
|
||||
func (c *JSONRPCClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) {
|
||||
// we need this step because we attempt to decode values using `go-wire`
|
||||
// (handlers.go:176) on the server side
|
||||
// encodedParams := make(map[string]interface{})
|
||||
// for k, v := range params {
|
||||
// bytes := json.RawMessage(wire.JSONBytes(v))
|
||||
// encodedParams[k] = &bytes
|
||||
// }
|
||||
request := types.RPCRequest{
|
||||
JSONRPC: "2.0",
|
||||
Method: method,
|
||||
|
@@ -154,13 +154,6 @@ func (wsc *WSClient) Unsubscribe(eventid string) error {
|
||||
// Call asynchronously calls a given method by sending an RPCRequest to the
|
||||
// server. Results will be available on ResultsCh, errors, if any, on ErrorsCh.
|
||||
func (wsc *WSClient) Call(method string, params map[string]interface{}) error {
|
||||
// we need this step because we attempt to decode values using `go-wire`
|
||||
// (handlers.go:470) on the server side
|
||||
// encodedParams := make(map[string]interface{})
|
||||
// for k, v := range params {
|
||||
// bytes := json.RawMessage(wire.JSONBytes(v))
|
||||
// encodedParams[k] = &bytes
|
||||
// }
|
||||
err := wsc.WriteJSON(types.RPCRequest{
|
||||
JSONRPC: "2.0",
|
||||
Method: method,
|
||||
|
@@ -58,7 +58,6 @@ func WriteRPCResponseHTTPError(w http.ResponseWriter, httpCode int, res types.RP
|
||||
}
|
||||
|
||||
func WriteRPCResponseHTTP(w http.ResponseWriter, res types.RPCResponse) {
|
||||
// jsonBytes := wire.JSONBytesPretty(res)
|
||||
jsonBytes, err := json.Marshal(res)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@@ -25,22 +25,6 @@ func NewRPCRequest(id string, method string, params map[string]interface{}) RPCR
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
/*
|
||||
Result is a generic interface.
|
||||
Applications should register type-bytes like so:
|
||||
|
||||
var _ = wire.RegisterInterface(
|
||||
struct{ Result }{},
|
||||
wire.ConcreteType{&ResultGenesis{}, ResultTypeGenesis},
|
||||
wire.ConcreteType{&ResultBlockchainInfo{}, ResultTypeBlockchainInfo},
|
||||
...
|
||||
)
|
||||
*/
|
||||
type Result interface {
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
type RPCResponse struct {
|
||||
JSONRPC string `json:"jsonrpc"`
|
||||
ID string `json:"id"`
|
||||
|
Reference in New Issue
Block a user