getLastTransaction method

Future<Map<String, Transaction>> getLastTransaction(
  1. List<String> addresses, {
  2. String request = Transaction.kTransactionQueryAllFields,
})

Query the network to find the last transaction from a liste of addresses

Implementation

Future<Map<String, Transaction>> getLastTransaction(
  List<String> addresses, {
  String request = Transaction.kTransactionQueryAllFields,
}) async {
  if (addresses.isEmpty) {
    return {};
  }

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

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

  manageLinkException(result);

  return result.parsedData ?? {};
}