-
Notifications
You must be signed in to change notification settings - Fork 0
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
iconbetdev420
wants to merge
7
commits into
master
Choose a base branch
from
fix-baseException
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
265c80d
make a variable for optimization purpose
iconbetdev420 1afc669
Remove Python runtime exception as eventlog
iconbetdev420 42d646f
remove baseException and replace with Exception
iconbetdev420 ef4c80a
Reuse the variable for optimization
iconbetdev420 c400cd0
Reuse the variable for optimization
iconbetdev420 73ed879
make revert message understandable.
iconbetdev420 d4e186a
remove `on_update()` variables
iconbetdev420 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
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: | ||
|
@@ -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] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make a single variable