Skip to content

Commit

Permalink
Fix get local state. Remove magic numbers.
Browse files Browse the repository at this point in the history
  • Loading branch information
cusma committed Nov 6, 2022
1 parent 2452346 commit a4897dd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Pipfile.lock

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

13 changes: 8 additions & 5 deletions algodices.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@
from algosdk import account
from algosdk import mnemonic
from algosdk.atomic_transaction_composer import AccountTransactionSigner
from algosdk.constants import MIN_TXN_FEE
from algosdk.constants import MIN_TXN_FEE, MNEMONIC_LEN

from beaker.client import ApplicationClient, Network
from beaker.client.api_providers import AlgoExplorer

from algodices_dapp import AlgoDices

ALGO_DICES_APP_ID = 120974808
RANDOMNESS_BEACON_DELAY = 8


def args_types(args: dict) -> dict:
Expand All @@ -51,7 +52,7 @@ def main():
# USER
mnemonic_phrase = getpass(prompt="Mnemonic (word_1 word_2 ... word_25):")
try:
assert len(mnemonic_phrase.split()) == 25
assert len(mnemonic_phrase.split()) == MNEMONIC_LEN
except AssertionError:
quit('\n⚠️ Enter mnemonic phrase, formatted as: "word_1 ... word_25"')
user = AccountTransactionSigner(mnemonic.to_private_key(mnemonic_phrase))
Expand All @@ -77,7 +78,7 @@ def main():
if args["book"]:
current_round = testnet.algod().status()["last-round"]
booked_round = current_round + args["<future_rounds>"]
reveal_round = booked_round + 8
reveal_round = booked_round + RANDOMNESS_BEACON_DELAY
print(f"\n --- 🔖 Booking a die roll for round {booked_round}...")
algo_dices.call(
method=AlgoDices.book_die_roll,
Expand All @@ -87,8 +88,10 @@ def main():

elif args["roll"]:
current_round = testnet.algod().status()["last-round"]
booked_round = algo_dices.get_account_state(user_address)["commitment_round"]
rounds_left = booked_round + 8 - current_round
booked_round = algo_dices.get_account_state(user_address)[
AlgoDices.randomness_round.key.byte_str[1:-1]
]
rounds_left = booked_round + RANDOMNESS_BEACON_DELAY - current_round
if rounds_left > 0:
print(f" --- ⏳ {rounds_left} round left to reveal die's roll...")
else:
Expand Down

0 comments on commit a4897dd

Please sign in to comment.