Created
June 18, 2022 01:47
-
-
Save dangell7/e1027a67e00641794d5adb978ada0d6c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
``` | |
def get_all_holders(w3, currency, issuer): | |
"""get_all_holders.""" | |
holders = {} | |
marker = None | |
has_marker = True | |
page = 1 | |
logger.info('SNAPSHOT {} FOR {}'.format(currency, issuer)) | |
while has_marker: | |
logger.info('PAGINATION: PAGE: {}'.format(page)) | |
acct_lines = AccountLines( | |
account=issuer, | |
ledger_index="current", | |
limit=1000, | |
marker=marker, | |
) | |
response = w3.request(acct_lines) | |
if 'status' in response.result and response.result['status'] == 'error': # noqa | |
raise ValueError(response.result['error_message']) | |
for line in response.result['lines']: | |
if line['currency'] != currency: | |
logger.info('SKIPPING WRONG CURRENCY') | |
continue | |
if float(abs(float(line['balance']))) < 1: | |
logger.info('SKIPPING NEGATIVE OR 0 BALANCE') | |
continue | |
holders[line['account']] = { | |
'limit': int(abs(float(line['limit_peer']))), # noqa | |
'balance': int(abs(float(line['balance']))), # noqa | |
} | |
if 'marker' in response.result: | |
marker = response.result['marker'] | |
page += 1 | |
continue | |
has_marker = False | |
logger.info('FINISHED PAGINATION') | |
return holders | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment