Skip to content

Commit

Permalink
feat: fetch explorer version
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Mar 14, 2024
1 parent aacc54a commit 49a6881
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions lib/src/network/explorer/explorer_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ class RetryHttpClient {
RetryClient retryClient;

Future<dynamic> _makeHttpRequest(
Future<http.Response> Function(Uri uri, {dynamic body}) requestMethod,
Uri uri,
dynamic data,
) async {
Future<http.Response> Function(Uri uri, {dynamic body}) requestMethod,
Uri uri,
dynamic data,
{bool getVersion = false}) async {
http.Response? response;
try {
response = await requestMethod(uri, body: data);
Expand All @@ -69,6 +69,9 @@ class RetryHttpClient {
}
if (response != null) {
if (response.statusCode ~/ 100 == 2) {
if (getVersion) {
return response.headers["x-version"].toString();
}
dynamic result = convert.jsonDecode(response.body);
if (response.headers["x-pagination"] != null) {
dynamic paginationHeaders =
Expand All @@ -93,14 +96,10 @@ class RetryHttpClient {
}
}

Future<dynamic> get(Uri uri) async {
return _makeHttpRequest(
(Uri uri, {dynamic body}) async {
return await retryClient.get(uri);
},
uri,
null,
);
Future<dynamic> get(Uri uri, {bool getVersion = false}) async {
return _makeHttpRequest((Uri uri, {dynamic body}) async {
return await retryClient.get(uri);
}, uri, null, getVersion: getVersion);
}

Future<dynamic> post(Uri uri, Map<String, dynamic> postData) async {
Expand Down Expand Up @@ -288,6 +287,15 @@ class ExplorerClient {
}
}

Future<String> version() async {
try {
return await client.get(api('status'), getVersion: true);
} on ExplorerException catch (e) {
throw ExplorerException(
code: e.code, message: '{"version": "${e.message}"}');
}
}

Future<dynamic> mempool(
{required String transactionType,
int? startEpoch,
Expand Down

0 comments on commit 49a6881

Please sign in to comment.