def deserialize_varint(data, pos=0): ensure_enough_data(data, pos, VARINT_SIZE_RANGE_IN_BYTES[0]) next_pos = pos + 1 first_byte = int.from_bytes(data[pos:next_pos], byteorder='little', signed=False) if first_byte <= 0xfc: return (first_byte, next_pos) if first_byte == 0xfd: return deserialize_uint16(data, next_pos) if first_byte == 0xfe: return deserialize_uint32(data, next_pos) if first_byte == 0xff: return deserialize_uint64(data, next_pos)
def deserialize_int64(data, pos=0): ensure_enough_data(data, pos, INT64_SIZE_IN_BYTES) next_pos = pos + INT64_SIZE_IN_BYTES res = int.from_bytes(data[pos : next_pos], byteorder="little", signed=True) return res, next_pos
def deserialize_txinput(data, pos=0): ensure_enough_data(data, pos, TXINPUT_SIZE_RANGE_IN_BYTES[0]) (outpoint, pos) = deserialize_outpoint(data, pos) (unlocking_script, pos) = deserialize_script(data, pos) (sequence_no, pos) = deserialize_uint32(data, pos) return (make_txinput(outpoint, unlocking_script, sequence_no), pos)
def deserialize_uint16(data, pos=0): ensure_enough_data(data, pos, UINT16_SIZE_IN_BYTES) next_pos = pos + UINT16_SIZE_IN_BYTES res = int.from_bytes(data[pos:next_pos], byteorder='little', signed=False) return (res, next_pos)