From efeadcc0f44f563ebab9870f446c89cb39509208 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Fri, 28 Apr 2017 23:18:38 -0400 Subject: [PATCH] some cleanup from review --- cmd/tendermint/commands/gen_validator.go | 4 +- rpc/core/types/responses.go | 88 +----------------------- rpc/lib/README.md | 12 +--- rpc/lib/client/http_client.go | 7 -- rpc/lib/client/ws_client.go | 7 -- rpc/lib/server/http_server.go | 1 - rpc/lib/types/types.go | 16 ----- rpc/test/helpers.go | 2 - 8 files changed, 6 insertions(+), 131 deletions(-) diff --git a/cmd/tendermint/commands/gen_validator.go b/cmd/tendermint/commands/gen_validator.go index a1217e1f0..97c583c22 100644 --- a/cmd/tendermint/commands/gen_validator.go +++ b/cmd/tendermint/commands/gen_validator.go @@ -1,11 +1,11 @@ package commands import ( + "encoding/json" "fmt" "github.com/spf13/cobra" - "github.com/tendermint/go-wire" "github.com/tendermint/tendermint/types" ) @@ -21,7 +21,7 @@ func init() { func genValidator(cmd *cobra.Command, args []string) { privValidator := types.GenPrivValidator() - privValidatorJSONBytes := wire.JSONBytesPretty(privValidator) + privValidatorJSONBytes, _ := json.MarshalIndent(privValidator, "", "\t") fmt.Printf(`%v `, string(privValidatorJSONBytes)) } diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index 23d68587b..7fa9e70b6 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -7,7 +7,6 @@ import ( "github.com/tendermint/go-crypto" "github.com/tendermint/go-wire/data" "github.com/tendermint/tendermint/p2p" - // "github.com/tendermint/tendermint/rpc/lib/types" "github.com/tendermint/tendermint/types" ) @@ -121,94 +120,11 @@ type ResultUnsafeSetConfig struct{} type ResultUnsafeProfile struct{} -type ResultSubscribe struct { -} +type ResultSubscribe struct{} -type ResultUnsubscribe struct { -} +type ResultUnsubscribe struct{} type ResultEvent struct { Name string `json:"name"` Data types.TMEventData `json:"data"` } - -//---------------------------------------- -// response & result types - -const ( - // 0x0 bytes are for the blockchain - ResultTypeGenesis = byte(0x01) - ResultTypeBlockchainInfo = byte(0x02) - ResultTypeBlock = byte(0x03) - ResultTypeCommit = byte(0x04) - - // 0x2 bytes are for the network - ResultTypeStatus = byte(0x20) - ResultTypeNetInfo = byte(0x21) - ResultTypeDialSeeds = byte(0x22) - - // 0x4 bytes are for the consensus - ResultTypeValidators = byte(0x40) - ResultTypeDumpConsensusState = byte(0x41) - - // 0x6 bytes are for txs / the application - ResultTypeBroadcastTx = byte(0x60) - ResultTypeUnconfirmedTxs = byte(0x61) - ResultTypeBroadcastTxCommit = byte(0x62) - ResultTypeTx = byte(0x63) - - // 0x7 bytes are for querying the application - ResultTypeABCIQuery = byte(0x70) - ResultTypeABCIInfo = byte(0x71) - - // 0x8 bytes are for events - ResultTypeSubscribe = byte(0x80) - ResultTypeUnsubscribe = byte(0x81) - ResultTypeEvent = byte(0x82) - - // 0xa bytes for testing - ResultTypeUnsafeSetConfig = byte(0xa0) - ResultTypeUnsafeStartCPUProfiler = byte(0xa1) - ResultTypeUnsafeStopCPUProfiler = byte(0xa2) - ResultTypeUnsafeWriteHeapProfile = byte(0xa3) - ResultTypeUnsafeFlushMempool = byte(0xa4) -) - -const ( - // for the blockchain - ResultNameGenesis = "genesis" - ResultNameBlockchainInfo = "info" - ResultNameBlock = "block" - ResultNameCommit = "commit" - - // for the network - ResultNameStatus = "status" - ResultNameNetInfo = "netinfo" - ResultNameDialSeeds = "dialseeds" - - // for the consensus - ResultNameValidators = "validators" - ResultNameDumpConsensusState = "consensus" - - // for txs / the application - ResultNameBroadcastTx = "broadcast_tx" - ResultNameUnconfirmedTxs = "unconfirmed_tx" - ResultNameBroadcastTxCommit = "broadcast_tx_commit" - ResultNameTx = "tx" - - // for querying the application - ResultNameABCIQuery = "abci_query" - ResultNameABCIInfo = "abci_info" - - // for events - ResultNameSubscribe = "subscribe" - ResultNameUnsubscribe = "unsubscribe" - ResultNameEvent = "event" - - // for testing - ResultNameUnsafeSetConfig = "unsafe_set_config" - ResultNameUnsafeStartCPUProfiler = "unsafe_start_profiler" - ResultNameUnsafeStopCPUProfiler = "unsafe_stop_profiler" - ResultNameUnsafeWriteHeapProfile = "unsafe_write_heap" - ResultNameUnsafeFlushMempool = "unsafe_flush_mempool" -) diff --git a/rpc/lib/README.md b/rpc/lib/README.md index 75531963e..6fe44c22f 100644 --- a/rpc/lib/README.md +++ b/rpc/lib/README.md @@ -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 } diff --git a/rpc/lib/client/http_client.go b/rpc/lib/client/http_client.go index 55963f506..5386779d3 100644 --- a/rpc/lib/client/http_client.go +++ b/rpc/lib/client/http_client.go @@ -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, diff --git a/rpc/lib/client/ws_client.go b/rpc/lib/client/ws_client.go index 8884068b9..df9cb3812 100644 --- a/rpc/lib/client/ws_client.go +++ b/rpc/lib/client/ws_client.go @@ -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, diff --git a/rpc/lib/server/http_server.go b/rpc/lib/server/http_server.go index ae0923c39..b51699c22 100644 --- a/rpc/lib/server/http_server.go +++ b/rpc/lib/server/http_server.go @@ -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) diff --git a/rpc/lib/types/types.go b/rpc/lib/types/types.go index 28ddfc0ff..a91811e53 100644 --- a/rpc/lib/types/types.go +++ b/rpc/lib/types/types.go @@ -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"` diff --git a/rpc/test/helpers.go b/rpc/test/helpers.go index a12d82f23..11a228bb1 100644 --- a/rpc/test/helpers.go +++ b/rpc/test/helpers.go @@ -131,11 +131,9 @@ func waitForEvent(t *testing.T, wsc *client.WSClient, eventid string, dieOnTimeo for { select { case r := <-wsc.ResultsCh: - fmt.Println("GOT IT", string(r)) result := new(ctypes.ResultEvent) err = json.Unmarshal(r, result) if err != nil { - fmt.Println("POOP", err) // cant distinguish between error and wrong type ... continue }