Browse Source

bug fix

cl-refactor
yann300 10 years ago
parent
commit
d06c1a6d14
  1. 4
      mix/ClientModel.cpp
  2. 4
      mix/ClientModel.h
  3. 14
      mix/qml/Block.qml
  4. 19
      mix/qml/BlockChain.qml
  5. 16
      mix/qml/KeyValuePanel.qml
  6. 13
      mix/qml/ScenarioExecution.qml
  7. 3
      mix/qml/StateListModel.qml
  8. 7
      mix/qml/TransactionDialog.qml
  9. 45
      mix/qml/Watchers.qml

4
mix/ClientModel.cpp

@ -206,12 +206,12 @@ QVariantList ClientModel::gasCosts() const
return res; return res;
} }
void ClientModel::addAccount(QString const& _secret, QString const& _amount) void ClientModel::addAccount(QString const& _secret)
{ {
KeyPair key(Secret(_secret.toStdString())); KeyPair key(Secret(_secret.toStdString()));
m_accountsSecret.push_back(key); m_accountsSecret.push_back(key);
Address address = key.address(); 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); m_ethAccounts->setAccounts(m_accountsSecret);
} }

4
mix/ClientModel.h

@ -188,7 +188,7 @@ public:
/// To Hex number /// To Hex number
Q_INVOKABLE QString toHex(QString const& _int); Q_INVOKABLE QString toHex(QString const& _int);
/// Add new account to the model /// 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 /// Return the address associated with the current secret
Q_INVOKABLE QString resolveAddress(QString const& _secret); Q_INVOKABLE QString resolveAddress(QString const& _secret);
@ -246,6 +246,8 @@ signals:
void stateCleared(); void stateCleared();
/// new state has been processed /// new state has been processed
void newState(unsigned _record, QVariantMap _accounts); void newState(unsigned _record, QVariantMap _accounts);
/// account has been added to the model
void accountAdded(QString _address, QString _amount);
private: private:
RecordLogEntry* lastBlock() const; RecordLogEntry* lastBlock() const;

14
mix/qml/Block.qml

@ -41,6 +41,7 @@ ColumnLayout
{ {
transactionDialog.stateAccounts = scenario.accounts transactionDialog.stateAccounts = scenario.accounts
transactionDialog.execute = false transactionDialog.execute = false
transactionDialog.editMode = true
transactionDialog.open(txIndex, blockIndex, transactions.get(txIndex)) transactionDialog.open(txIndex, blockIndex, transactions.get(txIndex))
} }
@ -164,11 +165,11 @@ ColumnLayout
Image { Image {
anchors.top: parent.top anchors.top: parent.top
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: -9 anchors.leftMargin: -4
anchors.topMargin: -4 anchors.topMargin: 0
id: saveStatusImage id: saveStatusImage
source: "qrc:/qml/img/recyclediscard@2x.png" source: "qrc:/qml/img/recyclediscard@2x.png"
width: statusWidth + 20 width: statusWidth + 10
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
} }
@ -317,10 +318,10 @@ ColumnLayout
Rectangle Rectangle
{ {
width: debugActionWidth width: debugActionWidth
height: trHeight height: trHeight - 10
anchors.left: rowContentTr.right anchors.right: rowContentTr.right
anchors.top: rowContentTr.top anchors.top: rowContentTr.top
anchors.leftMargin: -50 anchors.rightMargin: 10
color: "transparent" color: "transparent"
Image { Image {
@ -328,7 +329,6 @@ ColumnLayout
source: "qrc:/qml/img/rightarrow@2x.png" source: "qrc:/qml/img/rightarrow@2x.png"
width: debugActionWidth width: debugActionWidth
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
visible: transactions.get(index).recordIndex !== undefined visible: transactions.get(index).recordIndex !== undefined
} }

19
mix/qml/BlockChain.qml

@ -24,6 +24,7 @@ ColumnLayout {
signal chainReloaded signal chainReloaded
signal txSelected(var blockIndex, var txIndex) signal txSelected(var blockIndex, var txIndex)
signal rebuilding signal rebuilding
signal accountAdded(string address, string amount)
Connections Connections
{ {
@ -47,14 +48,12 @@ ColumnLayout {
{ {
fromWidth = 250 fromWidth = 250
toWidth = 240 toWidth = 240
//valueWidth = 200
} }
else else
{ {
var diff = (width - previousWidth) / 3; var diff = (width - previousWidth) / 3;
fromWidth = fromWidth + diff < 250 ? 250 : fromWidth + diff fromWidth = fromWidth + diff < 250 ? 250 : fromWidth + diff
toWidth = toWidth + diff < 240 ? 240 : toWidth + diff toWidth = toWidth + diff < 240 ? 240 : toWidth + diff
//valueWidth = valueWidth + diff < 200 ? 200 : valueWidth + diff
} }
previousWidth = width previousWidth = width
} }
@ -89,7 +88,7 @@ ColumnLayout {
{ {
id: header id: header
spacing: 0 spacing: 0
Layout.preferredHeight: 30 Layout.preferredHeight: 24
Rectangle Rectangle
{ {
Layout.preferredWidth: statusWidth Layout.preferredWidth: statusWidth
@ -100,12 +99,13 @@ ColumnLayout {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
source: "qrc:/qml/img/recycleicon@2x.png" source: "qrc:/qml/img/recycleicon@2x.png"
width: statusWidth + 20 width: statusWidth + 10
fillMode: Image.PreserveAspectFit fillMode: Image.PreserveAspectFit
} }
} }
Rectangle Rectangle
{ {
anchors.verticalCenter: parent.verticalCenter
Layout.preferredWidth: fromWidth Layout.preferredWidth: fromWidth
Label Label
{ {
@ -118,11 +118,13 @@ ColumnLayout {
Label Label
{ {
text: "To" text: "To"
anchors.verticalCenter: parent.verticalCenter
Layout.preferredWidth: toWidth + cellSpacing Layout.preferredWidth: toWidth + cellSpacing
} }
Label Label
{ {
text: "" text: ""
anchors.verticalCenter: parent.verticalCenter
Layout.preferredWidth: debugActionWidth Layout.preferredWidth: debugActionWidth
} }
} }
@ -363,6 +365,7 @@ ColumnLayout {
var item = TransactionHelper.defaultTransaction() var item = TransactionHelper.defaultTransaction()
transactionDialog.stateAccounts = model.accounts transactionDialog.stateAccounts = model.accounts
transactionDialog.execute = true transactionDialog.execute = true
transactionDialog.editMode = false
transactionDialog.open(model.blocks[model.blocks.length - 1].transactions.length, model.blocks.length - 1, item) transactionDialog.open(model.blocks[model.blocks.length - 1].transactions.length, model.blocks.length - 1, item)
} }
width: 100 width: 100
@ -414,7 +417,6 @@ ColumnLayout {
} }
else else
addNewBlock() addNewBlock()
} }
function addNewBlock() function addNewBlock()
@ -509,7 +511,12 @@ ColumnLayout {
id: newAccount id: newAccount
text: qsTr("New Account..") text: qsTr("New Account..")
onClicked: { 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.preferredWidth: 100
Layout.preferredHeight: 30 Layout.preferredHeight: 30

16
mix/qml/KeyValuePanel.qml

@ -18,6 +18,11 @@ ColumnLayout {
property string role property string role
property alias model: modelKeyValue property alias model: modelKeyValue
function add(key, value)
{
modelKeyValue.append({ "key": key, "value": value })
}
function clear() function clear()
{ {
modelKeyValue.clear() modelKeyValue.clear()
@ -29,10 +34,7 @@ ColumnLayout {
if (typeof(computeData) !== "undefined" && computeData instanceof Function) if (typeof(computeData) !== "undefined" && computeData instanceof Function)
computeData() computeData()
else else
{ {
console.log("--------------")
console.log(JSON.stringify(_data))
console.log(role)
if (_data !== undefined && _data[role] !== undefined) if (_data !== undefined && _data[role] !== undefined)
{ {
var keys = Object.keys(_data[role]) var keys = Object.keys(_data[role])
@ -77,6 +79,7 @@ ColumnLayout {
id: columnValues id: columnValues
horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff horizontalScrollBarPolicy: Qt.ScrollBarAlwaysOff
anchors.fill: parent anchors.fill: parent
clip: true
ColumnLayout ColumnLayout
{ {
anchors.margins: 10 anchors.margins: 10
@ -97,7 +100,7 @@ ColumnLayout {
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 10 anchors.leftMargin: 10
text: { text: {
if (index >= 0) if (index >= 0 && repeaterKeyValue.model.get(index).key !== undefined)
return repeaterKeyValue.model.get(index).key return repeaterKeyValue.model.get(index).key
else else
return "" return ""
@ -113,7 +116,7 @@ ColumnLayout {
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 10 anchors.rightMargin: 10
text: { text: {
if (index >= 0) if (index >= 0 && repeaterKeyValue.model.get(index).value !== undefined)
return repeaterKeyValue.model.get(index).value return repeaterKeyValue.model.get(index).value
else else
return "" return ""
@ -123,6 +126,7 @@ ColumnLayout {
} }
} }
} }
} }
} }
} }

13
mix/qml/ScenarioExecution.qml

@ -84,14 +84,27 @@ Rectangle {
Connections Connections
{ {
target: blockChain target: blockChain
property var currentSelectedBlock
property var currentSelectedTx
onTxSelected: { onTxSelected: {
currentSelectedBlock = blockIndex
currentSelectedTx = txIndex
updateWatchers(blockIndex, txIndex)
}
function updateWatchers(blockIndex, txIndex){
var tx = blockChain.model.blocks[blockIndex].transactions[txIndex] var tx = blockChain.model.blocks[blockIndex].transactions[txIndex]
var state = blockChain.getState(tx.recordIndex) var state = blockChain.getState(tx.recordIndex)
watchers.updateWidthTx(tx, state, blockIndex, txIndex) watchers.updateWidthTx(tx, state, blockIndex, txIndex)
} }
onRebuilding: { onRebuilding: {
watchers.clear() watchers.clear()
} }
onAccountAdded: {
watchers.addAccount(address, "0 wei")
}
} }
} }

3
mix/qml/StateListModel.qml

@ -257,8 +257,7 @@ Item {
_secret = clientModel.newSecret(); _secret = clientModel.newSecret();
var address = clientModel.address(_secret); var address = clientModel.address(_secret);
var name = qsTr("Account") + "-" + address.substring(0, 4); var name = qsTr("Account") + "-" + address.substring(0, 4);
var amount = QEtherHelper.createEther(_balance, _unit) var amount = QEtherHelper.createEther(_balance, _unit)
clientModel.addAccount(_secret, amount.toWei().value())
return { name: name, secret: _secret, balance: amount, address: address }; return { name: name, secret: _secret, balance: amount, address: address };
} }

7
mix/qml/TransactionDialog.qml

@ -16,7 +16,8 @@ Dialog {
width: 580 width: 580
height: 500 height: 500
visible: false visible: false
title: qsTr("Edit Transaction") title: editMode ? qsTr("Edit Transaction") : qsTr("Add Transaction")
property bool editMode
property int transactionIndex property int transactionIndex
property int blockIndex property int blockIndex
property alias gas: gasValueEdit.gasValue; property alias gas: gasValueEdit.gasValue;
@ -390,7 +391,7 @@ Dialog {
objectName: "trTypeExecute" objectName: "trTypeExecute"
exclusiveGroup: rbbuttonList exclusiveGroup: rbbuttonList
height: 30 height: 30
text: qsTr("Execute Contract") text: qsTr("Transact with Contract")
} }
} }
} }
@ -687,7 +688,7 @@ Dialog {
} }
Button { Button {
text: qsTr("Update"); text: editMode ? qsTr("Update") : qsTr("Ok")
onClicked: { onClicked: {
var invalid = InputValidator.validate(paramsModel, paramValues); var invalid = InputValidator.validate(paramsModel, paramValues);
if (invalid.length === 0) if (invalid.length === 0)

45
mix/qml/Watchers.qml

@ -24,16 +24,23 @@ Rectangle {
{ {
from.text = "" from.text = ""
to.text = "" to.text = ""
value.text = ""
inputParams.clear() inputParams.clear()
returnParams.clear() returnParams.clear()
accounts.clear() accounts.clear()
events.clear() events.clear()
} }
function addAccount(address, amount)
{
accounts.add(address, amount)
}
function updateWidthTx(_tx, _state, _blockIndex, _txIndex) function updateWidthTx(_tx, _state, _blockIndex, _txIndex)
{ {
from.text = _tx.sender from.text = clientModel.resolveAddress(_tx.sender)
to.text = _tx.label to.text = _tx.label
value.text = _tx.value.format()
tx = _tx tx = _tx
blockIndex = _blockIndex blockIndex = _blockIndex
txIndex = _txIndex txIndex = _txIndex
@ -43,10 +50,10 @@ Rectangle {
{ {
returnParams.role = "creationAddr" returnParams.role = "creationAddr"
returnParams._data = { returnParams._data = {
creationAddr : { creationAddr : {
"": _tx.returned
} }
} }
returnParams._data.creationAddr[qsTr("contract address")] = _tx.returned
} }
else else
{ {
@ -68,6 +75,7 @@ Rectangle {
color: "transparent" color: "transparent"
Row Row
{ {
id: rowHeader
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
height: 5 height: 5
@ -100,19 +108,28 @@ Rectangle {
clip: true clip: true
width: 100 width: 100
} }
Label {
id: value
color: "#EAB920"
font.italic: true
clip: true
}
}
Image { Image {
source: "qrc:/qml/img/edit.png" anchors.right: rowHeader.parent.right
height: 15 anchors.top: rowHeader.parent.top
fillMode: Image.PreserveAspectFit anchors.topMargin: 10
visible: from.text !== "" source: "qrc:/qml/img/edit.png"
MouseArea height: 15
fillMode: Image.PreserveAspectFit
visible: from.text !== ""
MouseArea
{
anchors.fill: parent
onClicked:
{ {
anchors.fill: parent bc.blockChainRepeater.editTx(blockIndex, txIndex)
onClicked:
{
bc.blockChainRepeater.editTx(blockIndex, txIndex)
}
} }
} }
} }

Loading…
Cancel
Save