Browse Source

Merge branch 'ide_m25' of https://github.com/yann300/cpp-ethereum into

mix_states

State management

Conflicts:
	mix/AssemblyDebuggerControl.cpp
	mix/KeyEventManager.h
cl-refactor
arkpar 10 years ago
parent
commit
f85c9108e4
  1. 12
      libdevcore/CommonJS.h
  2. 12
      mix/AssemblyDebuggerControl.cpp
  3. 6
      mix/AssemblyDebuggerControl.h
  4. 4
      mix/AssemblyDebuggerModel.cpp
  5. 13
      mix/AssemblyDebuggerModel.h
  6. 6
      mix/CodeEditorExtensionManager.cpp
  7. 1
      mix/DebuggingStateWrapper.h
  8. 16
      mix/StateListView.cpp
  9. 7
      mix/StateListView.h
  10. 1
      mix/qml.qrc
  11. 55
      mix/qml/TransactionDialog.qml
  12. 138
      mix/qml/TransactionList.qml

12
libdevcore/CommonJS.h

@ -46,19 +46,19 @@ inline std::string toJS(dev::bytes const& _n)
return "0x" + dev::toHex(_n);
}
/// Convert string to byte array.
/// Convert string to byte array. Input parameters can be hex or dec. Returns empty array if invalid input e.g neither dec or hex.
bytes jsToBytes(std::string const& _s);
/// Add '0' on the head of _b until _l.
bytes padded(bytes _b, unsigned _l);
/// Removing all trailing '0'.
/// Removing all trailing '0'. Returns empty array if input contains only '0' char.
bytes unpadded(bytes _s);
/// Remove all '0' on the head of _s.
/// Remove all '0' on the head of _s. Returns 0 if _s contains only '0'.
std::string unpadLeft(std::string _s);
/// Convert u256 to readable string.
/// Convert u256 into user-readable string. Returns int/hex value of 64 bits int, hex of 160 bits FixedHash. As a fallback try to handle input as h256.
std::string prettyU256(u256 _n);
/// Convert h256 to readable string.
/// Convert h256 into user-readable string (by directly using std::string constructor).
std::string fromRaw(h256 _n, unsigned* _inc = nullptr);
/// Convert string to Address (h160).
/// Convert string to Address (h160), returns empty address if (_a.size != 40).
Address fromString(std::string const& _a);
template <unsigned N> FixedHash<N> jsToFixed(std::string const& _s)

12
mix/AssemblyDebuggerControl.cpp

@ -17,6 +17,10 @@
* display opcode debugging.
*/
//These 2 includes should be at the top to avoid conflicts with macros defined in windows.h
//@todo fix this is solidity headers
#include <libsolidity/Token.h>
#include <libsolidity/Types.h>
#include <utility>
#include <QtConcurrent/QtConcurrent>
#include <QDebug>
@ -88,18 +92,20 @@ void AssemblyDebuggerControl::debugDeployment()
deployContract();
}
void AssemblyDebuggerControl::debugTransaction(QObject* _transaction)
void AssemblyDebuggerControl::debugState(QObject* _state)
{
/*
QString functionId = _transaction->property("functionId").toString();
u256 value = fromQString(_transaction->property("value").toString());
u256 gas = fromQString(_transaction->property("gas").toString());
u256 gasPrice = fromQString(_transaction->property("gasPrice").toString());
QVariantMap params = _transaction->property("parameters").toMap();
TransactionSettings transaction("", functionId, value, gas, gasPrice);
TransactionSettings transaction(functionId, value, gas, gasPrice);
for (auto p = params.cbegin(); p != params.cend(); ++p)
transaction.parameterValues.insert(std::make_pair(p.key(), fromQString(p.value().toString())));
runTransaction(transaction);
*/
}
void AssemblyDebuggerControl::resetState()
@ -108,7 +114,7 @@ void AssemblyDebuggerControl::resetState()
m_ctx->displayMessageDialog(QApplication::tr("State status"), QApplication::tr("State reseted ... need to redeploy contract"));
}
void AssemblyDebuggerControl::callContract(TransactionSettings _tr, Address _contract)
void AssemblyDebuggerControl::callContract(TransactionSettings _tr, dev::Address _contract)
{
auto compilerRes = m_ctx->codeModel()->code();
if (!compilerRes->successfull())

6
mix/AssemblyDebuggerControl.h

@ -19,6 +19,10 @@
#pragma once
//These 2 includes should be at the top to avoid conflicts with macros defined in windows.h
//@todo fix this is solidity headers
#include <libsolidity/Token.h>
#include <libsolidity/Types.h>
#include <QKeySequence>
#include "Extension.h"
#include "AssemblyDebuggerModel.h"
@ -65,7 +69,7 @@ private:
public slots:
void debugDeployment();
void debugTransaction(QObject* _transaction);
void debugState(QObject* _transaction);
void resetState();
/// Update UI with machine states result. Display a modal dialog.
void updateGUI(bool _success, DebuggingStatusResult const& _reason, QList<QVariableDefinition*> const& _returnParams = QList<QVariableDefinition*>(), QList<QObject*> const& _wStates = QList<QObject*>(), AssemblyDebuggerData const& _code = AssemblyDebuggerData());

4
mix/AssemblyDebuggerModel.cpp

@ -17,6 +17,10 @@
* used as a model to debug contract assembly code.
*/
//These 2 includes should be at the top to avoid conflicts with macros defined in windows.h
//@todo fix this is solidity headers
#include <libsolidity/Token.h>
#include <libsolidity/Types.h>
#include <QApplication>
#include <libdevcore/Common.h>
#include <libevm/VM.h>

13
mix/AssemblyDebuggerModel.h

@ -19,6 +19,10 @@
#pragma once
//These 2 includes should be at the top to avoid conflicts with macros defined in windows.h
//@todo fix this is solidity headers
#include <libsolidity/Token.h>
#include <libsolidity/Types.h>
#include <QObject>
#include <QList>
#include <libdevcore/Common.h>
@ -35,14 +39,9 @@ namespace mix
/// Backend transaction config class
struct TransactionSettings
{
TransactionSettings():
value(0), gas(10000), gasPrice(10 * dev::eth::szabo) {}
TransactionSettings(QString const& _functionId, u256 _value, u256 _gas, u256 _gasPrice):
functionId(_functionId), value(_value), gas(_gas), gasPrice(_gasPrice) {}
TransactionSettings(QString const& _title, QString const& _functionId, u256 _value, u256 _gas, u256 _gasPrice):
title(_title), functionId(_functionId), value(_value), gas(_gas), gasPrice(_gasPrice) {}
/// User specified transaction title
QString title;
/// Contract function name
QString functionId;
/// Transaction value

6
mix/CodeEditorExtensionManager.cpp

@ -28,7 +28,7 @@
#include <libevm/VM.h>
#include "ConstantCompilationControl.h"
#include "AssemblyDebuggerControl.h"
#include "TransactionListView.h"
#include "StateListView.h"
#include "AppContext.h"
#include "MixApplication.h"
#include "CodeModel.h"
@ -66,11 +66,11 @@ void CodeEditorExtensionManager::initExtensions()
{
initExtension(std::make_shared<ConstantCompilationControl>(m_appContext));
std::shared_ptr<AssemblyDebuggerControl> debug = std::make_shared<AssemblyDebuggerControl>(m_appContext);
std::shared_ptr<TransactionListView> tr = std::make_shared<TransactionListView>(m_appContext);
std::shared_ptr<StateListView> stateList = std::make_shared<StateListView>(m_appContext);
QObject::connect(m_doc, &QTextDocument::contentsChanged, [=]() { m_appContext->codeModel()->registerCodeChange(m_doc->toPlainText()); });
initExtension(debug);
initExtension(tr);
initExtension(stateList);
}
void CodeEditorExtensionManager::initExtension(std::shared_ptr<Extension> _ext)

1
mix/DebuggingStateWrapper.h

@ -23,6 +23,7 @@
#pragma once
#include <QStringList>
#include <QMap>
#include <libdevcore/Common.h>
#include <libethereum/State.h>
#include <libethereum/Executive.h>

16
mix/TransactionListView.cpp → mix/StateListView.cpp

@ -14,7 +14,7 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file TransactionListView.cpp
/** @file StateListView.cpp
* @author Arkadiy Paronyan arkadiy@ethdev.com
* @date 2014
* Ethereum IDE client.
@ -25,23 +25,23 @@
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QDebug>
#include "TransactionListView.h"
#include "StateListView.h"
using namespace dev::mix;
TransactionListView::TransactionListView(AppContext* _context): Extension(_context, ExtensionDisplayBehavior::RightTab)
StateListView::StateListView(AppContext* _context): Extension(_context, ExtensionDisplayBehavior::RightTab)
{
}
QString TransactionListView::contentUrl() const
QString StateListView::contentUrl() const
{
return QStringLiteral("qrc:/qml/TransactionList.qml");
return QStringLiteral("qrc:/qml/StateList.qml");
}
QString TransactionListView::title() const
QString StateListView::title() const
{
return QApplication::tr("Transactions");
return QApplication::tr("State");
}
void TransactionListView::start() const
void StateListView::start() const
{
}

7
mix/TransactionListView.h → mix/StateListView.h

@ -11,7 +11,7 @@
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file TransactionListView.h
/** @file StateListView.h
* @author Arkadiy Paronyan arkadiy@ethdev.com
* @date 2014
* Ethereum IDE client.
@ -21,7 +21,6 @@
#include <memory>
#include <QTextDocument>
#include "TransactionListView.h"
#include "Extension.h"
namespace dev
@ -31,12 +30,12 @@ namespace mix
/// Transactions list control
/// @todo This should be moved into state as a sequence
class TransactionListView: public Extension
class StateListView: public Extension
{
Q_OBJECT
public:
TransactionListView(AppContext* _context);
StateListView(AppContext* _context);
void start() const override;
QString title() const override;
QString contentUrl() const override;

1
mix/qml.qrc

@ -8,7 +8,6 @@
<file>qml/js/Debugger.js</file>
<file>qml/BasicMessage.qml</file>
<file>qml/TransactionDialog.qml</file>
<file>qml/TransactionList.qml</file>
<file>qml/ModalDialog.qml</file>
<file>qml/AlertMessageDialog.qml</file>
<file>qml/StateDialog.qml</file>

55
mix/qml/TransactionDialog.qml

@ -5,23 +5,10 @@ import QtQuick.Window 2.0
Window {
modality: Qt.WindowModal
width:640
height:480
visible: false
function open()
{
visible = true;
}
function close()
{
visible = false;
}
property alias focus : titleField.focus
property alias transactionTitle : titleField.text
property int transactionIndex
property alias transactionParams : paramsModel;
property alias gas : gasField.text;
@ -32,9 +19,8 @@ Window {
signal accepted;
function reset(index, item) {
function open(index, item) {
transactionIndex = index;
transactionTitle = item.title;
gas = item.gas;
gasPrice = item.gasPrice;
transactionValue = item.value;
@ -48,7 +34,14 @@ Window {
if (functions[f].name === item.functionId)
functionIndex = f;
}
if (functionIndex == -1 && functionsModel.count > 0)
functionIndex = 0; //@todo suggest unused funtion
functionComboBox.currentIndex = functionIndex;
loadParameters();
visible = true;
valueField.focus = true;
}
function loadParameters() {
@ -65,6 +58,27 @@ Window {
}
}
function close()
{
visible = false;
}
function getItem()
{
var item = {
functionId: transactionDialog.functionId,
gas: transactionDialog.gas,
gasPrice: transactionDialog.gasPrice,
value: transactionDialog.transactionValue,
parameters: {}
}
for (var p = 0; p < transactionDialog.transactionParams.count; p++) {
var parameter = transactionDialog.transactionParams.get(p);
item.parameters[parameter.name] = parameter.value;
}
return item;
}
GridLayout {
id: dialogContent
columns: 2
@ -73,19 +87,9 @@ Window {
rowSpacing: 10
columnSpacing: 10
Label {
text: qsTr("Title")
}
TextField {
id: titleField
focus: true
Layout.fillWidth: true
}
Label {
text: qsTr("Function")
}
ComboBox {
id: functionComboBox
Layout.fillWidth: true
@ -99,6 +103,7 @@ Window {
loadParameters();
}
}
Label {
text: qsTr("Value")
}

138
mix/qml/TransactionList.qml

@ -1,138 +0,0 @@
import QtQuick 2.2
import QtQuick.Controls.Styles 1.2
import QtQuick.Controls 1.2
import QtQuick.Dialogs 1.2
import QtQuick.Layouts 1.1
Rectangle {
color: "transparent"
id: transactionListContainer
focus: true
anchors.topMargin: 10
anchors.left: parent.left
height: parent.height
width: parent.width
Connections {
target: appContext
onProjectLoaded: {
var items = JSON.parse(_json);
for(var i = 0; i < items.length; i++) {
transactionListModel.append(items[i]);
}
}
}
ListView {
anchors.top: parent.top
height: parent.height
width: parent.width
id: transactionList
model: ListModel {
id: transactionListModel
function runTransaction(index) {
var item = transactionListModel.get(index);
debugModel.debugTransaction(item);
}
}
delegate: renderDelegate
}
Button {
anchors.bottom: parent.bottom
text: qsTr("Add")
onClicked:
{
// Set next id here to work around Qt bug
// https://bugreports.qt-project.org/browse/QTBUG-41327
// Second call to signal handler would just edit the item that was just created, no harm done
var item = {
title: "",
value: "",
functionId: "",
gas: "1000000000000",
gasPrice: "100000"
};
transactionDialog.reset(transactionListModel.count, item);
transactionDialog.open();
transactionDialog.focus = true;
}
}
TransactionDialog {
id: transactionDialog
onAccepted: {
var item = {
title: transactionDialog.transactionTitle,
functionId: transactionDialog.functionId,
gas: transactionDialog.gas,
gasPrice: transactionDialog.gasPrice,
value: transactionDialog.transactionValue,
parameters: {}
}
for (var p = 0; p < transactionDialog.transactionParams.count; p++) {
var parameter = transactionDialog.transactionParams.get(p);
item.parameters[parameter.name] = parameter.value;
}
console.log(item.title);
if (transactionDialog.transactionIndex < transactionListModel.count)
transactionListModel.set(transactionDialog.transactionIndex, item);
else
transactionListModel.append(item);
var items = [];
for (var i = 0; i < transactionListModel.count; i++)
items.push(transactionListModel.get(i));
var json = JSON.stringify(items, function(key, value) { return key === "objectName" ? undefined : value; });
appContext.saveProject(json);
}
}
Component {
id: renderDelegate
Item {
id: wrapperItem
height: 20
width: parent.width
RowLayout
{
anchors.fill: parent
Text {
//anchors.fill: parent
Layout.fillWidth: true
Layout.fillHeight: true
text: title
font.pointSize: 12
verticalAlignment: Text.AlignBottom
}
ToolButton {
text: qsTr("Edit");
Layout.fillHeight: true
onClicked: {
transactionDialog.reset(index, transactionListModel.get(index));
transactionDialog.open();
transactionDialog.focus = true;
}
}
ToolButton {
text: qsTr("Delete");
Layout.fillHeight: true
onClicked: {
}
}
ToolButton {
text: qsTr("Run");
Layout.fillHeight: true
onClicked: {
transactionListModel.runTransaction(index);
}
}
}
}
}
}
Loading…
Cancel
Save