getLastTransaction method
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',
)
.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 ?? {};
}