Skip to content

Commit

Permalink
Merge pull request #19 from AlgoRealm/develop
Browse files Browse the repository at this point in the history
Longevity and Braveness
  • Loading branch information
cusma authored Jan 3, 2023
2 parents bff6263 + 9054988 commit 3fba7df
Show file tree
Hide file tree
Showing 5 changed files with 237 additions and 78 deletions.
56 changes: 55 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ AlgoRealm, only generous heart will ever rule over Algorand. (by cusma)
Usage:
algorealm.py poem
algorealm.py dynasty [--test]
algorealm.py longevity (--crown | --sceptre) [--test]
algorealm.py braveness (--crown | --sceptre) [--test]
algorealm.py claim-majesty (--crown | --sceptre) <majesty-name> <microalgos> [--test]
algorealm.py claim-card
algorealm.py buy-order <microalgos> [--notify]
Expand All @@ -74,6 +76,8 @@ Usage:
Commands:
poem AlgoRealm's poem.
dynasty Print the glorious dynasty of AlgoRealm's Majesties.
longevity Print AlgoRealm's Majesties longevity.
braveness Print AlgoRealm's Majesties braveness.
claim-majesty Claim the Crown of Entropy or the Sceptre of Proof, become Majesty of Algorand.
claim-card Brake the spell and claim the AlgoRealm Card by AlgoWorld.
buy-order Place an order for the AlgoRealm Card.
Expand All @@ -91,7 +95,7 @@ Options:
> In case you want to give a try, you can play AlgoRealm on TestNet adding `-t`
> to CLI commands.
### 3. AlgoRealm Dynasty
### 3. AlgoRealm Dynasty, Longevity and Braveness

Who are the Majesties of the Algorand realm?

Expand Down Expand Up @@ -141,6 +145,56 @@ on Block: 14989913 donating: 4 microALGOs to the Rewards Pool.
on Block: 14989913 donating: 4 microALGOs to the Rewards Pool.
```

4. Which was the longest lasting Majesty?
```shell
$ python3 algorealm.py longevity --crown
```

```
*** 👑 RANDOMIC MAJESTY LONGEVITY ***
+--------------------+--------------------+
| Majesty Name | Longevity (blocks) |
+--------------------+--------------------+
| MillionAlgosFather | 5768768 |
| nullun | 3366046 |
| jkbishbish | 1357847 |
| Matt | 1248429 |
| renangeo | 416539 |
| 👑🅿️ | 158346 |
| tmc | 53895 |
| MillionAlgosFather | 32978 |
| nullun | 3369 |
+--------------------+--------------------+
```

5. Who is the bravest Majesty of all time?
```shell
$ python3 algorealm.py braveness --crown
```

```
*** 👑 RANDOMIC MAJESTY BRAVENESS ***
+--------------------+-----------+
| Majesty Name | Braveness |
+--------------------+-----------+
| renangeo | 7.824 |
| MillionAlgosFather | 4.605 |
| 👑🅿️ | 1.609 |
| jkbishbish | 1 |
| tmc | 0.405 |
| nullun | 0.288 |
| nullun | 0.0 |
| MillionAlgosFather | 0.0 |
| Matt | 0.0 |
+--------------------+-----------+
```

> Braveness is based on the relative gorwth of donation amounts (`d'`, `d`):
>
> `braveness = ln(d') - ln(d)`
### 4. Claim the Crown of Entropy or the Sceptre of Proof

Chose your `<majesty-name>` and become part of the Dynasty! Remember that to dethrone the current Majesties you must donate to the Algorand's Rewards Pool more `<microalgos>` than the last donation.
Expand Down
38 changes: 31 additions & 7 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ license = "MIT"
python = "^3.10"
docopt = "^0.6.2"
msgpack = "^1.0.4"
py-algorand-sdk = "^1.20.1"
py-algorand-sdk = "^1.20.2"
prettytable = "^3.5.0"

[tool.poetry.dev-dependencies]
black = "^22.10.0"
black = "^22.12.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
111 changes: 76 additions & 35 deletions src/algorealm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Usage:
algorealm.py poem
algorealm.py dynasty [--test]
algorealm.py longevity (--crown | --sceptre) [--test]
algorealm.py braveness (--crown | --sceptre) [--test]
algorealm.py claim-majesty (--crown | --sceptre) <majesty-name> <microalgos> [--test]
algorealm.py claim-card
algorealm.py buy-order <microalgos> [--notify]
Expand All @@ -14,6 +16,8 @@
Commands:
poem AlgoRealm's poem.
dynasty Print the glorious dynasty of AlgoRealm's Majesties.
longevity Print AlgoRealm's Majesties longevity.
braveness Print AlgoRealm's Majesties braveness.
claim-majesty Claim the Crown of Entropy or the Sceptre of Proof, become Majesty of Algorand.
claim-card Brake the spell and claim the AlgoRealm Card by AlgoWorld.
buy-order Place an order for the AlgoRealm Card.
Expand All @@ -35,6 +39,7 @@
from algosdk.v2client.algod import AlgodClient
from algosdk.v2client.indexer import IndexerClient
from docopt import docopt
from prettytable import PrettyTable

import actions
import query
Expand Down Expand Up @@ -135,60 +140,96 @@ def main():
algod_client = build_algod_client(test=args["--test"])
indexer_client = build_indexer_client(test=args["--test"])

if args["--test"]:
crown_nft_id = TEST_CROWN_ID
sceptre_nft_id = TEST_SCEPTRE_ID
algorealm_app_id = TEST_ALGOREALM_APP_ID
algorealm_contract = TEST_ALGOREALM_LAW_BYTECODE
algorealm_first_round = TEST_ALGOREALM_FIRST_BLOCK
else:
crown_nft_id = CROWN_ID
sceptre_nft_id = SCEPTRE_ID
algorealm_app_id = ALGOREALM_APP_ID
algorealm_contract = ALGOREALM_LAW_BYTECODE
algorealm_first_round = ALGOREALM_FIRST_BLOCK

# CLI
if args["dynasty"]:
if args["--test"]:
algorealm_app_id = TEST_ALGOREALM_APP_ID
algorealm_first_round = TEST_ALGOREALM_FIRST_BLOCK
claims = query.claims_history(
client=indexer_client,
algorealm_app_id=algorealm_app_id,
algorealm_first_round=algorealm_first_round,
)

print("\t\t\t\t*** DYNASTY ***\n")
return print(*["\n", *query.dynasty(claims)])

if args["longevity"]:
claims = query.claims_history(
client=indexer_client,
algorealm_app_id=algorealm_app_id,
algorealm_first_round=algorealm_first_round,
)
latest_block = algod_client.status()["last-round"]

if args["--crown"]:
majesty_title = "👑 RANDOMIC"
claim_select = "Crown"
else:
algorealm_app_id = ALGOREALM_APP_ID
algorealm_first_round = ALGOREALM_FIRST_BLOCK
print(
r"""
*** DYNASTY ***
"""
majesty_title = "🪄 VERIFIABLE"
claim_select = "Sceptre"

majesty_longevity = query.longevity(claims, latest_block, claim_select)

longevity_table = PrettyTable()
longevity_table.field_names = ["Majesty Name", "Longevity (blocks)"]
longevity_table.add_rows(
[[claim["name"], claim["longevity"]] for claim in majesty_longevity]
)
return print(
*[
"\n",
*query.history(
client=indexer_client,
algorealm_app_id=algorealm_app_id,
algorealm_first_round=algorealm_first_round,
),
]

print(f"\t\t*** {majesty_title} MAJESTY LONGEVITY ***\n")
return print(longevity_table)

if args["braveness"]:
claims = query.claims_history(
client=indexer_client,
algorealm_app_id=algorealm_app_id,
algorealm_first_round=algorealm_first_round,
)

if args["--crown"]:
majesty_title = "👑 RANDOMIC"
claim_select = "Crown"
else:
majesty_title = "🪄 VERIFIABLE"
claim_select = "Sceptre"

majesty_braveness = query.braveness(claims, claim_select)

braveness_table = PrettyTable()
braveness_table.field_names = ["Majesty Name", "Braveness"]
braveness_table.add_rows(
[[claim["name"], claim["braveness"]] for claim in majesty_braveness]
)

print(f"\t\t*** {majesty_title} MAJESTY BRAVENESS ***\n")
return print(braveness_table)

if args["claim-majesty"]:
majesty_name = args["<majesty-name>"]

if args["--test"]:
algorealm_first_round = TEST_ALGOREALM_FIRST_BLOCK
algorealm_contract = TEST_ALGOREALM_LAW_BYTECODE
algorealm_app_id = TEST_ALGOREALM_APP_ID
else:
algorealm_first_round = ALGOREALM_FIRST_BLOCK
algorealm_contract = ALGOREALM_LAW_BYTECODE
algorealm_app_id = ALGOREALM_APP_ID

if args["--crown"]:
proclaim = (
f"\n👑 Glory to {majesty_name}, the Randomic Majesty of Algorand! 🎉\n"
)
claim_select = "Crown"
if args["--test"]:
nft_id = TEST_CROWN_ID
else:
nft_id = CROWN_ID
nft_id = crown_nft_id
else:
proclaim = (
f"\n🪄 Glory to {majesty_name}, the Verifiable Majesty of Algorand! 🎉\n"
)
claim_select = "Sceptre"
if args["--test"]:
nft_id = TEST_SCEPTRE_ID
else:
nft_id = SCEPTRE_ID
nft_id = sceptre_nft_id

user = actions.get_user()
algorealm_law = actions.get_contract_account(algorealm_contract)
Expand Down
Loading

0 comments on commit 3fba7df

Please sign in to comment.