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. 14
      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)
{
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);
else
return _b;

1
mix/AppContext.cpp

@ -61,7 +61,6 @@ void AppContext::load()
m_applicationEngine->rootContext()->setContextProperty("fileIo", m_fileIo.get());
qmlRegisterType<QEther>("org.ethereum.qml.QEther", 1, 0, "QEther");
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<QRealType>("org.ethereum.qml.QRealType", 1, 0, "QRealType");
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");
c.encode(f);
for (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();
for (unsigned int p = 0; p < t.parameterValues.size(); p++)
c.push(t.parameterValues.at(p)->encodeValue());
}
transactonData.emplace_back(c.encodedData());
}

1
mix/ContractCallDataEncoder.cpp

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

5
mix/QVariableDefinition.cpp

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

8
mix/QVariableDefinition.h

@ -41,13 +41,17 @@ public:
QVariableDefinition() {}
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; }
/// Return the variable 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; }
/// Set a new Declaration for this instance. Invokable from QML.
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;
/// Decode the return value @a _rawValue.
virtual void decodeValue(std::string const& _rawValue) = 0;
private:
@ -82,6 +86,7 @@ public:
QIntType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {}
dev::bytes encodeValue() override;
void decodeValue(std::string const& _rawValue) override;
/// @returns an instance of QBigInt for the current value.
QBigInt* toBigInt() { return new QBigInt(value()); }
};
@ -127,6 +132,7 @@ public:
QBoolType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {}
dev::bytes encodeValue() override;
void decodeValue(std::string const& _rawValue) override;
/// @returns the boolean value for the current definition.
bool toBool() { return value() != "0"; }
};

1
mix/qml/QBoolType.qml

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

14
mix/qml/QBoolTypeView.qml

@ -5,22 +5,28 @@ Item
{
id: editRoot
property string text
property bool defaultValue
Rectangle {
anchors.fill: parent
ComboBox
{
Component.onCompleted:
{
text = (defaultValue ? "1" : "0");
currentIndex = parseInt(text);
}
id: boolCombo
anchors.fill: parent
onCurrentIndexChanged:
{
text = coolComboModel.get(currentIndex).value;
editRoot.textChanged();
text = comboModel.get(currentIndex).value;
}
model: ListModel
{
id: coolComboModel
ListElement { text: qsTr("True"); value: "1" }
id: comboModel
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
{
property string view: "qrc:/qml/QHashTypeView.qml"
}

1
mix/qml/QHashTypeView.qml

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

1
mix/qml/QIntType.qml

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

1
mix/qml/QIntTypeView.qml

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

1
mix/qml/QRealType.qml

@ -3,6 +3,5 @@ import org.ethereum.qml.QRealType 1.0
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
{
property string view: "qrc:/qml/QStringTypeView.qml"
}

1
mix/qml/QStringTypeView.qml

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

47
mix/qml/TransactionDialog.qml

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

Loading…
Cancel
Save