tweak info rpc view, make rpc views larger and padded

pull/2/head
fuwa 4 years ago
parent 1b10bf21d3
commit c028e7f485

@ -57,13 +57,13 @@ final _theme = ThemeData
body1: TextStyle
(
fontFamily: 'VT323',
fontSize: 16,
fontSize: 17,
height: 1,
),
body2: TextStyle
(
fontFamily: 'RobotoMono',
fontSize: 11,
fontSize: 12.5,
),
).apply
(

@ -93,16 +93,7 @@ Future<http.Response> getInfo() => rpc('get_info');
Future<Map<String, dynamic>> getInfoSimple() async {
final _getInfo = await rpc('get_info').then(asMap);
return _getInfo.map
(
(k, v) {
if (k == 'top_block_hash') {
return MapEntry(k, trimHash(v));
} else {
return MapEntry(k, v);
}
}
);
return cleanKey(rpcView.getInfoView(_getInfo));
}
Future<String> getInfoString() => rpcString('get_info');
@ -129,7 +120,7 @@ Future<List<dynamic>> getConnectionsSimple() async {
}
);
return _sortedConn.map(rpcView.rpcPeerView).toList();
return _sortedConn.map(rpcView.getConnectionView).map(cleanKey).toList();
}

@ -30,7 +30,7 @@ import 'package:intl/intl.dart';
import '../../config.dart' as config;
import '../../helper.dart';
import '../../logging.dart';
import 'rpc2View.dart';
import 'rpc2View.dart' as rpc2View;
Future<http.Response> rpc2(final String method) async {
final url = 'http://${config.host}:${config.c.port}/${method}';
@ -101,6 +101,6 @@ Future<List<dynamic>> getTransactionPoolSimple() async {
}
);
return _decodedPool.map(rpcTxView).toList();
return _decodedPool.map(rpc2View.txView).map(cleanKey).toList();
}
}

@ -26,7 +26,7 @@ import 'package:intl/intl.dart';
import '../../config.dart' as config;
import '../../helper.dart';
Map<String, dynamic> rpcTxView(Map<String, dynamic> x) {
Map<String, dynamic> txView(Map<String, dynamic> x) {
const _remove =
[
'tx_blob',
@ -85,7 +85,7 @@ Map<String, dynamic> rpcTxView(Map<String, dynamic> x) {
'vout': v['vout'].length,
};
final _outString = _out['vin'].toString() + '/' + _out['vout'].toString();
return MapEntry('in/out', _outString);
return MapEntry('i/o', _outString);
}
else {
@ -99,7 +99,7 @@ Map<String, dynamic> rpcTxView(Map<String, dynamic> x) {
'id',
'age',
'fee',
'in/out',
'i/o',
'size',
]
.where((k) => _tx.keys.contains(k))

@ -19,10 +19,12 @@ along with CyberWOW. If not, see <https://www.gnu.org/licenses/>.
*/
import 'package:intl/intl.dart';
import '../../config.dart' as config;
import '../../helper.dart';
Map<String, dynamic> rpcPeerView(Map<String, dynamic> x) {
Map<String, dynamic> getConnectionView(Map<String, dynamic> x) {
const _remove =
[
'address_type',
@ -137,3 +139,67 @@ Map<String, dynamic> simpleHeight(int height, Map<String, dynamic> x) {
}
);
}
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)
);
return _filteredInfo.map
(
(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',
'height',
'tx_count',
'cumulative_difficulty',
'free_space',
'database_size',
];
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");
return MapEntry('age', format(_diff));
}
else {
return MapEntry(k, v);
}
}
);
}

@ -20,6 +20,7 @@ along with CyberWOW. If not, see <https://www.gnu.org/licenses/>.
*/
import 'dart:convert';
import 'dart:math';
import 'config.dart' as config;
@ -27,11 +28,35 @@ String pretty(dynamic x) {
final JsonEncoder encoder = JsonEncoder.withIndent('');
return encoder.convert(x)
.replaceAll(RegExp(r'^{'), '\n')
.replaceAll(RegExp(r'["\[\],{}]'), '')
.replaceAll(RegExp(r'(["\[\],{}]|: )'), '')
;
}
String trimHash(String x) => x.substring(0, config.hashLength) + ' ...';
Map<String, dynamic> cleanKey(Map<String, dynamic> x) {
final _cleaned = x.map
(
(k, v) => MapEntry
(
k
.replaceAll('cumulative', 'Σ')
.replaceAll('current_', '')
.replaceAll('_count', '')
.replaceAll('_', ' ')
,
v
)
);
final int _maxLength = _cleaned.keys.map((x) => x.length).reduce(max);
final _padded = _cleaned.map
(
(k, v) => MapEntry(k.padRight(_maxLength + 2, ' '), v)
);
return _padded;
}
int asInt(dynamic x) => x?.toInt() ?? 0;