Skip to content

Commit

Permalink
refactor: get rid of anonymous func
Browse files Browse the repository at this point in the history
  • Loading branch information
quasisamurai committed May 15, 2024
1 parent 28219fa commit 9dc5e2f
Showing 1 changed file with 10 additions and 22 deletions.
32 changes: 10 additions & 22 deletions wasmbinding/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,6 @@ func (qp *QueryPlugin) DexQuery(ctx sdk.Context, query bindings.DexQuery) (data
func (qp *QueryPlugin) OracleQuery(ctx sdk.Context, query bindings.OracleQuery) ([]byte, error) {
oracleQueryServer := oraclekeeper.NewQueryServer(*qp.oracleKeeper)

// handle query processing and marshaling
processResponse := func(resp interface{}, err error) ([]byte, error) {
if err != nil {
return nil, errors.Wrapf(err, "failed to process request %T", query)
}
if q, ok := resp.(bindings.BindingMarshaller); ok {
return q.MarshalBinding()
}
return json.Marshal(resp)
}

switch {
case query.GetAllCurrencyPairs != nil:
return processResponse(oracleQueryServer.GetAllCurrencyPairs(ctx, query.GetAllCurrencyPairs))
Expand All @@ -237,17 +226,6 @@ func (qp *QueryPlugin) OracleQuery(ctx sdk.Context, query bindings.OracleQuery)
func (qp *QueryPlugin) MarketmapQuery(ctx sdk.Context, query bindings.MarketmapQuery) ([]byte, error) {
marketmapQueryServer := marketmapkeeper.NewQueryServer(qp.marketmapKeeper)

// handle query processing and marshaling
processResponse := func(resp interface{}, err error) ([]byte, error) {
if err != nil {
return nil, errors.Wrapf(err, "failed to process request %T", query)
}
if q, ok := resp.(bindings.BindingMarshaller); ok {
return q.MarshalBinding()
}
return json.Marshal(resp)
}

switch {
case query.Params != nil:
return processResponse(marketmapQueryServer.Params(ctx, query.Params))
Expand Down Expand Up @@ -280,6 +258,16 @@ func dexQuery[T, R any](ctx sdk.Context, query *T, queryHandler func(ctx context
return data, nil
}

func processResponse(resp interface{}, err error) ([]byte, error) {
if err != nil {
return nil, errors.Wrapf(err, "failed to process request %T", query)

Check failure on line 263 in wasmbinding/queries.go

View workflow job for this annotation

GitHub Actions / Test

undefined: query

Check failure on line 263 in wasmbinding/queries.go

View workflow job for this annotation

GitHub Actions / Test

undefined: query

Check failure on line 263 in wasmbinding/queries.go

View workflow job for this annotation

GitHub Actions / Test

undefined: query

Check failure on line 263 in wasmbinding/queries.go

View workflow job for this annotation

GitHub Actions / Test

undefined: query

Check failure on line 263 in wasmbinding/queries.go

View workflow job for this annotation

GitHub Actions / lint

undefined: query (typecheck)

Check failure on line 263 in wasmbinding/queries.go

View workflow job for this annotation

GitHub Actions / lint

undefined: query) (typecheck)

Check failure on line 263 in wasmbinding/queries.go

View workflow job for this annotation

GitHub Actions / lint

undefined: query (typecheck)

Check failure on line 263 in wasmbinding/queries.go

View workflow job for this annotation

GitHub Actions / lint

undefined: query) (typecheck)

Check failure on line 263 in wasmbinding/queries.go

View workflow job for this annotation

GitHub Actions / Test

undefined: query

Check failure on line 263 in wasmbinding/queries.go

View workflow job for this annotation

GitHub Actions / Test

undefined: query
}
if q, ok := resp.(bindings.BindingMarshaller); ok {
return q.MarshalBinding()
}
return json.Marshal(resp)
}

func mapGRPCRegisteredQueryToWasmBindings(grpcQuery types.RegisteredQuery) bindings.RegisteredQuery {
return bindings.RegisteredQuery{
ID: grpcQuery.GetId(),
Expand Down

0 comments on commit 9dc5e2f

Please sign in to comment.