transaction method

The transaction endpoint enables clients to query/validate a specific transaction at an anchor. Anchors must ensure that the SEP-10 JWT included in the request contains the Stellar account and optional memo value used when making the original deposit or withdraw request that resulted in the transaction requested using this endpoint. Throws a RequestErrorException if the server responds with an error and corresponding error message. Throws a SEP24AuthenticationRequiredException if the server responds with an authentication_required error. Throws a SEP24TransactionNotFoundException if the server could not find the transaction.

Implementation

Future<SEP24TransactionResponse> transaction(
    SEP24TransactionRequest request) async {
  Uri serverURI =
      Util.appendEndpointToUrl(_transferServiceAddress, 'transaction');

  _AnchorTransactionRequestBuilder requestBuilder =
      _AnchorTransactionRequestBuilder(httpClient, serverURI);

  final Map<String, String> queryParams = {};

  if (request.id != null) {
    queryParams["id"] = request.id!;
  }

  if (request.stellarTransactionId != null) {
    queryParams["stellar_transaction_id"] = request.stellarTransactionId!;
  }

  if (request.externalTransactionId != null) {
    queryParams["external_transaction_id"] = request.externalTransactionId!;
  }

  if (request.lang != null) {
    queryParams["lang"] = request.lang!;
  }

  SEP24TransactionResponse response;
  try {
    response = await requestBuilder
        .forQueryParameters(queryParams)
        .execute(request.jwt);
  } on ErrorResponse catch (e) {
    if (e.code == 404) {
      throw SEP24TransactionNotFoundException();
    } else if (e.code == 403) {
      _handleForbiddenResponse(e);
    } else if (e.code != 200) {
      _handleErrorResponse(e);
    }
    throw e;
  }
  return response;
}