getSubscribers static method

Future<Map<String, dynamic>?> getSubscribers({
  1. required String topic,
  2. int offset = 0,
  3. int limit = 10000,
  4. bool meta = true,
  5. bool txPool = true,
  6. Uint8List? subscriberHashPrefix,
  7. RpcConfig? config,
})

getSubscribers 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<Map<String, dynamic>?> getSubscribers({
  required String topic,
  int offset = 0,
  int limit = 10000,
  bool meta = true,
  bool txPool = true,
  Uint8List? subscriberHashPrefix,
  RpcConfig? config,
}) async {
  try {
    Map? resp = await _methodChannel.invokeMethod('getSubscribers', {
      'topic': topic,
      'offset': offset,
      'limit': limit,
      'meta': meta,
      'txPool': txPool,
      'subscriberHashPrefix': subscriberHashPrefix,
      'seedRpc': config?.seedRPCServerAddr?.isNotEmpty == true
          ? config?.seedRPCServerAddr
          : [DEFAULT_SEED_RPC_SERVER],
    });
    if (resp == null) {
      return null;
    }
    return Map<String, dynamic>.from(resp);
  } catch (e) {
    rethrow;
  }
}