From 0b23a156426821aafadb29ea6cf4099f5f766eba Mon Sep 17 00:00:00 2001 From: fuwa Date: Wed, 24 Jul 2019 01:44:12 +0800 Subject: [PATCH] add transaction pool rpc --- cyberwow/lib/controller/rpc.dart | 110 ++++++++++++++----------------- 1 file changed, 51 insertions(+), 59 deletions(-) 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 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', field: 'connections'); -Future getTransactionPoolString() async => rpcOtherString('get_transaction_pool'); + + +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 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; + } +}