Update README; Remove GetEvents() from Application

This commit is contained in:
Jae Kwon 2015-11-16 15:50:26 -08:00
parent d319c5be0d
commit 201bf2374b
5 changed files with 19 additions and 25 deletions

View File

@ -38,8 +38,7 @@ TMSP is an asynchronous streaming protocol: message responses are written back a
* __Arguments__:
* `EventsMode (int8)`:
* `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__:
* `RetCode (int8)`
* __Usage__:<br/>
@ -61,3 +60,13 @@ TMSP is an asynchronous streaming protocol: message responses are written back a
* __Usage__:<br/>
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.

View File

@ -51,9 +51,9 @@ func (dapp *DummyApplication) Info() []string {
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)
return 0
return nil, 0
}
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 {
return 0
}
func (dapp *DummyApplication) GetEvents() []types.Event {
return nil
}

View File

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

View File

@ -9,7 +9,7 @@ type Application interface {
Info() []string
// 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
GetHash() ([]byte, RetCode)
@ -28,7 +28,4 @@ type Application interface {
// Remove event listener
RemListener(key string) RetCode
// Get all events
GetEvents() []Event
}

View File

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