Browse Source

Query returns Code

pull/1780/head
Jae Kwon 9 years ago
parent
commit
028cc4aa06
6 changed files with 14 additions and 11 deletions
  1. +3
    -3
      client/client.go
  2. +2
    -2
      example/golang/counter.go
  3. +2
    -2
      example/golang/dummy.go
  4. +2
    -2
      server/server.go
  5. +1
    -1
      types/application.go
  6. +4
    -1
      types/messages.go

+ 3
- 3
client/client.go View File

@ -249,14 +249,14 @@ func (cli *TMSPClient) GetHashSync() (hash []byte, log string, err error) {
return res.Data, res.Log, nil
}
func (cli *TMSPClient) QuerySync(query []byte) (result []byte, log string, err error) {
func (cli *TMSPClient) QuerySync(query []byte) (code types.RetCode, result []byte, log string, err error) {
reqres := cli.queueRequest(types.RequestQuery(query))
cli.FlushSync()
if cli.err != nil {
return nil, "", cli.err
return types.RetCodeInternalError, nil, "", cli.err
}
res := reqres.Response
return res.Data, res.Log, nil
return types.RetCode(res.Code), res.Data, res.Log, nil
}
//----------------------------------------


+ 2
- 2
example/golang/counter.go View File

@ -66,6 +66,6 @@ func (app *CounterApplication) GetHash() (hash []byte, log string) {
}
}
func (app *CounterApplication) Query(query []byte) (result []byte, log string) {
return nil, fmt.Sprintf("Query is not supported")
func (app *CounterApplication) Query(query []byte) (code types.RetCode, result []byte, log string) {
return types.RetCodeOK, nil, fmt.Sprintf("Query is not supported")
}

+ 2
- 2
example/golang/dummy.go View File

@ -40,6 +40,6 @@ func (app *DummyApplication) GetHash() (hash []byte, log string) {
return hash, ""
}
func (app *DummyApplication) Query(query []byte) (result []byte, log string) {
return nil, "Query not supported"
func (app *DummyApplication) Query(query []byte) (code types.RetCode, result []byte, log string) {
return types.RetCodeOK, nil, "Query not supported"
}

+ 2
- 2
server/server.go View File

@ -116,8 +116,8 @@ func handleRequest(app types.Application, req *types.Request, responses chan<- *
hash, logStr := app.GetHash()
responses <- types.ResponseGetHash(hash, logStr)
case types.RequestTypeQuery:
result, logStr := app.Query(req.Data)
responses <- types.ResponseQuery(result, logStr)
code, result, logStr := app.Query(req.Data)
responses <- types.ResponseQuery(code, result, logStr)
default:
responses <- types.ResponseException("Unknown request")
}


+ 1
- 1
types/application.go View File

@ -18,5 +18,5 @@ type Application interface {
GetHash() (hash []byte, log string)
// Query for state
Query(query []byte) (result []byte, log string)
Query(query []byte) (code RetCode, result []byte, log string)
}

+ 4
- 1
types/messages.go View File

@ -125,6 +125,7 @@ func ResponseSetOption(log string) *Response {
func ResponseAppendTx(code RetCode, result []byte, log string) *Response {
return &Response{
Type: ResponseTypeAppendTx,
Code: uint32(code),
Data: result,
Log: log,
}
@ -133,6 +134,7 @@ func ResponseAppendTx(code RetCode, result []byte, log string) *Response {
func ResponseCheckTx(code RetCode, result []byte, log string) *Response {
return &Response{
Type: ResponseTypeCheckTx,
Code: uint32(code),
Data: result,
Log: log,
}
@ -146,9 +148,10 @@ func ResponseGetHash(hash []byte, log string) *Response {
}
}
func ResponseQuery(result []byte, log string) *Response {
func ResponseQuery(code RetCode, result []byte, log string) *Response {
return &Response{
Type: ResponseTypeQuery,
Code: uint32(code),
Data: result,
Log: log,
}


Loading…
Cancel
Save