You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
229 lines
4.9 KiB
229 lines
4.9 KiB
5 years ago
|
/*
|
||
|
|
||
|
Copyright 2019 fuwa
|
||
|
|
||
|
This file is part of CyberWOW.
|
||
|
|
||
|
CyberWOW is free software: you can redistribute it and/or modify
|
||
|
it under the terms of the GNU General Public License as published by
|
||
|
the Free Software Foundation, either version 3 of the License, or
|
||
|
(at your option) any later version.
|
||
|
|
||
|
CyberWOW is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
GNU General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU General Public License
|
||
|
along with CyberWOW. If not, see <https://www.gnu.org/licenses/>.
|
||
|
|
||
|
*/
|
||
|
|
||
5 years ago
|
import 'package:intl/intl.dart';
|
||
|
|
||
4 years ago
|
import '../../../config.dart' as config;
|
||
|
import '../../../helper.dart';
|
||
5 years ago
|
|
||
5 years ago
|
Map<String, dynamic> getConnectionView(Map<String, dynamic> x) {
|
||
5 years ago
|
const _remove =
|
||
|
[
|
||
|
'address_type',
|
||
|
'connection_id',
|
||
|
'ip',
|
||
|
'local_ip',
|
||
|
'localhost',
|
||
|
'peer_id',
|
||
|
'port',
|
||
|
'recv_count',
|
||
|
'rpc_port',
|
||
|
'send_count',
|
||
|
'support_flags',
|
||
|
|
||
|
// 'avg_download',
|
||
|
// 'avg_upload',
|
||
|
// 'current_download',
|
||
|
// 'current_upload',
|
||
|
'rpc_credits_per_hash',
|
||
|
'state',
|
||
|
'recv_idle_time',
|
||
|
'send_idle_time',
|
||
|
'incoming',
|
||
|
];
|
||
|
|
||
|
final _filteredConn = x..removeWhere
|
||
|
(
|
||
|
(k,v) => _remove.contains(k)
|
||
|
);
|
||
|
|
||
5 years ago
|
final _formattedConn = _filteredConn.map
|
||
5 years ago
|
(
|
||
|
(k, v) {
|
||
|
if (k == 'connection_id') {
|
||
5 years ago
|
return MapEntry(k, trimHash(v));
|
||
5 years ago
|
}
|
||
|
|
||
|
const speedField =
|
||
|
[
|
||
|
'avg_download',
|
||
|
'avg_upload',
|
||
|
'current_download',
|
||
|
'current_upload',
|
||
|
];
|
||
|
if (speedField.contains(k)) {
|
||
|
return MapEntry(k, '${v} kB/s');
|
||
|
}
|
||
|
|
||
|
else if (k == 'live_time') {
|
||
|
final _duration = Duration(seconds: v);
|
||
|
format(Duration d) => d.toString().split('.').first.padLeft(8, "0");
|
||
|
return MapEntry(k, format(_duration));
|
||
|
}
|
||
|
|
||
|
else {
|
||
|
return MapEntry(k, v);
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
|
||
|
final List<String> keys =
|
||
|
[
|
||
4 years ago
|
'host',
|
||
5 years ago
|
'height',
|
||
|
'live_time',
|
||
|
'current_download',
|
||
|
'current_upload',
|
||
|
'avg_download',
|
||
|
'avg_upload',
|
||
|
'pruning_seed',
|
||
|
]
|
||
5 years ago
|
.where((k) => _formattedConn.keys.contains(k))
|
||
5 years ago
|
.toList();
|
||
|
|
||
|
final _sortedConn = {
|
||
5 years ago
|
for (final k in keys) k: _formattedConn[k]
|
||
5 years ago
|
};
|
||
|
|
||
5 years ago
|
final _cleanedUpConn = _sortedConn..removeWhere
|
||
5 years ago
|
(
|
||
|
(k,v) => k == 'pruning_seed' && x[k] == 0
|
||
|
);
|
||
|
|
||
5 years ago
|
return _cleanedUpConn;
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
Map<String, dynamic> simpleHeight(int height, Map<String, dynamic> x) {
|
||
|
return x.map
|
||
|
(
|
||
|
(k, v) {
|
||
|
if (k == 'height') {
|
||
5 years ago
|
if (v == 0) {
|
||
|
return MapEntry(k, '☠');
|
||
|
}
|
||
|
|
||
|
else if (v < height) {
|
||
5 years ago
|
return MapEntry(k, '-${height - v}');
|
||
5 years ago
|
}
|
||
|
|
||
|
else if (v == height) {
|
||
5 years ago
|
return MapEntry(k, '✓');
|
||
5 years ago
|
}
|
||
|
|
||
|
else {
|
||
5 years ago
|
return MapEntry(k, '+${v - height}');
|
||
5 years ago
|
}
|
||
|
}
|
||
|
else {
|
||
|
return MapEntry(k, v);
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
}
|
||
5 years ago
|
|
||
|
Map<String, dynamic> getInfoView(Map<String, dynamic> x) {
|
||
|
const _remove =
|
||
|
[
|
||
|
'difficulty_top64',
|
||
|
'stagenet',
|
||
|
'testnet',
|
||
|
'top_hash',
|
||
|
'update_available',
|
||
|
'was_bootstrap_ever_used',
|
||
|
'bootstrap_daemon_address',
|
||
|
'height_without_bootstrap',
|
||
|
'wide_cumulative_difficulty',
|
||
|
'wide_difficulty',
|
||
|
'cumulative_difficulty_top64',
|
||
|
'credits',
|
||
|
];
|
||
|
|
||
|
final _filteredInfo = x..removeWhere
|
||
|
(
|
||
|
(k,v) => _remove.contains(k)
|
||
|
);
|
||
|
|
||
5 years ago
|
final int _difficulty = _filteredInfo['difficulty'] ?? 0;
|
||
|
final Map<String, double> _hashRate = {'hash_rate': _difficulty / 300};
|
||
5 years ago
|
final Map<String, dynamic> _ammendedInfo = {
|
||
|
..._filteredInfo,
|
||
|
..._hashRate,
|
||
|
};
|
||
|
|
||
|
final _formattedInfo = _ammendedInfo.map
|
||
5 years ago
|
(
|
||
|
(k, v) {
|
||
|
if (k == 'top_block_hash') {
|
||
|
return MapEntry(k, trimHash(v));
|
||
|
}
|
||
|
|
||
|
const sizeField =
|
||
|
[
|
||
|
'block_size_limit',
|
||
|
'block_size_median',
|
||
|
'block_weight_limit',
|
||
|
'block_weight_median',
|
||
|
'difficulty',
|
||
|
'tx_count',
|
||
|
'cumulative_difficulty',
|
||
|
'free_space',
|
||
|
'database_size',
|
||
5 years ago
|
'hash_rate',
|
||
5 years ago
|
];
|
||
|
if (sizeField.contains(k)) {
|
||
|
final formatter = NumberFormat.compact();
|
||
|
return MapEntry(k, formatter.format(v));
|
||
|
}
|
||
|
|
||
|
else if (k == 'start_time') {
|
||
|
final _receive_time = DateTime.fromMillisecondsSinceEpoch(v * 1000);
|
||
|
final _diff = DateTime.now().difference(_receive_time);
|
||
|
|
||
|
format(Duration d) => d.toString().split('.').first.padLeft(8, "0");
|
||
5 years ago
|
return MapEntry('uptime', format(_diff));
|
||
5 years ago
|
}
|
||
|
|
||
5 years ago
|
else {
|
||
|
return MapEntry(k, v);
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
|
||
5 years ago
|
final _cleanedUpInfo = _formattedInfo.map
|
||
5 years ago
|
(
|
||
|
(k, v) {
|
||
|
if (k.contains('_count') && k != 'tx_count') {
|
||
|
return MapEntry(k.replaceAll('_count', ''), v);
|
||
|
}
|
||
|
|
||
5 years ago
|
else {
|
||
|
return MapEntry(k, v);
|
||
|
}
|
||
|
}
|
||
|
);
|
||
5 years ago
|
|
||
|
final _sortedInfo = {
|
||
|
for (final k in _cleanedUpInfo.keys.toList()..sort()) k: _cleanedUpInfo[k]
|
||
|
};
|
||
|
|
||
|
return _sortedInfo;
|
||
5 years ago
|
}
|