graphprotocol / graphprotocol/graph-node

Automatically lower-case address inputs

Open
#3,890 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Stale
Dominant language
Rust
Stars
3.2k
Forks
1.1k
Avg merge
4d 1h
Merged PRs (30d)
1

Description

Do you want to request a feature or report a bug?
Both?

What is the current behavior?
A common pitfall for new users of The Graph is the ID or a Bytes fields actually contain an Ethereum address. When trying to query for that address with EIP-55 checksummed mixed-case strings or upper-case strings there is no match. Without further knowledge of the inner workings of the graph-node, this is a break in the developer journey. For example: "I know this address has a Punk but the subgraph does not show it. So it must be broken"

If the current behaviour is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.

{
  accounts(where: {id: "0xF22F00D0B95B1b728078066E5f4410F6B2Be8faE"}) {
    averageAmountSpent
    id
  }
}

What is the expected behavior?

Same as when sending this query to the above subgraph:

{
  accounts(where: {id: "0xf22f00d0b95b1b728078066e5f4410f6b2be8fae"}) {
    averageAmountSpent
    id
  }
}

Proposed steps
Since we don't know from the schema if an ID or Bytes field actually does contain an Ethereum address, I propose to do the following steps:

  • Check if the input string is an Ethereum address and the queried field is ID or Bytes. /^0x[a-fA-F0-9]{40}$/
  • For Bytes: Lowercase the input string before sending to the database
  • For ID: (This is a bit tricky): Maybe try to send the query and if it is null, resend it with lower-cased input?

Remarks
The possible solution here is good for backwards compatibility of subgraphs and probably easy to implement. A better long-term solution would be the introduction of an Address scalar type.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the GraphQL query behavior shown for the accounts id field and compare checksummed or uppercase addresses with the lowercase query. Resolve whether normalization should apply to Bytes, ID, or both, and define the expected fallback behavior before implementing and testing the result.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, rust
Domain
api, backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.