getTransactionContent method

Future<String> getTransactionContent(
  1. String address
)

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 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) 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 }} }"}';
  logger.d('getTransactionContent: requestHttp.body=' + _body);

  try {
    final http.Response responseHttp = await http.post(
        Uri.parse(endpoint! + '/api'),
        body: _body,
        headers: requestHeaders);
    logger.d('getTransactionContent: responseHttp.body=' + 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) {
    logger.d('getTransactionContent: error=' + e.toString());
  }

  _completer.complete(_content);
  return _completer.future;
}