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

Add smart_contract field to address object #1045

Merged
merged 1 commit into from
Nov 6, 2018
Merged

Conversation

sabondano
Copy link
Contributor

@sabondano sabondano commented Nov 5, 2018

Motivation

  • For GraphQL API users to be able to get a smart_contract by
    address. RPC API users could use this instead of the getabi and
    getsourcecode RPC actions.

    Example usage:

        query ($hashes: [AddressHash!]!) {
          addresses(hashes: $hashes) {
            fetched_coin_balance
            smart_contract {
              name
              compiler_version
              optimization
              contract_source_code
              abi
              address_hash
            }
          }
        }
    

Changelog

Enhancements

  • Adding jason dependency. Needed for JSON scalar type.
  • Adding dataloader dependency to help Absinthe efficiently load data
    in batches.
  • Editing Schema by adding context callback. It adds a dataloader
    source to context.
  • Adding JSON scalar type. Needed by abi field in smart_contract
    object.
  • Adding smart_contract object type.
  • Editing address object type to include smart_contract field.
  • Adding Explorer.Chain.data/0. It creates an Ecto Dataloader source
    for Absinthe to use.

@sabondano sabondano self-assigned this Nov 5, 2018
@ghost ghost added the in progress label Nov 5, 2018
@sabondano sabondano force-pushed the sa-graphql-contracts branch 3 times, most recently from 989203f to e820893 Compare November 5, 2018 18:27
@coveralls
Copy link

coveralls commented Nov 5, 2018

Pull Request Test Coverage Report for Build 98a52940-9fb1-4744-8ede-eddb58e78e45

  • 4 of 6 (66.67%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 89.113%

Changes Missing Coverage Covered Lines Changed/Added Lines %
apps/block_scout_web/lib/block_scout_web/schema/scalars/JSON.ex 1 2 50.0%
apps/explorer/lib/explorer/chain.ex 0 1 0.0%
Totals Coverage Status
Change from base Build 7472772c-0598-4edc-a74a-ec945e097ac7: 0.0%
Covered Lines: 3315
Relevant Lines: 3720

💛 - Coveralls

@sabondano sabondano force-pushed the sa-graphql-contracts branch 3 times, most recently from 3e9986a to 1f73d1c Compare November 5, 2018 19:46
@sabondano sabondano added the ready for review This PR is ready for reviews. label Nov 5, 2018
Copy link
Contributor

@KronicDeth KronicDeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the PR description you say

RPC API users could use this instead of the getabi and getsourcecode RPC actions.

But I don't see a change to the RPC API docs. You should add it in there to guide users on the GraphQL API upgrade path like we discussed before.

@sabondano
Copy link
Contributor Author

sabondano commented Nov 6, 2018

@KronicDeth yes 👍. It's on my list of things to do. My plan was to open a single PR editing the RPC API docs for all actions we currently have similar support for on the GraphQL API. I'm thinking it'll make the PR review easier and we can discuss what's the best way to do that on that separate PR. After that PR, all GraphQL API enhancements could include the necessary edits to the RPC API documentation. If that works for all, I'll proceed accordingly but let me know.

Why:

* For GraphQL API users to be able to get a `smart_contract` by
address. RPC API users could use this instead of the `getabi` and
`getsourcecode` RPC actions.

  Example usage:
  ```
      query ($hashes: [AddressHash!]!) {
        addresses(hashes: $hashes) {
          fetched_coin_balance
          smart_contract {
            name
            compiler_version
            optimization
            contract_source_code
            abi
            address_hash
          }
        }
      }
  ```
* Issue link: n/a

This change addresses the need by:

* Adding `jason` dependency. Needed for `JSON` scalar type.
* Adding `dataloader` dependency to help Absinthe efficiently load data
in batches.
* Editing `Schema` by adding `context` callback. It adds a dataloader
source to context.
* Adding JSON scalar type. Needed by `abi` field in `smart_contract`
object.
* Adding `smart_contract` object type.
* Editing `address` object type to include `smart_contract` field.
* Adding `Explorer.Chain.data/0`. It creates an Ecto Dataloader source
for Absinthe to use.
@KronicDeth KronicDeth merged commit 88a9515 into master Nov 6, 2018
@KronicDeth KronicDeth deleted the sa-graphql-contracts branch November 6, 2018 17:37
@ghost ghost removed the in progress label Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review This PR is ready for reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants