getTransaction method

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

Query the network to find a transaction Returns all informations represent transaction content.

Implementation

Future<Map<String, Transaction>> getTransaction(
  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: transaction(address:"$address") { ...fields }',
    );
  }
  body.write('} $fragment');
  final result = await _client
      .withLogger(
        'getTransaction',
      )
      .query(
        QueryOptions(
          document: gql(body.toString()),
          parserFn: (json) {
            final transactions = json.mapValues(
              (value) {
                if (value != null) {
                  return Transaction.fromJson(value as Map<String, dynamic>);
                }
              },
              keysToIgnore: _responseKeysToIgnore,
            );
            return removeAliasPrefix<Transaction>(transactions) ?? {};
          },
        ),
      );

  manageLinkException(result);

  return result.parsedData ?? {};
}