mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-21 00:46:32 +00:00
Refactor RPC to be more general
This commit is contained in:
@ -1,5 +1,9 @@
|
||||
package rpctypes
|
||||
|
||||
import (
|
||||
"github.com/tendermint/tendermint/events"
|
||||
)
|
||||
|
||||
type RPCRequest struct {
|
||||
JSONRPC string `json:"jsonrpc"`
|
||||
ID string `json:"id"`
|
||||
@ -16,14 +20,32 @@ func NewRPCRequest(id string, method string, params []interface{}) RPCRequest {
|
||||
}
|
||||
}
|
||||
|
||||
type RPCResponse struct {
|
||||
JSONRPC string `json:"jsonrpc"`
|
||||
ID string `json:"id"`
|
||||
Result interface{} `json:"result"`
|
||||
Error string `json:"error"`
|
||||
//----------------------------------------
|
||||
|
||||
/*
|
||||
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 {
|
||||
}
|
||||
|
||||
func NewRPCResponse(id string, res interface{}, err string) RPCResponse {
|
||||
//----------------------------------------
|
||||
|
||||
type RPCResponse struct {
|
||||
JSONRPC string `json:"jsonrpc"`
|
||||
ID string `json:"id"`
|
||||
Result Result `json:"result"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
func NewRPCResponse(id string, res Result, err string) RPCResponse {
|
||||
return RPCResponse{
|
||||
JSONRPC: "2.0",
|
||||
ID: id,
|
||||
@ -31,3 +53,19 @@ func NewRPCResponse(id string, res interface{}, err string) RPCResponse {
|
||||
Error: err,
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
// *wsConnection implements this interface.
|
||||
type WSRPCConnection interface {
|
||||
GetRemoteAddr() string
|
||||
GetEventSwitch() *events.EventSwitch
|
||||
WriteRPCResponse(resp RPCResponse)
|
||||
TryWriteRPCResponse(resp RPCResponse) bool
|
||||
}
|
||||
|
||||
// websocket-only RPCFuncs take this as the first parameter.
|
||||
type WSRPCContext struct {
|
||||
Request RPCRequest
|
||||
WSRPCConnection
|
||||
}
|
||||
|
Reference in New Issue
Block a user