diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index 89a836893..eae3f8834 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -206,12 +206,12 @@ QVariantList ClientModel::gasCosts() const return res; } -void ClientModel::addAccount(QString const& _secret, QString const& _amount) +void ClientModel::addAccount(QString const& _secret) { KeyPair key(Secret(_secret.toStdString())); m_accountsSecret.push_back(key); Address address = key.address(); - m_accounts[address] = Account(u256(_amount.toStdString()), Account::NormalCreation); + m_accounts[address] = Account(u256(0), Account::NormalCreation); m_ethAccounts->setAccounts(m_accountsSecret); } diff --git a/mix/ClientModel.h b/mix/ClientModel.h index e14c3c486..5428bb6f8 100644 --- a/mix/ClientModel.h +++ b/mix/ClientModel.h @@ -188,7 +188,7 @@ public: /// To Hex number Q_INVOKABLE QString toHex(QString const& _int); /// Add new account to the model - Q_INVOKABLE void addAccount(QString const& _secret, QString const& _amount); + Q_INVOKABLE void addAccount(QString const& _secret); /// Return the address associated with the current secret Q_INVOKABLE QString resolveAddress(QString const& _secret); @@ -246,6 +246,8 @@ signals: void stateCleared(); /// new state has been processed void newState(unsigned _record, QVariantMap _accounts); + /// account has been added to the model + void accountAdded(QString _address, QString _amount); private: RecordLogEntry* lastBlock() const; diff --git a/mix/qml/Block.qml b/mix/qml/Block.qml index cb6737292..732166628 100644 --- a/mix/qml/Block.qml +++ b/mix/qml/Block.qml @@ -41,6 +41,7 @@ ColumnLayout { transactionDialog.stateAccounts = scenario.accounts transactionDialog.execute = false + transactionDialog.editMode = true transactionDialog.open(txIndex, blockIndex, transactions.get(txIndex)) } @@ -164,11 +165,11 @@ ColumnLayout Image { anchors.top: parent.top anchors.left: parent.left - anchors.leftMargin: -9 - anchors.topMargin: -4 + anchors.leftMargin: -4 + anchors.topMargin: 0 id: saveStatusImage source: "qrc:/qml/img/recyclediscard@2x.png" - width: statusWidth + 20 + width: statusWidth + 10 fillMode: Image.PreserveAspectFit } @@ -317,10 +318,10 @@ ColumnLayout Rectangle { width: debugActionWidth - height: trHeight - anchors.left: rowContentTr.right + height: trHeight - 10 + anchors.right: rowContentTr.right anchors.top: rowContentTr.top - anchors.leftMargin: -50 + anchors.rightMargin: 10 color: "transparent" Image { @@ -328,7 +329,6 @@ ColumnLayout source: "qrc:/qml/img/rightarrow@2x.png" width: debugActionWidth fillMode: Image.PreserveAspectFit - anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter visible: transactions.get(index).recordIndex !== undefined } diff --git a/mix/qml/BlockChain.qml b/mix/qml/BlockChain.qml index ca7b60ce7..43bed678f 100644 --- a/mix/qml/BlockChain.qml +++ b/mix/qml/BlockChain.qml @@ -24,6 +24,7 @@ ColumnLayout { signal chainReloaded signal txSelected(var blockIndex, var txIndex) signal rebuilding + signal accountAdded(string address, string amount) Connections { @@ -47,14 +48,12 @@ ColumnLayout { { fromWidth = 250 toWidth = 240 - //valueWidth = 200 } else { var diff = (width - previousWidth) / 3; fromWidth = fromWidth + diff < 250 ? 250 : fromWidth + diff toWidth = toWidth + diff < 240 ? 240 : toWidth + diff - //valueWidth = valueWidth + diff < 200 ? 200 : valueWidth + diff } previousWidth = width } @@ -89,7 +88,7 @@ ColumnLayout { { id: header spacing: 0 - Layout.preferredHeight: 30 + Layout.preferredHeight: 24 Rectangle { Layout.preferredWidth: statusWidth @@ -100,12 +99,13 @@ ColumnLayout { anchors.verticalCenter: parent.verticalCenter anchors.horizontalCenter: parent.horizontalCenter source: "qrc:/qml/img/recycleicon@2x.png" - width: statusWidth + 20 + width: statusWidth + 10 fillMode: Image.PreserveAspectFit } } Rectangle { + anchors.verticalCenter: parent.verticalCenter Layout.preferredWidth: fromWidth Label { @@ -118,11 +118,13 @@ ColumnLayout { Label { text: "To" + anchors.verticalCenter: parent.verticalCenter Layout.preferredWidth: toWidth + cellSpacing } Label { text: "" + anchors.verticalCenter: parent.verticalCenter Layout.preferredWidth: debugActionWidth } } @@ -363,6 +365,7 @@ ColumnLayout { var item = TransactionHelper.defaultTransaction() transactionDialog.stateAccounts = model.accounts transactionDialog.execute = true + transactionDialog.editMode = false transactionDialog.open(model.blocks[model.blocks.length - 1].transactions.length, model.blocks.length - 1, item) } width: 100 @@ -414,7 +417,6 @@ ColumnLayout { } else addNewBlock() - } function addNewBlock() @@ -509,7 +511,12 @@ ColumnLayout { id: newAccount text: qsTr("New Account..") onClicked: { - model.accounts.push(projectModel.stateListModel.newAccount("1000000", QEther.Ether)) + var ac = projectModel.stateListModel.newAccount("O", QEther.Wei) + model.accounts.push(ac) + clientModel.addAccount(ac.secret); + for (var k in Object.keys(blockChainPanel.states)) + blockChainPanel.states[k].accounts["0x" + ac.address] = "0 wei" // add the account in all the previous state (balance at O) + accountAdded(ac.address, "0") } Layout.preferredWidth: 100 Layout.preferredHeight: 30 diff --git a/mix/qml/KeyValuePanel.qml b/mix/qml/KeyValuePanel.qml index 63baa3801..056384b9e 100644 --- a/mix/qml/KeyValuePanel.qml +++ b/mix/qml/KeyValuePanel.qml @@ -18,6 +18,11 @@ ColumnLayout { property string role property alias model: modelKeyValue + function add(key, value) + { + modelKeyValue.append({ "key": key, "value": value }) + } + function clear() { modelKeyValue.clear() @@ -29,10 +34,7 @@ ColumnLayout { if (typeof(computeData) !== "undefined" && computeData instanceof Function) computeData() else - { - console.log("--------------") - console.log(JSON.stringify(_data)) - console.log(role) + { if (_data !== undefined && _data[role] !== undefined) { var keys = Object.keys(_data[role]) @@ -77,6 +79,7 @@ ColumnLayout { id: columnValues horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff anchors.fill: parent + clip: true ColumnLayout { anchors.margins: 10 @@ -97,7 +100,7 @@ ColumnLayout { anchors.left: parent.left anchors.leftMargin: 10 text: { - if (index >= 0) + if (index >= 0 && repeaterKeyValue.model.get(index).key !== undefined) return repeaterKeyValue.model.get(index).key else return "" @@ -113,7 +116,7 @@ ColumnLayout { anchors.right: parent.right anchors.rightMargin: 10 text: { - if (index >= 0) + if (index >= 0 && repeaterKeyValue.model.get(index).value !== undefined) return repeaterKeyValue.model.get(index).value else return "" @@ -123,6 +126,7 @@ ColumnLayout { } } } + } } } diff --git a/mix/qml/ScenarioExecution.qml b/mix/qml/ScenarioExecution.qml index 1eb0c3d0c..687c8e99f 100644 --- a/mix/qml/ScenarioExecution.qml +++ b/mix/qml/ScenarioExecution.qml @@ -84,14 +84,27 @@ Rectangle { Connections { target: blockChain + property var currentSelectedBlock + property var currentSelectedTx onTxSelected: { + currentSelectedBlock = blockIndex + currentSelectedTx = txIndex + updateWatchers(blockIndex, txIndex) + } + + function updateWatchers(blockIndex, txIndex){ var tx = blockChain.model.blocks[blockIndex].transactions[txIndex] var state = blockChain.getState(tx.recordIndex) watchers.updateWidthTx(tx, state, blockIndex, txIndex) } + onRebuilding: { watchers.clear() } + + onAccountAdded: { + watchers.addAccount(address, "0 wei") + } } } diff --git a/mix/qml/StateListModel.qml b/mix/qml/StateListModel.qml index a5e6365e0..d3bf1c860 100644 --- a/mix/qml/StateListModel.qml +++ b/mix/qml/StateListModel.qml @@ -257,8 +257,7 @@ Item { _secret = clientModel.newSecret(); var address = clientModel.address(_secret); var name = qsTr("Account") + "-" + address.substring(0, 4); - var amount = QEtherHelper.createEther(_balance, _unit) - clientModel.addAccount(_secret, amount.toWei().value()) + var amount = QEtherHelper.createEther(_balance, _unit) return { name: name, secret: _secret, balance: amount, address: address }; } diff --git a/mix/qml/TransactionDialog.qml b/mix/qml/TransactionDialog.qml index f4aa9a5f0..4edc601de 100644 --- a/mix/qml/TransactionDialog.qml +++ b/mix/qml/TransactionDialog.qml @@ -16,7 +16,8 @@ Dialog { width: 580 height: 500 visible: false - title: qsTr("Edit Transaction") + title: editMode ? qsTr("Edit Transaction") : qsTr("Add Transaction") + property bool editMode property int transactionIndex property int blockIndex property alias gas: gasValueEdit.gasValue; @@ -390,7 +391,7 @@ Dialog { objectName: "trTypeExecute" exclusiveGroup: rbbuttonList height: 30 - text: qsTr("Execute Contract") + text: qsTr("Transact with Contract") } } } @@ -687,7 +688,7 @@ Dialog { } Button { - text: qsTr("Update"); + text: editMode ? qsTr("Update") : qsTr("Ok") onClicked: { var invalid = InputValidator.validate(paramsModel, paramValues); if (invalid.length === 0) diff --git a/mix/qml/Watchers.qml b/mix/qml/Watchers.qml index 2e436a634..087dd1105 100644 --- a/mix/qml/Watchers.qml +++ b/mix/qml/Watchers.qml @@ -24,16 +24,23 @@ Rectangle { { from.text = "" to.text = "" + value.text = "" inputParams.clear() returnParams.clear() accounts.clear() events.clear() } + function addAccount(address, amount) + { + accounts.add(address, amount) + } + function updateWidthTx(_tx, _state, _blockIndex, _txIndex) { - from.text = _tx.sender + from.text = clientModel.resolveAddress(_tx.sender) to.text = _tx.label + value.text = _tx.value.format() tx = _tx blockIndex = _blockIndex txIndex = _txIndex @@ -43,10 +50,10 @@ Rectangle { { returnParams.role = "creationAddr" returnParams._data = { - creationAddr : { - "": _tx.returned + creationAddr : { } } + returnParams._data.creationAddr[qsTr("contract address")] = _tx.returned } else { @@ -68,6 +75,7 @@ Rectangle { color: "transparent" Row { + id: rowHeader anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter height: 5 @@ -100,19 +108,28 @@ Rectangle { clip: true width: 100 } + Label { + id: value + color: "#EAB920" + font.italic: true + clip: true + } + } - Image { - source: "qrc:/qml/img/edit.png" - height: 15 - fillMode: Image.PreserveAspectFit - visible: from.text !== "" - MouseArea + Image { + anchors.right: rowHeader.parent.right + anchors.top: rowHeader.parent.top + anchors.topMargin: 10 + source: "qrc:/qml/img/edit.png" + height: 15 + fillMode: Image.PreserveAspectFit + visible: from.text !== "" + MouseArea + { + anchors.fill: parent + onClicked: { - anchors.fill: parent - onClicked: - { - bc.blockChainRepeater.editTx(blockIndex, txIndex) - } + bc.blockChainRepeater.editTx(blockIndex, txIndex) } } }