getSubscribersCount static method

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

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

static Future<int> getSubscribersCount(String topic,
    {Uint8List? subscriberHashPrefix, RpcConfig? config}) async {
  try {
    int count = await _methodChannel.invokeMethod('getSubscribersCount', {
      'topic': topic,
      'subscriberHashPrefix': subscriberHashPrefix,
      'seedRpc': config?.seedRPCServerAddr?.isNotEmpty == true
          ? config?.seedRPCServerAddr
          : [DEFAULT_SEED_RPC_SERVER],
    });
    return count;
  } catch (e) {
    rethrow;
  }
}