readapt to multiple sourceChains and targetChains
This commit is contained in:
parent
4051ad491f
commit
7c85ebf016
|
@ -2741,17 +2741,17 @@ const docTemplate = `{
|
|||
"type": "string"
|
||||
},
|
||||
"sourceChain": {
|
||||
"$ref": "#/definitions/operations.SourceChain"
|
||||
"$ref": "#/definitions/operations.SourceChains"
|
||||
},
|
||||
"targetChain": {
|
||||
"$ref": "#/definitions/operations.TargetChain"
|
||||
"$ref": "#/definitions/operations.TargetChains"
|
||||
},
|
||||
"vaa": {
|
||||
"$ref": "#/definitions/operations.Vaa"
|
||||
}
|
||||
}
|
||||
},
|
||||
"operations.SourceChain": {
|
||||
"operations.SourceChains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"attribute": {
|
||||
|
@ -2815,7 +2815,7 @@ const docTemplate = `{
|
|||
}
|
||||
}
|
||||
},
|
||||
"operations.TargetChain": {
|
||||
"operations.TargetChains": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"chainId": {
|
||||
|
|
|
@ -231,7 +231,7 @@ func (r *Repository) FindByChainAndAppId(ctx context.Context, query OperationQue
|
|||
|
||||
var pipeline mongo.Pipeline
|
||||
|
||||
if len(query.SourceChainIDs) != 0 || len(query.TargetChainIDs) != 0 {
|
||||
if len(query.SourceChainIDs) > 0 || len(query.TargetChainIDs) > 0 {
|
||||
matchBySourceTargetChain := buildQueryOperationsByChain(query.SourceChainIDs, query.TargetChainIDs)
|
||||
pipeline = append(pipeline, matchBySourceTargetChain)
|
||||
}
|
||||
|
|
|
@ -215,12 +215,12 @@ type TransactionDto struct {
|
|||
}
|
||||
|
||||
type ChainActivityTopsQuery struct {
|
||||
SourceChain []sdk.ChainID `json:"source_chain"`
|
||||
TargetChain []sdk.ChainID `json:"target_chain"`
|
||||
AppId string `json:"app_id"`
|
||||
From time.Time `json:"from"`
|
||||
To time.Time `json:"to"`
|
||||
Timespan Timespan `json:"timespan"`
|
||||
SourceChains []sdk.ChainID `json:"source_chain"`
|
||||
TargetChains []sdk.ChainID `json:"target_chain"`
|
||||
AppId string `json:"app_id"`
|
||||
From time.Time `json:"from"`
|
||||
To time.Time `json:"to"`
|
||||
Timespan Timespan `json:"timespan"`
|
||||
}
|
||||
|
||||
type Timespan string
|
||||
|
|
|
@ -1095,20 +1095,20 @@ func (r *Repository) buildChainActivityQueryTops(q ChainActivityTopsQuery) strin
|
|||
}
|
||||
|
||||
filterTargetChain := ""
|
||||
if len(q.TargetChain) > 0 {
|
||||
val := fmt.Sprintf("r.destination_chain == \"%d\"", q.TargetChain[0])
|
||||
if len(q.TargetChains) > 0 {
|
||||
val := fmt.Sprintf("r.destination_chain == \"%d\"", q.TargetChains[0])
|
||||
buff := ""
|
||||
for _, tc := range q.TargetChain[1:] {
|
||||
for _, tc := range q.TargetChains[1:] {
|
||||
buff += fmt.Sprintf("or r.destination_chain == \"%d\" ", tc)
|
||||
}
|
||||
filterTargetChain = fmt.Sprintf("|> filter(fn: (r) => %s %s)", val, buff)
|
||||
}
|
||||
|
||||
filterSourceChain := ""
|
||||
if len(q.SourceChain) > 0 {
|
||||
val := fmt.Sprintf("r.emitter_chain == \"%d\"", q.SourceChain[0])
|
||||
if len(q.SourceChains) > 0 {
|
||||
val := fmt.Sprintf("r.emitter_chain == \"%d\"", q.SourceChains[0])
|
||||
buff := ""
|
||||
for _, tc := range q.SourceChain[1:] {
|
||||
for _, tc := range q.SourceChains[1:] {
|
||||
buff += fmt.Sprintf("or r.emitter_chain == \"%d\" ", tc)
|
||||
}
|
||||
filterSourceChain = fmt.Sprintf("|> filter(fn: (r) => %s %s)", val, buff)
|
||||
|
@ -1119,7 +1119,7 @@ func (r *Repository) buildChainActivityQueryTops(q ChainActivityTopsQuery) strin
|
|||
filterAppId = "|> filter(fn: (r) => r.app_id == \"" + q.AppId + "\")"
|
||||
}
|
||||
|
||||
if q.TargetChain == nil && q.AppId == "" {
|
||||
if len(q.TargetChains) == 0 && q.AppId == "" {
|
||||
return r.buildQueryChainActivityTopsByEmitter(q, start, stop, filterSourceChain)
|
||||
}
|
||||
|
||||
|
|
|
@ -61,23 +61,6 @@ func ExtractToChain(c *fiber.Ctx, l *zap.Logger) (*sdk.ChainID, error) {
|
|||
return &result, nil
|
||||
}
|
||||
|
||||
func ExtractChain(c *fiber.Ctx, l *zap.Logger) (*sdk.ChainID, error) {
|
||||
return extractChainQueryParam(c, l, "chain")
|
||||
}
|
||||
|
||||
/*
|
||||
func ExtractSourceChain(c *fiber.Ctx, l *zap.Logger) (*sdk.ChainID, error) {
|
||||
return extractChainQueryParam(c, l, "sourceChain")
|
||||
}
|
||||
|
||||
|
||||
|
||||
func ExtractTargetChain(c *fiber.Ctx, l *zap.Logger) (*sdk.ChainID, error) {
|
||||
return extractChainQueryParam(c, l, "targetChain")
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
func ExtractSourceChain(c *fiber.Ctx, l *zap.Logger) ([]sdk.ChainID, error) {
|
||||
param := c.Query("sourceChain")
|
||||
if param == "" {
|
||||
|
|
|
@ -200,11 +200,11 @@ func (c *Controller) GetTopAssets(ctx *fiber.Ctx) error {
|
|||
// @Router /api/v1/x-chain-activity/tops [get]
|
||||
func (c *Controller) GetChainActivityTops(ctx *fiber.Ctx) error {
|
||||
|
||||
sourceChain, err := middleware.ExtractSourceChain(ctx, c.logger)
|
||||
sourceChains, err := middleware.ExtractSourceChain(ctx, c.logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
targetChain, err := middleware.ExtractTargetChain(ctx, c.logger)
|
||||
targetChains, err := middleware.ExtractTargetChain(ctx, c.logger)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -221,12 +221,12 @@ func (c *Controller) GetChainActivityTops(ctx *fiber.Ctx) error {
|
|||
}
|
||||
|
||||
payload := transactions.ChainActivityTopsQuery{
|
||||
SourceChain: sourceChain,
|
||||
TargetChain: targetChain,
|
||||
From: *from,
|
||||
To: *to,
|
||||
AppId: middleware.ExtractAppId(ctx, c.logger),
|
||||
Timespan: transactions.Timespan(ctx.Query("timespan")),
|
||||
SourceChains: sourceChains,
|
||||
TargetChains: targetChains,
|
||||
From: *from,
|
||||
To: *to,
|
||||
AppId: middleware.ExtractAppId(ctx, c.logger),
|
||||
Timespan: transactions.Timespan(ctx.Query("timespan")),
|
||||
}
|
||||
|
||||
if !payload.Timespan.IsValid() {
|
||||
|
|
Loading…
Reference in New Issue