diff --git a/cyberwow/lib/controller/daemon.dart b/cyberwow/lib/controller/daemon.dart index 39a1096..8dec29f 100644 --- a/cyberwow/lib/controller/daemon.dart +++ b/cyberwow/lib/controller/daemon.dart @@ -22,7 +22,7 @@ along with CyberWOW. If not, see . import 'dart:async'; import 'dart:convert'; -import 'rpc.dart' as rpc; +import 'rpc/rpc.dart' as rpc; import '../config.dart'; Future isConnected() async { diff --git a/cyberwow/lib/controller/refresh.dart b/cyberwow/lib/controller/refresh.dart index 4449fe0..67b25d6 100644 --- a/cyberwow/lib/controller/refresh.dart +++ b/cyberwow/lib/controller/refresh.dart @@ -23,7 +23,7 @@ import 'package:logging/logging.dart'; import 'dart:ui'; import 'dart:async'; -import 'rpc.dart' as rpc; +import 'rpc/rpc.dart' as rpc; import '../config.dart'; diff --git a/cyberwow/lib/controller/rpc.dart b/cyberwow/lib/controller/rpc/rpc.dart similarity index 69% rename from cyberwow/lib/controller/rpc.dart rename to cyberwow/lib/controller/rpc/rpc.dart index 94b0e94..1839d63 100644 --- a/cyberwow/lib/controller/rpc.dart +++ b/cyberwow/lib/controller/rpc/rpc.dart @@ -25,8 +25,8 @@ import 'dart:convert'; import 'package:http/http.dart' as http; import 'package:flutter/foundation.dart'; -import '../config.dart'; -import '../helper.dart'; +import '../../config.dart'; +import '../../helper.dart'; int rpcID = 0; @@ -153,67 +153,3 @@ Future incomingConnectionsCount() async { Future getConnectionsString() async => rpcString('get_connections', field: 'connections'); -Future rpcOther(String method) async { - final url = 'http://${host}:${config.port}/${method}'; - - var response; - try { - response = await http.post - ( url, - ); - } - catch (e) { - // print(e); - } - - return response; -} - -Future rpcOtherString(String method, {String field}) async { - final 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]; - - return pretty(_field); - } -} - - -// Future getTransactionPoolString() async => rpcOtherString('get_transaction_pool'); - -Future getTransactionPool() async => rpcOther('get_transaction_pool'); -Future> getTransactionPoolSimple() async { - final response = await getTransactionPool(); - // log.finer('getTransactionPoolSimple response: $response'); - - if (response == null) return []; - - // print('Response status: ${response.statusCode}'); - if (response.statusCode != 200) { - return []; - } else { - final responseBody = json.decode(response.body); - var result = responseBody['transactions']; - if (result == null) { - return []; - } - else { - result.forEach - ( - (tx) { - tx.remove('tx_blob'); - tx.remove('tx_json'); - tx.remove('last_failed_id_hash'); - tx.remove('max_used_block_id_hash'); - } - ); - return result; - } - } -} diff --git a/cyberwow/lib/controller/rpc/rpc2.dart b/cyberwow/lib/controller/rpc/rpc2.dart new file mode 100644 index 0000000..c736a32 --- /dev/null +++ b/cyberwow/lib/controller/rpc/rpc2.dart @@ -0,0 +1,93 @@ +/* + +Copyright 2019 fuwa + +This file is part of CyberWOW. + +CyberWOW is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +CyberWOW is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with CyberWOW. If not, see . + +*/ + +import 'dart:async'; +import 'dart:convert'; + +import 'package:http/http.dart' as http; +import 'package:flutter/foundation.dart'; + +import '../../config.dart'; +import '../../helper.dart'; + +Future rpc2(String method) async { + final url = 'http://${host}:${config.port}/${method}'; + + var response; + try { + response = await http.post + ( url, + ); + } + catch (e) { + // print(e); + } + + return response; +} + +Future rpc2String(String method, {String field}) async { + final response = await rpc2(method); + + if (response == null) return ''; + + if (response.statusCode != 200) { + return ''; + } else { + final _body= json.decode(response.body); + final _field = field == null ? _body: _body[field]; + + return pretty(_field); + } +} + +Future getTransactionPool() async => rpc2('get_transaction_pool'); + +Future> getTransactionPoolSimple() async { + final response = await getTransactionPool(); + + if (response == null) return []; + + log.finest('getTransactionPoolSimple response: ${response.body}'); + log.finest('Response status: ${response.statusCode}'); + + if (response.statusCode != 200) { + return []; + } else { + final responseBody = json.decode(response.body); + var result = responseBody['transactions']; + if (result == null) { + return []; + } + else { + result.forEach + ( + (tx) { + tx.remove('tx_blob'); + tx.remove('tx_json'); + tx.remove('last_failed_id_hash'); + tx.remove('max_used_block_id_hash'); + } + ); + return result; + } + } +} diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart index b903072..275fa02 100644 --- a/cyberwow/lib/state.dart +++ b/cyberwow/lib/state.dart @@ -29,7 +29,8 @@ import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; import 'controller/helper.dart'; -import 'controller/rpc.dart' as rpc; +import 'controller/rpc/rpc.dart' as rpc; +import 'controller/rpc/rpc2.dart' as rpc; import 'controller/daemon.dart' as daemon; import 'controller/refresh.dart' as refresh; import 'config.dart';