Fix issue in `txHash` search (#494)

### Description

Tracking issue: https://github.com/wormhole-foundation/wormhole-explorer/issues/493

Fix an issue in which transaction hash search was failing for VAAs that have the same `txHash`.
This commit is contained in:
agodnic 2023-07-04 09:58:21 -03:00 committed by GitHub
parent 4e8b43a598
commit 5aedf0247e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -55,6 +55,8 @@ func NewRepository(db *mongo.Database, logger *zap.Logger) *Repository {
//
// When the `q.txHash` field is set, this function will look up transaction hashes in the `globalTransactions` collection.
// Then, if the transaction hash is not found, it will fall back to searching in the `vaas` collection.
//
// Take into consideration that multiple VAAs could share the same transaction ID.
func (r *Repository) FindVaasByTxHashWorkaround(
ctx context.Context,
query *VaaQuery,
@ -91,9 +93,6 @@ func (r *Repository) FindVaasByTxHashWorkaround(
)
return nil, errors.WithStack(err)
}
if len(globalTxs) > 1 {
return nil, fmt.Errorf("expected at most one transaction, but found %d", len(globalTxs))
}
// If no documents were found, look up the transaction hash in the `vaas` collection instead.
if len(globalTxs) == 0 {
@ -114,6 +113,8 @@ func (r *Repository) FindVaasByTxHashWorkaround(
// FindVaas searches the database for VAAs matching the given filters.
//
// When the `q.txHash` field is set, this function will look up transaction hashes in the `vaas` collection.
//
// Take into consideration that multiple VAAs could share the same transaction ID.
func (r *Repository) FindVaas(
ctx context.Context,
q *VaaQuery,