Browse Source

Update README; Remove GetEvents() from Application

pull/1780/head
Jae Kwon 9 years ago
parent
commit
201bf2374b
5 changed files with 19 additions and 25 deletions
  1. +11
    -2
      README.md
  2. +2
    -6
      example/main.go
  3. +1
    -8
      server/server.go
  4. +1
    -4
      types/application.go
  5. +4
    -5
      types/events.go

+ 11
- 2
README.md View File

@ -38,8 +38,7 @@ TMSP is an asynchronous streaming protocol: message responses are written back a
* __Arguments__: * __Arguments__:
* `EventsMode (int8)`: * `EventsMode (int8)`:
* `EventsModeOff (0)`: Events are not reported. Used for mempool. * `EventsModeOff (0)`: Events are not reported. Used for mempool.
* `EventsModeCached (1)`: Events are cached.
* `EventsModeOn (2)`: Flush cache and report events.
* `EventsModeOn (1)`: Report events that are listened on.
* __Returns__: * __Returns__:
* `RetCode (int8)` * `RetCode (int8)`
* __Usage__:<br/> * __Usage__:<br/>
@ -61,3 +60,13 @@ TMSP is an asynchronous streaming protocol: message responses are written back a
* __Usage__:<br/> * __Usage__:<br/>
Remove event listener callback for events with given key. Remove event listener callback for events with given key.
#### Flush
* __Usage__:<br/>
Flush the response queue. Applications that implement `types.Application` need not implement this message -- it's handled by the project.
#### Info
* __Returns__:
* `Data ([]string)`
* __Usage__:<br/>
Return an array of strings about the application state. Application specific.

+ 2
- 6
example/main.go View File

@ -51,9 +51,9 @@ func (dapp *DummyApplication) Info() []string {
return []string{Fmt("size:%v", dapp.state.Size())} return []string{Fmt("size:%v", dapp.state.Size())}
} }
func (dapp *DummyApplication) AppendTx(tx []byte) types.RetCode {
func (dapp *DummyApplication) AppendTx(tx []byte) ([]types.Event, types.RetCode) {
dapp.state.Set(tx, tx) dapp.state.Set(tx, tx)
return 0
return nil, 0
} }
func (dapp *DummyApplication) GetHash() ([]byte, types.RetCode) { func (dapp *DummyApplication) GetHash() ([]byte, types.RetCode) {
@ -82,7 +82,3 @@ func (dapp *DummyApplication) AddListener(key string) types.RetCode {
func (dapp *DummyApplication) RemListener(key string) types.RetCode { func (dapp *DummyApplication) RemListener(key string) types.RetCode {
return 0 return 0
} }
func (dapp *DummyApplication) GetEvents() []types.Event {
return nil
}

+ 1
- 8
server/server.go View File

@ -78,9 +78,8 @@ func handleRequest(app types.Application, req types.Request, responses chan<- ty
data := app.Info() data := app.Info()
responses <- types.ResponseInfo{data} responses <- types.ResponseInfo{data}
case types.RequestAppendTx: case types.RequestAppendTx:
retCode := app.AppendTx(req.TxBytes)
events, retCode := app.AppendTx(req.TxBytes)
responses <- types.ResponseAppendTx{retCode} responses <- types.ResponseAppendTx{retCode}
events := app.GetEvents()
for _, event := range events { for _, event := range events {
responses <- types.ResponseEvent{event} responses <- types.ResponseEvent{event}
} }
@ -96,12 +95,6 @@ func handleRequest(app types.Application, req types.Request, responses chan<- ty
case types.RequestSetEventsMode: case types.RequestSetEventsMode:
retCode := app.SetEventsMode(req.EventsMode) retCode := app.SetEventsMode(req.EventsMode)
responses <- types.ResponseSetEventsMode{retCode} responses <- types.ResponseSetEventsMode{retCode}
if req.EventsMode == types.EventsModeOn {
events := app.GetEvents()
for _, event := range events {
responses <- types.ResponseEvent{event}
}
}
case types.RequestAddListener: case types.RequestAddListener:
retCode := app.AddListener(req.EventKey) retCode := app.AddListener(req.EventKey)
responses <- types.ResponseAddListener{retCode} responses <- types.ResponseAddListener{retCode}


+ 1
- 4
types/application.go View File

@ -9,7 +9,7 @@ type Application interface {
Info() []string Info() []string
// Append a tx, which may or may not get committed // Append a tx, which may or may not get committed
AppendTx(tx []byte) RetCode
AppendTx(tx []byte) ([]Event, RetCode)
// Return the application Merkle root hash // Return the application Merkle root hash
GetHash() ([]byte, RetCode) GetHash() ([]byte, RetCode)
@ -28,7 +28,4 @@ type Application interface {
// Remove event listener // Remove event listener
RemListener(key string) RetCode RemListener(key string) RetCode
// Get all events
GetEvents() []Event
} }

+ 4
- 5
types/events.go View File

@ -3,12 +3,11 @@ package types
type EventsMode int8 type EventsMode int8
const ( const (
EventsModeOff = EventsMode(0)
EventsModeCached = EventsMode(1)
EventsModeOn = EventsMode(2)
EventsModeOff = EventsMode(0)
EventsModeOn = EventsMode(1)
) )
type Event struct { type Event struct {
Key string
TxBytes []byte
Key string
Data []byte
} }

Loading…
Cancel
Save