diff --git a/cyberwow/lib/controller/helper.dart b/cyberwow/lib/controller/helper.dart
index 2ca3808..94fa3a6 100644
--- a/cyberwow/lib/controller/helper.dart
+++ b/cyberwow/lib/controller/helper.dart
@@ -21,10 +21,8 @@ along with CyberWOW. If not, see .
import 'dart:async';
import 'dart:io';
-import 'dart:convert';
import 'package:path_provider/path_provider.dart';
-import 'package:http/http.dart' as http;
import 'package:flutter/foundation.dart';
Future getBinaryPath(String name) async {
@@ -37,36 +35,3 @@ Future binaryExists(String name) async {
return new File(binPath).exists();
}
-Future targetHeight() async {
- var url = '';
- if (kReleaseMode) {
- url = 'http://127.0.0.1:34568/json_rpc';
- } else {
- url = 'http://192.168.10.100:34568/json_rpc';
- }
-
- final body = json.encode
- (
- {
- 'jsonrpc': '2.0',
- 'id': '0',
- 'method': 'sync_info',
- }
- );
-
- var response = await http.post
- ( url,
- body: body
- );
-
- // print('Response status: ${response.statusCode}');
- if (response.statusCode != 200) {
- return -1;
- } else {
- final responseBody = json.decode(response.body)['result'];
- final targetHeight = responseBody["target_height"];
- // print('height: ${responseBody["height"]}');
-
- return targetHeight;
- }
-}
diff --git a/cyberwow/lib/controller/rpc.dart b/cyberwow/lib/controller/rpc.dart
new file mode 100644
index 0000000..5d3688c
--- /dev/null
+++ b/cyberwow/lib/controller/rpc.dart
@@ -0,0 +1,79 @@
+/*
+
+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';
+
+Future rpc(String method) async {
+ var url = '';
+ if (kReleaseMode) {
+ url = 'http://127.0.0.1:34568/json_rpc';
+ } else {
+ url = 'http://192.168.10.100:34568/json_rpc';
+ }
+
+ final body = json.encode
+ (
+ {
+ 'jsonrpc': '2.0',
+ 'id': '0',
+ 'method': method,
+ }
+ );
+
+ var response = await http.post
+ ( url,
+ body: body
+ );
+
+ return response;
+}
+
+Future syncInfo() async {
+ return rpc('sync_info');
+}
+
+Future targetHeight() async {
+ var response = await syncInfo();
+
+ // print('Response status: ${response.statusCode}');
+ if (response.statusCode != 200) {
+ return -1;
+ } else {
+ final responseBody = json.decode(response.body)['result'];
+ return responseBody["target_height"];
+ }
+}
+
+Future height() async {
+ var response = await syncInfo();
+
+ // print('Response status: ${response.statusCode}');
+ if (response.statusCode != 200) {
+ return -1;
+ } else {
+ final responseBody = json.decode(response.body)['result'];
+ return responseBody["height"];
+ }
+}
diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart
index 9fc83b1..521493c 100644
--- a/cyberwow/lib/state.dart
+++ b/cyberwow/lib/state.dart
@@ -29,6 +29,7 @@ import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import 'controller/helper.dart';
+import 'controller/rpc.dart' as rpc;
import 'config.dart';
abstract class AppState {
@@ -145,13 +146,14 @@ class SyncingState extends HookedState {
append(line);
print(line);
- final _targetHeight = await targetHeight();
+ final _targetHeight = await rpc.targetHeight();
if (_targetHeight == 0) break;
}
SyncedState _next = SyncedState(setState, stdout, processOutput);
+ _next.height = await rpc.height();
setState(_next);
return _next;
}
@@ -159,6 +161,7 @@ class SyncingState extends HookedState {
class SyncedState extends HookedState {
String stdout;
+ int height;
Stream processOutput;
SyncedState(f, this.stdout, this.processOutput) : super (f);
@@ -167,8 +170,9 @@ class SyncedState extends HookedState {
print("Synced next");
while (true) {
- final _targetHeight = await targetHeight();
+ final _targetHeight = await rpc.targetHeight();
if (_targetHeight != 0) break;
+ height = await rpc.height();
await Future.delayed(const Duration(seconds: 2), () => "1");
}
@@ -201,14 +205,14 @@ class ReSyncingState extends HookedState {
append(line);
print(line);
- final _targetHeight = await targetHeight();
+ final _targetHeight = await rpc.targetHeight();
if (_targetHeight == 0) break;
}
print('resync: await exit');
-
SyncedState _next = SyncedState(setState, stdout, processOutput);
+ _next.height = await rpc.height();
setState(_next);
return _next;
}
diff --git a/cyberwow/lib/widget/synced.dart b/cyberwow/lib/widget/synced.dart
index 23240cf..798b562 100644
--- a/cyberwow/lib/widget/synced.dart
+++ b/cyberwow/lib/widget/synced.dart
@@ -45,7 +45,7 @@ Widget buildSynced(BuildContext context, SyncedState state) {
(
child: Text
(
- 'Synced',
+ '${state.height}',
style: TextStyle
(
fontFamily: 'RobotoMono',