예제 #1
0
def coerce_to_hex(x):
    if isinstance(x, int):
        return util.hexlify(zpad(rlp.int_to_big_endian(x), 20))
    elif len(x) == 40 or len(x) == 0:
        return x
    else:
        return util.hexlify(zpad(x, 20)[-20:])
예제 #2
0
def encode_int(v):
    # encodes an integer into serialization
    if not isinstance(v, int) or v < 0 or v >= 2 ** 256:
        raise Exception("Integer invalid or out of range")
    return rlp.int_to_big_endian(v)