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;
}
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);
}

4
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;

14
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
}

19
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

16
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 {
}
}
}
}
}
}

13
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")
}
}
}

3
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 };
}

7
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)

45
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)
}
}
}

Loading…
Cancel
Save