diff --git a/cyberwow/lib/controller/rpc/rpc.dart b/cyberwow/lib/controller/rpc/rpc.dart index 1839d63..c62c569 100644 --- a/cyberwow/lib/controller/rpc/rpc.dart +++ b/cyberwow/lib/controller/rpc/rpc.dart @@ -58,37 +58,30 @@ Future rpc(String method) async { return response; } -Future rpcString(String method, {String field}) async { +Future rpcDynamic(String method, {String field}) async { final response = await rpc(method); - if (response == null) return ''; + if (response == null) return null; if (response.statusCode != 200) { - return ''; + return null; } else { final _result = json.decode(response.body)['result']; final _field = field == null ? _result : _result[field]; - return pretty(_field); + return _field; } } +Future rpcString(String method, {String field}) async { + final _field = await rpcDynamic(method, field: field); + return pretty(_field); +} + Future syncInfo() async => rpc('sync_info'); Future syncInfoString() async => rpcString('sync_info'); -Future targetHeight() async { - final response = await syncInfo(); - - if (response == null) return -1; - - // print('Response status: ${response.statusCode}'); - if (response.statusCode != 200) { - return -1; - } else { - final responseBody = json.decode(response.body)['result']; - return responseBody["target_height"]; - } -} +Future targetHeight() => rpcDynamic('sync_info', field: 'target_height'); Future height() async { final response = await syncInfo(); @@ -150,6 +143,7 @@ Future incomingConnectionsCount() async { } } +// Future> getConnections() async => rpc('get_connections', field: 'connections'); Future getConnectionsString() async => rpcString('get_connections', field: 'connections');