Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: For each account, query if it was used to add a package #40

Open
jefft0 opened this issue Jan 15, 2025 · 0 comments
Open

feat: For each account, query if it was used to add a package #40

jefft0 opened this issue Jan 15, 2025 · 0 comments

Comments

@jefft0
Copy link
Collaborator

jefft0 commented Jan 15, 2025

The following GraphQL query gets the packages added by an account address (creator):

query {
  getTransactions(
    where: {
      messages: { value: { MsgAddPackage: {creator: { eq: "g1juz2yxmdsa6audkp6ep9vfv80c8p5u76e03vvh"}}}}
      success: { eq: true }
    }
  ) { messages { value { ... on MsgAddPackage { package{name}}}}}
}

If there are no matches, the result is:

{
  "data": {
    "getTransactions": null
  }
}

If there is a match, the result is something like:

{
  "data": {
    "getTransactions": [
      {
        "messages": [
          {
            "value": {
              "package": {
                "name": "deep2"
              }
            }
          }
        ]
      }
    ]
  }
}

The following code uses this to query txIndexerRemote for the packages added by address:

  const txIndexerRemote = "https://txindexer.gno.berty.io/graphql/query"
  const address = "g1juz2yxmdsa6audkp6ep9vfv80c8p5u76e03vvh"
  const requestOptions = {
    method: "POST",
    headers: { "content-type": "application/json" },
    body: JSON.stringify({
      'query': `query { getTransactions(where: { messages: { value: { MsgAddPackage: {creator: { eq: "${address}"}}}} success: { eq: true }}) { messages { value { ... on MsgAddPackage { package{name}}}}}}`
    }),
  }
  const response = await fetch(txIndexerRemote, requestOptions)
  const result = await response.json()

If there are no packages, result.data.getTransactions is null. Otherwise result.data.getTransactions is something like:

[{"messages":[{"value":{"package":{"name":"mypackage"}}}]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant