getTransactionChain method
Query the network to find a transaction chain
@param {String} The address scalar type represents a cryptographic hash used in the ArchEthic network with an identification byte to specify from which algorithm the hash was generated. The Hash appears in a JSON response as Base16 formatted string. The parsed hash will be converted to a binary and any invalid hash with an invalid algorithm or invalid size will be rejected
@param {int} The page
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<List<Transaction>> getTransactionChain(
String address, int page) async {
final Completer<List<Transaction>> _completer =
Completer<List<Transaction>>();
TransactionChainResponse? transactionChainResponse =
TransactionChainResponse();
List<Transaction> transactionChain =
List<Transaction>.empty(growable: true);
final Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Accept': 'application/json',
};
final String _body =
'{"query":"query { transactionChain(address: \\"$address\\", page: $page) { ' +
Transaction.getQLFields() +
' } }"}';
logger.d('getTransactionChain: requestHttp.body=' + _body);
try {
final http.Response responseHttp = await http.post(
Uri.parse(endpoint! + '/api'),
body: _body,
headers: requestHeaders);
logger.d('getTransactionChain: responseHttp.body=' + responseHttp.body);
if (responseHttp.statusCode == 200) {
transactionChainResponse =
transactionChainResponseFromJson(responseHttp.body);
if (transactionChainResponse.data != null) {
transactionChain = transactionChainResponse.data!.transactionChain!;
}
}
} catch (e) {
logger.d('getTransactionChain: error=' + e.toString());
}
_completer.complete(transactionChain);
return _completer.future;
}