mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2024-12-24 20:39:21 +00:00
27 lines
850 B
Dart
27 lines
850 B
Dart
|
import 'dart:convert';
|
||
|
|
||
|
import 'package:http/http.dart' as http;
|
||
|
import 'package:stackwallet/utilities/logger.dart';
|
||
|
|
||
|
Future<bool> testMoneroNodeConnection(Uri uri) async {
|
||
|
try {
|
||
|
final client = http.Client();
|
||
|
final response = await client
|
||
|
.post(
|
||
|
uri,
|
||
|
headers: {'Content-Type': 'application/json'},
|
||
|
body: jsonEncode({"jsonrpc": "2.0", "id": "0", "method": "get_info"}),
|
||
|
)
|
||
|
.timeout(const Duration(milliseconds: 1200),
|
||
|
onTimeout: () async => http.Response('Error', 408));
|
||
|
|
||
|
final result = jsonDecode(response.body);
|
||
|
// TODO: json decoded without error so assume connection exists?
|
||
|
// or we can check for certain values in the response to decide
|
||
|
return true;
|
||
|
} catch (e, s) {
|
||
|
Logging.instance.log("$e\n$s", level: LogLevel.Warning);
|
||
|
return false;
|
||
|
}
|
||
|
}
|