decodeEvents method

DecodedBlockEvents decodeEvents(
  1. RawBlockEvents rawBlockEvents
)

Implementation

DecodedBlockEvents decodeEvents(RawBlockEvents rawBlockEvents) {
  final blockNumber = rawBlockEvents.blockNumber;

  final VersionDescription? versionDescription =
      getVersionDescription(blockNumber);

  // Check if this is not empty, throw Exception if it is.
  if (versionDescription == null) {
    throw BlockNotFoundException(blockNumber);
  }

  assertion(blockNumber >= versionDescription.blockNumber);

  final input = Input.fromHex(rawBlockEvents.events);

  final List<dynamic> events =
      versionDescription.chainInfo.scaleCodec.decode('EventCodec', input);

  // Check if the event is fully consumed
  input.assertEndOfDataReached(' At block: $blockNumber');

  return DecodedBlockEvents(
    blockNumber: blockNumber,
    events: events,
  );
}