Skip to content

Commit

Permalink
[API] Fix issue in VAA search filters (#211)
Browse files Browse the repository at this point in the history
### Summary

Searching for VAAs with the `txHash` and the `parsedPayload` parameters simultaneously wasn't working correctly. This commit fixes the problem.

Tracking issue: #210
  • Loading branch information
agodnic committed Mar 27, 2023
1 parent 02ffff9 commit d0cf9cc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
7 changes: 7 additions & 0 deletions api/handlers/vaa/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ func (r *Repository) FindVaasWithPayload(
})
}

// filter by txHash
if q.txHash != "" {
pipeline = append(pipeline, bson.D{
{"$match", bson.D{bson.E{"txHash", q.txHash}}},
})
}

// left outer join on the `parsedVaa` collection
pipeline = append(pipeline, bson.D{
{"$lookup", bson.D{
Expand Down
1 change: 1 addition & 0 deletions common/domain/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ const (
P2pDevNet = "devnet"
)

const AppIdPortalTokenBridge = "PORTAL_TOKEN_BRIDGE"
4 changes: 2 additions & 2 deletions parser/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import (
"context"

"github.com/mitchellh/mapstructure"
"github.com/wormhole-foundation/wormhole-explorer/common/domain"
"github.com/wormhole-foundation/wormhole-explorer/parser/metrics"
"github.com/wormhole-foundation/wormhole-explorer/parser/parser"
"go.uber.org/zap"
)

const (
portalTokenBridgeAppID = "PORTAL_TOKEN_BRIDGE"
transferPayloadType = 1
attestMetaPayloadType = 2
transferWithPayloadPayloadType = 3
Expand Down Expand Up @@ -48,7 +48,7 @@ func (p *Processor) Process(ctx context.Context, vaaParsed *parser.ParsedVaaUpda

p.logger.Info("Vaa save in repository", zap.String("id", vaaParsed.ID))

if vaaParsed.AppID == portalTokenBridgeAppID {
if vaaParsed.AppID == domain.AppIdPortalTokenBridge {
input, ok := vaaParsed.Result.(map[string]interface{})
if ok {
var result portalTokenBridgePayload
Expand Down
5 changes: 2 additions & 3 deletions tx-tracker/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"time"

"github.com/wormhole-foundation/wormhole-explorer/common/domain"
"github.com/wormhole-foundation/wormhole-explorer/parser/parser"

"github.com/wormhole-foundation/wormhole-explorer/txtracker/chains"
Expand Down Expand Up @@ -35,8 +36,6 @@ const (
retryDelay = 10 * time.Second
)

const AppIdPortalTokenBridge = "PORTAL_TOKEN_BRIDGE"

// Consumer consumer struct definition.
type Consumer struct {
consumeFunc queue.VAAConsumeFunc
Expand Down Expand Up @@ -118,7 +117,7 @@ func (c *Consumer) Start(ctx context.Context) {
}

// Skip messages that have not been generated by the portal token bridge
if parsedPayload.AppID != AppIdPortalTokenBridge {
if parsedPayload.AppID != domain.AppIdPortalTokenBridge {
c.logger.Debug("Skipping VAA because it was not generated by the portal token bridge",
zap.String("vaaId", event.ID),
)
Expand Down

0 comments on commit d0cf9cc

Please sign in to comment.