|
|
|
@ -30,7 +30,7 @@ import '../../helper.dart';
|
|
|
|
|
|
|
|
|
|
int rpcID = 0;
|
|
|
|
|
|
|
|
|
|
Future<http.Response> rpc(String method) async {
|
|
|
|
|
Future<http.Response> rpcHTTP(String method) async {
|
|
|
|
|
final url = 'http://${host}:${config.port}/json_rpc';
|
|
|
|
|
|
|
|
|
|
rpcID += 1;
|
|
|
|
@ -58,8 +58,8 @@ Future<http.Response> rpc(String method) async {
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<dynamic> rpcDynamic(String method, {String field}) async {
|
|
|
|
|
final response = await rpc(method);
|
|
|
|
|
Future<dynamic> rpc(String method, {String field}) async {
|
|
|
|
|
final response = await rpcHTTP(method);
|
|
|
|
|
|
|
|
|
|
if (response == null) return null;
|
|
|
|
|
|
|
|
|
@ -74,76 +74,52 @@ Future<dynamic> rpcDynamic(String method, {String field}) async {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<String> rpcString(String method, {String field}) async {
|
|
|
|
|
final _field = await rpcDynamic(method, field: field);
|
|
|
|
|
final _field = await rpc(method, field: field);
|
|
|
|
|
return pretty(_field);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<http.Response> syncInfo() async => rpc('sync_info');
|
|
|
|
|
Future<String> syncInfoString() async => rpcString('sync_info');
|
|
|
|
|
Future<http.Response> syncInfo() => rpc('sync_info');
|
|
|
|
|
Future<String> syncInfoString() => rpcString('sync_info');
|
|
|
|
|
|
|
|
|
|
Future<int> targetHeight() => rpcDynamic('sync_info', field: 'target_height');
|
|
|
|
|
Future<dynamic> targetHeight() => rpc('sync_info', field: 'target_height');
|
|
|
|
|
Future<dynamic> height() => rpc('sync_info', field: 'height');
|
|
|
|
|
|
|
|
|
|
Future<int> height() async {
|
|
|
|
|
final response = await syncInfo();
|
|
|
|
|
|
|
|
|
|
if (response == null) return -1;
|
|
|
|
|
Future<http.Response> getInfo() => rpc('get_info');
|
|
|
|
|
Future<String> getInfoString() => rpcString('get_info');
|
|
|
|
|
|
|
|
|
|
// print('Response status: ${response.statusCode}');
|
|
|
|
|
if (response.statusCode != 200) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else {
|
|
|
|
|
final responseBody = json.decode(response.body)['result'];
|
|
|
|
|
return responseBody["height"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<http.Response> getInfo() async => rpc('get_info');
|
|
|
|
|
Future<String> getInfoString() async => rpcString('get_info');
|
|
|
|
|
|
|
|
|
|
Future<bool> offline() async {
|
|
|
|
|
final response = await getInfo();
|
|
|
|
|
|
|
|
|
|
if (response == null) return true;
|
|
|
|
|
|
|
|
|
|
// print('Response status: ${response.statusCode}');
|
|
|
|
|
if (response.statusCode != 200) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
final responseBody = json.decode(response.body)['result'];
|
|
|
|
|
return responseBody["offline"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Future<dynamic> offline() => rpc('get_info', field: 'offline');
|
|
|
|
|
|
|
|
|
|
Future<int> outgoingConnectionsCount() async {
|
|
|
|
|
final response = await getInfo();
|
|
|
|
|
Future<dynamic> outgoingConnectionsCount() => rpc('get_info', field: 'outgoing_connections_count');
|
|
|
|
|
Future<dynamic> incomingConnectionsCount() => rpc('get_info', field: 'incoming_connections_count');
|
|
|
|
|
|
|
|
|
|
if (response == null) return -1;
|
|
|
|
|
// Future<http.Response>> getConnections() async => rpcHTTP('get_connections', field: 'connections');
|
|
|
|
|
Future<List<dynamic>> getConnectionsSimple() async {
|
|
|
|
|
final List<dynamic> _connections = await rpc('get_connections', field: 'connections');
|
|
|
|
|
|
|
|
|
|
// print('Response status: ${response.statusCode}');
|
|
|
|
|
if (response.statusCode != 200) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else {
|
|
|
|
|
final responseBody = json.decode(response.body)['result'];
|
|
|
|
|
return responseBody["outgoing_connections_count"];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<int> incomingConnectionsCount() async {
|
|
|
|
|
final response = await getInfo();
|
|
|
|
|
|
|
|
|
|
if (response == null) return -1;
|
|
|
|
|
|
|
|
|
|
// print('Response status: ${response.statusCode}');
|
|
|
|
|
if (response.statusCode != 200) {
|
|
|
|
|
return -1;
|
|
|
|
|
} else {
|
|
|
|
|
final responseBody = json.decode(response.body)['result'];
|
|
|
|
|
return responseBody["incoming_connections_count"];
|
|
|
|
|
}
|
|
|
|
|
return _connections.map
|
|
|
|
|
(
|
|
|
|
|
(x) {
|
|
|
|
|
const _remove =
|
|
|
|
|
[
|
|
|
|
|
// 'tx_blob',
|
|
|
|
|
// 'tx_json',
|
|
|
|
|
// 'last_failed_id_hash',
|
|
|
|
|
// 'max_used_block_id_hash',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return x.map
|
|
|
|
|
(
|
|
|
|
|
(k, v) {
|
|
|
|
|
if (k == 'connection_id') {
|
|
|
|
|
return MapEntry(k, v.substring(0, 12) + '...');
|
|
|
|
|
} else {
|
|
|
|
|
return MapEntry(k, v);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
).toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Future<http.Response>> getConnections() async => rpc('get_connections', field: 'connections');
|
|
|
|
|
Future<String> getConnectionsString() async => rpcString('get_connections', field: 'connections');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|