mirror of
https://github.com/wownero/cyberwow.git
synced 2026-10-19 16:28:45 +02:00
add connections page
This commit is contained in:
@@ -53,11 +53,57 @@ Future<http.Response> rpc(String method) async {
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<http.Response> syncInfo() async {
|
||||
// print('rpc sync_info');
|
||||
return rpc('sync_info');
|
||||
Future<String> rpcString(String method) async {
|
||||
var response = await rpc(method);
|
||||
|
||||
if (response == null) return '';
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return '';
|
||||
} else {
|
||||
final _result = json.decode(response.body)['result'];
|
||||
|
||||
final JsonEncoder encoder = new JsonEncoder.withIndent(' ');
|
||||
return encoder.convert(_result);
|
||||
}
|
||||
}
|
||||
|
||||
Future<http.Response> rpcOther(String method) async {
|
||||
final url = 'http://127.0.0.1:${config.port}/json_rpc';
|
||||
|
||||
var response;
|
||||
try {
|
||||
response = await http.post
|
||||
( url,
|
||||
);
|
||||
}
|
||||
catch (e) {
|
||||
// print(e);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<String> rpcOtherString(String method) async {
|
||||
var response = await rpcOther(method);
|
||||
|
||||
if (response == null) return '';
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return '';
|
||||
} else {
|
||||
final _result = json.decode(response.body);
|
||||
|
||||
final JsonEncoder encoder = new JsonEncoder.withIndent(' ');
|
||||
return encoder.convert(_result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Future<http.Response> syncInfo() async => rpc('sync_info');
|
||||
Future<String> syncInfoString() async => rpcString('sync_info');
|
||||
|
||||
Future<int> targetHeight() async {
|
||||
var response = await syncInfo();
|
||||
|
||||
@@ -87,28 +133,8 @@ Future<int> height() async {
|
||||
}
|
||||
|
||||
|
||||
|
||||
Future<http.Response> getInfo() async {
|
||||
// print('rpc get_info');
|
||||
return rpc('get_info');
|
||||
}
|
||||
|
||||
|
||||
Future<String> getInfoString() async {
|
||||
var response = await getInfo();
|
||||
|
||||
if (response == null) return '';
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
return '';
|
||||
} else {
|
||||
final _getInfo = json.decode(response.body)['result'];
|
||||
|
||||
JsonEncoder encoder = new JsonEncoder.withIndent(' ');
|
||||
String _prettyInfo = encoder.convert(_getInfo);
|
||||
return _prettyInfo;
|
||||
}
|
||||
}
|
||||
Future<http.Response> getInfo() async => rpc('get_info');
|
||||
Future<String> getInfoString() async => rpcString('get_info');
|
||||
|
||||
Future<bool> offline() async {
|
||||
var response = await getInfo();
|
||||
@@ -151,3 +177,30 @@ Future<int> incomingConnectionsCount() async {
|
||||
return responseBody["incoming_connections_count"];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Future<http.Response> getInfo() async {
|
||||
// // print('rpc get_info');
|
||||
// return rpc('get_info');
|
||||
// }
|
||||
|
||||
|
||||
// Future<String> getInfoString() async {
|
||||
// var response = await getInfo();
|
||||
|
||||
// if (response == null) return '';
|
||||
|
||||
// if (response.statusCode != 200) {
|
||||
// return '';
|
||||
// } else {
|
||||
// final _getInfo = json.decode(response.body)['result'];
|
||||
|
||||
// JsonEncoder encoder = new JsonEncoder.withIndent(' ');
|
||||
// String _prettyInfo = encoder.convert(_getInfo);
|
||||
// return _prettyInfo;
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
Future<String> getConnectionsString() async => rpcString('get_connections');
|
||||
Future<String> getTransactionPoolString() async => rpcOtherString('get_transaction_pool');
|
||||
|
||||
@@ -197,7 +197,10 @@ class SyncedState extends HookedState {
|
||||
Stream<String> processOutput;
|
||||
bool synced = true;
|
||||
bool connected = true;
|
||||
String daemonInfo = 'daemonInfo';
|
||||
String getInfo = 'getInfo';
|
||||
String syncInfo = 'syncInfo';
|
||||
String getConnections = 'getConnections';
|
||||
String getTransactionPool = 'getTransactionPool';
|
||||
|
||||
SyncedState(f, s, this.stdout, this.processOutput) : super (f, s);
|
||||
|
||||
@@ -224,7 +227,10 @@ class SyncedState extends HookedState {
|
||||
// print('synced loop');
|
||||
height = await rpc.height();
|
||||
connected = await daemon.isConnected();
|
||||
daemonInfo = await rpc.getInfoString();
|
||||
getInfo = await rpc.getInfoString();
|
||||
// syncInfo = await rpc.syncInfoString();
|
||||
getConnections = await rpc.getConnectionsString();
|
||||
// getTransactionPool = await rpc.getTransactionPoolString();
|
||||
syncState();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ Widget summary(SyncedState state) {
|
||||
);
|
||||
}
|
||||
|
||||
Widget getInfo(SyncedState state) {
|
||||
Widget rpcView(String title, String body) {
|
||||
return Container
|
||||
(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
@@ -103,6 +103,22 @@ Widget getInfo(SyncedState state) {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>
|
||||
[
|
||||
Text
|
||||
(
|
||||
title,
|
||||
style: TextStyle
|
||||
(
|
||||
fontFamily: 'RobotoMono',
|
||||
fontSize: 35,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: config.textColor,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
height: 1,
|
||||
color: config.textColor,
|
||||
margin: const EdgeInsets.only(bottom: 20, top: 20),
|
||||
),
|
||||
Expanded
|
||||
(
|
||||
flex: 1,
|
||||
@@ -111,7 +127,7 @@ Widget getInfo(SyncedState state) {
|
||||
scrollDirection: Axis.vertical,
|
||||
child: Text
|
||||
(
|
||||
state.daemonInfo,
|
||||
body,
|
||||
style: TextStyle
|
||||
(
|
||||
fontFamily: 'RobotoMono',
|
||||
@@ -127,6 +143,11 @@ Widget getInfo(SyncedState state) {
|
||||
);
|
||||
}
|
||||
|
||||
Widget getInfo(SyncedState state) => rpcView('daemon info', state.getInfo);
|
||||
Widget getConnections(SyncedState state) => rpcView('connections', state.getConnections);
|
||||
Widget syncInfo(SyncedState state) => rpcView('sync info', state.syncInfo);
|
||||
Widget getTransactionPool(SyncedState state) => rpcView('transaction pool', state.getTransactionPool);
|
||||
|
||||
Widget pageView (SyncedState state, PageController controller) {
|
||||
return PageView (
|
||||
controller: controller,
|
||||
@@ -134,6 +155,9 @@ Widget pageView (SyncedState state, PageController controller) {
|
||||
[
|
||||
summary(state),
|
||||
getInfo(state),
|
||||
getConnections(state),
|
||||
// syncInfo(state),
|
||||
// getTransactionPool(state),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user