How to use the iconservice.base.exception.InvalidRequestException function in iconservice

To help you get started, we’ve selected a few iconservice examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github icon-project / icon-service / tests / unit_test / iconscore / test_icon_score_step.py View on Github external
def test_invalid_get_deploy_content_size_greater_than_revision_three(self,
                                                                         mock_get_data_size_recursively,
                                                                         revision, input_data):
        with pytest.raises(InvalidRequestException) as e:
            get_deploy_content_size(revision, input_data)

        assert 'Invalid content data' == e.value.args[0]
        mock_get_data_size_recursively.assert_not_called()
github icon-project / icon-service / iconservice / fee / engine.py View on Github external
def _withdraw_deposit(self, context: 'IconScoreContext', deposit_id: bytes):
        if context.msg.value != 0:
            raise InvalidRequestException(f'Invalid value: must be zero')
        withdrawal_amount, penalty = context.engine.fee.withdraw_deposit(
            context, context.msg.sender, deposit_id, context.block.height)

        event_log_args = [deposit_id, context.msg.sender, withdrawal_amount, penalty]
        self._emit_event(context, DepositHandler.EventType.WITHDRAW, event_log_args)
github icon-project / icon-service / iconservice / iconscore / icon_pre_validator.py View on Github external
def _validate_deploy_transaction(self, context: "IconScoreContext", params: dict):
        to: "Address" = params["to"]

        value: int = params.get("value", 0)
        if value != 0:
            raise InvalidParamsException("value must be 0 in a deploy transaction")

        if self._is_inactive_score(context, to):
            raise InvalidRequestException(f"{to} is an inactive SCORE")

        data = params.get("data", None)
        if not isinstance(data, dict):
            raise InvalidRequestException("Data not found")

        if "contentType" not in data:
            raise InvalidRequestException("ContentType not found")

        if "content" not in data:
            raise InvalidRequestException("Content not found")

        self._validate_new_score_address_on_deploy_transaction(context, params)
github icon-project / icon-service / iconservice / fee / engine.py View on Github external
def _check_score_ownership(self, context: 'IconScoreContext', sender: 'Address', score_address: 'Address') -> None:
        deploy_info = self._get_score_deploy_info(context, score_address)

        if deploy_info.owner != sender:
            raise InvalidRequestException('Invalid SCORE owner')
github icon-project / icon-service / iconservice / iconscore / icon_pre_validator.py View on Github external
"""Validate deposit transaction

        :param params:
        :return:
        """
        to: "Address" = params["to"]

        if self._is_inactive_score(context, to):
            raise InvalidRequestException(f"{to} is inactive SCORE")

        data = params.get("data", None)
        if not isinstance(data, dict):
            raise InvalidRequestException("Data not found")

        if "action" not in data:
            raise InvalidRequestException("Action not found")
github icon-project / icon-service / iconservice / iiss / engine.py View on Github external
context: 'IconScoreContext',
                                      sender: 'Address', delegating: int,
                                      cached_accounts: Dict['Address', Tuple['Account', int]]):
        """

        :param context:
        :param sender:
        :param cached_accounts:
        :param delegating:
        :return:
        """
        account: 'Account' = context.storage.icx.get_account(context, sender, Intent.ALL)
        assert isinstance(account, Account)

        if account.voting_weight < delegating:
            raise InvalidRequestException("Not enough voting power")

        cached_accounts[sender] = account, 0
github icon-project / icon-service / iconservice / iconscore / icon_pre_validator.py View on Github external
def _validate_call_transaction(self, context: "IconScoreContext", params: dict):
        """Validate call transaction
        It is not icx_call

        :param params:
        :return:
        """
        to: "Address" = params["to"]

        if self._is_inactive_score(context, to):
            raise InvalidRequestException(f"{to} is inactive SCORE")

        data = params.get("data", None)
        if not isinstance(data, dict):
            raise InvalidRequestException("Data not found")

        if "method" not in data:
            raise InvalidRequestException("Method not found")
github icon-project / icon-service / iconservice / iconscore / icon_score_step.py View on Github external
def apply_step(self, step_type: StepType, count: int) -> int:
        """ Increases steps for given step cost
        """

        if step_type == StepType.CONTRACT_CALL:
            self._external_call_count += 1
            if self._external_call_count > MAX_EXTERNAL_CALL_COUNT:
                raise InvalidRequestException('Too many external calls')

        step: int = self._step_costs.get(step_type, 0) * count

        return self.consume_step(step_type, step)
github icon-project / icon-service / iconservice / iconscore / icon_pre_validator.py View on Github external
def _validate_deploy_transaction(self, context: "IconScoreContext", params: dict):
        to: "Address" = params["to"]

        value: int = params.get("value", 0)
        if value != 0:
            raise InvalidParamsException("value must be 0 in a deploy transaction")

        if self._is_inactive_score(context, to):
            raise InvalidRequestException(f"{to} is an inactive SCORE")

        data = params.get("data", None)
        if not isinstance(data, dict):
            raise InvalidRequestException("Data not found")

        if "contentType" not in data:
            raise InvalidRequestException("ContentType not found")

        if "content" not in data:
            raise InvalidRequestException("Content not found")

        self._validate_new_score_address_on_deploy_transaction(context, params)
github icon-project / icon-service / iconservice / iconscore / icon_pre_validator.py View on Github external
def _check_minimum_step(params: dict, minimum_step: int):
        step_limit = params.get("stepLimit", 0)
        if step_limit < minimum_step:
            raise InvalidRequestException("Step limit too low")