mirror of
https://github.com/wownero/cyberwow.git
synced 2026-10-19 16:28:45 +02:00
tune rpc
This commit is contained in:
@@ -29,14 +29,14 @@ import '../config.dart';
|
||||
|
||||
typedef GetNotificationFunc = AppLifecycleState Function();
|
||||
|
||||
Stream<Null> pull(GetNotificationFunc getNotification) async* {
|
||||
Stream<Null> pull(GetNotificationFunc getNotification, String puller) async* {
|
||||
while (true) {
|
||||
final _appState = getNotification();
|
||||
log.finer('refresh targetHeight: app state: ${_appState}');
|
||||
log.finer('refresh pull by ${puller}: app state: ${_appState}');
|
||||
|
||||
if (_appState == AppLifecycleState.resumed) {
|
||||
yield null;
|
||||
await Future.delayed(const Duration(milliseconds: 400), () => null);
|
||||
await Future.delayed(const Duration(milliseconds: 1000), () => null);
|
||||
} else {
|
||||
await Future.delayed(const Duration(seconds: 2), () => null);
|
||||
}
|
||||
|
||||
@@ -27,14 +27,18 @@ import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../config.dart';
|
||||
|
||||
int rpcID = 0;
|
||||
|
||||
Future<http.Response> rpc(String method) async {
|
||||
final url = 'http://127.0.0.1:${config.port}/json_rpc';
|
||||
|
||||
rpcID += 1;
|
||||
|
||||
final body = json.encode
|
||||
(
|
||||
{
|
||||
'jsonrpc': '2.0',
|
||||
'id': '0',
|
||||
'id': rpcID.toString(),
|
||||
'method': method,
|
||||
}
|
||||
);
|
||||
|
||||
@@ -164,8 +164,8 @@ class SyncingState extends HookedState {
|
||||
}
|
||||
|
||||
Future<void> checkSync() async {
|
||||
await for (var _null in refresh.pull(getNotification)) {
|
||||
log.finer('syncing: checkSync loop');
|
||||
await for (var _null in refresh.pull(getNotification, 'syncingState')) {
|
||||
log.finer('SyncingState: checkSync loop');
|
||||
|
||||
// here doc is wrong, targetHeight could match height when synced
|
||||
// potential bug, targetHeight could be smaller then height
|
||||
@@ -219,12 +219,12 @@ class SyncedState extends HookedState {
|
||||
logStdout();
|
||||
|
||||
Future<void> checkSync() async {
|
||||
await for (var _null in refresh.pull(getNotification)) {
|
||||
await for (var _null in refresh.pull(getNotification, 'syncedState')) {
|
||||
if (await daemon.isNotSynced()) {
|
||||
synced = false;
|
||||
break;
|
||||
}
|
||||
// print('synced loop');
|
||||
// log.finer('SyncedState: checkSync loop');
|
||||
height = await rpc.height();
|
||||
connected = await daemon.isConnected();
|
||||
getInfo = await rpc.getInfoString();
|
||||
@@ -270,7 +270,7 @@ class ReSyncingState extends HookedState {
|
||||
}
|
||||
|
||||
Future<void> checkSync() async {
|
||||
await for (var _null in refresh.pull(getNotification)) {
|
||||
await for (var _null in refresh.pull(getNotification, 'ReSyncingState')) {
|
||||
|
||||
if (await daemon.isSynced()) {
|
||||
synced = true;
|
||||
|
||||
Reference in New Issue
Block a user