some cleanup from review
This commit is contained in:
parent
297772e009
commit
efeadcc0f4
|
@ -1,11 +1,11 @@
|
||||||
package commands
|
package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
"github.com/tendermint/go-wire"
|
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ func init() {
|
||||||
|
|
||||||
func genValidator(cmd *cobra.Command, args []string) {
|
func genValidator(cmd *cobra.Command, args []string) {
|
||||||
privValidator := types.GenPrivValidator()
|
privValidator := types.GenPrivValidator()
|
||||||
privValidatorJSONBytes := wire.JSONBytesPretty(privValidator)
|
privValidatorJSONBytes, _ := json.MarshalIndent(privValidator, "", "\t")
|
||||||
fmt.Printf(`%v
|
fmt.Printf(`%v
|
||||||
`, string(privValidatorJSONBytes))
|
`, string(privValidatorJSONBytes))
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"github.com/tendermint/go-crypto"
|
"github.com/tendermint/go-crypto"
|
||||||
"github.com/tendermint/go-wire/data"
|
"github.com/tendermint/go-wire/data"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
// "github.com/tendermint/tendermint/rpc/lib/types"
|
|
||||||
"github.com/tendermint/tendermint/types"
|
"github.com/tendermint/tendermint/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -121,94 +120,11 @@ type ResultUnsafeSetConfig struct{}
|
||||||
|
|
||||||
type ResultUnsafeProfile struct{}
|
type ResultUnsafeProfile struct{}
|
||||||
|
|
||||||
type ResultSubscribe struct {
|
type ResultSubscribe struct{}
|
||||||
}
|
|
||||||
|
|
||||||
type ResultUnsubscribe struct {
|
type ResultUnsubscribe struct{}
|
||||||
}
|
|
||||||
|
|
||||||
type ResultEvent struct {
|
type ResultEvent struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Data types.TMEventData `json:"data"`
|
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"
|
|
||||||
)
|
|
||||||
|
|
|
@ -59,25 +59,17 @@ though this is configurable when starting the server.
|
||||||
Define some types and routes:
|
Define some types and routes:
|
||||||
|
|
||||||
```
|
```
|
||||||
// Define a type for results and register concrete versions with go-wire
|
|
||||||
type Result interface{}
|
|
||||||
|
|
||||||
type ResultStatus struct {
|
type ResultStatus struct {
|
||||||
Value string
|
Value string
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = wire.RegisterInterface(
|
|
||||||
struct{ Result }{},
|
|
||||||
wire.ConcreteType{&ResultStatus{}, 0x1},
|
|
||||||
)
|
|
||||||
|
|
||||||
// Define some routes
|
// Define some routes
|
||||||
var Routes = map[string]*rpcserver.RPCFunc{
|
var Routes = map[string]*rpcserver.RPCFunc{
|
||||||
"status": rpcserver.NewRPCFunc(StatusResult, "arg"),
|
"status": rpcserver.NewRPCFunc(Status, "arg"),
|
||||||
}
|
}
|
||||||
|
|
||||||
// an rpc function
|
// an rpc function
|
||||||
func StatusResult(v string) (Result, error) {
|
func Status(v string) (*ResultStatus, error) {
|
||||||
return &ResultStatus{v}, nil
|
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) {
|
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{
|
request := types.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: method,
|
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
|
// Call asynchronously calls a given method by sending an RPCRequest to the
|
||||||
// server. Results will be available on ResultsCh, errors, if any, on ErrorsCh.
|
// server. Results will be available on ResultsCh, errors, if any, on ErrorsCh.
|
||||||
func (wsc *WSClient) Call(method string, params map[string]interface{}) error {
|
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{
|
err := wsc.WriteJSON(types.RPCRequest{
|
||||||
JSONRPC: "2.0",
|
JSONRPC: "2.0",
|
||||||
Method: method,
|
Method: method,
|
||||||
|
|
|
@ -58,7 +58,6 @@ func WriteRPCResponseHTTPError(w http.ResponseWriter, httpCode int, res types.RP
|
||||||
}
|
}
|
||||||
|
|
||||||
func WriteRPCResponseHTTP(w http.ResponseWriter, res types.RPCResponse) {
|
func WriteRPCResponseHTTP(w http.ResponseWriter, res types.RPCResponse) {
|
||||||
// jsonBytes := wire.JSONBytesPretty(res)
|
|
||||||
jsonBytes, err := json.Marshal(res)
|
jsonBytes, err := json.Marshal(res)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
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 {
|
type RPCResponse struct {
|
||||||
JSONRPC string `json:"jsonrpc"`
|
JSONRPC string `json:"jsonrpc"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
|
|
@ -131,11 +131,9 @@ func waitForEvent(t *testing.T, wsc *client.WSClient, eventid string, dieOnTimeo
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case r := <-wsc.ResultsCh:
|
case r := <-wsc.ResultsCh:
|
||||||
fmt.Println("GOT IT", string(r))
|
|
||||||
result := new(ctypes.ResultEvent)
|
result := new(ctypes.ResultEvent)
|
||||||
err = json.Unmarshal(r, result)
|
err = json.Unmarshal(r, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("POOP", err)
|
|
||||||
// cant distinguish between error and wrong type ...
|
// cant distinguish between error and wrong type ...
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue