getTransactionInputs method

Future<Map<String, List<TransactionInput>>> getTransactionInputs(
  1. List<String> addresses, {
  2. String request = Transaction.kTransactionInputQueryAllFields,
  3. int limit = 0,
  4. int pagingOffset = 0,
})

Query the network to list the transaction inputs from a list of addresses

Implementation

Future<Map<String, List<TransactionInput>>> getTransactionInputs(
  List<String> addresses, {
  String request = Transaction.kTransactionInputQueryAllFields,
  int limit = 0,
  int pagingOffset = 0,
}) async {
  if (addresses.isEmpty) {
    return {};
  }

  final fragment = 'fragment fields on TransactionInput { $request }';
  final body = StringBuffer()..write('query { ');
  for (final address in addresses) {
    body.write(' _$address: transactionInputs(address:"$address" ');
    if (limit > 0) {
      body.write(
        ' limit:$limit ',
      );
    }
    if (pagingOffset > 0) {
      body.write(
        ' pagingOffset:$pagingOffset ',
      );
    }
    body.write(
      '  ) { ...fields } ',
    );
  }
  body.write(' } $fragment');

  final result = await _client
      .withLogger(
        'getTransactionInputs',
        logsActivation: logsActivation,
      )
      .query(
        QueryOptions(
          document: gql(body.toString()),
          parserFn: (json) {
            final transactionInputs = json.mapValues(
              (transactionInputs) => (transactionInputs as List<dynamic>)
                  .map(
                    (transactionInput) => TransactionInput.fromJson(
                      transactionInput as Map<String, dynamic>,
                    ),
                  )
                  .toList(),
              keysToIgnore: _responseKeysToIgnore,
            );
            return removeAliasPrefix<List<TransactionInput>>(
                  transactionInputs,
                ) ??
                {};
          },
        ),
      );

  manageLinkException(result);
  return result.parsedData ?? {};
}