Skip to content

Commit

Permalink
new api endpoint to get supported strategy operators
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmenendez committed Sep 22, 2023
1 parent f8783cc commit c7aadc7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
26 changes: 26 additions & 0 deletions api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
5 changes: 5 additions & 0 deletions api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
)
16 changes: 16 additions & 0 deletions api/strategies.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
12 changes: 12 additions & 0 deletions api/strategyoperators/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c7aadc7

Please sign in to comment.