Browse Source

- Cleaning.

- Bug fix in hash decoding.
cl-refactor
yann300 10 years ago
committed by yann300
parent
commit
a78c3668b5
  1. 2
      libdevcore/CommonJS.cpp
  2. 1
      mix/AppContext.cpp
  3. 7
      mix/ClientModel.cpp
  4. 1
      mix/ContractCallDataEncoder.cpp
  5. 5
      mix/QVariableDefinition.cpp
  6. 8
      mix/QVariableDefinition.h
  7. 1
      mix/qml/QBoolType.qml
  8. 18
      mix/qml/QBoolTypeView.qml
  9. 1
      mix/qml/QHashType.qml
  10. 1
      mix/qml/QHashTypeView.qml
  11. 1
      mix/qml/QIntType.qml
  12. 1
      mix/qml/QIntTypeView.qml
  13. 1
      mix/qml/QRealType.qml
  14. 1
      mix/qml/QStringType.qml
  15. 1
      mix/qml/QStringTypeView.qml
  16. 47
      mix/qml/TransactionDialog.qml

2
libdevcore/CommonJS.cpp

@ -64,7 +64,7 @@ std::string unpadRight(std::string _b)
while (true) while (true)
{ {
auto p = _b.find_last_of("0"); auto p = _b.find_last_of("0");
if (p == _b.size() - 1) if (p == _b.size() - 1 && p != std::string::npos)
_b = _b.substr(0, _b.size() - 1); _b = _b.substr(0, _b.size() - 1);
else else
return _b; return _b;

1
mix/AppContext.cpp

@ -61,7 +61,6 @@ void AppContext::load()
m_applicationEngine->rootContext()->setContextProperty("fileIo", m_fileIo.get()); m_applicationEngine->rootContext()->setContextProperty("fileIo", m_fileIo.get());
qmlRegisterType<QEther>("org.ethereum.qml.QEther", 1, 0, "QEther"); qmlRegisterType<QEther>("org.ethereum.qml.QEther", 1, 0, "QEther");
qmlRegisterType<QBigInt>("org.ethereum.qml.QBigInt", 1, 0, "QBigInt"); qmlRegisterType<QBigInt>("org.ethereum.qml.QBigInt", 1, 0, "QBigInt");
//qmlRegisterType<QVariableDefinition>("org.ethereum.qml.QVariableDefinition", 1, 0, "QVariableDefinition");
qmlRegisterType<QIntType>("org.ethereum.qml.QIntType", 1, 0, "QIntType"); qmlRegisterType<QIntType>("org.ethereum.qml.QIntType", 1, 0, "QIntType");
qmlRegisterType<QRealType>("org.ethereum.qml.QRealType", 1, 0, "QRealType"); qmlRegisterType<QRealType>("org.ethereum.qml.QRealType", 1, 0, "QRealType");
qmlRegisterType<QStringType>("org.ethereum.qml.QStringType", 1, 0, "QStringType"); qmlRegisterType<QStringType>("org.ethereum.qml.QStringType", 1, 0, "QStringType");

7
mix/ClientModel.cpp

@ -171,13 +171,8 @@ void ClientModel::executeSequence(std::vector<TransactionSettings> const& _seque
throw std::runtime_error("function " + t.functionId.toStdString() + " not found"); throw std::runtime_error("function " + t.functionId.toStdString() + " not found");
c.encode(f); c.encode(f);
for (int p = 0; p < t.parameterValues.size(); p++) for (unsigned int p = 0; p < t.parameterValues.size(); p++)
{
qDebug() << " encode input parameters : " + t.parameterValues.at(p)->declaration()->type();
qDebug() << t.parameterValues.at(p)->declaration()->type();
qDebug() << t.parameterValues.at(p)->value();
c.push(t.parameterValues.at(p)->encodeValue()); c.push(t.parameterValues.at(p)->encodeValue());
}
transactonData.emplace_back(c.encodedData()); transactonData.emplace_back(c.encodedData());
} }

1
mix/ContractCallDataEncoder.cpp

@ -35,7 +35,6 @@ using namespace dev::mix;
bytes ContractCallDataEncoder::encodedData() bytes ContractCallDataEncoder::encodedData()
{ {
qDebug() << " encoded data " << QString::fromStdString(toJS(m_encodedData));
return m_encodedData; return m_encodedData;
} }

5
mix/QVariableDefinition.cpp

@ -66,7 +66,6 @@ dev::bytes QIntType::encodeValue()
i = i + dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + 1; i = i + dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + 1;
std::ostringstream s; std::ostringstream s;
s << std::hex << "0x" << i; s << std::hex << "0x" << i;
qDebug() << " int input " << QString::fromStdString(toJS(padded(jsToBytes(s.str()), 32)));
return padded(jsToBytes(s.str()), 32); return padded(jsToBytes(s.str()), 32);
} }
@ -78,7 +77,6 @@ void QIntType::decodeValue(std::string const& _rawValue)
bigint = bigint - dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") - 1; bigint = bigint - dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") - 1;
std::ostringstream s; std::ostringstream s;
s << std::dec << bigint; s << std::dec << bigint;
qDebug() << " int output " << QString::fromStdString(s.str());
setValue(QString::fromStdString(s.str())); setValue(QString::fromStdString(s.str()));
} }
@ -87,7 +85,7 @@ void QIntType::decodeValue(std::string const& _rawValue)
*/ */
dev::bytes QHashType::encodeValue() dev::bytes QHashType::encodeValue()
{ {
return padded(asBytes(value().toStdString()), 32); return padded(jsToBytes("0x" + value().toStdString()), 32);
} }
void QHashType::decodeValue(std::string const& _rawValue) void QHashType::decodeValue(std::string const& _rawValue)
@ -140,7 +138,6 @@ void QStringType::decodeValue(std::string const& _rawValue)
*/ */
dev::bytes QBoolType::encodeValue() dev::bytes QBoolType::encodeValue()
{ {
qDebug() << QString::fromStdString(toJS(padded(jsToBytes(value().toStdString()), 32)));
return padded(jsToBytes(value().toStdString()), 32); return padded(jsToBytes(value().toStdString()), 32);
} }

8
mix/QVariableDefinition.h

@ -41,13 +41,17 @@ public:
QVariableDefinition() {} QVariableDefinition() {}
QVariableDefinition(QVariableDeclaration* _def, QString _value): QObject(), m_value(_value), m_dec(_def) {} QVariableDefinition(QVariableDeclaration* _def, QString _value): QObject(), m_value(_value), m_dec(_def) {}
/// Return the associated declaration of this variable definition. /// Return the associated declaration of this variable definition. Invokable from QML.
Q_INVOKABLE QVariableDeclaration* declaration() const { return m_dec; } Q_INVOKABLE QVariableDeclaration* declaration() const { return m_dec; }
/// Return the variable value. /// Return the variable value.
QString value() const { return m_value; } QString value() const { return m_value; }
/// Set a new value for this instance. Invokable from QML.
Q_INVOKABLE void setValue(QString _value) { m_value = _value; } Q_INVOKABLE void setValue(QString _value) { m_value = _value; }
/// Set a new Declaration for this instance. Invokable from QML.
Q_INVOKABLE void setDeclaration(QVariableDeclaration* _dec) { m_dec = _dec; } Q_INVOKABLE void setDeclaration(QVariableDeclaration* _dec) { m_dec = _dec; }
/// Encode the current value in order to be used as function parameter.
virtual bytes encodeValue() = 0; virtual bytes encodeValue() = 0;
/// Decode the return value @a _rawValue.
virtual void decodeValue(std::string const& _rawValue) = 0; virtual void decodeValue(std::string const& _rawValue) = 0;
private: private:
@ -82,6 +86,7 @@ public:
QIntType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} QIntType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {}
dev::bytes encodeValue() override; dev::bytes encodeValue() override;
void decodeValue(std::string const& _rawValue) override; void decodeValue(std::string const& _rawValue) override;
/// @returns an instance of QBigInt for the current value.
QBigInt* toBigInt() { return new QBigInt(value()); } QBigInt* toBigInt() { return new QBigInt(value()); }
}; };
@ -127,6 +132,7 @@ public:
QBoolType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} QBoolType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {}
dev::bytes encodeValue() override; dev::bytes encodeValue() override;
void decodeValue(std::string const& _rawValue) override; void decodeValue(std::string const& _rawValue) override;
/// @returns the boolean value for the current definition.
bool toBool() { return value() != "0"; } bool toBool() { return value() != "0"; }
}; };

1
mix/qml/QBoolType.qml

@ -3,6 +3,5 @@ import org.ethereum.qml.QBoolType 1.0
QBoolType QBoolType
{ {
property string view: "qrc:/qml/QBoolTypeView.qml"
} }

18
mix/qml/QBoolTypeView.qml

@ -5,23 +5,29 @@ Item
{ {
id: editRoot id: editRoot
property string text property string text
property bool defaultValue
Rectangle { Rectangle {
anchors.fill: parent anchors.fill: parent
ComboBox ComboBox
{ {
Component.onCompleted:
{
text = (defaultValue ? "1" : "0");
currentIndex = parseInt(text);
}
id: boolCombo id: boolCombo
anchors.fill: parent anchors.fill: parent
onCurrentIndexChanged: onCurrentIndexChanged:
{ {
text = coolComboModel.get(currentIndex).value; text = comboModel.get(currentIndex).value;
editRoot.textChanged();
} }
model: ListModel model: ListModel
{ {
id: coolComboModel id: comboModel
ListElement { text: qsTr("True"); value: "1" } ListElement { text: qsTr("False"); value: "0" }
ListElement { text: qsTr("False"); value: "0" } ListElement { text: qsTr("True"); value: "1" }
} }
} }
} }
} }

1
mix/qml/QHashType.qml

@ -3,6 +3,5 @@ import org.ethereum.qml.QHashType 1.0
QHashType QHashType
{ {
property string view: "qrc:/qml/QHashTypeView.qml"
} }

1
mix/qml/QHashTypeView.qml

@ -10,7 +10,6 @@ Item
id: textinput id: textinput
text: text text: text
anchors.fill: parent anchors.fill: parent
onTextChanged: editRoot.textChanged()
MouseArea { MouseArea {
id: mouseArea id: mouseArea
anchors.fill: parent anchors.fill: parent

1
mix/qml/QIntType.qml

@ -3,6 +3,5 @@ import org.ethereum.qml.QIntType 1.0
QIntType QIntType
{ {
property string view: "qrc:/qml/QIntTypeView.qml"
} }

1
mix/qml/QIntTypeView.qml

@ -10,7 +10,6 @@ Item
id: textinput id: textinput
text: text text: text
anchors.fill: parent anchors.fill: parent
onTextChanged: editRoot.textChanged()
MouseArea { MouseArea {
id: mouseArea id: mouseArea
anchors.fill: parent anchors.fill: parent

1
mix/qml/QRealType.qml

@ -3,6 +3,5 @@ import org.ethereum.qml.QRealType 1.0
QRealType QRealType
{ {
property string view: "qrc:/qml/QRealTypeView.qml"
} }

1
mix/qml/QStringType.qml

@ -3,6 +3,5 @@ import org.ethereum.qml.QStringType 1.0
QStringType QStringType
{ {
property string view: "qrc:/qml/QStringTypeView.qml"
} }

1
mix/qml/QStringTypeView.qml

@ -10,7 +10,6 @@ Item
id: textinput id: textinput
text: text text: text
anchors.fill: parent anchors.fill: parent
onTextChanged: editRoot.textChanged()
MouseArea { MouseArea {
id: mouseArea id: mouseArea
anchors.fill: parent anchors.fill: parent

47
mix/qml/TransactionDialog.qml

@ -9,7 +9,7 @@ Window {
id: modalTransactionDialog id: modalTransactionDialog
modality: Qt.WindowModal modality: Qt.WindowModal
width:640 width:640
height:480 height:640
visible: false visible: false
property int transactionIndex property int transactionIndex
@ -41,8 +41,6 @@ Window {
rowFunction.visible = !item.executeConstructor; rowFunction.visible = !item.executeConstructor;
itemParams = item.parameters !== undefined ? item.parameters : {}; itemParams = item.parameters !== undefined ? item.parameters : {};
console.log("save parameters : ");
console.log(JSON.stringify(item.qType));
functionsModel.clear(); functionsModel.clear();
var functionIndex = -1; var functionIndex = -1;
var functions = codeModel.code.contract.functions; var functions = codeModel.code.contract.functions;
@ -72,6 +70,7 @@ Window {
} }
function loadParameters() { function loadParameters() {
paramsModel.clear();
if (!paramsModel) if (!paramsModel)
return; return;
if (functionComboBox.currentIndex >= 0 && functionComboBox.currentIndex < functionsModel.count) { if (functionComboBox.currentIndex >= 0 && functionComboBox.currentIndex < functionsModel.count) {
@ -109,7 +108,7 @@ Window {
visible = false; visible = false;
} }
function getqTypeParam(name) function qTypeParam(name)
{ {
for (var k in qType) for (var k in qType)
{ {
@ -145,11 +144,11 @@ Window {
var orderedQType = []; var orderedQType = [];
for (var p = 0; p < transactionDialog.transactionParams.count; p++) { for (var p = 0; p < transactionDialog.transactionParams.count; p++) {
var parameter = transactionDialog.transactionParams.get(p); var parameter = transactionDialog.transactionParams.get(p);
getqTypeParam(parameter.name).setValue(parameter.value); var qtypeParam = qTypeParam(parameter.name);
orderedQType.push(getqTypeParam(parameter.name)); qtypeParam.setValue(parameter.value);
orderedQType.push(qtypeParam);
item.parameters[parameter.name] = parameter.value; item.parameters[parameter.name] = parameter.value;
} }
console.log(JSON.stringify(qType));
item.qType = orderedQType; item.qType = orderedQType;
return item; return item;
} }
@ -253,7 +252,10 @@ Window {
} }
TableView { TableView {
model: paramsModel model: paramsModel
Layout.fillWidth: true Layout.preferredWidth: 120 * 2 + 240
Layout.minimumHeight: 150
Layout.preferredHeight: 400
Layout.maximumHeight: 600
TableViewColumn { TableViewColumn {
role: "name" role: "name"
title: "Name" title: "Name"
@ -267,18 +269,10 @@ Window {
TableViewColumn { TableViewColumn {
role: "value" role: "value"
title: "Value" title: "Value"
width: 120 width: 240
}
rowDelegate:
{
return rowDelegate
}
itemDelegate:
{
return editableDelegate;
} }
rowDelegate: rowDelegate
itemDelegate: editableDelegate
} }
} }
} }
@ -324,15 +318,20 @@ Window {
target: loaderEditor.item target: loaderEditor.item
onTextChanged: { onTextChanged: {
if (styleData.role === "value" && styleData.row < paramsModel.count) if (styleData.role === "value" && styleData.row < paramsModel.count)
paramsModel.setProperty(styleData.row, styleData.role, loaderEditor.item.text); loaderEditor.updateValue(styleData.row, styleData.role, loaderEditor.item.text);
} }
} }
function updateValue(row, role, value)
{
paramsModel.setProperty(styleData.row, styleData.role, value);
}
sourceComponent: sourceComponent:
{ {
if (styleData.role === "value") if (styleData.role === "value")
{ {
if (paramsModel.get(styleData.row) === 'undefined') if (paramsModel.get(styleData.row) === undefined)
return null; return null;
if (paramsModel.get(styleData.row).type.indexOf("int") !== -1) if (paramsModel.get(styleData.row).type.indexOf("int") !== -1)
return intViewComp; return intViewComp;
@ -365,6 +364,12 @@ Window {
{ {
id: boolView id: boolView
text: styleData.value text: styleData.value
defaultValue: true
Component.onCompleted:
{
//default value
loaderEditor.updateValue(styleData.row, styleData.role, "1");
}
} }
} }

Loading…
Cancel
Save