parent
ce0c6754cf
commit
7f81b822e2
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
import '../../config.dart' as config;
|
||||||
|
|
||||||
|
Map<String, dynamic> rpcTxView(x) {
|
||||||
|
const _remove =
|
||||||
|
[
|
||||||
|
'tx_blob',
|
||||||
|
// 'tx_json',
|
||||||
|
'last_failed_id_hash',
|
||||||
|
'max_used_block_id_hash',
|
||||||
|
// fields not useful for noobs
|
||||||
|
'last_relayed_time',
|
||||||
|
'kept_by_block',
|
||||||
|
'double_spend_seen',
|
||||||
|
'relayed',
|
||||||
|
'do_not_relay',
|
||||||
|
'last_failed_height',
|
||||||
|
'max_used_block_height',
|
||||||
|
'weight',
|
||||||
|
// 'blob_size',
|
||||||
|
];
|
||||||
|
|
||||||
|
final _filteredTx = x..removeWhere
|
||||||
|
(
|
||||||
|
(k,v) => _remove.contains(k)
|
||||||
|
);
|
||||||
|
|
||||||
|
final _tx = _filteredTx.map
|
||||||
|
(
|
||||||
|
(k, v) {
|
||||||
|
if (k == 'id_hash') {
|
||||||
|
return MapEntry('id', v.substring(0, config.hashLength) + '...');
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (k == 'blob_size') {
|
||||||
|
return MapEntry('size', (v / 1024).toStringAsFixed(2) + ' kB');
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (k == 'fee') {
|
||||||
|
final formatter = NumberFormat.currency
|
||||||
|
(
|
||||||
|
symbol: '',
|
||||||
|
decimalDigits: 2,
|
||||||
|
);
|
||||||
|
return MapEntry(k, formatter.format(v / pow(10, 11)) + ' ⍵');
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (k == 'receive_time') {
|
||||||
|
final _dateTime = DateTime.fromMillisecondsSinceEpoch(v * 1000);
|
||||||
|
final _dateFormat = DateFormat.yMd().add_jm() ;
|
||||||
|
return MapEntry('time', _dateFormat.format(_dateTime));
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (k == 'tx_decoded') {
|
||||||
|
final _out =
|
||||||
|
{
|
||||||
|
'vin': v['vin'].length,
|
||||||
|
'vout': v['vout'].length,
|
||||||
|
};
|
||||||
|
final _outString = _out['vin'].toString() + '/' + _out['vout'].toString();
|
||||||
|
return MapEntry('in/out', _outString);
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
return MapEntry(k, v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
final List<String> keys =
|
||||||
|
[
|
||||||
|
'id',
|
||||||
|
'time',
|
||||||
|
'fee',
|
||||||
|
'in/out',
|
||||||
|
'size',
|
||||||
|
]
|
||||||
|
.where((k) => _tx.keys.contains(k))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
final _sortedTx = {
|
||||||
|
for (var k in keys) k: _tx[k]
|
||||||
|
};
|
||||||
|
|
||||||
|
return _sortedTx;
|
||||||
|
}
|
@ -0,0 +1,106 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
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/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
import '../../config.dart' as config;
|
||||||
|
|
||||||
|
Map<String, dynamic> rpcPeerView(Map<String, dynamic> x) {
|
||||||
|
const _remove =
|
||||||
|
[
|
||||||
|
'address_type',
|
||||||
|
'connection_id',
|
||||||
|
'host',
|
||||||
|
'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)
|
||||||
|
);
|
||||||
|
|
||||||
|
final _conn = _filteredConn.map
|
||||||
|
(
|
||||||
|
(k, v) {
|
||||||
|
if (k == 'connection_id') {
|
||||||
|
return MapEntry(k, v.substring(0, config.hashLength) + '...');
|
||||||
|
}
|
||||||
|
|
||||||
|
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 =
|
||||||
|
[
|
||||||
|
'address',
|
||||||
|
'height',
|
||||||
|
'live_time',
|
||||||
|
'current_download',
|
||||||
|
'current_upload',
|
||||||
|
'avg_download',
|
||||||
|
'avg_upload',
|
||||||
|
'pruning_seed',
|
||||||
|
]
|
||||||
|
.where((k) => _conn.keys.contains(k))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
final _sortedConn = {
|
||||||
|
for (var k in keys) k: _conn[k]
|
||||||
|
};
|
||||||
|
|
||||||
|
return _sortedConn;
|
||||||
|
}
|
||||||
|
|
Reference in new issue