decode method

List decode(
  1. List<int> data,
  2. List<List<int>?> topics
)

Decodes the event data from the encoded bytes and topics.

Implementation

List<dynamic> decode(List<int> data, List<List<int>?> topics) {
  final List<dynamic> result = [];
  final noIndexed = inputs.where((e) {
    return !e.indexed;
  }).toList();
  final indexed = inputs.where((e) {
    return e.indexed;
  }).toList();
  int nonIndexedCounter =
      topics.length > indexed.length ? topics.length - indexed.length : 0;
  int noneIndexCounter = 0;
  final abi = AbiParameter(name: "", type: "tuple", components: noIndexed)
      .decode(data);
  for (int i = 0; i < inputs.length; i++) {
    final input = inputs.elementAt(i);
    if (input.indexed) {
      final topicBytes = topics.elementAt(nonIndexedCounter);
      nonIndexedCounter++;
      if (topicBytes == null || input.isDynamic) {
        result.add(topicBytes);
        continue;
      }
      final decode = input.decode(topicBytes).result;
      result.add(decode);
    } else {
      result.add(abi.result[noneIndexCounter]);
      noneIndexCounter++;
    }
  }

  return result;
}