getSubscribersCount method

Future<int> getSubscribersCount({
  1. required String topic,
  2. Uint8List? subscriberHashPrefix,
})

getSubscribersCount RPC returns the number of subscribers of a topic (not including txPool). If subscriberHashPrefix is not empty, only subscriber whose sha256(pubkey+identifier) contains this prefix will be counted. Each prefix byte will reduce result count to about 1/256, and also reduce response time to about 1/256 if there are a lot of subscribers. This is a good way to sample subscribers randomly with low cost.

Implementation

Future<int> getSubscribersCount({required String topic, Uint8List? subscriberHashPrefix}) async {
  try {
    int count = await _methodChannel.invokeMethod('getSubscribersCount', {
      '_id': this.address,
      'topic': topic,
      'subscriberHashPrefix': subscriberHashPrefix,
    });
    return count;
  } catch (e) {
    rethrow;
  }
}