-
-
Notifications
You must be signed in to change notification settings - Fork 775
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 function for retrieving token recipient senders #6398
Conversation
91faf08
to
99a44cd
Compare
Codecov Report
@@ Coverage Diff @@
## master #6398 +/- ##
==========================================
+ Coverage 26.23% 26.27% +0.04%
==========================================
Files 300 300
Lines 29323 29343 +20
Branches 4317 4319 +2
==========================================
+ Hits 7693 7711 +18
- Misses 21360 21361 +1
- Partials 270 271 +1
Continue to review full report at Codecov.
|
@dylanjw thanks for the PR! Generally, for testing, we either would like to see unit tests (mocking API responses usually works fine) or just describe how you tested or show your test cases like with your gist 👍 |
def get_token_recipient_senders(recipient_address, token_addres): | ||
w3 = Web3(HTTPProvider(settings.WEB3_HTTP_PROVIDER)) | ||
contract = w3.eth.contract( | ||
address=token_address, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
token_address is not defined
app/dashboard/utils.py
Outdated
if balance == 0: | ||
return [] | ||
|
||
transfers = contract.events.Transfer.getLogs( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AttributeError: type object 'Transfer' has no attribute 'getLogs'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what version of web3py are you running? im running 4.6.0, which is the version in the requirements/base.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I wrote this using the latest web3. Ill get this fixed later today.
fc05982
to
0ca458c
Compare
0ca458c
to
8e2cdd4
Compare
8e2cdd4
to
eabfd8e
Compare
app/dashboard/utils.py
Outdated
balance = contract.functions.balanceOf(recipient_address).call() | ||
|
||
if balance == 0: | ||
return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I probably should take this out. If a user receives tokens, and then transfers them out; this function will return []
as if they never received them. I intended to create a fast exit path, but to determine if a address has ever received tokens, I dont think I can avoid retrieving the token transfer event logs.
@owocki Ive updated the function to work with web3, 4.6, and added a test. Let me know if you need any other changes. |
@owocki Are you planning to upgrade to web3 >=5 soon? I have time to help if that is on the todo list. |
defer to @danlipert and @gitcoinco/engineers on that |
ref: #6395
Description
Add a function
get_token_recipient_senders
todashboard.utils
. It will retrieve and filter event logs for erc20 token transfers. Always returns a list.Refers/Fixes
#6395
Testing
Let me know if you want tests written. I was unsure how to deal with the set up of test blockchain state. Here is a gist with a few assertions against some addresses I set up on rinkeby: https://gist.github.com/dylanjw/f3c0d876aee170b71a61858a322d24ed