Replace SetEventsMode with SetOption
This commit is contained in:
parent
9a72da4fcd
commit
e40c4834a8
20
README.md
20
README.md
|
@ -34,16 +34,6 @@ TMSP is an asynchronous streaming protocol: message responses are written back a
|
||||||
* __Usage__:<br/>
|
* __Usage__:<br/>
|
||||||
Roll back to the last commit
|
Roll back to the last commit
|
||||||
|
|
||||||
#### SetEventsMode
|
|
||||||
* __Arguments__:
|
|
||||||
* `EventsMode (int8)`:
|
|
||||||
* `EventsModeOff (0)`: Events are not reported. Used for mempool.
|
|
||||||
* `EventsModeOn (1)`: Report events that are listened on.
|
|
||||||
* __Returns__:
|
|
||||||
* `RetCode (int8)`
|
|
||||||
* __Usage__:<br/>
|
|
||||||
Set event reporting mode for future transactions
|
|
||||||
|
|
||||||
#### AddListener
|
#### AddListener
|
||||||
* __Arguments__:
|
* __Arguments__:
|
||||||
* `EventKey (string)`
|
* `EventKey (string)`
|
||||||
|
@ -70,3 +60,13 @@ TMSP is an asynchronous streaming protocol: message responses are written back a
|
||||||
* __Usage__:<br/>
|
* __Usage__:<br/>
|
||||||
Return an array of strings about the application state. Application specific.
|
Return an array of strings about the application state. Application specific.
|
||||||
|
|
||||||
|
#### SetOption
|
||||||
|
* __Arguments__:
|
||||||
|
* `Key (string)`
|
||||||
|
* `Value (string)`
|
||||||
|
* __Returns__:
|
||||||
|
* `RetCode (int8)`
|
||||||
|
* __Usage__:<br/>
|
||||||
|
Set application options. E.g. Key="mode", Value="mempool" for a mempool connection, or Key="mode", Value="consensus" for a consensus connection.
|
||||||
|
Other options are application specific.
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,10 @@ func (dapp *DummyApplication) Info() []string {
|
||||||
return []string{Fmt("size:%v", dapp.state.Size())}
|
return []string{Fmt("size:%v", dapp.state.Size())}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (dapp *DummyApplication) SetOption(key string, value string) types.RetCode {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
func (dapp *DummyApplication) AppendTx(tx []byte) ([]types.Event, types.RetCode) {
|
func (dapp *DummyApplication) AppendTx(tx []byte) ([]types.Event, types.RetCode) {
|
||||||
dapp.state.Set(tx, tx)
|
dapp.state.Set(tx, tx)
|
||||||
return nil, 0
|
return nil, 0
|
||||||
|
@ -71,10 +75,6 @@ func (dapp *DummyApplication) Rollback() types.RetCode {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dapp *DummyApplication) SetEventsMode(mode types.EventsMode) types.RetCode {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (dapp *DummyApplication) AddListener(key string) types.RetCode {
|
func (dapp *DummyApplication) AddListener(key string) types.RetCode {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,9 @@ func handleRequest(app types.Application, req types.Request, responses chan<- ty
|
||||||
case types.RequestInfo:
|
case types.RequestInfo:
|
||||||
data := app.Info()
|
data := app.Info()
|
||||||
responses <- types.ResponseInfo{data}
|
responses <- types.ResponseInfo{data}
|
||||||
|
case types.RequestSetOption:
|
||||||
|
retCode := app.SetOption(req.Key, req.Value)
|
||||||
|
responses <- types.ResponseSetOption{retCode}
|
||||||
case types.RequestAppendTx:
|
case types.RequestAppendTx:
|
||||||
events, retCode := app.AppendTx(req.TxBytes)
|
events, retCode := app.AppendTx(req.TxBytes)
|
||||||
responses <- types.ResponseAppendTx{retCode}
|
responses <- types.ResponseAppendTx{retCode}
|
||||||
|
@ -92,9 +95,6 @@ func handleRequest(app types.Application, req types.Request, responses chan<- ty
|
||||||
case types.RequestRollback:
|
case types.RequestRollback:
|
||||||
retCode := app.Rollback()
|
retCode := app.Rollback()
|
||||||
responses <- types.ResponseRollback{retCode}
|
responses <- types.ResponseRollback{retCode}
|
||||||
case types.RequestSetEventsMode:
|
|
||||||
retCode := app.SetEventsMode(req.EventsMode)
|
|
||||||
responses <- types.ResponseSetEventsMode{retCode}
|
|
||||||
case types.RequestAddListener:
|
case types.RequestAddListener:
|
||||||
retCode := app.AddListener(req.EventKey)
|
retCode := app.AddListener(req.EventKey)
|
||||||
responses <- types.ResponseAddListener{retCode}
|
responses <- types.ResponseAddListener{retCode}
|
||||||
|
|
|
@ -8,6 +8,9 @@ type Application interface {
|
||||||
// Return application info
|
// Return application info
|
||||||
Info() []string
|
Info() []string
|
||||||
|
|
||||||
|
// Set application option (e.g. mode=mempool, mode=consensus)
|
||||||
|
SetOption(key string, value string) RetCode
|
||||||
|
|
||||||
// Append a tx, which may or may not get committed
|
// Append a tx, which may or may not get committed
|
||||||
AppendTx(tx []byte) ([]Event, RetCode)
|
AppendTx(tx []byte) ([]Event, RetCode)
|
||||||
|
|
||||||
|
@ -20,9 +23,6 @@ type Application interface {
|
||||||
// Rollback to the latest commit
|
// Rollback to the latest commit
|
||||||
Rollback() RetCode
|
Rollback() RetCode
|
||||||
|
|
||||||
// Set events reporting mode
|
|
||||||
SetEventsMode(mode EventsMode) RetCode
|
|
||||||
|
|
||||||
// Add event listener
|
// Add event listener
|
||||||
AddListener(key string) RetCode
|
AddListener(key string) RetCode
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
type EventsMode int8
|
|
||||||
|
|
||||||
const (
|
|
||||||
EventsModeOff = EventsMode(0)
|
|
||||||
EventsModeOn = EventsMode(1)
|
|
||||||
)
|
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
Key string
|
Key string
|
||||||
Data []byte
|
Data []byte
|
||||||
|
|
|
@ -3,32 +3,34 @@ package types
|
||||||
import "github.com/tendermint/go-wire"
|
import "github.com/tendermint/go-wire"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
requestTypeEcho = byte(0x01)
|
requestTypeEcho = byte(0x01)
|
||||||
requestTypeFlush = byte(0x02)
|
requestTypeFlush = byte(0x02)
|
||||||
requestTypeInfo = byte(0x03)
|
requestTypeInfo = byte(0x03)
|
||||||
|
requestTypeSetOption = byte(0x04)
|
||||||
|
// reserved for GetOption = byte(0x05)
|
||||||
|
|
||||||
responseTypeException = byte(0x10)
|
responseTypeException = byte(0x10)
|
||||||
responseTypeEcho = byte(0x11)
|
responseTypeEcho = byte(0x11)
|
||||||
responseTypeFlush = byte(0x12)
|
responseTypeFlush = byte(0x12)
|
||||||
responseTypeInfo = byte(0x13)
|
responseTypeInfo = byte(0x13)
|
||||||
|
responseTypeSetOption = byte(0x14)
|
||||||
|
// reserved for GetOption = byte(0x15)
|
||||||
|
|
||||||
requestTypeAppendTx = byte(0x21)
|
requestTypeAppendTx = byte(0x21)
|
||||||
requestTypeGetHash = byte(0x22)
|
requestTypeGetHash = byte(0x22)
|
||||||
requestTypeCommit = byte(0x23)
|
requestTypeCommit = byte(0x23)
|
||||||
requestTypeRollback = byte(0x24)
|
requestTypeRollback = byte(0x24)
|
||||||
requestTypeSetEventsMode = byte(0x25)
|
requestTypeAddListener = byte(0x25)
|
||||||
requestTypeAddListener = byte(0x26)
|
requestTypeRemListener = byte(0x26)
|
||||||
requestTypeRemListener = byte(0x27)
|
// reserved for responseTypeEvent 0x27
|
||||||
// reserved for responseTypeEvent 0x28
|
|
||||||
|
|
||||||
responseTypeAppendTx = byte(0x31)
|
responseTypeAppendTx = byte(0x31)
|
||||||
responseTypeGetHash = byte(0x32)
|
responseTypeGetHash = byte(0x32)
|
||||||
responseTypeCommit = byte(0x33)
|
responseTypeCommit = byte(0x33)
|
||||||
responseTypeRollback = byte(0x34)
|
responseTypeRollback = byte(0x34)
|
||||||
responseTypeSetEventsMode = byte(0x35)
|
responseTypeAddListener = byte(0x35)
|
||||||
responseTypeAddListener = byte(0x36)
|
responseTypeRemListener = byte(0x36)
|
||||||
responseTypeRemListener = byte(0x37)
|
responseTypeEvent = byte(0x37)
|
||||||
responseTypeEvent = byte(0x38)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//----------------------------------------
|
//----------------------------------------
|
||||||
|
@ -43,6 +45,11 @@ type RequestFlush struct {
|
||||||
type RequestInfo struct {
|
type RequestInfo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RequestSetOption struct {
|
||||||
|
Key string
|
||||||
|
Value string
|
||||||
|
}
|
||||||
|
|
||||||
type RequestAppendTx struct {
|
type RequestAppendTx struct {
|
||||||
TxBytes []byte
|
TxBytes []byte
|
||||||
}
|
}
|
||||||
|
@ -56,10 +63,6 @@ type RequestCommit struct {
|
||||||
type RequestRollback struct {
|
type RequestRollback struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type RequestSetEventsMode struct {
|
|
||||||
EventsMode
|
|
||||||
}
|
|
||||||
|
|
||||||
type RequestAddListener struct {
|
type RequestAddListener struct {
|
||||||
EventKey string
|
EventKey string
|
||||||
}
|
}
|
||||||
|
@ -72,27 +75,27 @@ type Request interface {
|
||||||
AssertRequestType()
|
AssertRequestType()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ RequestEcho) AssertRequestType() {}
|
func (_ RequestEcho) AssertRequestType() {}
|
||||||
func (_ RequestFlush) AssertRequestType() {}
|
func (_ RequestFlush) AssertRequestType() {}
|
||||||
func (_ RequestInfo) AssertRequestType() {}
|
func (_ RequestInfo) AssertRequestType() {}
|
||||||
func (_ RequestAppendTx) AssertRequestType() {}
|
func (_ RequestSetOption) AssertRequestType() {}
|
||||||
func (_ RequestGetHash) AssertRequestType() {}
|
func (_ RequestAppendTx) AssertRequestType() {}
|
||||||
func (_ RequestCommit) AssertRequestType() {}
|
func (_ RequestGetHash) AssertRequestType() {}
|
||||||
func (_ RequestRollback) AssertRequestType() {}
|
func (_ RequestCommit) AssertRequestType() {}
|
||||||
func (_ RequestSetEventsMode) AssertRequestType() {}
|
func (_ RequestRollback) AssertRequestType() {}
|
||||||
func (_ RequestAddListener) AssertRequestType() {}
|
func (_ RequestAddListener) AssertRequestType() {}
|
||||||
func (_ RequestRemListener) AssertRequestType() {}
|
func (_ RequestRemListener) AssertRequestType() {}
|
||||||
|
|
||||||
var _ = wire.RegisterInterface(
|
var _ = wire.RegisterInterface(
|
||||||
struct{ Request }{},
|
struct{ Request }{},
|
||||||
wire.ConcreteType{RequestEcho{}, requestTypeEcho},
|
wire.ConcreteType{RequestEcho{}, requestTypeEcho},
|
||||||
wire.ConcreteType{RequestFlush{}, requestTypeFlush},
|
wire.ConcreteType{RequestFlush{}, requestTypeFlush},
|
||||||
wire.ConcreteType{RequestInfo{}, requestTypeInfo},
|
wire.ConcreteType{RequestInfo{}, requestTypeInfo},
|
||||||
|
wire.ConcreteType{RequestSetOption{}, requestTypeSetOption},
|
||||||
wire.ConcreteType{RequestAppendTx{}, requestTypeAppendTx},
|
wire.ConcreteType{RequestAppendTx{}, requestTypeAppendTx},
|
||||||
wire.ConcreteType{RequestGetHash{}, requestTypeGetHash},
|
wire.ConcreteType{RequestGetHash{}, requestTypeGetHash},
|
||||||
wire.ConcreteType{RequestCommit{}, requestTypeCommit},
|
wire.ConcreteType{RequestCommit{}, requestTypeCommit},
|
||||||
wire.ConcreteType{RequestRollback{}, requestTypeRollback},
|
wire.ConcreteType{RequestRollback{}, requestTypeRollback},
|
||||||
wire.ConcreteType{RequestSetEventsMode{}, requestTypeSetEventsMode},
|
|
||||||
wire.ConcreteType{RequestAddListener{}, requestTypeAddListener},
|
wire.ConcreteType{RequestAddListener{}, requestTypeAddListener},
|
||||||
wire.ConcreteType{RequestRemListener{}, requestTypeRemListener},
|
wire.ConcreteType{RequestRemListener{}, requestTypeRemListener},
|
||||||
)
|
)
|
||||||
|
@ -110,6 +113,10 @@ type ResponseInfo struct {
|
||||||
Data []string
|
Data []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ResponseSetOption struct {
|
||||||
|
RetCode
|
||||||
|
}
|
||||||
|
|
||||||
type ResponseAppendTx struct {
|
type ResponseAppendTx struct {
|
||||||
RetCode
|
RetCode
|
||||||
}
|
}
|
||||||
|
@ -127,10 +134,6 @@ type ResponseRollback struct {
|
||||||
RetCode
|
RetCode
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResponseSetEventsMode struct {
|
|
||||||
RetCode
|
|
||||||
}
|
|
||||||
|
|
||||||
type ResponseAddListener struct {
|
type ResponseAddListener struct {
|
||||||
RetCode
|
RetCode
|
||||||
}
|
}
|
||||||
|
@ -151,29 +154,29 @@ type Response interface {
|
||||||
AssertResponseType()
|
AssertResponseType()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ ResponseEcho) AssertResponseType() {}
|
func (_ ResponseEcho) AssertResponseType() {}
|
||||||
func (_ ResponseFlush) AssertResponseType() {}
|
func (_ ResponseFlush) AssertResponseType() {}
|
||||||
func (_ ResponseInfo) AssertResponseType() {}
|
func (_ ResponseInfo) AssertResponseType() {}
|
||||||
func (_ ResponseAppendTx) AssertResponseType() {}
|
func (_ ResponseSetOption) AssertResponseType() {}
|
||||||
func (_ ResponseGetHash) AssertResponseType() {}
|
func (_ ResponseAppendTx) AssertResponseType() {}
|
||||||
func (_ ResponseCommit) AssertResponseType() {}
|
func (_ ResponseGetHash) AssertResponseType() {}
|
||||||
func (_ ResponseRollback) AssertResponseType() {}
|
func (_ ResponseCommit) AssertResponseType() {}
|
||||||
func (_ ResponseSetEventsMode) AssertResponseType() {}
|
func (_ ResponseRollback) AssertResponseType() {}
|
||||||
func (_ ResponseAddListener) AssertResponseType() {}
|
func (_ ResponseAddListener) AssertResponseType() {}
|
||||||
func (_ ResponseRemListener) AssertResponseType() {}
|
func (_ ResponseRemListener) AssertResponseType() {}
|
||||||
func (_ ResponseException) AssertResponseType() {}
|
func (_ ResponseException) AssertResponseType() {}
|
||||||
func (_ ResponseEvent) AssertResponseType() {}
|
func (_ ResponseEvent) AssertResponseType() {}
|
||||||
|
|
||||||
var _ = wire.RegisterInterface(
|
var _ = wire.RegisterInterface(
|
||||||
struct{ Response }{},
|
struct{ Response }{},
|
||||||
wire.ConcreteType{ResponseEcho{}, responseTypeEcho},
|
wire.ConcreteType{ResponseEcho{}, responseTypeEcho},
|
||||||
wire.ConcreteType{ResponseFlush{}, responseTypeFlush},
|
wire.ConcreteType{ResponseFlush{}, responseTypeFlush},
|
||||||
wire.ConcreteType{ResponseInfo{}, responseTypeInfo},
|
wire.ConcreteType{ResponseInfo{}, responseTypeInfo},
|
||||||
|
wire.ConcreteType{ResponseSetOption{}, responseTypeSetOption},
|
||||||
wire.ConcreteType{ResponseAppendTx{}, responseTypeAppendTx},
|
wire.ConcreteType{ResponseAppendTx{}, responseTypeAppendTx},
|
||||||
wire.ConcreteType{ResponseGetHash{}, responseTypeGetHash},
|
wire.ConcreteType{ResponseGetHash{}, responseTypeGetHash},
|
||||||
wire.ConcreteType{ResponseCommit{}, responseTypeCommit},
|
wire.ConcreteType{ResponseCommit{}, responseTypeCommit},
|
||||||
wire.ConcreteType{ResponseRollback{}, responseTypeRollback},
|
wire.ConcreteType{ResponseRollback{}, responseTypeRollback},
|
||||||
wire.ConcreteType{ResponseSetEventsMode{}, responseTypeSetEventsMode},
|
|
||||||
wire.ConcreteType{ResponseAddListener{}, responseTypeAddListener},
|
wire.ConcreteType{ResponseAddListener{}, responseTypeAddListener},
|
||||||
wire.ConcreteType{ResponseRemListener{}, responseTypeRemListener},
|
wire.ConcreteType{ResponseRemListener{}, responseTypeRemListener},
|
||||||
wire.ConcreteType{ResponseException{}, responseTypeException},
|
wire.ConcreteType{ResponseException{}, responseTypeException},
|
||||||
|
|
Loading…
Reference in New Issue