Пример #1
0
def check_param_num(args, expected, needEqual=False):
    """
    check param num
    """
    if needEqual is False:
        if len(args) < expected:
            raise ArgumentsError(("invalid arguments, expected num >= {},"
                                  "real num: {}").format(expected, len(args)))
    else:
        if len(args) != expected:
            raise ArgumentsError(("invalid arguments, expected num {},"
                                  "real num: {}").format(expected, len(args)))
Пример #2
0
 def getSystemConfigByKey(self, key):
     if key not in BcosClient.sysconfig_keys:
         raise ArgumentsError("invalid system key, must be {}"
                              .format(BcosClient.sysconfig_keys))
     cmd = "getSystemConfigByKey"
     params = [self.groupid, key]
     return self.common_request(cmd, params)
Пример #3
0
def check_nodeId(nodeId):
    """
    check nodeId
    """
    nodeId_len = 128
    if len(nodeId) != nodeId_len:
        raise ArgumentsError("invalid nodeId, must be {} bytes".format(nodeId_len))
    check_word(nodeId)
Пример #4
0
def check_word(word):
    """
    check world
    """
    result = re.findall(r'([0x]*[a-fA-F0-9]*)', word)
    if result[0] != word:
        raise ArgumentsError(("invalid input {},"
                              " must be in 'a-f' or '0-9' or 'A-F'")
                             .format(word))
Пример #5
0
def check_and_format_address(address):
    """
    check address
    """
    try:
        formatted_address = to_checksum_address(address)
        return formatted_address
    except Exception as e:
        raise ArgumentsError("invalid address {}, reason: {}"
                             .format(address, e))
Пример #6
0
def check_int_range(number_str, limit=max_block_number):
    """
    check integer range
    """
    try:
        if isinstance(number_str, int):
            return number_str
        number = 0
        if isinstance(number_str, str):
            if number_str.startswith("0x"):
                number = int(number_str, 16)
            else:
                number = int(number_str)
        else:
            number = number_str
        if number > limit or number < 0:
            raise ArgumentsError(("invalid input: {},"
                                  " must between 0 and {}").
                                 format(number, limit))
        return number
    except Exception as e:
        raise ArgumentsError("invalid input:{}, error info: {}".format(number, e))
Пример #7
0
def check_and_trans_to_bool(param):
    """
    check bool
    """
    if isinstance(param, bool):
        return param
    true_str = "true"
    false_str = "false"
    if isinstance(param, str):
        if param.lower() == true_str:
            return True
        if param.lower() == false_str:
            return False
    raise ArgumentsError(("invalid input: {}, "
                          "must be true/True/false/False").format(param))
Пример #8
0
def check_address_startwith_0x(address):
    """
    check the address: must be starts with 0x
    """
    if address.startswith("0x") is False:
        raise ArgumentsError("invalid address {}, must be start with 0x".format(address))