getToken method

Future<Map<String, Token>> getToken(
  1. List<String> addresses, {
  2. String request = 'genesis, name, id, supply, symbol, type, properties, decimals, collection, ownerships { authorizedPublicKeys { encryptedSecretKey, publicKey }, secret }',
})

Query the network to find a token's data from a list of token addresses

Implementation

Future<Map<String, Token>> getToken(
  List<String> addresses, {
  String request =
      'genesis, name, id, supply, symbol, type, properties, decimals, collection, ownerships { authorizedPublicKeys { encryptedSecretKey,  publicKey }, secret }',
}) async {
  if (addresses.isEmpty) {
    return {};
  }

  final fragment = 'fragment fields on Token { $request }';
  final body = StringBuffer()..write('query { ');
  for (final address in addresses) {
    body.write(
      ' _$address: token(address:"$address") { ...fields }',
    );
  }
  body.write(' } $fragment');

  final result = await _client
      .withLogger(
        'getToken',
        logsActivation: logsActivation,
      )
      .query(
        QueryOptions(
          document: gql(body.toString()),
          parserFn: (json) {
            final tokens = json.mapValues(
              (value) {
                if (value != null) {
                  return Token.fromJson(value as Map<String, dynamic>);
                }
              },
              keysToIgnore: _responseKeysToIgnore,
            );
            return removeAliasPrefix<Token>(tokens) ?? {};
          },
        ),
      );
  manageLinkException(result);

  return result.parsedData ?? {};
}