From c4b87dcf14e2fe3c95838688ca7747ae334e8c87 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sat, 23 Jan 2016 20:49:15 -0800 Subject: [PATCH] new_message --- README.md | 30 +++++-------- types/messages.go | 110 +++++++++++++++++----------------------------- 2 files changed, 53 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index 8924f57c8..2991b5340 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ For more information on TMSP, motivations, and tutorials, please visit [our blog * `TxBytes ([]byte)` * __Returns__: * `RetCode (int8)` + * `RetData ([]KVPair)` + * `Error (string)` * __Usage__:
Append and run a transaction. The transaction may or may not be final. @@ -21,32 +23,17 @@ For more information on TMSP, motivations, and tutorials, please visit [our blog * `TxBytes ([]byte)` * __Returns__: * `RetCode (int8)` + * `RetData ([]KVPair)` + * `Error (string)` * __Usage__:
Validate a transaction. This message should not mutate the state. #### GetHash * __Returns__: - * `RetCode (int8)` * `Hash ([]byte)` * __Usage__:
Return a Merkle root hash of the application state -#### AddListener - * __Arguments__: - * `EventKey (string)` - * __Returns__: - * `RetCode (int8)` - * __Usage__:
- Add event listener callback for events with given key. - -#### RemoveListener - * __Arguments__: - * `EventKey (string)` - * __Returns__: - * `RetCode (int8)` - * __Usage__:
- Remove event listener callback for events with given key. - #### Flush * __Usage__:
Flush the response queue. Applications that implement `types.Application` need not implement this message -- it's handled by the project. @@ -62,13 +49,20 @@ For more information on TMSP, motivations, and tutorials, please visit [our blog * `Key (string)` * `Value (string)` * __Returns__: - * `RetCode (int8)` + * `Error (string)` * __Usage__:
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. ## Changelog +### Jan 23th, 2016 + +* Added CheckTx/Query TMSP message types +* Added RetData/Error fields to AppendTx/CheckTx/SetOption +* Removed Listener messages +* Removed RetCode from ResponseSetOption and ResponseGetHash + ### Jan 12th, 2016 * Added "RetCodeBadNonce = 0x06" return code diff --git a/types/messages.go b/types/messages.go index fa9b30d98..063e2a577 100644 --- a/types/messages.go +++ b/types/messages.go @@ -16,21 +16,15 @@ const ( ResponseTypeSetOption = byte(0x14) // reserved for GetOption = byte(0x15) - RequestTypeAppendTx = byte(0x21) - RequestTypeCheckTx = byte(0x22) - RequestTypeGetHash = byte(0x23) - RequestTypeAddListener = byte(0x24) - RequestTypeRemListener = byte(0x25) - // reserved for ResponseTypeEvent 0x26 - RequestTypeQuery = byte(0x27) - - ResponseTypeAppendTx = byte(0x31) - ResponseTypeCheckTx = byte(0x32) - ResponseTypeGetHash = byte(0x33) - ResponseTypeAddListener = byte(0x34) - ResponseTypeRemListener = byte(0x35) - ResponseTypeEvent = byte(0x36) - ResponseTypeQuery = byte(0x37) + RequestTypeAppendTx = byte(0x21) + RequestTypeCheckTx = byte(0x22) + RequestTypeGetHash = byte(0x23) + RequestTypeQuery = byte(0x24) + + ResponseTypeAppendTx = byte(0x31) + ResponseTypeCheckTx = byte(0x32) + ResponseTypeGetHash = byte(0x33) + ResponseTypeQuery = byte(0x34) ) //---------------------------------------- @@ -61,14 +55,6 @@ type RequestCheckTx struct { type RequestGetHash struct { } -type RequestAddListener struct { - EventKey string -} - -type RequestRemListener struct { - EventKey string -} - type RequestQuery struct { QueryBytes []byte } @@ -77,16 +63,14 @@ type Request interface { AssertRequestType() } -func (_ RequestEcho) AssertRequestType() {} -func (_ RequestFlush) AssertRequestType() {} -func (_ RequestInfo) AssertRequestType() {} -func (_ RequestSetOption) AssertRequestType() {} -func (_ RequestAppendTx) AssertRequestType() {} -func (_ RequestCheckTx) AssertRequestType() {} -func (_ RequestGetHash) AssertRequestType() {} -func (_ RequestAddListener) AssertRequestType() {} -func (_ RequestRemListener) AssertRequestType() {} -func (_ RequestQuery) AssertRequestType() {} +func (_ RequestEcho) AssertRequestType() {} +func (_ RequestFlush) AssertRequestType() {} +func (_ RequestInfo) AssertRequestType() {} +func (_ RequestSetOption) AssertRequestType() {} +func (_ RequestAppendTx) AssertRequestType() {} +func (_ RequestCheckTx) AssertRequestType() {} +func (_ RequestGetHash) AssertRequestType() {} +func (_ RequestQuery) AssertRequestType() {} var _ = wire.RegisterInterface( struct{ Request }{}, @@ -97,13 +81,20 @@ var _ = wire.RegisterInterface( wire.ConcreteType{RequestAppendTx{}, RequestTypeAppendTx}, wire.ConcreteType{RequestCheckTx{}, RequestTypeCheckTx}, wire.ConcreteType{RequestGetHash{}, RequestTypeGetHash}, - wire.ConcreteType{RequestAddListener{}, RequestTypeAddListener}, - wire.ConcreteType{RequestRemListener{}, RequestTypeRemListener}, wire.ConcreteType{RequestQuery{}, RequestTypeQuery}, ) //---------------------------------------- +type KVPair struct { + Key []byte + Value []byte +} + +type ResponseException struct { + Error string +} + type ResponseEcho struct { Message string } @@ -116,59 +107,43 @@ type ResponseInfo struct { } type ResponseSetOption struct { - RetCode + Error string } type ResponseAppendTx struct { RetCode + RetData []KVPair + Error string } type ResponseCheckTx struct { RetCode + RetData []KVPair + Error string } type ResponseGetHash struct { - RetCode Hash []byte } -type ResponseAddListener struct { - RetCode -} - -type ResponseRemListener struct { - RetCode -} - -type ResponseException struct { - Error string -} - -type ResponseEvent struct { - Event -} - type ResponseQuery struct { - RetCode Result []byte + Error string } type Response interface { AssertResponseType() } -func (_ ResponseEcho) AssertResponseType() {} -func (_ ResponseFlush) AssertResponseType() {} -func (_ ResponseInfo) AssertResponseType() {} -func (_ ResponseSetOption) AssertResponseType() {} -func (_ ResponseAppendTx) AssertResponseType() {} -func (_ ResponseCheckTx) AssertResponseType() {} -func (_ ResponseGetHash) AssertResponseType() {} -func (_ ResponseAddListener) AssertResponseType() {} -func (_ ResponseRemListener) AssertResponseType() {} -func (_ ResponseException) AssertResponseType() {} -func (_ ResponseEvent) AssertResponseType() {} -func (_ ResponseQuery) AssertResponseType() {} +func (_ ResponseEcho) AssertResponseType() {} +func (_ ResponseFlush) AssertResponseType() {} +func (_ ResponseInfo) AssertResponseType() {} +func (_ ResponseSetOption) AssertResponseType() {} +func (_ ResponseAppendTx) AssertResponseType() {} +func (_ ResponseCheckTx) AssertResponseType() {} +func (_ ResponseGetHash) AssertResponseType() {} +func (_ ResponseException) AssertResponseType() {} +func (_ ResponseQuery) AssertResponseType() {} var _ = wire.RegisterInterface( struct{ Response }{}, @@ -179,9 +154,6 @@ var _ = wire.RegisterInterface( wire.ConcreteType{ResponseAppendTx{}, ResponseTypeAppendTx}, wire.ConcreteType{ResponseCheckTx{}, ResponseTypeCheckTx}, wire.ConcreteType{ResponseGetHash{}, ResponseTypeGetHash}, - wire.ConcreteType{ResponseAddListener{}, ResponseTypeAddListener}, - wire.ConcreteType{ResponseRemListener{}, ResponseTypeRemListener}, wire.ConcreteType{ResponseException{}, ResponseTypeException}, - wire.ConcreteType{ResponseEvent{}, ResponseTypeEvent}, wire.ConcreteType{ResponseQuery{}, ResponseTypeQuery}, )