getTransactionContent method Null safety
Query the network to find a transaction @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 {String} The endpoint Returns the content scalar type represents transaction content. Depending if the content can displayed it will be rendered as plain text otherwise in hexadecimal
Implementation
Future<String> getTransactionContent(String address, String endpoint) async {
final Completer<String> _completer = Completer<String>();
String _content = '';
TransactionContentResponse? transactionContentResponse =
TransactionContentResponse();
final Map<String, String> requestHeaders = {
'Content-type': 'application/json',
'Accept': 'application/json',
};
final String _body =
'{"query":"query { transaction(address: \\"$address\\") { data { content }} }"}';
print(_body);
try {
final http.Response responseHttp = await http.post(
Uri.parse(endpoint + '/api'),
body: _body,
headers: requestHeaders);
print(responseHttp.body);
if (responseHttp.statusCode == 200) {
transactionContentResponse =
transactionContentResponseFromJson(responseHttp.body);
if (transactionContentResponse.data != null &&
transactionContentResponse.data!.transaction != null &&
transactionContentResponse.data!.transaction!.data != null) {
_content =
transactionContentResponse.data!.transaction!.data!.content!;
}
}
} catch (e) {
print('error: ' + e.toString());
}
_completer.complete(_content);
return _completer.future;
}