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,
}) async {
if (addresses.isEmpty) {
return {};
}
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" ');
if (value.isNotEmpty) {
body.write(' pagingAddress:"$value"');
}
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.fromJson(
transaction as Map<String, dynamic>,
),
)
.toList(),
keysToIgnore: _responseKeysToIgnore,
);
return removeAliasPrefix<List<Transaction>>(transactions) ?? {};
},
),
);
if (result.exception?.linkException != null) {
throw ArchethicConnectionException(
result.exception!.linkException.toString(),
);
}
return result.parsedData ?? {};
}