Skip to content

🐛 Transaction Type Filter Broken Due to Wrong MongoDB Query Structure #40

@MrLutik

Description

@MrLutik

Bug Description

The /api/transactions endpoint's types filter does not work. Filtering by transaction type always returns 0 results, even when matching transactions exist in the database.

Root Cause

The MongoDB query uses nested map structure instead of dot notation for querying array fields.

Current code (manager/gateway/cosmos_agregated3.go:391-397):

criteria["messages"] = map[string]interface{}{
    "typeUrl": map[string]interface{}{
        "$in": request.Types,
    },
}

This generates the MongoDB query:

{"messages": {"typeUrl": {"$in": ["..."]}}}

This query looks for documents where messages equals an object with only a typeUrl field - an exact subdocument match. Since messages is an array containing objects with multiple fields (typeUrl, from_address, to_address, amount), this never matches.

Should be:

criteria["messages.typeUrl"] = map[string]interface{}{
    "$in": request.Types,
}

This generates the correct MongoDB query using dot notation:

{"messages.typeUrl": {"$in": ["..."]}}

Reproduction

1. Get transactions without filter (works):

curl -s -X POST "http://<INTERX_HOST>:11000/api/transactions" \
  -H "Content-Type: application/json" \
  -d '{}' | jq '.transactions | length'

Output: 3

2. Get transaction types in database:

curl -s -X POST "http://<INTERX_HOST>:11000/api/transactions" \
  -H "Content-Type: application/json" \
  -d '{}' | jq '[.transactions[].messages[].typeUrl] | unique'

Output:

[
  "/cosmos.bank.v1beta1.MsgSend"
]

3. Filter by type (BUG - returns 0):

curl -s -X POST "http://<INTERX_HOST>:11000/api/transactions" \
  -H "Content-Type: application/json" \
  -d '{"types": ["/cosmos.bank.v1beta1.MsgSend"]}' | jq '.transactions | length'

Output: 0

Expected: 3

Comparison with Working Filter

The statuses filter works correctly because it uses dot notation at line 429:

criteria["tx_result.code"] = 0
curl -s -X POST "http://<INTERX_HOST>:11000/api/transactions" \
  -H "Content-Type: application/json" \
  -d '{"statuses": ["success"]}' | jq '.transactions | length'

Output: 3

Fix

Change line 391-397 from:

if len(request.Types) > 0 {
    criteria["messages"] = map[string]interface{}{
        "typeUrl": map[string]interface{}{
            "$in": request.Types,
        },
    }
}

To:

if len(request.Types) > 0 {
    criteria["messages.typeUrl"] = map[string]interface{}{
        "$in": request.Types,
    }
}

Related

Closes #17

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions