forked from ethereum/mix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeploymentOptions.qml
482 lines (443 loc) · 9.92 KB
/
DeploymentOptions.qml
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
/*
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file DeploymentOptions.qml
* @author Yann [email protected]
* @author Arkadiy Paronyan [email protected]
* @date 2015
* Ethereum IDE client.
*/
import QtQuick 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.3
import QtQuick.Dialogs 1.2
import Qt.labs.settings 1.0
import "js/TransactionHelper.js" as TransactionHelper
import "js/NetworkDeployment.js" as NetworkDeploymentCode
import "js/QEtherHelper.js" as QEtherHelper
import org.ethereum.qml.QEther 1.0
Rectangle
{
property variant worker
anchors.fill: parent
color: "#E3E3E3E3"
id: root
property bool verifyDeploy: true
property variant deployStep
function show()
{
accountsModel.clear()
for (var k in worker.accounts)
accountsModel.append(worker.accounts[k])
verifyDeployedContract()
deployedAddresses.refresh()
worker.renewCtx()
verifyDeploy = true
visible = true
worker.pooler.onTriggered.connect(function() {
if (root.visible && verifyDeploy)
verifyDeployedContract();
})
ctrDeployCtrLabel.setCost()
}
function verifyDeployedContract()
{
if (projectModel.deployBlockNumber !== -1)
{
worker.verifyHashes(projectModel.deploymentTrHashes, function (bn, trLost)
{
root.updateVerification(bn, trLost)
});
}
}
function updateVerification(blockNumber, trLost)
{
if (projectModel.deployBlockNumber === "")
verificationLabel.text = ""
else
{
var nb = parseInt(blockNumber - projectModel.deployBlockNumber)
verificationTextArea.visible = false
verificationLabel.visible = true
if (nb >= 10)
{
verificationLabel.text = qsTr("contracts deployment verified")
verificationLabel.color = "green"
}
else
{
verificationLabel.text = nb
if (trLost.length > 0)
{
verifyDeploy = false
verificationTextArea.visible = true
verificationLabel.visible = false
verificationTextArea.text = qsTr("Following transactions are invalidated:") + "\n"
deploymentStepChanged(qsTr("Following transactions are invalidated:"))
verificationTextArea.textColor = "red"
for (var k in trLost)
{
deploymentStepChanged(trLost[k])
verificationTextArea.text += trLost[k] + "\n"
}
}
}
}
}
Column
{
anchors.top: parent.top
anchors.fill: parent
id: deploymentOption
anchors.margins: 10
spacing: 10
DefaultLabel
{
id: deploylabel
text: qsTr("Select deployment options")
font.bold: true
}
DefaultLabel
{
id: nodeError
visible: false
color: "red"
text: qsTr("Unable to contact Ethereum node on ") + appSettings.nodeAddress
}
Connections
{
target: worker
property int connectState: 0
onNodeUnreachable:
{
if (!root.visible && connectState === -1)
return
connectState = -1
nodeError.visible = true
deploylabel.visible = false
deployBtn.enabled = false
}
onNodeReachable:
{
if (!root.visible && connectState === 1)
return
connectState = 1
nodeError.visible = false
deploylabel.visible = true
deployBtn.enabled = true
}
}
ListModel
{
id: accountsModel
}
RowLayout
{
width: parent.width
height: 30
Rectangle
{
width: deploymentOption.width / 5
anchors.verticalCenter: parent.verticalCenter
DefaultLabel
{
text: qsTr("Deployment account")
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
}
DefaultCombobox
{
id: accountsList
textRole: "id"
rootItem: root
Layout.fillWidth: true
model: accountsModel
onCurrentTextChanged:
{
worker.currentAccount = currentText
accountBalance.text = worker.balance(currentText).format()
}
}
DefaultLabel
{
id: accountBalance
Layout.preferredWidth: 70
visible: text !== ""
}
}
RowLayout
{
width: parent.width
height: 60
Rectangle
{
width: deploymentOption.width / 5
anchors.verticalCenter: parent.verticalCenter
DefaultLabel
{
text: qsTr("Gas price")
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
}
Rectangle
{
color: "transparent"
Layout.fillWidth: true
height: 60
GasPrice
{
width: 360
anchors.left: parent.left
id: gasPriceConf
onGasPriceChanged: ctrDeployCtrLabel.setCost()
defaultGasPrice: true
defaultUnit: QEther.Finney
}
}
Connections
{
target: worker
id: gasPriceLoad
property bool loaded: false
onGasPriceLoaded:
{
if (!loaded)
{
gasPriceConf.init(worker.gasPriceInt.value())
ctrDeployCtrLabel.setCost()
}
loaded = true
}
}
}
RowLayout
{
id: ctrDeployCtrLabel
width: parent.width
height: 30
function setCost()
{
if (gasPriceConf.gasPrice && deployStep.gasUsed)
{
var ether = QEtherHelper.createBigInt(deployStep.gasUsed);
var gasPriceWei = gasPriceConf.gasPrice.toWei();
if (gasPriceWei !== null)
{
var gasTotal = ether.multiply(gasPriceWei);
if (gasTotal !== null)
gasToUseInput.value = QEtherHelper.createEther(gasTotal.value(), QEther.Wei, parent);
}
}
}
Rectangle
{
width: deploymentOption.width / 5
anchors.verticalCenter: parent.verticalCenter
DefaultLabel
{
text: qsTr("Deployment cost")
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
}
Ether
{
id: gasToUseInput
displayUnitSelection: false
displayFormattedValue: true
edit: false
Layout.preferredWidth: 400
}
}
RowLayout
{
id: deployedRow
width: parent.width
height: 50
Rectangle
{
width: deploymentOption.width / 5
anchors.verticalCenter: parent.verticalCenter
DefaultLabel
{
id: labelAddresses
text: qsTr("Deployed Contracts")
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
}
Rectangle
{
color: "#cccccc"
Layout.fillWidth: true
Layout.minimumHeight: 50
CopyButton
{
anchors.top: parent.top
anchors.left: parent.left
anchors.leftMargin: -18
width: 20
height: 20
id: copyBtn
getContent: function()
{
return JSON.stringify(projectModel.deploymentAddresses, null, ' ')
}
}
ScrollView
{
anchors.fill: parent
flickableItem.interactive: false
Rectangle
{
anchors.fill: parent
color: "#cccccc"
anchors.margins: 8
ColumnLayout
{
spacing: 1
ListModel
{
id: addresses
}
Repeater
{
id: deployedAddresses
Layout.fillWidth: true
function refresh()
{
addresses.clear()
for (var k in projectModel.deploymentAddresses)
{
if (k.indexOf("<") === 0)
addresses.append({ name: k, address: projectModel.deploymentAddresses[k]})
}
}
model: addresses
Item
{
height: 40
DefaultLabel
{
id: name
text: addresses.get(index).name
}
DefaultLabel
{
anchors.top: name.bottom
anchors.left: name.left
anchors.leftMargin: 30
id: address
text: addresses.get(index).address
}
}
}
}
}
}
}
}
Style
{
id: style
}
RowLayout
{
id: verificationRow
width: parent.width
height: 50
Rectangle
{
Layout.preferredWidth: deploymentOption.width / 5
anchors.verticalCenter: parent.verticalCenter
id: verLabel
DefaultLabel
{
text: qsTr("Verifications")
anchors.left: parent.left
anchors.verticalCenter: parent.verticalCenter
}
}
Rectangle
{
Layout.minimumHeight: 50
Layout.preferredWidth: parent.width - verLabel.width - 5
color: "#cccccc"
visible: false
DefaultTextArea
{
id: verificationTextArea
visible: false
backgroundVisible: false
anchors.fill: parent
onVisibleChanged:
{
parent.visible = visible
}
}
}
DefaultLabel
{
id: verificationLabel
visible: true
}
}
}
Rectangle
{
anchors.right: parent.right
anchors.bottom: parent.bottom
anchors.bottomMargin: 35
anchors.rightMargin: 10
MessageDialog
{
id: warning
text: qsTr("Contracts are going to be deployed. Are you sure? (Another actions may be required on the remote node in order to complere deployment)")
onYes: {
deployBtn.deploy()
}
standardButtons: StandardButton.Yes | StandardButton.No
}
DefaultButton
{
id: deployBtn
anchors.right: parent.right
text: qsTr("Deploy Scenario")
onClicked:
{
warning.open()
}
function deploy()
{
projectModel.deployedScenarioIndex = deployStep.selectedScenarioIndex
NetworkDeploymentCode.deployContracts(deployStep.gasByTx, gasPriceConf.toHexWei(), function(addresses, trHashes)
{
projectModel.deploymentTrHashes = trHashes
worker.verifyHashes(trHashes, function (nb, trLost)
{
projectModel.deployBlockNumber = nb
projectModel.saveProject()
root.updateVerification(nb, trLost)
root.deployStep.deployed()
})
projectModel.deploymentAddresses = addresses
projectModel.saveProject()
deployedAddresses.refresh()
});
}
}
}
}