decodeEventWithTopics method

List<Object> decodeEventWithTopics(
  1. Uint8List data,
  2. List<Uint8List> topics
)

Implementation

List<Object> decodeEventWithTopics(Uint8List data, List<Uint8List> topics) {
  if (topics.isEmpty) {
    return [];
  }
  try {
    final e = entries.firstWhere((element) =>
        element.type == AbiEntryType.event &&
        topics.first.hex == element.encodeSignature().hex) as EventEntry;
    final result = <Object>[];
    final argTopics = e.anonymous ? topics : topics.skip(1);
    final bytesBuilder = BytesBuilder(copy: false);
    for (final topic in argTopics) {
      bytesBuilder.add(topic);
    }
    final bytes = bytesBuilder.takeBytes();
    final indexed = AbiEntry.decodeList(e.filteredInputs(true), bytes);
    final notIndexed = AbiEntry.decodeList(e.filteredInputs(false), data);
    for (final input in e.inputs) {
      result.add(
        input.indexed ? indexed.removeAt(0) : notIndexed.removeAt(0),
      );
    }
    return result;
  } on StateError {
    throw Exception('Unknown event');
  }
}