getTransactionChain method
Query the network to find transaction chains from a map of addresses and pagingAddress
Returns the content scalar type represents transaction content List<Transaction>. Depending if the content can displayed it will be rendered as plain text otherwise in hexadecimal
Implementation
Future<Map<String, List<Transaction>>> getTransactionChain(
Map<String, String> addresses, {
String request = Transaction.kTransactionQueryAllFields,
bool orderAsc = true,
int? fromCriteria,
}) async {
if (addresses.isEmpty) {
return {};
}
final order = orderAsc == true ? 'ASC ' : 'DESC';
final fragment = 'fragment fields on Transaction { $request }';
final body = StringBuffer()..write('query { ');
// TODO(reddwarf03): Not good the '_' system to define alias but address format is not accepted by graphQL
addresses.forEach((key, value) {
body.write(' _$key: transactionChain(address:"$key" ');
body.write(' order: $order ');
if (value.isNotEmpty) {
body.write(' pagingAddress:"$value"');
}
if (fromCriteria != null) {
body.write(' from:$fromCriteria');
}
body.write(') { ...fields }');
});
body.write('} $fragment');
final result = await _client
.withLogger(
'getTransactionChain',
)
.query(
QueryOptions(
document: gql(body.toString()),
parserFn: (object) {
final transactions = object.mapValues(
(transactions) => (transactions as List<dynamic>)
.map(
(transaction) => Transaction.fromNodeRPC(
transaction as Map<String, dynamic>,
),
)
.toList(),
keysToIgnore: _responseKeysToIgnore,
);
return removeAliasPrefix<List<Transaction>>(transactions) ?? {};
},
),
);
manageLinkException(result);
return result.parsedData ?? {};
}