mirror of
https://github.com/wownero/cyberwow.git
synced 2026-11-12 11:13:55 +01:00
copy re-sync logic to sync
This commit is contained in:
+32
-16
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user