-
Notifications
You must be signed in to change notification settings - Fork 919
Expand file tree
/
Copy pathMining.qml
More file actions
706 lines (645 loc) · 33.1 KB
/
Copy pathMining.qml
File metadata and controls
706 lines (645 loc) · 33.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
// Copyright (c) 2014-2024, The Monero Project
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import QtQml.Models 2.2
import QtQuick 2.9
import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.2
import "../components" as MoneroComponents
import moneroComponents.Wallet 1.0
import moneroComponents.P2PoolManager 1.0
import moneroComponents.DaemonManager 1.0
Rectangle {
id: root
color: "transparent"
property alias miningHeight: mainLayout.height
property double currentHashRate: 0
property int threads: idealThreadCount / 2
property alias stopMiningEnabled: stopSoloMinerButton.enabled
property string args: ""
ColumnLayout {
id: mainLayout
Layout.fillWidth: true
anchors.margins: 20
anchors.topMargin: 0
anchors.left: parent.left
anchors.top: parent.top
anchors.right: parent.right
spacing: 20
MoneroComponents.Label {
id: soloTitleLabel
fontSize: 24
text: qsTr("Mining") + translationManager.emptyString
}
MoneroComponents.WarningBox {
Layout.bottomMargin: 8
id: localDaemonWarning
text: qsTr("Mining is only available on local daemons.") + translationManager.emptyString
visible: persistentSettings.useRemoteNode && !persistentSettings.allowRemoteNodeMining
}
MoneroComponents.WarningBox {
Layout.bottomMargin: 8
text: qsTr("Your daemon must be synchronized before you can start mining") + translationManager.emptyString
visible: !persistentSettings.useRemoteNode && !appWindow.daemonSynced
}
MoneroComponents.TextPlain {
id: soloMainLabel
text: qsTr("Mining with your computer helps strengthen the Monero network. The more people mine, the harder it is for the network to be attacked, and every little bit helps.\n\nMining also gives you a small chance to earn some Monero. Your computer will create hashes looking for block solutions. If you find a block, you will get the associated reward. Good luck!") + "\n\n" + qsTr("P2Pool mining is a decentralized way to pool mine that pays out more frequently compared to solo mining, while also supporting the network.") + translationManager.emptyString
wrapMode: Text.Wrap
Layout.fillWidth: true
font.family: MoneroComponents.Style.fontRegular.name
font.pixelSize: 14
color: MoneroComponents.Style.defaultFontColor
}
MoneroComponents.WarningBox {
id: warningLabel
Layout.topMargin: 8
Layout.bottomMargin: 8
text: qsTr("Mining may reduce the performance of other running applications and processes.") + translationManager.emptyString
}
GridLayout {
columns: 2
Layout.fillWidth: true
columnSpacing: 20
rowSpacing: 16
ListModel {
id: miningModeModel
ListElement { column1: qsTr("Solo") ; column2: ""; priority: 0}
ListElement { column1: "P2Pool" ; column2: ""; priority: 1}
}
ColumnLayout {
Layout.fillWidth: true
Layout.alignment : Qt.AlignTop | Qt.AlignLeft
MoneroComponents.Label {
id: miningModeLabel
color: MoneroComponents.Style.defaultFontColor
text: qsTr("Mining mode") + translationManager.emptyString
fontSize: 16
}
}
ColumnLayout {
Layout.topMargin: 5
spacing: 10
MoneroComponents.StandardDropdown {
Layout.maximumWidth: 200
id: miningModeDropdown
visible: true
currentIndex: persistentSettings.miningModeSelected
dataModel: miningModeModel
onChanged: {
persistentSettings.allow_p2pool_mining = miningModeDropdown.currentIndex === 1;
persistentSettings.miningModeSelected = miningModeDropdown.currentIndex;
walletManager.stopMining();
p2poolManager.exit();
}
}
}
ColumnLayout {
Layout.fillWidth: true
Layout.alignment : Qt.AlignTop | Qt.AlignLeft
MoneroComponents.Label {
id: soloMinerThreadsLabel
color: MoneroComponents.Style.defaultFontColor
text: qsTr("CPU threads") + translationManager.emptyString
fontSize: 16
wrapMode: Text.WordWrap
}
}
ColumnLayout {
Layout.fillWidth: true
spacing: 16
RowLayout {
MoneroComponents.StandardButton {
id: removeThreadButton
small: true
primary: false
text: "−"
enabled: threads > 1
onClicked: threads--
}
MoneroComponents.TextPlain {
Layout.bottomMargin: 1
Layout.minimumWidth: 45
color: MoneroComponents.Style.defaultFontColor
text: threads
horizontalAlignment: Text.AlignHCenter
font.pixelSize: 16
MouseArea {
anchors.fill: parent
scrollGestureEnabled: false
onWheel: {
if (wheel.angleDelta.y > 0 && threads < idealThreadCount) {
return threads++
} else if (wheel.angleDelta.y < 0 && threads > 1) {
return threads--
}
}
}
}
MoneroComponents.StandardButton {
id: addThreadButton
small: true
primary: false
text: "+"
enabled: threads < idealThreadCount
onClicked: threads++
}
}
RowLayout {
MoneroComponents.StandardButton {
id: autoRecommendedThreadsButton
small: true
primary: false
text: qsTr("Use half (recommended)") + translationManager.emptyString
enabled: startSoloMinerButton.enabled
onClicked: {
threads = idealThreadCount / 2
appWindow.showStatusMessage(qsTr("Set to use recommended # of threads"),3)
}
}
MoneroComponents.StandardButton {
id: autoSetMaxThreadsButton
small: true
primary: false
text: qsTr("Use all threads") + " (" + idealThreadCount + ")" + translationManager.emptyString
enabled: startSoloMinerButton.enabled
onClicked: {
threads = idealThreadCount
appWindow.showStatusMessage(qsTr("Set to use all threads") + translationManager.emptyString,3)
}
}
}
RowLayout {
// Disable this option until stable
visible: false
MoneroComponents.CheckBox {
id: ignoreBattery
enabled: startSoloMinerButton.enabled
checked: !persistentSettings.miningIgnoreBattery
onClicked: {persistentSettings.miningIgnoreBattery = !checked}
text: qsTr("Enable mining when running on battery") + translationManager.emptyString
}
}
}
ColumnLayout {
Layout.alignment: Qt.AlignTop | Qt.AlignLeft
Layout.minimumWidth: 140
MoneroComponents.Label {
id: optionsLabel
color: MoneroComponents.Style.defaultFontColor
visible: !persistentSettings.allow_p2pool_mining
text: qsTr("Options") + translationManager.emptyString
fontSize: 16
wrapMode: Text.Wrap
Layout.preferredWidth: manageSoloMinerLabel.textWidth
}
}
ColumnLayout {
Layout.fillWidth: true
spacing: 16
RowLayout {
MoneroComponents.CheckBox {
id: backgroundMining
visible: !persistentSettings.allow_p2pool_mining
enabled: startSoloMinerButton.enabled && !persistentSettings.allow_p2pool_mining
checked: persistentSettings.allow_background_mining
onClicked: persistentSettings.allow_background_mining = checked
text: qsTr("Background mining (experimental)") + translationManager.emptyString
}
}
}
ColumnLayout {
Layout.alignment : Qt.AlignTop | Qt.AlignLeft
MoneroComponents.Label {
id: manageSoloMinerLabel
color: MoneroComponents.Style.defaultFontColor
text: qsTr("Manage miner") + translationManager.emptyString
fontSize: 16
wrapMode: Text.Wrap
Layout.preferredWidth: manageSoloMinerLabel.textWidth
}
}
ColumnLayout {
Layout.fillWidth: true
spacing: 16
RowLayout {
MoneroComponents.StandardButton {
visible: true
id: startSoloMinerButton
small: true
primary: !stopSoloMinerButton.enabled
text: qsTr("Start mining") + translationManager.emptyString
onClicked: {
var daemonReady = appWindow.daemonSynced && appWindow.daemonRunning && !persistentSettings.useRemoteNode
if (persistentSettings.allowRemoteNodeMining) {
daemonReady = persistentSettings.useRemoteNode && appWindow.daemonSynced
}
if (daemonReady) {
var success;
if (persistentSettings.allow_p2pool_mining) {
if (p2poolManager.isInstalled()) {
args = daemonManager.getArgs(persistentSettings.blockchainDataDir) //updates arguments
if (persistentSettings.allowRemoteNodeMining || (args.includes("--zmq-pub tcp://127.0.0.1:18083") || args.includes("--zmq-pub=tcp://127.0.0.1:18083")) && !args.includes("--no-zmq")) {
startP2Pool()
}
else {
daemonManager.stopAsync(persistentSettings.nettype, persistentSettings.blockchainDataDir, startP2PoolLocal)
}
}
else {
confirmationDialog.title = qsTr("P2Pool installation") + translationManager.emptyString;
confirmationDialog.text = qsTr("P2Pool will be installed at %1. Proceed?").arg(applicationDirectory) + translationManager.emptyString;
confirmationDialog.icon = StandardIcon.Question;
confirmationDialog.cancelText = qsTr("No") + translationManager.emptyString;
confirmationDialog.okText = qsTr("Yes") + translationManager.emptyString;
confirmationDialog.onAcceptedCallback = function() {
p2poolManager.proxyAddress = persistentSettings.getProxyAddress();
p2poolManager.download();
statusMessageText.text = "Downloading P2Pool...";
statusMessage.visible = true
startSoloMinerButton.enabled = false;
stopSoloMinerButton.enabled = false;
}
confirmationDialog.open();
}
}
else
{
success = walletManager.startMining(appWindow.currentWallet.address(0, 0), threads, persistentSettings.allow_background_mining, persistentSettings.miningIgnoreBattery)
if (success)
{
update()
}
else
{
miningError(qsTr("Couldn't start mining.<br>") + translationManager.emptyString)
}
}
}
else {
miningError(qsTr("Couldn't start mining.<br>") + translationManager.emptyString)
}
}
}
MoneroComponents.StandardButton {
visible: true
id: stopSoloMinerButton
small: true
primary: stopSoloMinerButton.enabled
text: qsTr("Stop mining") + translationManager.emptyString
onClicked: {
walletManager.stopMining()
p2poolManager.exit()
update()
}
}
}
}
ColumnLayout {
Layout.fillWidth: true
Layout.alignment : Qt.AlignTop | Qt.AlignLeft
MoneroComponents.Label {
id: statusLabel
color: MoneroComponents.Style.defaultFontColor
text: qsTr("Status") + translationManager.emptyString
fontSize: 16
}
}
ColumnLayout {
Layout.fillWidth: true
spacing: 16
MoneroComponents.LineEditMulti {
id: statusText
Layout.minimumWidth: 300
text: qsTr("Not mining") + translationManager.emptyString
borderDisabled: true
readOnly: true
wrapMode: Text.Wrap
inputPaddingLeft: 0
}
}
ListModel {
id: chainModel
ListElement { column1: qsTr("Mini") ; column2: ""; priority: 0}
ListElement { column1: qsTr("Main") ; column2: ""; priority: 1}
ListElement { column1: qsTr("Nano") ; column2: ""; priority: 2}
}
ColumnLayout {
Layout.fillWidth: true
Layout.alignment : Qt.AlignTop | Qt.AlignLeft
MoneroComponents.Label {
id: chainLabel
color: MoneroComponents.Style.defaultFontColor
visible: persistentSettings.allow_p2pool_mining
text: qsTr("Chain") + translationManager.emptyString
fontSize: 16
}
MoneroComponents.Tooltip {
id: chainsHelpTooltip
text: qsTr("Use the mini or nano chains if you have a low hashrate.") + translationManager.emptyString
}
MouseArea {
id: chainsTooltipArea
width: parent.width
height: parent.height
enabled: persistentSettings.allow_p2pool_mining
hoverEnabled: true
onEntered: {
chainsHelpTooltip.tooltipPopup.open();
}
onExited: {
chainsHelpTooltip.tooltipPopup.close();
}
}
}
ColumnLayout {
Layout.topMargin: 5
spacing: 10
MoneroComponents.StandardDropdown {
Layout.maximumWidth: 200
id: chainDropdown
visible: persistentSettings.allow_p2pool_mining
currentIndex: persistentSettings.chainDropdownSelected
dataModel: chainModel
onChanged: persistentSettings.chainDropdownSelected = chainDropdown.currentIndex;
}
}
ColumnLayout {
Layout.fillWidth: true
Layout.alignment : Qt.AlignTop | Qt.AlignLeft
MoneroComponents.Label {
id: flagsLabel
visible: persistentSettings.allow_p2pool_mining
color: MoneroComponents.Style.defaultFontColor
text: qsTr("Flags") + translationManager.emptyString
fontSize: 16
}
MoneroComponents.Tooltip {
id: flagsHelpTooltip
text: "
Usage:<br>
--wallet Wallet address to mine to. Subaddresses and integrated addresses are not supported!<br>
--host IP address of your Monero node, default is 127.0.0.1<br>
--rpc-port monerod RPC API port number, default is 18081<br>
--zmq-port monerod ZMQ pub port number, default is 18083 (same port as in monerod\'s \"--zmq-pub\" command line parameter)<br>
--stratum Comma-separated list of IP:port for stratum server to listen on<br>
--p2p Comma-separated list of IP:port for p2p server to listen on<br>
--addpeers Comma-separated list of IP:port of other p2pool nodes to connect to<br>
--stratum-ban-time N Number of seconds to ban misbehaving stratum client, default is 600<br>
--light-mode Don't allocate RandomX dataset, saves 2GB of RAM<br>
--loglevel Verbosity of the log, integer number between 0 and 6<br>
--data-dir Path to store general p2pool files (log, cache, peer data, etc.), default is current directory<br>
--sidechain-config Name of the p2pool sidechain parameters file (only use it if you run your own sidechain)<br>
--data-api Path to the p2pool JSON data (use it in tandem with an external web-server)<br>
--local-api Enable /local/ path in api path for Stratum Server and built-in miner statistics<br>
--stratum-api An alias for --local-api<br>
--no-cache Disable p2pool.cache<br>
--no-color Disable colors in console output<br>
--no-randomx Disable internal RandomX hasher: p2pool will use RPC calls to monerod to check PoW hashes<br>
--out-peers N Maximum number of outgoing connections for p2p server (any value between 10 and 1000)<br>
--in-peers N Maximum number of incoming connections for p2p server (any value between 10 and 1000)<br>
--start-mining N Start built-in miner using N threads (any value between 1 and 64)<br>
--no-autodiff Disable automatic difficulty adjustment for miners connected to stratum (WARNING: incompatible with Nicehash and MRR)<br>
--rpc-login Specify username[:password] required for Monero RPC server<br>
--socks5 Specify IP:port of a SOCKS5 proxy to use for outgoing connections<br>
--no-dns Disable DNS queries, use only IP addresses to connect to peers (seed node DNS will be unavailable too)<br>
--p2p-external-port Port number that your router uses for mapping to your local p2p port. Use it if you are behind a NAT and still want to accept incoming connections<br>
--no-upnp Disable UPnP port forwarding<br>
--no-igd An alias for --no-upnp<br>
--upnp-stratum Port forward Stratum port (it's not forwarded by default)<br>
--merge-mine IP:port and wallet address for another blockchain to merge mine with<br>
--version Print p2pool's version and build details<br>
--tls-cert file Load TLS certificate chain from \"file\" in the PEM format<br>
--tls-cert-key file Load TLS certificate private key from \"file\" in the PEM format<br>
--rpc-ssl Enable SSL on RPC connections to the Monero node<br>
--rpc-ssl-fingerprint base64-encoded fingerprint of the Monero node's certificate (optional, use it for certificate pinning)<br>
--no-stratum-http Disable HTTP on Stratum ports<br>
--help Show this help message
"
}
MouseArea {
id: flagsTooltipArea
width: parent.width
height: parent.height
enabled: persistentSettings.allow_p2pool_mining
hoverEnabled: true
onEntered: {
flagsHelpTooltip.tooltipPopup.open();
}
onExited: {
flagsHelpTooltip.tooltipPopup.close();
}
}
}
ColumnLayout {
Layout.fillWidth: true
MoneroComponents.LineEditMulti {
id: p2poolFlags
Layout.minimumWidth: 100
Layout.bottomMargin: 20
labelFontSize: 14
fontSize: 15
visible: persistentSettings.allow_p2pool_mining
wrapMode: Text.WrapAnywhere
labelText: qsTr("P2Pool startup flags") + translationManager.emptyString
placeholderText: qsTr("(optional)") + translationManager.emptyString
placeholderFontSize: 15
text: persistentSettings.p2poolFlags
addressValidation: false
onEditingFinished: {
persistentSettings.allowRemoteNodeMining = p2poolFlags.text.includes("--host");
persistentSettings.p2poolFlags = p2poolFlags.text;
}
}
}
}
}
function updateStatusText(p2poolHashrate) {
if (appWindow.isMining) {
if (persistentSettings.allow_p2pool_mining) {
if (p2poolHashrate === 0) {
statusText.text = qsTr("Starting P2Pool") + translationManager.emptyString;
}
else {
statusText.text = qsTr("Mining with P2Pool, at %1 H/s").arg(p2poolHashrate) + translationManager.emptyString;
}
}
else {
var userHashRate = walletManager.miningHashRate();
if (userHashRate === 0) {
statusText.text = qsTr("Mining temporarily suspended.") + translationManager.emptyString;
}
else {
var blockTime = 120;
var blocksPerDay = 86400 / blockTime;
var globalHashRate = walletManager.networkDifficulty() / blockTime;
var probabilityFindNextBlock = userHashRate / globalHashRate;
var probabilityFindBlockDay = 1 - Math.pow(1 - probabilityFindNextBlock, blocksPerDay);
var chanceFindBlockDay = Math.round(1 / probabilityFindBlockDay);
statusText.text = qsTr("Mining at %1 H/s. It gives you a 1 in %2 daily chance of finding a block.").arg(userHashRate).arg(chanceFindBlockDay) + translationManager.emptyString;
}
}
}
else {
statusText.text = qsTr("Not mining") + translationManager.emptyString;
}
}
function onMiningStatus(isMining, hashrate) {
var daemonReady = appWindow.daemonSynced
if (!persistentSettings.allowRemoteNodeMining) {
var daemonReady = !persistentSettings.useRemoteNode && daemonReady
}
appWindow.isMining = isMining;
updateStatusText(hashrate)
startSoloMinerButton.enabled = !appWindow.isMining && daemonReady
stopSoloMinerButton.enabled = !startSoloMinerButton.enabled && daemonReady
}
function update() {
persistentSettings.allow_p2pool_mining = miningModeDropdown.currentIndex === 1;
if (persistentSettings.allow_p2pool_mining) {
p2poolManager.getStatus();
}
else {
walletManager.miningStatusAsync();
}
}
function miningError(message) {
p2poolManager.exit()
errorPopup.title = qsTr("Error starting mining") + translationManager.emptyString;
errorPopup.text = message
if (persistentSettings.useRemoteNode && !persistentSettings.allowRemoteNodeMining)
errorPopup.text += qsTr("Mining is only available on local daemons. Run a local daemon to be able to mine.<br>") + translationManager.emptyString
errorPopup.icon = StandardIcon.Critical
errorPopup.open()
}
MoneroComponents.StandardDialog {
id: errorPopup
cancelVisible: false
}
Timer {
id: timer
interval: 2000
running: middlePanel.advancedView.state === "Mining" && middlePanel.state === "Advanced" && currentWallet !== undefined && (!persistentSettings.useRemoteNode || persistentSettings.allowRemoteNodeMining)
repeat: true
onTriggered: update()
}
function startP2PoolLocal() {
var noSync = false;
//these args will be deleted because DaemonManager::start will re-add them later.
//--no-zmq must be deleted. removing '--zmq-pub=tcp...' lets us blindly add '--zmq-pub tcp...' later without risking duplication.
var defaultArgs = ["--detach","--data-dir","--bootstrap-daemon-address","--prune-blockchain","--no-sync","--check-updates","--non-interactive","--max-concurrency","--no-zmq","--zmq-pub=tcp://127.0.0.1:18083"]
var customDaemonArgsArray = args.split(' ');
var flag = "";
var allArgs = [];
var p2poolArgs = ["--zmq-pub tcp://127.0.0.1:18083"];
//create an array (allArgs) of ['--arg value','--arg2','--arg3']
for (let i = 0; i < customDaemonArgsArray.length; i++) {
if(!customDaemonArgsArray[i].startsWith("--")) {
flag += " " + customDaemonArgsArray[i]
} else {
if(flag){
allArgs.push(flag)
}
flag = customDaemonArgsArray[i]
}
}
allArgs.push(flag)
//pop from allArgs if value is inside the deleteme array (defaultArgs)
allArgs = allArgs.filter( ( el ) => !defaultArgs.includes( el.split(" ")[0] ) )
//append required p2pool flags
for (let i = 0; i < p2poolArgs.length; i++) {
if(!allArgs.includes(p2poolArgs[i])) {
allArgs.push(p2poolArgs[i])
continue
}
}
var success = daemonManager.start(allArgs.join(" "), persistentSettings.nettype, persistentSettings.blockchainDataDir, persistentSettings.bootstrapNodeAddress, noSync, persistentSettings.pruneBlockchain)
if (success) {
startP2Pool()
}
else {
miningError(qsTr("Couldn't start mining.<br>") + translationManager.emptyString)
}
}
function startP2Pool() {
var address = currentWallet.address(0, 0);
var chain = "mini"
if (chainDropdown.currentIndex === 1) {
chain = "main"
}
if (chainDropdown.currentIndex === 2) {
chain = "nano"
}
var p2poolArgs = persistentSettings.p2poolFlags;
p2poolManager.proxyAddress = persistentSettings.getProxyAddress();
var success = p2poolManager.start(p2poolArgs, address, chain, threads);
if (success)
{
update()
}
else {
miningError(qsTr("Couldn't start mining.<br>") + translationManager.emptyString)
}
}
function p2poolDownloadFailed(errorCode) {
statusMessage.visible = false
errorPopup.title = qsTr("P2Pool Installation Failed") + translationManager.emptyString;
switch (errorCode) {
case P2PoolManager.HashVerificationFailed:
errorPopup.text = qsTr("Hash verification failed.") + translationManager.emptyString;
break;
case P2PoolManager.BinaryNotAvailable:
errorPopup.text = qsTr("P2Pool download is not available.") + translationManager.emptyString;
break;
case P2PoolManager.ConnectionIssue:
errorPopup.text = qsTr("P2Pool download failed due to a connection issue.") + translationManager.emptyString;
break;
case P2PoolManager.InstallationFailed:
errorPopup.text = qsTr("P2Pool installation failed.") + (isWindows ? (" " + qsTr("Try starting the program with administrator privileges.")) : "")
break;
default:
errorPopup.text = qsTr("Unknown error.") + translationManager.emptyString;
}
errorPopup.icon = StandardIcon.Critical
errorPopup.open()
update()
}
function p2poolDownloadSucceeded() {
statusMessage.visible = false
informationPopup.title = qsTr("P2Pool Installation Succeeded") + translationManager.emptyString;
informationPopup.text = qsTr("P2Pool has successfully installed.");
informationPopup.icon = StandardIcon.Critical
informationPopup.open()
update()
}
Component.onCompleted: {
walletManager.miningStatus.connect(onMiningStatus);
p2poolManager.p2poolStatus.connect(onMiningStatus);
p2poolManager.p2poolDownloadFailure.connect(p2poolDownloadFailed);
p2poolManager.p2poolDownloadSuccess.connect(p2poolDownloadSucceeded);
}
}