Skip to content

Commit

Permalink
Merge pull request #1 from cusma/dynasty
Browse files Browse the repository at this point in the history
AlgoRealm Dynasty
  • Loading branch information
cusma authored Aug 31, 2021
2 parents fc018ff + 34767e1 commit 021a61b
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 14 deletions.
86 changes: 72 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
```
_ __ _______ __
/ \ [ | |_ __ \ [ |
/ _ \ | | .--./) .--. | |__) | .---. ,--. | | _ .--..--.
/ ___ \ | | / /'`\;/ .'`\ \ | __ / / /__\\`'_\ : | | [ `.-. .-. |
_/ / \ \_ | | \ \._//| \__. |_| | \ \_| \__.,// | |, | | | | | | | |
|____| |____|[___].',__` '.__.'|____| |___|'.__.'\'-;__/[___][___||__||__]
( ( __))
by cusma
__ __ ___ __ __
\*) \*) \*/ (*/ (*/
\*\_\*\_|O|_/*/_/*/
\_______________/
_ __ _______ __
/ \ [ | |_ __ \ [ |
/ _ \ | | .--./) .--. | |__) | .---. ,--. | | _ .--..--.
/ ___ \ | | / /'`\;/ .'`\ \ | __ / / /__\\`'_\ : | | [ `.-. .-. |
_/ / \ \_ | | \ \._//| \__. |_| | \ \_| \__.,// | |, | | | | | | | |
|____| |____|[___].',__` '.__.'|____| |___|'.__.'\'-;__/[___][___||__||__]
( ( __))
by cusma
```

## Incipit
Expand All @@ -23,23 +27,77 @@ Brings Consensus over realm vastness,
So Algorand never fork.
```

## Majesties of Algorand
## Become a Majesty of Algorand

Only generous hearts will rule over Algorand realm.

Show how generous is your heart donating some ALGOs to the [Rewards Pool](https://developer.algorand.org/docs/reference/algorand-networks/mainnet/#rewardspool-address) and claim the title of **Randomic Majesty of Algorand** or **Verifiable Majesty of Algorand**.

The more generous you are, the harder will be to be dethroned.

## AlgoRealm Dynasty

Who are the Majesties of the Algorand realm?

Check it on your node:
1. Discover it directly on [Algorand blockchain](https://algoexplorer.io/application/137491307)

```bash
2. Discover it with your node:
```shell
$ ./goal app read --app-id 137491307 --global
```

Or on [AlgoExplorer](https://algoexplorer.io/application/137491307).
3. Discover it with `algorealm_dynasty.py`:
```shell
AlgoRealm Dynasty

Show how generous is your heart donating some ALGO to the [Rewards Pool](https://developer.algorand.org/docs/reference/algorand-networks/mainnet/#rewardspool-address) and claim the title of **Randomic Majesty of Algorand** or **Verifiable Majesty of Algorand**.
Usage:
algorealm_dynasty.py <purestake-api-token>
algorealm_dynasty.py local-host <api-token> [--indexer-address=<ia>]
algorealm_dynasty.py [--help]

The more generous you are, the harder will be to be dethroned.
Commands:
local-host Use your local Indexer.

Options:
-i <ia> --indexer-address=<ia> [default: http://localhost:8980/]
-h --help
```

```shell
$ python3 aloreal_dynasty.py <purestake-api-token>

__ __ ___ __ __
\*) \*) \*/ (*/ (*/
\*\_\*\_|O|_/*/_/*/
\_______________/
_ __ _______ __
/ \ [ | |_ __ \ [ |
/ _ \ | | .--./) .--. | |__) | .---. ,--. | | _ .--..--.
/ ___ \ | | / /'`\;/ .'`\ \ | __ / / /__\\`'_\ : | | [ `.-. .-. |
_/ / \ \_ | | \ \._//| \__. |_| | \ \_| \__.,// | |, | | | | | | | |
|____| |____|[___].',__` '.__.'|____| |___|'.__.'\'-;__/[___][___||__||__]
( ( __))
*** DYNASTY ***
👑 jkbishbish claimed the Crown of Entropy
on Block: 13578171 donating: 2 microALGOs.
🪄 jkbishbish claimed the Sceptre of Proof
on Block: 13578330 donating: 2 microALGOs.
👑 tmc claimed the Crown of Entropy
on Block: 14936018 donating: 3 microALGOs.
🪄 tmc claimed the Sceptre of Proof
on Block: 14936235 donating: 3 microALGOs.
👑 nullun claimed the Crown of Entropy
on Block: 14989913 donating: 4 microALGOs.
🪄 nullun claimed the Sceptre of Proof
on Block: 14989913 donating: 4 microALGOs.
```

## Claim the Crown of Entropy

Expand Down
141 changes: 141 additions & 0 deletions algorealm_dynasty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
"""
AlgoRealm Dynasty
Usage:
algorealm_dynasty.py <purestake-api-token>
algorealm_dynasty.py local-host <api-token> [--indexer-address=<ia>]
algorealm_dynasty.py [--help]
Commands:
local-host Use your local Indexer.
Options:
-i <ia> --indexer-address=<ia> [default: http://localhost:8980/]
-h --help
"""


import sys
from docopt import docopt
import time
import base64
from algosdk.v2client import indexer
from algosdk.error import IndexerHTTPError


MAX_CONNECTION_ATTEMPTS = 10
CONNECTION_ATTEMPT_DELAY_SEC = 2


def search_algorelm_calls(indexer_client):
nexttoken = ""
numtx = 1
calls = []
while numtx > 0:
result = indexer_client.search_transactions(
limit=1000,
next_page=nexttoken,
application_id=137491307,
min_round=13578170,
)
calls += result['transactions']
numtx = len(result['transactions'])
if numtx > 0:
# pointer to the next chunk of requests
nexttoken = result['next-token']
return calls


def history(indexer_client):
attempts = 1
algorealm_calls = None
while attempts <= MAX_CONNECTION_ATTEMPTS:
try:
algorealm_calls = search_algorelm_calls(indexer_client)
break
except IndexerHTTPError:
print(f'Indexer Client connection attempt '
f'{attempts}/{MAX_CONNECTION_ATTEMPTS}')
print('Trying to contact Indexer Client again...')
time.sleep(CONNECTION_ATTEMPT_DELAY_SEC)
finally:
attempts += 1
if not algorealm_calls:
quit("Unable to connect to Indexer Client.")

claims_history = []
for call in algorealm_calls:
title = base64.b64decode(
call['global-state-delta'][1]['key']).decode()
name = base64.b64decode(
call['global-state-delta'][1]['value']['bytes']).decode()
donation = call['global-state-delta'][0]['value']['uint']
block = call['confirmed-round']

claims_history += [
{
'title': title,
'name': name,
'donation': donation,
'block': block,
}
]
return claims_history


def main():
if len(sys.argv) == 1:
# Display help if no arguments, see:
# https://github.com/docopt/docopt/issues/420#issuecomment-405018014
sys.argv.append('--help')

args = docopt(__doc__)

if args['local-host']:
token = args['<api-token>']
header = None
indexer_address = args['--indexer-address']
else:
token = args['<purestake-api-token>']
header = {'X-Api-key': token}
indexer_address = "https://mainnet-algorand.api.purestake.io/idx2"

indexer_client = indexer.IndexerClient(
indexer_token=token,
indexer_address=indexer_address,
headers=header
)

dynasty = history(indexer_client)

print(r"""
__ __ ___ __ __
\*) \*) \*/ (*/ (*/
\*\_\*\_|O|_/*/_/*/
\_______________/
_ __ _______ __
/ \ [ | |_ __ \ [ |
/ _ \ | | .--./) .--. | |__) | .---. ,--. | | _ .--..--.
/ ___ \ | | / /'`\;/ .'`\ \ | __ / / /__\\`'_\ : | | [ `.-. .-. |
_/ / \ \_ | | \ \._//| \__. |_| | \ \_| \__.,// | |, | | | | | | | |
|____| |____|[___].',__` '.__.'|____| |___|'.__.'\'-;__/[___][___||__||__]
( ( __))
*** DYNASTY ***
""")

for majesty in dynasty:
if majesty['title'] == 'RandomicMajestyOfAlgorand':
print(f"👑 {majesty['name']} claimed the Crown of Entropy")
print(f"on Block: {majesty['block']} "
f"donating: {majesty['donation']} microALGOs.\n")
elif majesty['title'] == 'VerifiableMajestyOfAlgorand':
print(f"🪄 {majesty['name']} claimed the Sceptre of Proof")
print(f"on Block: {majesty['block']} "
f"donating: {majesty['donation']} microALGOs.\n")
else:
quit("Error: Invalid AlgoRealm Majesty Title.")


if __name__ == "__main__":
main()

0 comments on commit 021a61b

Please sign in to comment.