add targetHeight helper

master
fuwa 5 years ago
parent ac7168dee2
commit 6f79a8b010

@ -21,8 +21,11 @@ along with CyberWOW. If not, see <https://www.gnu.org/licenses/>.
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<String> getBinaryPath(String name) async {
final tmpDir = await getTemporaryDirectory();
@ -33,3 +36,37 @@ Future<bool> binaryExists(String name) async {
final binPath = await getBinaryPath(name);
return new File(binPath).exists();
}
Future<int> 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;
}
}

Loading…
Cancel
Save