mirror of
https://github.com/wownero/cyberwow.git
synced 2026-12-03 13:43:59 +01:00
split the two types of rpc
This commit is contained in:
@@ -22,7 +22,7 @@ along with CyberWOW. If not, see <https://www.gnu.org/licenses/>.
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'rpc.dart' as rpc;
|
||||
import 'rpc/rpc.dart' as rpc;
|
||||
import '../config.dart';
|
||||
|
||||
Future<bool> isConnected() async {
|
||||
|
||||
@@ -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';
|
||||
|
||||
|
||||
@@ -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<int> incomingConnectionsCount() async {
|
||||
Future<String> getConnectionsString() async => rpcString('get_connections', field: 'connections');
|
||||
|
||||
|
||||
Future<http.Response> 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<String> 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<String> getTransactionPoolString() async => rpcOtherString('get_transaction_pool');
|
||||
|
||||
Future<http.Response> getTransactionPool() async => rpcOther('get_transaction_pool');
|
||||
Future<List<dynamic>> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
|
||||
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<http.Response> 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<String> 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<http.Response> getTransactionPool() async => rpc2('get_transaction_pool');
|
||||
|
||||
Future<List<dynamic>> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user