8000 chore: rewrite report endpoint by thelostone-mc · Pull Request #8883 · gitcoinco/web · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore: rewrite report endpoint #8883

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

Merged
merged 3 commits into from
May 27, 2021
Merged

Conversation

thelostone-mc
Copy link
Contributor
@thelostone-mc thelostone-mc commented May 11, 2021

Description

This PR retries the report_real which takes a lot of resources and times out on heavy grants
Instead, Gitcoin will now offer 2 endpoints for public consumption

Note:

  • The results are paginated and return upto 30
  • These endpoints are rate limited by IP to 5/s
  • The API will return a valid response only for a max of 30 days
  • These endpoints aren't restricted to just eth address but instead provide info on all chains supported
  • A new metadata object has been added to the response which provides details like total count, current page, how many pages, next_page, etc
  • The original API is being retired but the data structure stays the safe and the info which was provided by the older endpoint, continues to be provided in the 2 new endpoints

Get all grant contributions made by an address

Endpoint: api/v0.1/grants/contributions_sent_report/?address=0x997D35b300bA1775fdB175dF045252e57D6EA5B0&format=json

Parameters:

  • address : String
  • format: json
  • page: number
  • from_timestamp: YYYY-MM-DD
  • to_timestamp: YYYY-MM-DD

sample response:

{
  "metadata": {
    "from": "2021-04-11T06:22:23.082709",
    "to": "2021-05-11T06:22:23.082709",
    "count": 2,
    "current_page": "1",
    "num_pages": 1,
    "has_next": false
  },
  "data": [
    {
      "grant_name": "Gitcoin Grants Round 8 + Dev Fund",
      "asset": "ETH",
      "timestamp": "2020-08-14T22:13:01.132221Z",
      "grant_amount": "1000000000000000",
      "gitcoin_maintenance_amount": "0",
      "grant_usd_value": 0.43796,
      "gitcoin_usd_value": 0.0
    },
    {
      "grant_name": "Gitcoin Grants Round 8 + Dev Fund",
      "asset": "ETH",
      "timestamp": "2020-08-14T22:13:01.392117Z",
      "grant_amount": "0",
      "gitcoin_maintenance_amount": "0",
      "grant_usd_value": 0.0,
      "gitcoin_usd_value": 0.0
    }
  ]
}

Get all grant contributions received by an grant

Endpoint: api/v0.1/grants/contributions_rec_report/?id=23&format=json

Parameters:

  • id : number (grant id)
  • format: json
  • page: number
  • from_timestamp: YYYY-MM-DD
  • to_timestamp: YYYY-MM-DD

sample response:

{
  "transactions": [
    {
        "asset": "DAI",
        "timestamp": "2021-04-05T18:09:13.664911Z",
        "amount": "2958149082487300",
        "clr_round": null,
        "usd_value": 0.0029581490824873
    }
  ],
  "clr_payouts": [
    {
      "amount": 530,
      "asset": "DAI",
      "usd_value": 530,
      "timestamp": "2019-06-04T16:06:59.354432Z",
      "round": 2
    }
  ],
  "metadata": {
    "grant_name": "The Gitcoin Open Source Support Fund",
    "from_timestamp": "2021-04-11T06:17:15.472045",
    "to_timestamp": "2021-05-11T06:17:15.472045",
    "count": 1,
    "current_page": "1",
    "num_pages": 1,
    "has_next": false
  }
}

Fixes: #8868

@thelostone-mc thelostone-mc marked this pull request as ready for review May 11, 2021 06:25
Copy link
Contributor
@gdixon gdixon left a comment

Choose a reason for hiding this comment

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

LGTM! I've left a few comments, but nothing that is blocking!

@@ -96,28 +96,6 @@ class Meta:

fields = ('amount', 'asset', 'usd_value', 'timestamp', 'round')
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider: Now that we're including all chains, would it make sense to include the chain that the asset is associated with in the output?

Copy link
Contributor Author
@thelostone-mc thelostone-mc May 18, 2021

Choose a reason for hiding this comment

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

This is for pubic consumption!
Do you see value adding it on? I figured we'd provide it if folks need it.
The data provided was what folks initially wanted so I haven't excluded / included anything new

"""Generate Grants report for an ethereum address"""
@ratelimit(key='ip', rate='5/s')
def contributions_rec_report(self, request):
"""Genrate Grantee Report for an Grant"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider: Would it be worth including details of the expected request format here?

Copy link
Contributor Author
@thelostone-mc thelostone-mc May 18, 2021

Choose a reason for hiding this comment

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

I can throw it in a readme file (basically the PR description) !
Would you rather we add it here. It might get a lil bloated though?

Copy link
Contributor

Choose a reason for hiding this comment

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

We can assume (or can we?) that users who will be accessing our end-points will likely check the code, I think that it would be useful to include these details inline, and later we can look to create documentation from the code itself? If theres a better place we can leave these details though, we can explore that, but I still feel inline would be a safe approach?

@action(detail=False)
@ratelimit(key='ip', rate='5/s')
def contributions_sent_report(self, request):
"""Generate report for grant contributions made by an address"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider: Same again here (detail what a request should look like)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add pagination to the Gitcoin Grants API
3 participants
0