diff --git a/cyberwow/lib/controller/rpc.dart b/cyberwow/lib/controller/rpc.dart index 0e6e70e..8e8d3b2 100644 --- a/cyberwow/lib/controller/rpc.dart +++ b/cyberwow/lib/controller/rpc.dart @@ -73,40 +73,6 @@ Future rpcString(String method, {String field}) async { } } -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, {String field}) async { - var response = await rpcOther(method); - - if (response == null) return ''; - - if (response.statusCode != 200) { - return ''; - } else { - final _body= json.decode(response.body); - final _field = field == null ? _body: _body[field]; - - final JsonEncoder encoder = new JsonEncoder.withIndent(' '); - return encoder.convert(_field); - } -} - - - Future syncInfo() async => rpc('sync_info'); Future syncInfoString() async => rpcString('sync_info'); @@ -184,29 +150,55 @@ Future incomingConnectionsCount() async { } } +Future getConnectionsString() async => rpcString('get_connections', field: 'connections'); -// Future getInfo() async { -// // print('rpc get_info'); -// return rpc('get_info'); -// } +Future rpcOther(String method) async { + final url = 'http://127.0.0.1:${config.port}/json_rpc'; -// Future getInfoString() async { -// var response = await getInfo(); + var response; + try { + response = await http.post + ( url, + ); + } + catch (e) { + // print(e); + } -// if (response == null) return ''; + return response; +} -// if (response.statusCode != 200) { -// return ''; -// } else { -// final _getInfo = json.decode(response.body)['result']; +Future rpcOtherString(String method, {String field}) async { + var response = await rpcOther(method); -// JsonEncoder encoder = new JsonEncoder.withIndent(' '); -// String _prettyInfo = encoder.convert(_getInfo); -// return _prettyInfo; -// } -// } + if (response == null) return ''; + if (response.statusCode != 200) { + return ''; + } else { + final _body= json.decode(response.body); + final _field = field == null ? _body: _body[field]; -Future getConnectionsString() async => rpcString('get_connections', field: 'connections'); -Future getTransactionPoolString() async => rpcOtherString('get_transaction_pool'); + final JsonEncoder encoder = new JsonEncoder.withIndent(' '); + return encoder.convert(_field); + } +} + + +// Future getTransactionPoolString() async => rpcOtherString('get_transaction_pool'); + +Future getTransactionPool() async => rpc('get_transaction_pool'); +Future> getTransactionPoolSimple() async { + var response = await getTransactionPool(); + + if (response == null) return {}; + + // print('Response status: ${response.statusCode}'); + if (response.statusCode != 200) { + return {}; + } else { + final responseBody = json.decode(response.body); + return responseBody; + } +}