Skip to content

Commit

Permalink
Add TestNet option.
Browse files Browse the repository at this point in the history
  • Loading branch information
cusma committed Sep 3, 2023
1 parent f33087d commit 132045e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 25 deletions.
17 changes: 11 additions & 6 deletions ppos_dex.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Algorand PPoS Decentralization Index.
Usage:
ppos_dex.py publish [--algo-threshold=<t>] [--localhost]
ppos_dex.py plot [--publisher=<p>] [--algo-threshold=<t>] [--start-block=<s>] [--end-block=<e>] [--localhost]
ppos_dex.py snapshot [--publisher=<p>] [--algo-threshold=<t>] [--start-block=<s>] [--localhost]
ppos_dex.py export [--publisher=<p>] [--algo-threshold=<t>] [--start-block=<s>] [--end-block=<e>] [--localhost]
ppos_dex.py health [--localhost]
ppos_dex.py publish [--algo-threshold=<a>] [--localhost | --test]
ppos_dex.py plot [--publisher=<p>] [--algo-threshold=<a>] [--start-block=<s>] [--end-block=<e>] [--localhost | --test]
ppos_dex.py snapshot [--publisher=<p>] [--algo-threshold=<a>] [--start-block=<s>] [--localhost | --test]
ppos_dex.py export [--publisher=<p>] [--algo-threshold=<a>] [--start-block=<s>] [--end-block=<e>] [--localhost | --test]
ppos_dex.py health [--localhost | --test]
ppos_dex.py [--help]
Commands:
Expand All @@ -17,10 +17,12 @@
health Check Algod and Indexer status.
Options:
-t, --algo-threshold=<t> [default: 1000]
-a, --algo-threshold=<a> [default: 1000]
-p, --publisher=<p> [default: WIPE4JSUWLXKZZK6GJ6VI32PX6ZWPKBRH5YFRJCHWOVC73P5RI4DGUQUWQ]
-s, --start-block=<s> [default: 11476070]
-e, --end-block=<e>
-l, --localhost
-t, --test
-h, --help
"""

Expand Down Expand Up @@ -79,6 +81,9 @@ def main():
if args["--localhost"]:
algod_config = get_default_localnet_config("algod")
indexer_config = get_default_localnet_config("indexer")
elif args["--test"]:
algod_config = get_algonode_config("testnet", "algod", "")
indexer_config = get_algonode_config("testnet", "indexer", "")
else:
algod_config = get_algonode_config("mainnet", "algod", "")
indexer_config = get_algonode_config("mainnet", "indexer", "")
Expand Down
50 changes: 31 additions & 19 deletions src/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,14 @@ def wrapper(*args, **kwargs) -> Any:
while attempts <= MAX_ATTEMPTS:
try:
return request(*args, **kwargs)
except IndexerHTTPError:
except IndexerHTTPError as err:
print(err)
print(f"Indexer request attempt {attempts}/{MAX_ATTEMPTS}")
print("Trying submit request again...")
time.sleep(ATTEMPT_DELAY_SEC)
finally:
attempts += 1
quit("Unable to connect to the Algorand Indexer.")
quit("Algorand Indexer request failed.")

return wrapper

Expand All @@ -68,23 +69,29 @@ def get_algo_holders(
microalgo_min_balance: microALGO minimum balance
Returns:
Accounts holding a balance greater than `algo_min_balance`
Accounts holding a balance greater than `microalgo_min_balance`
"""
nexttoken = ""
num_acc = 1
has_result = True

holders: list[dict] = []
while num_acc > 0:
response = indexer_client.accounts(
min_balance=microalgo_min_balance, next_page=nexttoken, limit=1000
while has_result:
result = indexer_client.accounts(
next_page=nexttoken,
min_balance=microalgo_min_balance,
exclude="all",
)
accounts = response["accounts"]

accounts = result["accounts"]
has_result = len(accounts) > 0
holders += accounts
num_acc = len(accounts)
if num_acc > 0:
# Pointer to the next chunk of requests
nexttoken = response["next-token"]

if has_result:
nexttoken = result["next-token"]

if not holders:
quit(f"No account with minimum balance {microalgo_min_balance} microAlgo.")
quit(f"No account with {microalgo_min_balance} microAlgo balance found.")

return holders


Expand All @@ -108,27 +115,32 @@ def get_address_txns_note(
Notes published by `address`
"""
nexttoken = ""
num_tx = 1
has_result = True

address_txns: list[dict] = []
while num_tx > 0:
while has_result:
result = indexer_client.search_transactions_by_address(
address=address,
limit=1000,
next_page=nexttoken,
min_round=start_block,
max_round=end_block,
)
txns = result["transactions"]
has_result = len(txns) > 0
address_txns += txns
num_tx = len(txns)
if num_tx > 0:
# Pointer to the next chunk of requests

if has_result:
nexttoken = result["next-token"]

txns_note: list[str] = []
for txn in address_txns:
note = txn.get("note")
if note is not None:
txns_note.append(note)

if not txns_note:
quit(f"No published note found for account {address}.")

return txns_note


Expand Down

0 comments on commit 132045e

Please sign in to comment.