Skip to content

🐛 Transaction Query Filters Not Implemented or Broken #41

@MrLutik

Description

@MrLutik

Bug Description

The /api/transactions endpoint has several query parameters defined in QueryTxsParams struct that are either not implemented or have bugs:

  1. address - Not implemented (parsed but ignored)
  2. directions - Not implemented
  3. end_date - Uses wrong variable (copy-paste bug)

Location

  • manager/gateway/cosmos_agregated3.go:352-444
  • manager/types/cosmos.go:176-187

1. Address Filter Not Implemented

The address field is defined in the struct but never used in the query criteria.

Struct definition (types/cosmos.go:179):

type QueryTxsParams struct {
    Address    string   `json:"address,omitempty"`
    // ...
}

Problem: No code adds address to the MongoDB query criteria.

Reproduction:

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

Output: 3

# Request with non-existent address (should return 0)
curl -s -X POST "http://<INTERX_HOST>:11000/api/transactions" \
  -H "Content-Type: application/json" \
  -d '{"address": "kira1nonexistentaddress123456789"}' \
  | jq '.transactions | length'

Output: 3

Expected: 0


2. Directions Filter Not Implemented

The directions field is defined but never used.

Struct definition (types/cosmos.go:182):

Directions []string `json:"directions,omitempty"`

Problem: No code processes or applies this filter.


3. EndDate Filter Uses Wrong Variable

Location: cosmos_agregated3.go:407-413

if request.EndDate > 0 {
    criteria["timestamp"] = map[string]interface{}{
        "$lt": request.StartDate,  // BUG: should be request.EndDate
    }
}

Problem: Copy-paste error - uses request.StartDate instead of request.EndDate.


4. Date Filters Overwrite Each Other

If both start_date and end_date are provided, the second criteria overwrites the first:

// Line 399-405
if request.StartDate > 0 {
    criteria["timestamp"] = map[string]interface{}{
        "$gt": request.StartDate,
    }
}

// Line 407-413 - OVERWRITES the above!
if request.EndDate > 0 {
    criteria["timestamp"] = map[string]interface{}{
        "$lt": request.StartDate,
    }
}

Should combine into single query:

if request.StartDate > 0 || request.EndDate > 0 {
    timestampCriteria := map[string]interface{}{}
    if request.StartDate > 0 {
        timestampCriteria["$gt"] = request.StartDate
    }
    if request.EndDate > 0 {
        timestampCriteria["$lt"] = request.EndDate
    }
    criteria["timestamp"] = timestampCriteria
}

Summary of Required Fixes

Parameter Issue Fix Required
address Not implemented Add address filtering logic
directions Not implemented Add directions filtering logic
end_date Wrong variable Change StartDateEndDate at line 409
start_date + end_date Overwrite each other Combine into single timestamp criteria

Related

Closes #34

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions