Skip to content

Commit

Permalink
Merge pull request #2 from starcoinorg/dag_miner
Browse files Browse the repository at this point in the history
Dag miner for proxima
  • Loading branch information
welbon authored Feb 1, 2024
2 parents c2b7981 + 217bf5d commit 412efdc
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 71 deletions.
1 change: 1 addition & 0 deletions lib/generated_plugin_registrant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Generated file. Do not edit.
//

// ignore_for_file: directives_ordering
// ignore_for_file: lines_longer_than_80_chars

import 'package:shared_preferences_web/shared_preferences_web.dart';
Expand Down
77 changes: 19 additions & 58 deletions lib/pages/localizations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,70 +6,31 @@ class StarcoinLocalizations {
StarcoinLocalizations(this.isZh);
//是否为中文
bool isZh = false;

//为了使用方便,我们定义一个静态方法
static StarcoinLocalizations of(BuildContext context) {
return Localizations.of<StarcoinLocalizations>(
context, StarcoinLocalizations);
}

//Locale相关值,title为应用标题
String get title {
return isZh ? "Starcoin 挖矿程序" : "Starcoin Miner";
}

String get slogon {
return isZh ? "参与测试网挖矿 瓜分万U!" : "Start Mining Win10K USDT/STC!";
}

String get currentTask {
return isZh ? "当前任务" : "Current Task";
}

String get progress {
return isZh ? "进度" : "Progress";
}

String get balance {
return isZh ? "当前余额" : "Balance";
}

String get minedBlocks {
return isZh ? "已挖块数" : "Mined";
}

String get blockUnit {
return isZh ? "块" : "Blocks";
}

String get currentDiff {
return isZh ? "当前难度" : "Current Difficulty";
}

String get createNickyName {
return isZh ? "创建昵称" : "Create Nicky Name";
}

String get confirm {
return isZh ? "确认" : "Confirm";
}

String get generatePoster {
return isZh ? "生成海报" : "Share Poster";
}

String get offcialWebSite {
return isZh ? "官网" : "Offcial Website";
}

String get privateKey {
return isZh ? "保存私钥" : "Save Private Key";
}

String get nodeNotRun {
return isZh
? "节点没有运行,请先启动节点"
: "Node is not running,please start node first.";
}
String _t(String zh, String en) => isZh ? zh : en;

String get title => _t("Starcoin 挖矿程序", "Starcoin Miner");
String get slogan => _t("参与测试网挖矿 瓜分万U!", "Start Mining Win10K USDT/STC!");
String get currentTask => _t("当前任务", "Current Task");
String get progress => _t("进度", "Progress");
String get balance => _t("当前余额", "Balance");
String get minedBlocks => _t("已挖块数", "Mined");
String get blockUnit => _t("块", "Blocks");
String get currentDiff => _t("当前难度", "Current Difficulty");
String get createNickyName => _t("创建昵称", "Create Nicky Name");
String get confirm => _t("确认", "Confirm");
String get generatePoster => _t("生成海报", "Share Poster");
String get officialWebsite => _t("官网", "Official Website");
String get privateKey => _t("保存私钥", "Save Private Key");
String get nodeNotRun => _t("节点没有运行,请先启动节点", "Node is not running, please start node first.");
String get fileNotFound => _t("Starcoin.exe 节点启动文件未找到,请重新配置节点文件,位置:", "Starcoin.exe file cannot found, Please check the file has exists!, Locate: ");
String get alertTitle => _t("警告", "alert");
}

class StarcoinLocalizationsDelegate
Expand Down
50 changes: 39 additions & 11 deletions lib/pages/node_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:hex/hex.dart';
import 'package:starcoin_wallet/starcoin/starcoin.dart';
import 'package:starcoin_wallet/wallet/host_manager.dart';
import 'package:starcoin_wallet/wallet/node.dart';
import 'dart:io';
import 'dart:convert';
Expand All @@ -15,7 +16,7 @@ import 'package:date_format/date_format.dart';
import "package:path/path.dart" show join;
import 'package:image/image.dart' as img;

const LOCALURL = "http://localhost:9850";
const LOCALURL = "localhost";

class NodePage extends StatefulWidget {
static const String routeName = Routes.main + "/index";
Expand Down Expand Up @@ -79,28 +80,54 @@ class _NodePageState extends State<NodePage> with TickerProviderStateMixin {
if (!startRequest) {
onclick = () async {
var command = "";
File file ;
if (Platform.isMacOS) {
final current = await DirectoryService.getCurrentDirectory();
final dir = Directory.fromUri(Uri.parse(current));
command = join(dir.path, 'Contents/Resources/starcoin');
file = File(command);
//command = 'Contents/Resources/starcoin';
}
if (Platform.isWindows) {
Directory current = Directory.current;
command = join(current.path, 'starcoin/starcoin');
command = join(current.path, 'starcoin/starcoin.exe');
file = File(command);
}

if (!await file.exists()) {
// 文件不存在,显示警告对话框
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text(StarcoinLocalizations.of(context).alertTitle),
content: Text(StarcoinLocalizations.of(context).fileNotFound + '$command'),
actions: <Widget>[
TextButton(
child: Text(StarcoinLocalizations.of(context).confirm),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
return ;
}

process = await Process.start(
command,
[
"-n",
"barnard",
"proxima",
"--http-apis",
"all",
"--disable-ipc-rpc",
"--push-server-url",
"http://miner-metrics-pushgw.starcoin.org:9191/",
"--push-interval",
"5"
// "--push-server-url",
// "http://miner-metrics-pushgw.starcoin.org:9191/",
// "--push-interval",
// "5"
//"--disable-mint-empty-block",
//"false"
],
Expand All @@ -124,6 +151,7 @@ class _NodePageState extends State<NodePage> with TickerProviderStateMixin {
await freshData();
};
}

var startButton = RaisedButton(
padding: EdgeInsets.only(top: 10.0, bottom: 10, left: 30, right: 30),
color: blue,
Expand Down Expand Up @@ -198,12 +226,12 @@ class _NodePageState extends State<NodePage> with TickerProviderStateMixin {
width: 50,
),
Column(children: <Widget>[
Text(StarcoinLocalizations.of(context).slogon,
Text(StarcoinLocalizations.of(context).slogan,
style: TextStyle(
color: Colors.white, fontSize: 15)),
Text(
StarcoinLocalizations.of(context)
.offcialWebSite +
.officialWebsite +
': starcoin.org',
style: TextStyle(color: blue, fontSize: 15)),
]),
Expand Down Expand Up @@ -397,7 +425,7 @@ class _NodePageState extends State<NodePage> with TickerProviderStateMixin {

void freshData() async {
await Future.delayed(Duration(seconds: 5));
final node = Node(LOCALURL);
final node = Node(SimpleHostManager(Set.from([LOCALURL])));
Timer.periodic(Duration(seconds: 10), (timer) async {
if (startRequest) {
final account = await node.defaultAccount();
Expand Down Expand Up @@ -472,7 +500,7 @@ class _NodePageState extends State<NodePage> with TickerProviderStateMixin {
}

savePrivateKey() async {
final node = Node(LOCALURL);
final node = Node(SimpleHostManager(Set.from([LOCALURL])));
final account = await node.defaultAccount();
if (account == null) {
return;
Expand Down
2 changes: 1 addition & 1 deletion lib/style/themes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ final LTheme kLightTheme = new LTheme(mode: ThemeMode.Light,themeData: _buildLig

TextTheme _buildTextTheme(TextTheme base,bool isDark) {
return base.copyWith(
title: base.title.copyWith(
titleMedium: base.titleMedium.copyWith(
fontFamily: 'GoogleSans',
fontSize: 16.0,
color: Color(0xFF42495A)
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ dependencies:
starcoin_wallet:
git:
url: git://github.com/starcoinorg/starcoin.dart
#path: /Users/fanngyuan/Documents/workspace/starcoin_wallet.dart
# path: G:\\sources\\starcoin\\starcoin.dart

dev_dependencies:
flutter_test:
Expand Down
51 changes: 51 additions & 0 deletions test/rpc_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:starcoin_wallet/wallet/host_manager.dart';
import 'package:starcoin_wallet/wallet/node.dart';

void main() {
Process process;
Completer<void> processReadyCompleter;

setUp(() async {
Directory current = Directory.current;
var command = join(current.path, 'starcoin/starcoin.exe');
process = await Process.start( command, ["-n", "proxima",], runInShell: true);
processReadyCompleter = Completer<void>();

process.stdout.transform(utf8.decoder).listen((data) {
print('Process stdout: $data');

// 检查输出中是否有表明进程已就绪的特定消息
if (data.contains('Waiting Ctrl-C')) {
processReadyCompleter.complete();
}
});

// 等待进程就绪的信号或者超时
await Future.any([
processReadyCompleter.future,
Future.delayed(Duration(seconds: 100))
]).catchError((_) => print('Process did not become ready in time.'));
});

test('node rpc test', () async {
expect(processReadyCompleter.isCompleted, isTrue);

final node = Node(SimpleHostManager(Set.from(["localhost"])));
final account = await node.defaultAccount();
expect(account.containsKey("address"), true);
});

tearDown(() async {
if (process != null) {
process.kill(ProcessSignal.sigquit);
await process.exitCode;
}
});
}
2 changes: 2 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//

// clang-format off

#include "generated_plugin_registrant.h"


Expand Down
2 changes: 2 additions & 0 deletions windows/flutter/generated_plugin_registrant.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Generated file. Do not edit.
//

// clang-format off

#ifndef GENERATED_PLUGIN_REGISTRANT_
#define GENERATED_PLUGIN_REGISTRANT_

Expand Down

0 comments on commit 412efdc

Please sign in to comment.