diff --git a/api/README.md b/api/README.md index 700e6016..a07543e9 100644 --- a/api/README.md +++ b/api/README.md @@ -429,6 +429,32 @@ Returns if the provided strategy predicate is valid and well-formatted. If the p | 400 | `the predicate provided is not valid` | 4015 | | 500 | `error encoding validated strategy predicate` | 5024 | +### GET `/strategies/predicate/operators` +Returns the list of supported operators to build strategy predicates. + +- 📥 response: + +```json +{ + "operators": [ + { + "description": "logical operator that returns the common token holders between symbols with fixed balance to 1", + "tag": "AND" + }, + { + "description": "logical operator that returns the token holders of both symbols with fixed balance to 1", + "tag": "OR" + } + ] +} +``` + +- ⚠️ errors: + +| HTTP Status | Message | Internal error | +|:---:|:---|:---:| +| 500 | `error encoding supported strategy predicate operators` | 5027 | + ## Censuses ### POST `/censuses` diff --git a/api/errors.go b/api/errors.go index 6f86901d..6612e0f0 100644 --- a/api/errors.go +++ b/api/errors.go @@ -233,4 +233,9 @@ var ( HTTPstatus: apirest.HTTPstatusInternalErr, Err: fmt.Errorf("error evaluating strategy predicate"), } + ErrEncodeStrategyPredicateOperators = apirest.APIerror{ + Code: 5027, + HTTPstatus: apirest.HTTPstatusInternalErr, + Err: fmt.Errorf("error encoding supported strategy predicate operators"), + } ) diff --git a/api/strategies.go b/api/strategies.go index 717e9457..5121b2aa 100644 --- a/api/strategies.go +++ b/api/strategies.go @@ -38,6 +38,10 @@ func (capi *census3API) initStrategiesHandlers() error { api.MethodAccessTypePublic, capi.validateStrategyPredicate); err != nil { return err } + if err := capi.endpoint.RegisterMethod("/strategies/predicate/operators", "GET", + api.MethodAccessTypePublic, capi.supportedStrategyPredicateOperators); err != nil { + return err + } return nil } @@ -305,3 +309,15 @@ func (capi *census3API) validateStrategyPredicate(msg *api.APIdata, ctx *httprou } return ctx.Send(res, api.HTTPstatusOK) } + +// supportedStrategyPredicateOperators function handler returns the information +// of the current supported operators to build strategy predicates. +func (capi *census3API) supportedStrategyPredicateOperators(msg *api.APIdata, ctx *httprouter.HTTPContext) error { + res, err := json.Marshal(map[string]any{ + "operators": strategyoperators.ValidOperators, + }) + if err != nil { + return ErrEncodeStrategyPredicateOperators.WithErr(err) + } + return ctx.Send(res, api.HTTPstatusOK) +} diff --git a/api/strategyoperators/operators.go b/api/strategyoperators/operators.go index e875131d..f68c76e7 100644 --- a/api/strategyoperators/operators.go +++ b/api/strategyoperators/operators.go @@ -21,6 +21,18 @@ const ( // ValidOperatorsTags variable contains the supported operator tags var ValidOperatorsTags = []string{ANDTag, ORTag} +// ValidOperators variable contains the information of the supported operators +var ValidOperators = []map[string]string{ + { + "tag": ANDTag, + "description": "logical operator that returns the common token holders between symbols with fixed balance to 1", + }, + { + "tag": ORTag, + "description": "logical operator that returns the token holders of both symbols with fixed balance to 1", + }, +} + type TokenInformation struct { ID string ChainID uint64