Пример #1
0
def consume_length_prefix(rlp, start):
    """Read a length prefix from an RLP string.

    :param rlp: the rlp string to read from
    :param start: the position at which to start reading
    :returns: a tuple ``(type, length, end)``, where ``type`` is either ``str``
              or ``list`` depending on the type of the following payload,
              ``length`` is the length of the payload in bytes, and ``end`` is
              the position of the first payload byte in the rlp string
    """
    b0 = safe_ord(rlp[start])
    if b0 < 128:  # single byte
        return (str, 1, start)
    elif b0 < 128 + 56:  # short string
        return (str, b0 - 128, start + 1)
    elif b0 < 192:  # long string
        ll = b0 - 128 - 56 + 1
        l_idx = big_endian_to_int(rlp[start + 1:start + 1 + ll])
        return (str, l_idx, start + 1 + ll)
    elif b0 < 192 + 56:  # short list
        return (list, b0 - 192, start + 1)
    else:  # long list
        ll = b0 - 192 - 56 + 1
        l_idx = big_endian_to_int(rlp[start + 1:start + 1 + ll])
        return (list, l_idx, start + 1 + ll)
Пример #2
0
 def __hash__(self):
     return utils.big_endian_to_int(str_to_bytes(self.__repr__()))
Пример #3
0
 def __hash__(self):
     return utils.big_endian_to_int(str_to_bytes(self.__repr__()))