From 028cc4aa0684e28531c0ef6685f9783c98615ce1 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Sun, 31 Jan 2016 18:11:24 -0800 Subject: [PATCH] Query returns Code --- client/client.go | 6 +++--- example/golang/counter.go | 4 ++-- example/golang/dummy.go | 4 ++-- server/server.go | 4 ++-- types/application.go | 2 +- types/messages.go | 5 ++++- 6 files changed, 14 insertions(+), 11 deletions(-) diff --git a/client/client.go b/client/client.go index e95639473..c19a1ec43 100644 --- a/client/client.go +++ b/client/client.go @@ -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 } //---------------------------------------- diff --git a/example/golang/counter.go b/example/golang/counter.go index 962c0760b..120eb3189 100644 --- a/example/golang/counter.go +++ b/example/golang/counter.go @@ -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") } diff --git a/example/golang/dummy.go b/example/golang/dummy.go index 9835eeb81..59d77dc32 100644 --- a/example/golang/dummy.go +++ b/example/golang/dummy.go @@ -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" } diff --git a/server/server.go b/server/server.go index 74b4ce74c..b95f9e8bb 100644 --- a/server/server.go +++ b/server/server.go @@ -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") } diff --git a/types/application.go b/types/application.go index cedf12405..0610d4182 100644 --- a/types/application.go +++ b/types/application.go @@ -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) } diff --git a/types/messages.go b/types/messages.go index 8c21f327c..061d34da6 100644 --- a/types/messages.go +++ b/types/messages.go @@ -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, }