copy re-sync logic to sync

This commit is contained in:
fuwa
2019-06-25 17:32:55 +00:00
parent 8a3f479bde
commit f27f5914e1
+32 -16
View File
@@ -134,6 +134,7 @@ class LoadingState extends HookedState {
class SyncingState extends HookedState {
String stdout;
bool synced = false;
SyncingState(f, s, this.stdout) : super (f, s);
@@ -145,24 +146,39 @@ class SyncingState extends HookedState {
Future<SyncedState> next(Stream<String> processOutput) async {
print("Syncing next");
await for (var line in processOutput) {
append(line);
print(line);
final _targetHeight = await rpc.targetHeight();
final _height = await rpc.height();
// print('syncing: target height ${_targetHeight}');
// print('syncing: height ${_height}');
// final _offline = await rpc.offline();
// print('syncing: offline ${_offline}');
final _out_peers = await rpc.outgoing_connections_count();
// print('syncing: out_peers ${_out_peers}');
if (_targetHeight == 0 && _out_peers > 0) break;
Future<void> printStdout() async {
await for (var line in processOutput) {
if (synced) break;
// print('syncing: print stdout loop');
append(line);
print(line);
}
}
Future<void> checkSync() async {
await for (var _targetHeight in refresh.targetHeight(getNotification)) {
print('syncing: target height ${_targetHeight}');
final _height = await rpc.height();
print('syncing: height ${_height}');
// final _offline = await rpc.offline();
// print('syncing: offline ${_offline}');
final _out_peers = await rpc.outgoing_connections_count();
print('syncing: out_peers ${_out_peers}');
if (_targetHeight == 0 && _out_peers > 0) {
synced = true;
break;
}
// print('syncing: checkSync loop');
}
}
printStdout();
await checkSync();
print('syncing: loop exit');
SyncedState _next = SyncedState(setState, getNotification, stdout, processOutput);