diff --git a/cyberwow/lib/controller/rpc.dart b/cyberwow/lib/controller/rpc.dart index 5135c77..139e2d7 100644 --- a/cyberwow/lib/controller/rpc.dart +++ b/cyberwow/lib/controller/rpc.dart @@ -53,11 +53,57 @@ Future rpc(String method) async { return response; } -Future syncInfo() async { - // print('rpc sync_info'); - return rpc('sync_info'); +Future 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 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 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 syncInfo() async => rpc('sync_info'); +Future syncInfoString() async => rpcString('sync_info'); + Future targetHeight() async { var response = await syncInfo(); @@ -87,28 +133,8 @@ Future height() async { } - -Future getInfo() async { - // print('rpc get_info'); - return rpc('get_info'); -} - - -Future 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 getInfo() async => rpc('get_info'); +Future getInfoString() async => rpcString('get_info'); Future offline() async { var response = await getInfo(); @@ -151,3 +177,30 @@ Future incomingConnectionsCount() async { return responseBody["incoming_connections_count"]; } } + + +// Future getInfo() async { +// // print('rpc get_info'); +// return rpc('get_info'); +// } + + +// Future 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 getConnectionsString() async => rpcString('get_connections'); +Future getTransactionPoolString() async => rpcOtherString('get_transaction_pool'); diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart index 562018e..05112c2 100644 --- a/cyberwow/lib/state.dart +++ b/cyberwow/lib/state.dart @@ -197,7 +197,10 @@ class SyncedState extends HookedState { Stream 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(); } } diff --git a/cyberwow/lib/widget/synced.dart b/cyberwow/lib/widget/synced.dart index 265548c..f5594e7 100644 --- a/cyberwow/lib/widget/synced.dart +++ b/cyberwow/lib/widget/synced.dart @@ -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: [ + 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), ], ); }