diff --git a/pkg/services/oracle/filter.go b/pkg/services/oracle/filter.go index 560320e0c..87d762626 100644 --- a/pkg/services/oracle/filter.go +++ b/pkg/services/oracle/filter.go @@ -6,6 +6,8 @@ import ( "unicode/utf8" "github.com/PaesslerAG/jsonpath" + "github.com/nspcc-dev/neo-go/pkg/core/state" + "github.com/nspcc-dev/neo-go/pkg/core/transaction" ) func filter(value []byte, path string) ([]byte, error) { @@ -22,3 +24,14 @@ func filter(value []byte, path string) ([]byte, error) { } return json.Marshal([]interface{}{result}) } + +func filterRequest(result []byte, req *state.OracleRequest) (transaction.OracleResponseCode, []byte) { + if req.Filter != nil { + var err error + result, err = filter(result, *req.Filter) + if err != nil { + return transaction.Error, nil + } + } + return transaction.Success, result +} diff --git a/pkg/services/oracle/request.go b/pkg/services/oracle/request.go index 323423a1c..11546b338 100644 --- a/pkg/services/oracle/request.go +++ b/pkg/services/oracle/request.go @@ -117,16 +117,7 @@ func (o *Oracle) processRequest(priv *keys.PrivateKey, req request) error { } break } - if req.Req.Filter != nil { - res, err := filter(result, *req.Req.Filter) - if err != nil { - resp.Code = transaction.Error - break - } - result = res - } - resp.Code = transaction.Success - resp.Result = result + resp.Code, resp.Result = filterRequest(result, req.Req) case r.StatusCode == http.StatusForbidden: resp.Code = transaction.Forbidden case r.StatusCode == http.StatusNotFound: @@ -144,8 +135,7 @@ func (o *Oracle) processRequest(priv *keys.PrivateKey, req request) error { if err != nil { resp.Code = transaction.Error } else { - resp.Code = transaction.Success - resp.Result = res + resp.Code, resp.Result = filterRequest(res, req.Req) } }