def pack_logging_topics(event_id, args, expected_topics, context):
topics = [event_id]
for pos, expected_topic in enumerate(expected_topics):
typ = expected_topic.typ
arg = args[pos]
value = parse_expr(arg, context)
if isinstance(typ, ByteArrayType) and (isinstance(arg, ast.Str) or (isinstance(arg, ast.Name) and arg.id not in reserved_words)):
if value.typ.maxlen > typ.maxlen:
raise TypeMismatchException("Topic input bytes are to big: %r %r" % (value.typ, typ))
if isinstance(arg, ast.Str):
bytez, bytez_length = string_to_bytes(arg.s)
if len(bytez) > 32:
raise InvalidLiteralException("Can only log a maximum of 32 bytes at a time.")
topics.append(bytes_to_int(bytez + b'\x00' * (32 - bytez_length)))
else:
size = context.vars[arg.id].size
topics.append(byte_array_to_num(value, arg, 'num256', size))
else:
value = unwrap_location(value)
value = base_type_conversion(value, value.typ, typ)
topics.append(value)
return topics
评论列表
文章目录