How to use the iconservice.base.exception.InvalidParamsException 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 / t-bears / tbears / libs / scoretest / patch / context.py View on Github external
def get_icon_score(address: 'Address'):
    """This method will be called when SCORE call get_icon_score method while test using score-unittest-framework

    :param address: address of SCORE
    :return: SCORE
    """
    if address.is_contract is False:
        raise InvalidParamsException(f"{address} is not SCORE")
    elif isinstance(score_mapper.get(address, None), IconScoreBase) is False:
        raise InvalidParamsException(f"{address} is not active SCORE")
    return score_mapper[address]
github icon-project / icon-service / iconservice / icx / icx_account.py View on Github external
def deposit(self, value: int):
        if self.coin_part is None:
            raise InvalidParamsException("Failed to delegation: InvalidAccount")

        self.coin_part.deposit(value)
github icon-project / icon-service / iconservice / deploy / engine.py View on Github external
def _initialize_score(
        deploy_type: DeployType, score: "IconScoreBase", params: dict
    ):
        """Call on_install() or on_update() of a SCORE
        only once when installing or updating it
        :param deploy_type: DeployType.INSTALL or DeployType.UPDATE
        :param score: SCORE to install or update
        :param params: parameters passed to on_install or on_update()
        """
        if deploy_type == DeployType.INSTALL:
            on_init = score.on_install
        elif deploy_type == DeployType.UPDATE:
            on_init = score.on_update
        else:
            raise InvalidParamsException(f"Invalid deployType: {deploy_type}")

        TypeConverter.adjust_params_to_method(on_init, params)
        on_init(**params)
github icon-project / icon-service / iconservice / iiss / engine.py View on Github external
def _put_end_calc_block_height(cls,
                                   context: 'IconScoreContext'):
        calc_period: int = context.storage.iiss.get_calc_period(context)
        if calc_period is None:
            raise InvalidParamsException("Fail put next calc block height: didn't init yet")
        context.storage.iiss.put_end_block_height_of_calc(context, context.block.height + calc_period)
github icon-project / icon-service / iconservice / iconscore / icon_pre_validator.py View on Github external
)

                deploy_info = context.storage.deploy.get_deploy_info(
                    context, score_address
                )
                if deploy_info is not None:
                    raise InvalidRequestException(
                        f"SCORE address already in use: {score_address}"
                    )
            elif content_type == "application/tbears":
                pass
            else:
                raise InvalidRequestException(f"Invalid contentType: {content_type}")

        except KeyError as ke:
            raise InvalidParamsException(f"Invalid params: {ke}")
        except BaseException as e:
            raise e
github icon-project / icon-service / iconservice / iiss / engine.py View on Github external
def _put_end_calc_block_height(cls,
                                   context: 'IconScoreContext'):
        calc_period: int = context.storage.iiss.get_calc_period(context)
        if calc_period is None:
            raise InvalidParamsException("Fail put next calc block height: didn't init yet")
        context.storage.iiss.put_end_block_height_of_calc(context, context.block.height + calc_period)
github icon-project / icon-service / iconservice / icon_service_engine.py View on Github external
to: Address = params['to']
        data: dict = params['data']

        assert to == ZERO_SCORE_ADDRESS, "Invalid to Address"

        # Only 'registerPRep' method is allowed to set value
        if context.msg.value > 0 and data.get("method") != "registerPRep":
            raise InvalidParamsException(f"Do not allow to set value in this method: {data.get('method')}")

        if self._check_iiss_process(params):
            context.engine.iiss.invoke(context, data)
        elif self._check_prep_process(params):
            context.engine.prep.invoke(context, data)
        else:
            raise InvalidParamsException("Invalid method")
github icon-project / icon-service / iconservice / base / type_converter.py View on Github external
def _convert_value_int(value: str) -> int:
        if isinstance(value, str):
            if value.startswith("0x") or value.startswith("-0x"):
                return int(value, 16)
            else:
                return int(value)
        else:
            raise InvalidParamsException(
                f"TypeConvert Exception int value :{value}, type: {type(value)}"
            )
github icon-project / icon-service / iconservice / icx / engine.py View on Github external
def transfer(self,
                 context: 'IconScoreContext',
                 from_: 'Address',
                 to: 'Address',
                 amount: int) -> bool:
        if amount < 0:
            raise InvalidParamsException('Amount is less than zero')

        return self._transfer(context, from_, to, amount)
github icon-project / icon-service / iconservice / iconscore / icon_score_engine.py View on Github external
def _validate_score_blacklist(
        context: "IconScoreContext", icon_score_address: "Address"
    ):
        if icon_score_address is None or not icon_score_address.is_contract:
            raise InvalidParamsException(
                f"Invalid score address: ({icon_score_address})"
            )

        IconScoreContextUtil.validate_score_blacklist(context, icon_score_address)