subscribeEvents method

Future<StreamSubscription<Events>> subscribeEvents(
  1. BlockHash at,
  2. dynamic onData(
    1. Events
    )
)

Implementation

Future<StreamSubscription<Events>> subscribeEvents(
    BlockHash at, Function(Events) onData) async {
  latestRuntimeMetadata = await getMetadata();

  final subscription = await _provider.subscribe('state_subscribeStorage', [
    ['0x${hex.encode(at)}']
  ], onCancel: (subscription) async {
    await _provider.send('state_unsubscribeStorage', [subscription]);
  });

  return subscription.stream.map((response) {
    return Events.fromJson(response.result, latestRuntimeMetadata.chainInfo);
  }).listen(onData);
}