Browse Source

move ResultEvent to go-events

pull/178/head
Ethan Buchman 9 years ago
parent
commit
ee449a94c8
4 changed files with 7 additions and 15 deletions
  1. +2
    -1
      node/node.go
  2. +2
    -2
      rpc/core/events.go
  3. +0
    -9
      rpc/core/types/responses.go
  4. +3
    -3
      rpc/test/helpers.go

+ 2
- 1
node/node.go View File

@ -188,7 +188,8 @@ func (n *Node) StartRPC() (net.Listener, error) {
// conflicts with their own rpc
wire.RegisterInterface(
struct{ rpctypes.Result }{},
wire.ConcreteType{&ctypes.TendermintResult{}, 0x1},
wire.ConcreteType{&events.EventResult{}, 0x1},
wire.ConcreteType{&ctypes.TendermintResult{}, 0x2},
)
mux := http.NewServeMux()


+ 2
- 2
rpc/core/events.go View File

@ -11,7 +11,7 @@ func Subscribe(wsCtx rpctypes.WSRPCContext, event string) (*ctypes.ResultSubscri
wsCtx.GetEventSwitch().AddListenerForEvent(wsCtx.GetRemoteAddr(), event, func(msg events.EventData) {
// NOTE: EventSwitch callbacks must be nonblocking
// NOTE: RPCResponses of subscribed events have id suffix "#event"
wsCtx.TryWriteRPCResponse(rpctypes.NewRPCResponse(wsCtx.Request.ID+"#event", &ctypes.TendermintResult{&ctypes.ResultEvent{event, msg}}, ""))
wsCtx.TryWriteRPCResponse(rpctypes.NewRPCResponse(wsCtx.Request.ID+"#event", &events.EventResult{event, msg}, ""))
})
return &ctypes.ResultSubscribe{}, nil
}
@ -21,7 +21,7 @@ func Unsubscribe(wsCtx rpctypes.WSRPCContext, event string) (*ctypes.ResultUnsub
wsCtx.GetEventSwitch().AddListenerForEvent(wsCtx.GetRemoteAddr(), event, func(msg events.EventData) {
// NOTE: EventSwitch callbacks must be nonblocking
// NOTE: RPCResponses of subscribed events have id suffix "#event"
wsCtx.TryWriteRPCResponse(rpctypes.NewRPCResponse(wsCtx.Request.ID+"#event", &ctypes.TendermintResult{&ctypes.ResultEvent{event, msg}}, ""))
wsCtx.TryWriteRPCResponse(rpctypes.NewRPCResponse(wsCtx.Request.ID+"#event", &events.EventResult{event, msg}, ""))
})
return &ctypes.ResultUnsubscribe{}, nil
}

+ 0
- 9
rpc/core/types/responses.go View File

@ -2,7 +2,6 @@ package core_types
import (
"github.com/tendermint/go-crypto"
"github.com/tendermint/go-events"
"github.com/tendermint/go-p2p"
"github.com/tendermint/go-wire"
"github.com/tendermint/tendermint/types"
@ -67,12 +66,6 @@ type ResultSubscribe struct {
type ResultUnsubscribe struct {
}
// TODO: something about this
type ResultEvent struct {
Event string `json:"event"`
Data events.EventData `json:"data"`
}
//----------------------------------------
// response & result types
@ -88,7 +81,6 @@ const (
ResultTypeListUnconfirmedTxs = byte(0x09)
ResultTypeSubscribe = byte(0x0A)
ResultTypeUnsubscribe = byte(0x0B)
ResultTypeEvent = byte(0x0C)
)
type TendermintResultInterface interface{}
@ -112,5 +104,4 @@ var _ = wire.RegisterInterface(
wire.ConcreteType{&ResultListUnconfirmedTxs{}, ResultTypeListUnconfirmedTxs},
wire.ConcreteType{&ResultSubscribe{}, ResultTypeSubscribe},
wire.ConcreteType{&ResultUnsubscribe{}, ResultTypeUnsubscribe},
wire.ConcreteType{&ResultEvent{}, ResultTypeEvent},
)

+ 3
- 3
rpc/test/helpers.go View File

@ -11,11 +11,11 @@ import (
"github.com/tendermint/go-p2p"
"github.com/tendermint/go-wire"
"github.com/tendermint/go-events"
client "github.com/tendermint/go-rpc/client"
"github.com/tendermint/go-rpc/types"
_ "github.com/tendermint/tendermint/config/tendermint_test"
nm "github.com/tendermint/tendermint/node"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
)
@ -137,7 +137,7 @@ func waitForEvent(t *testing.T, con *websocket.Conn, eventid string, dieOnTimeou
errCh <- err
break
}
event, ok := response.Result.(*ctypes.TendermintResult).Result.(*ctypes.ResultEvent)
event, ok := response.Result.(*events.EventResult)
if ok && event.Event == eventid {
goodCh <- p
break
@ -191,7 +191,7 @@ func unmarshalResponseNewBlock(b []byte) (*types.Block, error) {
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
block := response.Result.(*ctypes.TendermintResult).Result.(*ctypes.ResultEvent).Data.(types.EventDataNewBlock).Block
block := response.Result.(*events.EventResult).Data.(types.EventDataNewBlock).Block
return block, nil
}


Loading…
Cancel
Save