Browse Source

Client: DumpConsensusState, not DialSeeds. Cleanup

pull/418/head
Ethan Frey 8 years ago
parent
commit
98450ee2db
5 changed files with 21 additions and 95 deletions
  1. +8
    -5
      rpc/client/httpclient.go
  2. +1
    -2
      rpc/client/interface.go
  3. +8
    -43
      rpc/client/localclient.go
  4. +0
    -43
      rpc/client/mock/client.go
  5. +4
    -2
      rpc/client/rpc_test.go

+ 8
- 5
rpc/client/httpclient.go View File

@ -39,6 +39,10 @@ func (c *HTTP) _assertIsClient() Client {
return c
}
func (c *HTTP) _assertIsNetworkClient() NetworkClient {
return c
}
func (c *HTTP) Status() (*ctypes.ResultStatus, error) {
tmResult := new(ctypes.TMResult)
_, err := c.rpc.Call("status", []interface{}{}, tmResult)
@ -102,14 +106,13 @@ func (c *HTTP) NetInfo() (*ctypes.ResultNetInfo, error) {
return (*tmResult).(*ctypes.ResultNetInfo), nil
}
func (c *HTTP) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
func (c *HTTP) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
tmResult := new(ctypes.TMResult)
// TODO: is this the correct way to marshall seeds?
_, err := c.rpc.Call("dial_seeds", []interface{}{seeds}, tmResult)
_, err := c.rpc.Call("dump_consensus_state", nil, tmResult)
if err != nil {
return nil, errors.Wrap(err, "DialSeeds")
return nil, errors.Wrap(err, "DumpConsensusState")
}
return (*tmResult).(*ctypes.ResultDialSeeds), nil
return (*tmResult).(*ctypes.ResultDumpConsensusState), nil
}
func (c *HTTP) BlockchainInfo(minHeight, maxHeight int) (*ctypes.ResultBlockchainInfo, error) {


+ 1
- 2
rpc/client/interface.go View File

@ -53,8 +53,7 @@ type SignClient interface {
// by concrete implementations.
type NetworkClient interface {
NetInfo() (*ctypes.ResultNetInfo, error)
// remove this???
DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error)
DumpConsensusState() (*ctypes.ResultDumpConsensusState, error)
}
// HistoryClient shows us data from genesis to now in large chunks.


+ 8
- 43
rpc/client/localclient.go View File

@ -42,6 +42,10 @@ func (c Local) _assertIsClient() Client {
return c
}
func (c Local) _assertIsNetworkClient() NetworkClient {
return c
}
func (c Local) Status() (*ctypes.ResultStatus, error) {
return core.Status()
}
@ -70,6 +74,10 @@ func (c Local) NetInfo() (*ctypes.ResultNetInfo, error) {
return core.NetInfo()
}
func (c Local) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) {
return core.DumpConsensusState()
}
func (c Local) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) {
return core.UnsafeDialSeeds(seeds)
}
@ -93,46 +101,3 @@ func (c Local) Commit(height int) (*ctypes.ResultCommit, error) {
func (c Local) Validators() (*ctypes.ResultValidators, error) {
return core.Validators()
}
/** websocket event stuff here... **/
/*
// StartWebsocket starts up a websocket and a listener goroutine
// if already started, do nothing
func (c Client) StartWebsocket() error {
var err error
if c.ws == nil {
ws := rpcclient.NewWSClient(c.remote, c.endpoint)
_, err = ws.Start()
if err == nil {
c.ws = ws
}
}
return errors.Wrap(err, "StartWebsocket")
}
// StopWebsocket stops the websocket connection
func (c Client) StopWebsocket() {
if c.ws != nil {
c.ws.Stop()
c.ws = nil
}
}
// GetEventChannels returns the results and error channel from the websocket
func (c Client) GetEventChannels() (chan json.RawMessage, chan error) {
if c.ws == nil {
return nil, nil
}
return c.ws.ResultsCh, c.ws.ErrorsCh
}
func (c Client) Subscribe(event string) error {
return errors.Wrap(c.ws.Subscribe(event), "Subscribe")
}
func (c Client) Unsubscribe(event string) error {
return errors.Wrap(c.ws.Unsubscribe(event), "Unsubscribe")
}
*/

+ 0
- 43
rpc/client/mock/client.go View File

@ -124,46 +124,3 @@ func (c Client) Commit(height int) (*ctypes.ResultCommit, error) {
func (c Client) Validators() (*ctypes.ResultValidators, error) {
return core.Validators()
}
/** websocket event stuff here... **/
/*
// StartWebsocket starts up a websocket and a listener goroutine
// if already started, do nothing
func (c Client) StartWebsocket() error {
var err error
if c.ws == nil {
ws := rpcclient.NewWSClient(c.remote, c.endpoint)
_, err = ws.Start()
if err == nil {
c.ws = ws
}
}
return errors.Wrap(err, "StartWebsocket")
}
// StopWebsocket stops the websocket connection
func (c Client) StopWebsocket() {
if c.ws != nil {
c.ws.Stop()
c.ws = nil
}
}
// GetEventChannels returns the results and error channel from the websocket
func (c Client) GetEventChannels() (chan json.RawMessage, chan error) {
if c.ws == nil {
return nil, nil
}
return c.ws.ResultsCh, c.ws.ErrorsCh
}
func (c Client) Subscribe(event string) error {
return errors.Wrap(c.ws.Subscribe(event), "Subscribe")
}
func (c Client) Unsubscribe(event string) error {
return errors.Wrap(c.ws.Unsubscribe(event), "Unsubscribe")
}
*/

+ 4
- 2
rpc/client/rpc_test.go View File

@ -67,13 +67,15 @@ func TestNetInfo(t *testing.T) {
}
}
func TestDialSeeds(t *testing.T) {
func TestDumpConsensusState(t *testing.T) {
for i, c := range GetClients() {
// FIXME: fix server so it doesn't panic on invalid input
nc, ok := c.(client.NetworkClient)
require.True(t, ok, "%d", i)
_, err := nc.DialSeeds([]string{"12.34.56.78:12345"})
cons, err := nc.DumpConsensusState()
require.Nil(t, err, "%d: %+v", i, err)
assert.NotEmpty(t, cons.RoundState)
assert.Empty(t, cons.PeerRoundStates)
}
}


Loading…
Cancel
Save