queryChain static method
Sends a GET request the given url
with optional client
and returns
the JSON deserialized result or null
if some error happens.
This method it's intended to query the chain that exposes JSON responses
with a result
field in where we are interested.
Implementation
static Future<dynamic> queryChain(
Uri url, {
http.Client? client,
}) async {
try {
final responseBody = await query(url, client: client);
// Return the result part of the response
final json = responseBody != null
? jsonDecode(responseBody) as Map<String, dynamic>
: null;
if (json != null && !json.containsKey('result')) {
throw Exception('The JSON response does not contains the "result" key');
}
return json!['result'];
} catch (exception) {
return null;
}
}