You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

541 lines
12 KiB

10 years ago
import QtQuick 2.0
import QtQuick.Layouts 1.0
import QtQuick.Controls 1.1
import QtQuick.Controls.Styles 1.3
import Qt.labs.settings 1.0
10 years ago
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 paramsModel: []
property variant worker
property variant gas: []
10 years ago
property alias gasPrice: gasPriceInput
10 years ago
color: "#E3E3E3E3"
10 years ago
signal deployed
10 years ago
anchors.fill: parent
id: root
property int labelWidth: 150
10 years ago
property bool verifyDeploy: true
10 years ago
function show()
{
visible = true
contractList.currentIndex = 0
contractList.change()
accountsModel.clear()
for (var k in worker.accounts)
accountsModel.append(worker.accounts[k])
if (worker.currentAccount === "" && worker.accounts.length > 0)
10 years ago
{
10 years ago
worker.currentAccount = worker.accounts[0].id
10 years ago
accountsList.currentIndex = 0
}
verifyDeployedContract()
deployedAddresses.refresh()
10 years ago
worker.renewCtx()
verifyDeploy = true
worker.pooler.onTriggered.connect(function() {
10 years ago
if (root.visible && verifyDeploy)
verifyDeployedContract();
})
}
function verifyDeployedContract()
{
if (projectModel.deployBlockNumber !== -1)
{
worker.verifyHashes(projectModel.deploymentTrHashes, function (bn, trLost)
{
root.updateVerification(bn, trLost)
});
}
}
function updateVerification(blockNumber, trLost)
{
10 years ago
var nb = parseInt(blockNumber - projectModel.deployBlockNumber)
10 years ago
verificationTextArea.visible = false
verificationLabel.visible = true
10 years ago
if (nb >= 10)
{
10 years ago
verificationLabel.text = qsTr("contracts deployment verified")
verificationLabel.color = "green"
}
else
{
verificationLabel.text = nb
if (trLost.length > 0)
{
10 years ago
verifyDeploy = false
10 years ago
verificationTextArea.visible = true
verificationLabel.visible = false
10 years ago
verificationTextArea.text = ""
10 years ago
deploymentStepChanged("following transactions are invalidated:")
10 years ago
verificationTextArea.text += "\n" + qsTr("Transactions lost") + "\n"
10 years ago
verificationTextArea.textColor = "red"
10 years ago
for (var k in trLost)
{
deploymentStepChanged(trLost[k])
10 years ago
verificationTextArea.text += trLost[k] + "\n"
10 years ago
}
}
}
10 years ago
}
RowLayout
{
anchors.fill: parent
anchors.margins: 10
ColumnLayout
{
anchors.top: parent.top
Layout.preferredWidth: parent.width * 0.40 - 20
Layout.fillHeight: true
id: scenarioList
Label
{
Layout.fillWidth: true
text: qsTr("Pick Scenario to deploy")
}
ComboBox
{
id: contractList
Layout.preferredWidth: parent.width - 20
model: projectModel.stateListModel
textRole: "title"
onCurrentIndexChanged:
{
if (root.visible)
change()
10 years ago
}
function change()
{
trListModel.clear()
if (currentIndex > -1)
{
for (var k = 0; k < projectModel.stateListModel.get(currentIndex).blocks.count; k++)
{
for (var j = 0; j < projectModel.stateListModel.get(currentIndex).blocks.get(k).transactions.count; j++)
trListModel.append(projectModel.stateListModel.get(currentIndex).blocks.get(k).transactions.get(j));
}
for (var k = 0; k < trListModel.count; k++)
trList.itemAt(k).init()
ctrDeployCtrLabel.calculateContractDeployGas();
}
}
}
Rectangle
{
Layout.fillHeight: true
Layout.preferredWidth: parent.width - 20
id: trContainer
color: "white"
border.color: "#cccccc"
border.width: 1
ScrollView
{
anchors.fill: parent
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
10 years ago
ColumnLayout
{
spacing: 0
10 years ago
ListModel
{
id: trListModel
}
Repeater
{
id: trList
model: trListModel
ColumnLayout
{
Layout.fillWidth: true
spacing: 5
Layout.preferredHeight:
{
if (index > -1)
return 20 + trListModel.get(index)["parameters"].count * 20
else
return 20
}
function init()
{
paramList.clear()
if (trListModel.get(index).parameters)
{
for (var k in trListModel.get(index).parameters)
paramList.append({ "name": k, "value": trListModel.get(index).parameters[k] })
}
}
Label
{
id: trLabel
Layout.preferredHeight: 20
anchors.left: parent.left
anchors.top: parent.top
anchors.topMargin: 5
anchors.leftMargin: 10
text:
{
if (index > -1)
return trListModel.get(index).label
else
return ""
}
}
ListModel
{
id: paramList
}
Repeater
{
Layout.preferredHeight:
{
if (index > -1)
return trListModel.get(index)["parameters"].count * 20
else
return 0
}
model: paramList
Label
{
Layout.preferredHeight: 20
anchors.left: parent.left
anchors.leftMargin: 20
text: name + "=" + value
font.italic: true
}
}
Rectangle
{
Layout.preferredWidth: scenarioList.width
Layout.preferredHeight: 1
color: "#cccccc"
}
10 years ago
}
}
}
}
}
}
ColumnLayout
{
anchors.top: parent.top
Layout.preferredHeight: parent.height - 25
ColumnLayout
{
anchors.top: parent.top
Layout.preferredWidth: parent.width * 0.60
Layout.fillHeight: true
id: deploymentOption
spacing: 8
10 years ago
Label
{
anchors.left: parent.left
anchors.leftMargin: 105
text: qsTr("Deployment options")
}
ListModel
{
id: accountsModel
}
RowLayout
{
Layout.fillWidth: true
Rectangle
{
width: labelWidth
10 years ago
Label
{
text: qsTr("Account")
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
}
}
ComboBox
{
id: accountsList
textRole: "id"
model: accountsModel
Layout.preferredWidth: 235
onCurrentTextChanged:
{
worker.currentAccount = currentText
accountBalance.text = worker.balance(currentText).format()
10 years ago
}
}
Label
{
id: accountBalance
}
10 years ago
}
RowLayout
{
Layout.fillWidth: true
Rectangle
{
width: labelWidth
10 years ago
Label
{
text: qsTr("Gas Price")
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
}
}
Ether
{
id: gasPriceInput
displayUnitSelection: true
displayFormattedValue: true
edit: true
10 years ago
function toHexWei()
{
return "0x" + gasPriceInput.value.toWei().hexValue()
}
10 years ago
}
Connections
{
target: gasPriceInput
onValueChanged:
{
ctrDeployCtrLabel.calculateContractDeployGas()
}
onAmountChanged:
{
ctrDeployCtrLabel.setCost()
}
onUnitChanged:
{
ctrDeployCtrLabel.setCost()
}
}
Connections
{
target: worker
id: gasPriceLoad
property bool loaded: false
onGasPriceLoaded:
{
gasPriceInput.value = QEtherHelper.createEther(worker.gasPriceInt.value(), QEther.Wei)
gasPriceLoad.loaded = true
ctrDeployCtrLabel.calculateContractDeployGas()
}
}
}
RowLayout
{
id: ctrDeployCtrLabel
Layout.fillWidth: true
property int cost
function calculateContractDeployGas()
{
if (!root.visible)
return;
var sce = projectModel.stateListModel.getState(contractList.currentIndex)
worker.estimateGas(sce, function(gas) {
if (gasPriceLoad.loaded)
{
root.gas = gas
10 years ago
cost = 0
for (var k in gas)
cost += gas[k]
setCost()
}
});
}
function setCost()
{
var ether = QEtherHelper.createBigInt(cost);
var gasTotal = ether.multiply(gasPriceInput.value);
gasToUseInput.value = QEtherHelper.createEther(gasTotal.value(), QEther.Wei, parent);
}
Rectangle
{
width: labelWidth
10 years ago
Label
{
10 years ago
text: qsTr("Deployment Cost")
10 years ago
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
}
}
Ether
{
id: gasToUseInput
displayUnitSelection: false
displayFormattedValue: true
edit: false
Layout.preferredWidth: 350
}
}
10 years ago
Rectangle
{
10 years ago
border.color: "#cccccc"
border.width: 2
Layout.fillWidth: true
10 years ago
Layout.preferredHeight: parent.height + 25
color: "transparent"
10 years ago
id: rectDeploymentVariable
10 years ago
ScrollView
{
10 years ago
anchors.fill: parent
10 years ago
anchors.topMargin: 4
anchors.bottomMargin: 4
10 years ago
ColumnLayout
{
10 years ago
RowLayout
{
10 years ago
id: deployedRow
Layout.fillWidth: true
Rectangle
{
10 years ago
width: labelWidth
Label
{
id: labelAddresses
text: qsTr("Deployed Contracts")
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
}
}
ColumnLayout
{
anchors.top: parent.top
anchors.topMargin: 1
width: parent.width
id: deployedAddresses
function refresh()
{
textAddresses.text = ""
deployedRow.visible = Object.keys(projectModel.deploymentAddresses).length > 0
textAddresses.text = JSON.stringify(projectModel.deploymentAddresses, null, ' ')
}
TextArea
{
anchors.fill: parent
id: textAddresses
}
}
}
10 years ago
RowLayout
{
10 years ago
id: verificationRow
Layout.fillWidth: true
visible: Object.keys(projectModel.deploymentAddresses).length > 0
Rectangle
{
10 years ago
width: labelWidth
Label
{
text: qsTr("Verifications")
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
}
}
10 years ago
TextArea
10 years ago
{
id: verificationTextArea
visible: false
}
Label
{
10 years ago
id: verificationLabel
10 years ago
visible: true
}
}
}
}
}
10 years ago
}
Rectangle
{
Layout.preferredWidth: parent.width
Layout.alignment: Qt.BottomEdge
Button
{
10 years ago
Layout.preferredHeight: 22
anchors.right: deployBtn.left
text: qsTr("Reset")
action: clearDeployAction
}
Action {
id: clearDeployAction
onTriggered: {
worker.forceStopPooling()
if (projectModel.deploymentDir && projectModel.deploymentDir !== "")
fileIo.deleteDir(projectModel.deploymentDir)
10 years ago
projectModel.cleanDeploymentStatus()
deploymentDialog.steps.reset()
}
}
Button
{
id: deployBtn
10 years ago
anchors.right: parent.right
text: qsTr("Deploy Contracts")
onClicked:
{
projectModel.deployedScenarioIndex = contractList.currentIndex
10 years ago
NetworkDeploymentCode.deployContracts(root.gas, gasPriceInput.toHexWei(), function(addresses, trHashes)
{
projectModel.deploymentTrHashes = trHashes
worker.verifyHashes(trHashes, function (nb, trLost)
{
projectModel.deployBlockNumber = nb
projectModel.saveProject()
root.updateVerification(nb, trLost)
10 years ago
root.deployed()
})
10 years ago
projectModel.deploymentAddresses = addresses
projectModel.saveProject()
deployedAddresses.refresh()
});
10 years ago
}
}
}
}
}
}