Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix base exception #3

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 30 additions & 28 deletions authorization/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,22 +269,24 @@ def submit_game_proposal(self, _gamedata: str) -> None:
revert(f'50 ICX is required for submitting game proposal')
metadata = json_loads(_gamedata)
self._check_game_metadata(metadata)
score_at_address = self.create_interface_score(Address.from_string(metadata['scoreAddress']),
ScoreOwnerInterface)
scoreAddress = metadata['scoreAddress']
game_address = Address.from_string(scoreAddress)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make a single variable

score_at_address = self.create_interface_score(game_address, ScoreOwnerInterface)

if self.msg.sender != score_at_address.get_score_owner():
revert('Owner not matched')
self.ProposalSubmitted(self.msg.sender, Address.from_string(metadata['scoreAddress']))
if Address.from_string(metadata['scoreAddress']) in self._proposal_list:

self.ProposalSubmitted(self.msg.sender, game_address)
if game_address in self._proposal_list:
revert(f'Already listed scoreAddress in the proposal list.')
self._proposal_list.put(Address.from_string(metadata['scoreAddress']))
self._owner_data[Address.from_string(metadata['scoreAddress'])] = self.msg.sender
self._proposal_list.put(game_address)
self._owner_data[game_address] = self.msg.sender

self._status_data[Address.from_string(metadata['scoreAddress'])] = 'waiting'
self._proposal_data[Address.from_string(metadata['scoreAddress'])] = _gamedata
self._status_data[game_address] = 'waiting'
self._proposal_data[game_address] = _gamedata

if self._apply_watch_dog_method.get():
self._maximum_payouts[Address.from_string(metadata['scoreAddress'])] = metadata['maxPayout']
self._maximum_payouts[game_address] = metadata['maxPayout']

@external
def set_game_status(self, _status: str, _scoreAddress: Address) -> None:
Expand All @@ -300,14 +302,15 @@ def set_game_status(self, _status: str, _scoreAddress: Address) -> None:
revert('Sender not an admin')
if _status not in self.STATUS_TYPE:
revert('Invalid status')
if _status == 'gameRejected' and self._status_data[_scoreAddress] != 'gameReady':
revert(f'This game cannot be rejected from state {self._status_data[_scoreAddress]}')
if _status == 'gameApproved' and not (self._status_data[_scoreAddress] == 'gameReady'
or self._status_data[_scoreAddress] == 'gameSuspended'):
revert(f'This game cannot be approved from state {self._status_data[_scoreAddress]}')
if _status == 'gameSuspended' and self._status_data[_scoreAddress] != 'gameApproved':
gameAddress = self._status_data[_scoreAddress]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change variable name to gameStatus

if _status == 'gameRejected' and gameAddress != 'gameReady':
revert(f'This game cannot be rejected from state {gameAddress}')
if _status == 'gameApproved' and not (gameAddress == 'gameReady'
or gameAddress == 'gameSuspended'):
revert(f'This game cannot be approved from state {gameAddress}')
if _status == 'gameSuspended' and gameAddress != 'gameApproved':
revert('Only approved games may be suspended.')
if _status == 'gameDeleted' and self._status_data[_scoreAddress] != 'gameSuspended':
if _status == 'gameDeleted' and gameAddress != 'gameSuspended':
revert('Only suspended games may be deleted.')

self._status_data[_scoreAddress] = _status
Expand Down Expand Up @@ -369,8 +372,8 @@ def _check_game_metadata(self, _metadata: dict):
revWalletAddress = Address.from_string(revwallet)
if revWalletAddress.is_contract:
revert('Not a wallet address')
except BaseException as e:
Logger.debug(f'Failed. Exception: {e}', TAG)
except Exception:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make revert message clear

Logger.debug(f'Failed.', TAG)
revert('Invalid address')

@external
Expand Down Expand Up @@ -425,17 +428,16 @@ def accumulate_daily_payouts(self, game: Address, payout: int) -> bool:
day = (self.now() // U_SECONDS_DAY)

if self._apply_watch_dog_method.get():
try:
if payout > self._maximum_payouts[game]:
revert(f'Preventing Overpayment. Requested payout: {payout}. MaxPayout for this game: '
f'{self._maximum_payouts[game]}. {TAG}')

if self._payouts[day][game] + payout - self._wagers[day][game] >= self._maximum_loss.get():
revert(f'Limit loss. MaxLoss: {self._maximum_loss.get()}. Loss Incurred if payout: '
f'{self._payouts[day][game] + payout - self._wagers[day][game]}, {TAG}')
except BaseException as e:
if payout > self._maximum_payouts[game]:
self._status_data[game] = 'gameSuspended'
self.GameSuspended(game, f'To prevent overpayment. Requested payout: {payout}. '
f'MaxPayout: {self._maximum_payouts[game]}. {TAG}')
return False

if self._payouts[day][game] + payout - self._wagers[day][game] >= self._maximum_loss.get():
self._status_data[game] = 'gameSuspended'
self.GameSuspended(game, str(e))
self.GameSuspended(game, f'To limit loss. MaxLoss: {self._maximum_loss.get()}. '
f'Loss Incurred if payout: {self._payouts[day][game] + payout - self._wagers[day][game]}, {TAG}')
return False

self._payouts[day][game] += payout
Expand Down