Update README; Remove GetEvents() from Application
This commit is contained in:
parent
d319c5be0d
commit
201bf2374b
13
README.md
13
README.md
|
@ -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 (1)`: Report events that are listened on.
|
||||||
* `EventsModeOn (2)`: Flush cache and report events.
|
|
||||||
* __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.
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
||||||
}
|
|
||||||
|
|
|
@ -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}
|
||||||
|
|
|
@ -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,11 +4,10 @@ type EventsMode int8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
EventsModeOff = EventsMode(0)
|
EventsModeOff = EventsMode(0)
|
||||||
EventsModeCached = EventsMode(1)
|
EventsModeOn = EventsMode(1)
|
||||||
EventsModeOn = EventsMode(2)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Key string
|
Key string
|
||||||
TxBytes []byte
|
Data []byte
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue