2021-12-24 12:52:08 +00:00
|
|
|
abstract class SyncStatus {
|
|
|
|
const SyncStatus();
|
|
|
|
double progress();
|
|
|
|
}
|
|
|
|
|
|
|
|
class SyncingSyncStatus extends SyncStatus {
|
|
|
|
SyncingSyncStatus(this.blocksLeft, this.ptc);
|
|
|
|
|
|
|
|
final double ptc;
|
|
|
|
final int blocksLeft;
|
|
|
|
|
|
|
|
@override
|
|
|
|
double progress() => ptc;
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() => '$blocksLeft';
|
2024-02-26 18:32:54 +00:00
|
|
|
|
|
|
|
factory SyncingSyncStatus.fromHeightValues(int chainTip, int initialSyncHeight, int syncHeight) {
|
|
|
|
final track = chainTip - initialSyncHeight;
|
|
|
|
final diff = track - (chainTip - syncHeight);
|
|
|
|
final ptc = diff <= 0 ? 0.0 : diff / track;
|
|
|
|
final left = chainTip - syncHeight;
|
|
|
|
|
|
|
|
// sum 1 because if at the chain tip, will say "0 blocks left"
|
|
|
|
return SyncingSyncStatus(left + 1, ptc);
|
|
|
|
}
|
2021-12-24 12:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class SyncedSyncStatus extends SyncStatus {
|
|
|
|
@override
|
|
|
|
double progress() => 1.0;
|
|
|
|
}
|
|
|
|
|
2024-04-17 19:35:11 +00:00
|
|
|
class SyncronizingSyncStatus extends SyncStatus {
|
|
|
|
@override
|
|
|
|
double progress() => 0.0;
|
|
|
|
}
|
|
|
|
|
2021-12-24 12:52:08 +00:00
|
|
|
class NotConnectedSyncStatus extends SyncStatus {
|
|
|
|
const NotConnectedSyncStatus();
|
|
|
|
|
|
|
|
@override
|
|
|
|
double progress() => 0.0;
|
|
|
|
}
|
|
|
|
|
2022-11-09 10:14:21 +00:00
|
|
|
class AttemptingSyncStatus extends SyncStatus {
|
2021-12-24 12:52:08 +00:00
|
|
|
@override
|
|
|
|
double progress() => 0.0;
|
|
|
|
}
|
|
|
|
|
2024-04-17 19:35:11 +00:00
|
|
|
class FailedSyncStatus extends NotConnectedSyncStatus {}
|
2021-12-24 12:52:08 +00:00
|
|
|
|
|
|
|
class ConnectingSyncStatus extends SyncStatus {
|
|
|
|
@override
|
|
|
|
double progress() => 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
class ConnectedSyncStatus extends SyncStatus {
|
|
|
|
@override
|
|
|
|
double progress() => 0.0;
|
|
|
|
}
|
|
|
|
|
2024-04-17 19:35:11 +00:00
|
|
|
class UnsupportedSyncStatus extends NotConnectedSyncStatus {}
|
2024-02-27 14:40:56 +00:00
|
|
|
|
2024-04-17 19:35:11 +00:00
|
|
|
class TimedOutSyncStatus extends NotConnectedSyncStatus {
|
2024-03-11 12:46:20 +00:00
|
|
|
@override
|
|
|
|
String toString() => 'Timed out';
|
|
|
|
}
|
|
|
|
|
2024-04-17 19:35:11 +00:00
|
|
|
class LostConnectionSyncStatus extends NotConnectedSyncStatus {
|
2024-02-26 18:32:54 +00:00
|
|
|
@override
|
|
|
|
String toString() => 'Reconnecting';
|
|
|
|
}
|