From ef7561b16e611d0fbe797ad763380061370183cf Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 27 Jan 2015 14:36:46 +0100 Subject: [PATCH 01/55] - Manage solidity parameter types --- mix/AppContext.cpp | 5 ++ mix/ClientModel.cpp | 21 +++--- mix/ClientModel.h | 2 +- mix/ContractCallDataEncoder.cpp | 115 +++++++++++++++++----------- mix/ContractCallDataEncoder.h | 12 ++- mix/QBigInt.h | 1 + mix/QFunctionDefinition.cpp | 2 + mix/QVariableDeclaration.h | 11 ++- mix/QVariableDefinition.cpp | 130 ++++++++++++++++++++++++++++++++ mix/QVariableDefinition.h | 74 +++++++++++++++++- mix/qml.qrc | 5 ++ mix/qml/QBoolType.qml | 8 ++ mix/qml/QHashType.qml | 8 ++ mix/qml/QIntType.qml | 8 ++ mix/qml/QRealType.qml | 8 ++ mix/qml/QVariableDefinition.qml | 13 ++++ mix/qml/TransactionDialog.qml | 44 +++++++++-- 17 files changed, 399 insertions(+), 68 deletions(-) create mode 100644 mix/qml/QBoolType.qml create mode 100644 mix/qml/QHashType.qml create mode 100644 mix/qml/QIntType.qml create mode 100644 mix/qml/QRealType.qml create mode 100644 mix/qml/QVariableDefinition.qml diff --git a/mix/AppContext.cpp b/mix/AppContext.cpp index fb44a1cde..8ffa0f6dd 100644 --- a/mix/AppContext.cpp +++ b/mix/AppContext.cpp @@ -71,6 +71,11 @@ void AppContext::load() m_applicationEngine->rootContext()->setContextProperty("fileIo", m_fileIo.get()); qmlRegisterType("org.ethereum.qml.QEther", 1, 0, "QEther"); qmlRegisterType("org.ethereum.qml.QBigInt", 1, 0, "QBigInt"); + //qmlRegisterType("org.ethereum.qml.QVariableDefinition", 1, 0, "QVariableDefinition"); + qmlRegisterType("org.ethereum.qml.QIntType", 1, 0, "QIntType"); + qmlRegisterType("org.ethereum.qml.QRealType", 1, 0, "QRealType"); + qmlRegisterType("org.ethereum.qml.QStringType", 1, 0, "QStringType"); + qmlRegisterType("org.ethereum.qml.QHashType", 1, 0, "QHashType"); QQmlComponent projectModelComponent(m_applicationEngine, QUrl("qrc:/qml/ProjectModel.qml")); QObject* projectModel = projectModelComponent.create(); if (projectModelComponent.isError()) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index eb61c8554..7f9a37aad 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -42,6 +42,10 @@ ClientModel::ClientModel(AppContext* _context): m_context(_context), m_running(false) { qRegisterMetaType("QBigInt*"); + qRegisterMetaType("QIntType*"); + qRegisterMetaType("QStringType*"); + qRegisterMetaType("QRealType*"); + qRegisterMetaType("QHashType*"); qRegisterMetaType("QEther*"); qRegisterMetaType("QVariableDefinition*"); qRegisterMetaType("QVariableDefinitionList*"); @@ -80,8 +84,10 @@ void ClientModel::debugState(QVariantMap _state) TransactionSettings transactionSettings(functionId, value, gas, gasPrice); for (auto p = params.cbegin(); p != params.cend(); ++p) - transactionSettings.parameterValues.insert(std::make_pair(p.key(), (qvariant_cast(p.value()))->toU256Wei())); - + { + QVariableDefinition* param = qvariant_cast(p.value()); + transactionSettings.parameterValues.push_back(param); + } transactionSequence.push_back(transactionSettings); } executeSequence(transactionSequence, balance); @@ -123,15 +129,8 @@ void ClientModel::executeSequence(std::vector const& _seque throw std::runtime_error("function " + t.functionId.toStdString() + " not found"); c.encode(f); - for (int p = 0; p < f->parametersList().size(); p++) - { - QVariableDeclaration* var = (QVariableDeclaration*)f->parametersList().at(p); - u256 value = 0; - auto v = t.parameterValues.find(var->name()); - if (v != t.parameterValues.cend()) - value = v->second; - c.encode(var, value); - } + for (int p = 0; p < t.parameterValues.size(); p++) + c.push(t.parameterValues.at(p)->encodeValue()); transactonData.emplace_back(c.encodedData()); } diff --git a/mix/ClientModel.h b/mix/ClientModel.h index 0e7f9c092..5170fcde3 100644 --- a/mix/ClientModel.h +++ b/mix/ClientModel.h @@ -54,7 +54,7 @@ struct TransactionSettings /// Gas price u256 gasPrice; /// Mapping from contract function parameter name to value - std::map parameterValues; + QList parameterValues; }; diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index 7a38db22b..e3dcf9abb 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -44,26 +44,9 @@ void ContractCallDataEncoder::encode(QFunctionDefinition const* _function) m_encodedData.insert(m_encodedData.end(), hash.begin(), hash.end()); } -void ContractCallDataEncoder::encode(QVariableDeclaration const* _dec, bool _value) +void ContractCallDataEncoder::push(bytes _b) { - return encode(_dec, QString(formatBool(_value))); -} - -void ContractCallDataEncoder::encode(QVariableDeclaration const* _dec, QString _value) -{ - int padding = this->padding(_dec->type()); - bytes data = padded(jsToBytes(_value.toStdString()), padding); - m_encodedData.insert(m_encodedData.end(), data.begin(), data.end()); -} - -void ContractCallDataEncoder::encode(QVariableDeclaration const* _dec, u256 _value) -{ - int padding = this->padding(_dec->type()); - std::ostringstream s; - s << std::hex << "0x" << _value; - bytes data = padded(jsToBytes(s.str()), padding); - m_encodedData.insert(m_encodedData.end(), data.begin(), data.end()); - encodedData(); + m_encodedData.insert(m_encodedData.end(), _b.begin(), _b.end()); } QList ContractCallDataEncoder::decode(QList _returnParameters, bytes _value) @@ -74,37 +57,79 @@ QList ContractCallDataEncoder::decode(QListpadding(dec->type()); - std::string rawParam = returnValue.substr(0, padding * 2); - r.append(new QVariableDefinition(dec, convertToReadable(unpadLeft(rawParam), dec))); - returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1); + QVariableDefinition* def = nullptr; + if (dec->type().contains("int")) + def = new QIntType(dec, QString()); + else if (dec->type().contains("real")) + def = new QRealType(dec, QString()); + else if (dec->type().contains("string") || dec->type().contains("text")) + def = new QStringType(dec, QString()); + else if (dec->type().contains("hash") || dec->type().contains("address")) + def = new QHashType(dec, QString()); + + def->decodeValue(returnValue); + r.push_back(def); + returnValue = returnValue.substr(def->length(), returnValue.length() - 1); + + /*QStringList tLength = typeLength(dec->type()); + + QRegExp intTest("(uint|int|hash|address)"); + QRegExp stringTest("(string|text)"); + QRegExp realTest("(real|ureal)"); + if (intTest.indexIn(dec->type()) != -1) + { + std::string rawParam = returnValue.substr(0, (tLength.first().toInt() / 8) * 2); + QString value = resolveNumber(QString::fromStdString(rawParam)); + r.append(new QVariableDefinition(dec, value)); + returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1); + } + else if (dec->type() == "bool") + { + std::string rawParam = returnValue.substr(0, 2); + std::string unpadded = unpadLeft(rawParam); + r.append(new QVariableDefinition(dec, QString::fromStdString(unpadded))); + returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1); + } + else if (stringTest.indexIn(dec->type()) != -1) + { + if (tLength.length() == 0) + { + QString strLength = QString::fromStdString(returnValue.substr(0, 2)); + returnValue = returnValue.substr(2, returnValue.length() - 1); + QString strValue = QString::fromStdString(returnValue.substr(0, strLength.toInt())); + r.append(new QVariableDefinition(dec, strValue)); + returnValue = returnValue.substr(strValue.length(), returnValue.length() - 1); + } + else + { + std::string rawParam = returnValue.substr(0, (tLength.first().toInt() / 8) * 2); + r.append(new QVariableDefinition(dec, QString::fromStdString(rawParam))); + returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1); + } + } + else if (realTest.indexIn(dec->type()) != -1) + { + QString value; + for (QString str: tLength) + { + std::string rawParam = returnValue.substr(0, (str.toInt() / 8) * 2); + QString value = resolveNumber(QString::fromStdString(rawParam)); + value += value + "x"; + returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1); + } + r.append(new QVariableDefinition(dec, value)); + }*/ } return r; } -int ContractCallDataEncoder::padding(QString type) -{ - // TODO : to be improved (load types automatically from solidity library). - if (type.indexOf("uint") != -1) - return integerPadding(type.remove("uint").toInt()); - else if (type.indexOf("int") != -1) - return integerPadding(type.remove("int").toInt()); - else if (type.indexOf("bool") != -1) - return 1; - else if ((type.indexOf("address") != -1)) - return 32; - else - return 0; -} - -int ContractCallDataEncoder::integerPadding(int bitValue) -{ - return bitValue / 8; -} - -QString ContractCallDataEncoder::formatBool(bool _value) +QString ContractCallDataEncoder::resolveNumber(QString const& _rawParam) { - return (_value ? "1" : "0"); + std::string unPadded = unpadLeft(_rawParam.toStdString()); + int x = std::stol(unPadded, nullptr, 16); + std::stringstream ss; + ss << std::dec << x; + return QString::fromStdString(ss.str()); } QString ContractCallDataEncoder::convertToReadable(std::string _v, QVariableDeclaration* _dec) diff --git a/mix/ContractCallDataEncoder.h b/mix/ContractCallDataEncoder.h index 49410a7cd..f92b25902 100644 --- a/mix/ContractCallDataEncoder.h +++ b/mix/ContractCallDataEncoder.h @@ -42,9 +42,9 @@ class ContractCallDataEncoder public: ContractCallDataEncoder() {} /// Encode variable in order to be sent as parameter. - void encode(QVariableDeclaration const* _dec, QString _value); + void encode(QVariableDeclaration const* _dec, QString _baseType, QStringList _length, QString _value); /// Encode variable in order to be sent as parameter. - void encode(QVariableDeclaration const* _dec, u256 _value); + void encode(QVariableDeclaration const* _dec, QString _value); /// Encode variable in order to be sent as parameter. void encode(QVariableDeclaration const* _dec, bool _value); /// Encode hash of the function to call. @@ -53,15 +53,21 @@ public: QList decode(QList _dec, bytes _value); /// Get all encoded data encoded by encode function. bytes encodedData(); + /// Encode the given list of parameters (@a _p) + void encode(QVariableDefinition const* _dec); + /// Push the given @ _b to the current stored bytes. + void push(bytes _b); private: - int padding(QString _type); + //int padding(QString _type); bytes m_encodedData; + static bytes encodeNumber(QString _value, QString _length); static QString convertToReadable(std::string _v, QVariableDeclaration* _dec); static QString convertToBool(std::string _v); static QString convertToInt(std::string _v); static int integerPadding(int _bitValue); static QString formatBool(bool _value); + static QString resolveNumber(QString const& _rawParams); }; } diff --git a/mix/QBigInt.h b/mix/QBigInt.h index 842b86c7d..e68b92259 100644 --- a/mix/QBigInt.h +++ b/mix/QBigInt.h @@ -28,6 +28,7 @@ #include #include #include +#include "QVariableDefinition.h" using namespace dev; diff --git a/mix/QFunctionDefinition.cpp b/mix/QFunctionDefinition.cpp index 97ce0ff58..1630ffe83 100644 --- a/mix/QFunctionDefinition.cpp +++ b/mix/QFunctionDefinition.cpp @@ -33,6 +33,8 @@ QFunctionDefinition::QFunctionDefinition(dev::solidity::FunctionDefinition const for (unsigned i = 0; i < parameters.size(); i++) m_parameters.append(new QVariableDeclaration(parameters.at(i).get())); + + std::vector> returnParameters = _f->getReturnParameters(); for (unsigned i = 0; i < returnParameters.size(); i++) m_returnParameters.append(new QVariableDeclaration(returnParameters.at(i).get())); diff --git a/mix/QVariableDeclaration.h b/mix/QVariableDeclaration.h index 966ee0ff3..78f97994f 100644 --- a/mix/QVariableDeclaration.h +++ b/mix/QVariableDeclaration.h @@ -19,6 +19,7 @@ * @date 2014 */ +#include #include #include "QBasicNodeDefinition.h" @@ -37,7 +38,15 @@ class QVariableDeclaration: public QBasicNodeDefinition public: QVariableDeclaration() {} QVariableDeclaration(solidity::VariableDeclaration const* _v): QBasicNodeDefinition(_v), m_type(QString::fromStdString(_v->getType()->toString())) {} - QString type() const { return m_type; } + Q_INVOKABLE QString type() const { return m_type; } + QStringList typeLength() + { + QRegExp rules("\\d"); + int pos = 0; + while ((pos = rules.indexIn(m_type, pos)) != -1) {} + return rules.capturedTexts(); + } + private: QString m_type; }; diff --git a/mix/QVariableDefinition.cpp b/mix/QVariableDefinition.cpp index 4f38e84b2..3ac036222 100644 --- a/mix/QVariableDefinition.cpp +++ b/mix/QVariableDefinition.cpp @@ -19,6 +19,7 @@ * @date 2014 */ +#include #include "QVariableDefinition.h" using namespace dev::mix; @@ -53,3 +54,132 @@ QVariableDefinition* QVariableDefinitionList::val(int _idx) return nullptr; return m_def.at(_idx); } + +/* + * QIntType + */ +dev::bytes QIntType::encodeValue() +{ + std::ostringstream s; + s << std::hex << "0x" << value().toStdString(); + return padded(jsToBytes(s.str()), declaration()->typeLength().first().toInt() / 8); +} + +int QIntType::length() +{ + return (declaration()->typeLength().first().toInt() / 8) * 2; +} + +void QIntType::decodeValue(std::string const& _rawValue) +{ + std::string unPadded = unpadLeft(_rawValue); + int x = std::stol(unPadded, nullptr, 16); + std::stringstream ss; + ss << std::dec << x; + setValue(QString::fromStdString(ss.str())); +} + +/* + * QHashType + */ +dev::bytes QHashType::encodeValue() +{ + return bytes(); +} + +int QHashType::length() +{ + return (declaration()->typeLength().first().toInt() / 8) * 2; +} + +void QHashType::decodeValue(std::string const& _rawValue) +{ + Q_UNUSED(_rawValue); +} + +/* + * QRealType + */ +dev::bytes QRealType::encodeValue() +{ + + std::ostringstream s; + s << std::hex << "0x" << value().split("x").first().toStdString(); + bytes first = padded(jsToBytes(s.str()), declaration()->typeLength().first().toInt() / 8); + s << std::hex << "0x" << value().split("x").last().toStdString(); + bytes second = padded(jsToBytes(s.str()), declaration()->typeLength().last().toInt() / 8); + first.insert(first.end(), second.begin(), second.end()); + return first; +} + +int QRealType::length() +{ + return (declaration()->typeLength().first().toInt() / 8) * 2 + (declaration()->typeLength().last().toInt() / 8) * 2; +} + +void QRealType::decodeValue(std::string const& _rawValue) +{ + QString value; + for (QString str: declaration()->typeLength()) + { + std::string rawParam = _rawValue.substr(0, (str.toInt() / 8) * 2); + std::string unPadded = unpadLeft(rawParam); + int x = std::stol(unPadded, nullptr, 16); + std::stringstream ss; + ss << std::dec << x; + value += QString::fromStdString(ss.str()) + "x"; + } + setValue(value); +} + +/* + * QStringType + */ +dev::bytes QStringType::encodeValue() +{ + return padded(jsToBytes(value().toStdString()), declaration()->typeLength().first().toInt() / 8); +} + +int QStringType::length() +{ + if (declaration()->typeLength().length() == 0) + return value().length() + 2; + else + return (declaration()->typeLength().first().toInt() / 8) * 2; +} + +void QStringType::decodeValue(std::string const& _rawValue) +{ + if (declaration()->typeLength().first().length() == 0) + { + std::string strLength = _rawValue.substr(0, 2); + std::string strValue = _rawValue.substr(2, std::stoi(strLength)); + setValue(QString::fromStdString(strValue)); + } + else + { + std::string rawParam = _rawValue.substr(0, (declaration()->typeLength().first().toInt() / 8) * 2); + setValue(QString::fromStdString(rawParam)); + } +} + +/* + * QBoolType + */ +dev::bytes QBoolType::encodeValue() +{ + return padded(jsToBytes(value().toStdString()), 1); +} + +int QBoolType::length() +{ + return 1; +} + +void QBoolType::decodeValue(std::string const& _rawValue) +{ + std::string rawParam = _rawValue.substr(0, 2); + std::string unpadded = unpadLeft(rawParam); + setValue(QString::fromStdString(unpadded)); +} + diff --git a/mix/QVariableDefinition.h b/mix/QVariableDefinition.h index f55e51346..6f90e1da5 100644 --- a/mix/QVariableDefinition.h +++ b/mix/QVariableDefinition.h @@ -37,12 +37,18 @@ class QVariableDefinition: public QObject Q_PROPERTY(QVariableDeclaration* declaration READ declaration CONSTANT) public: + QVariableDefinition() {} QVariableDefinition(QVariableDeclaration* _def, QString _value): QObject(), m_value(_value), m_dec(_def) {} /// Return the associated declaration of this variable definition. - QVariableDeclaration* declaration() const { return m_dec; } + Q_INVOKABLE QVariableDeclaration* declaration() const { return m_dec; } /// Return the variable value. QString value() const { return m_value; } + Q_INVOKABLE void setValue(QString _value) { m_value = _value; } + Q_INVOKABLE void setDeclaration(QVariableDeclaration* _dec) { m_dec = _dec; } + virtual bytes encodeValue() = 0; + virtual void decodeValue(std::string const& _rawValue) = 0; + virtual int length() = 0; private: QString m_value; @@ -67,7 +73,71 @@ private: QList m_def; }; +class QIntType: public QVariableDefinition +{ + Q_OBJECT + +public: + QIntType() {} + QIntType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} + dev::bytes encodeValue() override; + void decodeValue(std::string const& _rawValue) override; + int length() override; +}; + +class QRealType: public QVariableDefinition +{ + Q_OBJECT + +public: + QRealType() {} + QRealType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} + dev::bytes encodeValue() override; + void decodeValue(std::string const& _rawValue) override; + int length() override; +}; + +class QStringType: public QVariableDefinition +{ + Q_OBJECT + +public: + QStringType() {} + QStringType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} + dev::bytes encodeValue() override; + void decodeValue(std::string const& _rawValue) override; + int length() override; +}; + +class QHashType: public QVariableDefinition +{ + Q_OBJECT + +public: + QHashType() {} + QHashType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} + dev::bytes encodeValue() override; + void decodeValue(std::string const& _rawValue) override; + int length() override; +}; + +class QBoolType: public QVariableDefinition +{ + Q_OBJECT + +public: + QBoolType() {} + QBoolType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} + dev::bytes encodeValue() override; + void decodeValue(std::string const& _rawValue) override; + int length() override; +}; + } } -Q_DECLARE_METATYPE(dev::mix::QVariableDefinition*) +//Q_DECLARE_METATYPE(dev::mix::QVariableDefinition*) +Q_DECLARE_METATYPE(dev::mix::QIntType*) +Q_DECLARE_METATYPE(dev::mix::QStringType*) +Q_DECLARE_METATYPE(dev::mix::QHashType*) +Q_DECLARE_METATYPE(dev::mix::QBoolType*) diff --git a/mix/qml.qrc b/mix/qml.qrc index 169d1ebcb..fecea2e2c 100644 --- a/mix/qml.qrc +++ b/mix/qml.qrc @@ -43,5 +43,10 @@ qml/Ether.qml qml/EtherValue.qml qml/BigIntValue.qml + qml/QVariableDefinition.qml + qml/QBoolType.qml + qml/QHashType.qml + qml/QIntType.qml + qml/QRealType.qml diff --git a/mix/qml/QBoolType.qml b/mix/qml/QBoolType.qml new file mode 100644 index 000000000..a6dc54035 --- /dev/null +++ b/mix/qml/QBoolType.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 +import org.ethereum.qml.QBoolType 1.0 + +QBoolType +{ + property string view: "qrc:/qml/QBoolTypeView.qml" +} + diff --git a/mix/qml/QHashType.qml b/mix/qml/QHashType.qml new file mode 100644 index 000000000..a7913d414 --- /dev/null +++ b/mix/qml/QHashType.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 +import org.ethereum.qml.QHashType 1.0 + +QHashType +{ + property string view: "qrc:/qml/QHashTypeView.qml" +} + diff --git a/mix/qml/QIntType.qml b/mix/qml/QIntType.qml new file mode 100644 index 000000000..7533d367f --- /dev/null +++ b/mix/qml/QIntType.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 +import org.ethereum.qml.QIntType 1.0 + +QIntType +{ + property string view: "qrc:/qml/QIntTypeView.qml" +} + diff --git a/mix/qml/QRealType.qml b/mix/qml/QRealType.qml new file mode 100644 index 000000000..ba3cf82bf --- /dev/null +++ b/mix/qml/QRealType.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 +import org.ethereum.qml.QRealType 1.0 + +QRealType +{ + property string view: "qrc:/qml/QRealTypeView.qml" +} + diff --git a/mix/qml/QVariableDefinition.qml b/mix/qml/QVariableDefinition.qml new file mode 100644 index 000000000..af0cd4ea0 --- /dev/null +++ b/mix/qml/QVariableDefinition.qml @@ -0,0 +1,13 @@ +/* + * Used to instanciate a QVariableDefinition obj using Qt.createComponent function. +*/ +import QtQuick 2.2 +import QtQuick.Controls 1.1 +import QtQuick.Layouts 1.1 +import QtQuick.Controls.Styles 1.1 +import org.ethereum.qml.QVariableDefinition 1.0 + +QVariableDefinition +{ + id: qVariableDefinition +} diff --git a/mix/qml/TransactionDialog.qml b/mix/qml/TransactionDialog.qml index 22995d66b..eb9fd5914 100644 --- a/mix/qml/TransactionDialog.qml +++ b/mix/qml/TransactionDialog.qml @@ -28,6 +28,8 @@ Window { valueField.value = item.value; var functionId = item.functionId; itemParams = item.parameters !== undefined ? item.parameters : {}; + console.log("opening ..."); + console.log(JSON.stringify(itemParams)); functionsModel.clear(); var functionIndex = -1; var functions = codeModel.code.contract.functions; @@ -41,21 +43,48 @@ Window { functionIndex = 0; //@todo suggest unused funtion functionComboBox.currentIndex = functionIndex; + console.log("opening2 ..."); + console.log(JSON.stringify(itemParams)); loadParameters(); visible = true; valueField.focus = true; } function loadParameters() { + console.log("opening3 ..."); + console.log(JSON.stringify(itemParams)); if (!paramsModel) return; + console.log("opening4 ..."); + console.log(JSON.stringify(itemParams)); paramsModel.clear(); + console.log("opening5 ..."); + console.log(JSON.stringify(itemParams)); if (functionComboBox.currentIndex >= 0 && functionComboBox.currentIndex < functionsModel.count) { var func = codeModel.code.contract.functions[functionComboBox.currentIndex]; var parameters = func.parameters; for (var p = 0; p < parameters.length; p++) { var pname = parameters[p].name; - paramsModel.append({ name: pname, type: parameters[p].type, value: itemParams[pname] !== undefined ? itemParams[pname].value() : "" }); + var varComponent; + var type = parameters[p].type; + console.log("type : " + type); + console.log("name : " + pname); + if (type.indexOf("int") !== -1) + varComponent = Qt.createComponent("qrc:/qml/QIntType.qml"); + else if (type.indexOf("real") !== -1) + varComponent = Qt.createComponent("qrc:/qml/QRealType.qml"); + else if (type.indexOf("string") !== -1 || type.indexOf("text") !== -1) + varComponent = Qt.createComponent("qrc:/qml/QStringType.qml"); + else if (type.indexOf("hash") !== -1 || type.indexOf("address") !== -1) + varComponent = Qt.createComponent("qrc:/qml/QHashType.qml"); + var param = varComponent.createObject(modalTransactionDialog); + var value = itemParams[pname] !== undefined ? itemParams[pname].value : ""; + + console.log("loading parameters"); + console.log(JSON.stringify(itemParams)); + param.setValue(value); + param.setDeclaration(parameters[p]); + paramsModel.append({ internalValue: param, name: pname, type: parameters[p].type, value: itemParams[pname] !== undefined ? itemParams[pname].value : "" }); } } } @@ -76,11 +105,16 @@ Window { } for (var p = 0; p < transactionDialog.transactionParams.count; p++) { var parameter = transactionDialog.transactionParams.get(p); - var intComponent = Qt.createComponent("qrc:/qml/BigIntValue.qml"); - var param = intComponent.createObject(modalTransactionDialog); - param.setValue(parameter.value); - item.parameters[parameter.name] = param; + //var intComponent = Qt.createComponent("qrc:/qml/BigIntValue.qml"); + //var param = intComponent.createObject(modalTransactionDialog); + //param.setValue(parameter.value); + //parameter.internalValue.setValue(parameter.value); + console.log("onget"); + console.log(JSON.stringify(parameter)); + item.parameters[parameter.name] = parameter; } + console.log("return item"); + console.log(JSON.stringify(item)); return item; } From b271a9df51ddb520ee05fcd60dce11ddbe38ff86 Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 29 Jan 2015 17:54:58 +0100 Subject: [PATCH 02/55] Manage solidity types: - uint, uint - int, int - hash, hash, address - bool - string --- libdevcore/CommonJS.cpp | 19 +++++ libdevcore/CommonJS.h | 4 + mix/AppContext.cpp | 1 + mix/ClientModel.cpp | 12 ++- mix/CodeHighlighter.cpp | 25 +++--- mix/ContractCallDataEncoder.cpp | 89 ++------------------- mix/ContractCallDataEncoder.h | 18 +---- mix/QBigInt.h | 2 +- mix/QFunctionDefinition.cpp | 2 - mix/QVariableDeclaration.h | 8 +- mix/QVariableDefinition.cpp | 105 +++++++++--------------- mix/QVariableDefinition.h | 10 +-- mix/qml.qrc | 8 +- mix/qml/QBoolTypeView.qml | 30 +++++++ mix/qml/QHashTypeView.qml | 22 ++++++ mix/qml/QIntTypeView.qml | 25 ++++++ mix/qml/QRealTypeView.qml | 15 ++++ mix/qml/QStringType.qml | 8 ++ mix/qml/QStringTypeView.qml | 25 ++++++ mix/qml/StateList.qml | 1 - mix/qml/TransactionDialog.qml | 136 ++++++++++++++++++++++++-------- 21 files changed, 327 insertions(+), 238 deletions(-) create mode 100644 mix/qml/QBoolTypeView.qml create mode 100644 mix/qml/QHashTypeView.qml create mode 100644 mix/qml/QIntTypeView.qml create mode 100644 mix/qml/QRealTypeView.qml create mode 100644 mix/qml/QStringType.qml create mode 100644 mix/qml/QStringTypeView.qml diff --git a/libdevcore/CommonJS.cpp b/libdevcore/CommonJS.cpp index ee2074cd1..1a49d71ec 100644 --- a/libdevcore/CommonJS.cpp +++ b/libdevcore/CommonJS.cpp @@ -45,6 +45,13 @@ bytes padded(bytes _b, unsigned _l) return asBytes(asString(_b).substr(_b.size() - std::max(_l, _l))); } +bytes paddedRight(bytes _b, unsigned _l) +{ + while (_b.size() < _l) + _b.insert(_b.end(), 0); + return asBytes(asString(_b).substr(_b.size() - std::max(_l, _l))); +} + bytes unpadded(bytes _b) { auto p = asString(_b).find_last_not_of((char)0); @@ -52,6 +59,18 @@ bytes unpadded(bytes _b) return _b; } +std::string unpadRight(std::string _b) +{ + while (true) + { + auto p = _b.find_last_of("0"); + if (p == _b.size() - 1) + _b = _b.substr(0, _b.size() - 1); + else + return _b; + } +} + std::string unpadLeft(std::string _b) { auto p = _b.find_first_not_of('0'); diff --git a/libdevcore/CommonJS.h b/libdevcore/CommonJS.h index 8e6c5fe53..4f7ef8495 100644 --- a/libdevcore/CommonJS.h +++ b/libdevcore/CommonJS.h @@ -50,6 +50,10 @@ inline std::string toJS(dev::bytes const& _n) bytes jsToBytes(std::string const& _s); /// Add '0' on the head of _b until _l. bytes padded(bytes _b, unsigned _l); +/// Add '0' on the queue of _b until _l. +bytes paddedRight(bytes _b, unsigned _l); +/// Remove all trailing '0' +std::string unpadRight(std::string _b); /// 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. Returns 0 if _s contains only '0'. diff --git a/mix/AppContext.cpp b/mix/AppContext.cpp index e35bb8a5d..49cf64c56 100644 --- a/mix/AppContext.cpp +++ b/mix/AppContext.cpp @@ -66,6 +66,7 @@ void AppContext::load() qmlRegisterType("org.ethereum.qml.QRealType", 1, 0, "QRealType"); qmlRegisterType("org.ethereum.qml.QStringType", 1, 0, "QStringType"); qmlRegisterType("org.ethereum.qml.QHashType", 1, 0, "QHashType"); + qmlRegisterType("org.ethereum.qml.QBoolType", 1, 0, "QBoolType"); QQmlComponent projectModelComponent(m_applicationEngine, QUrl("qrc:/qml/ProjectModel.qml")); QObject* projectModel = projectModelComponent.create(); if (projectModelComponent.isError()) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index 694561479..df489403b 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -119,12 +119,11 @@ void ClientModel::debugState(QVariantMap _state) u256 gas = (qvariant_cast(transaction.value("gas")))->toU256Wei(); u256 value = (qvariant_cast(transaction.value("value")))->toU256Wei(); u256 gasPrice = (qvariant_cast(transaction.value("gasPrice")))->toU256Wei(); - QVariantMap params = transaction.value("parameters").toMap(); TransactionSettings transactionSettings(functionId, value, gas, gasPrice); - - for (auto p = params.cbegin(); p != params.cend(); ++p) + QVariantList qParams = transaction.value("qType").toList(); + for (QVariant const& variant: qParams) { - QVariableDefinition* param = qvariant_cast(p.value()); + QVariableDefinition* param = qvariant_cast(variant); transactionSettings.parameterValues.push_back(param); } @@ -173,7 +172,12 @@ void ClientModel::executeSequence(std::vector const& _seque 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(); c.push(t.parameterValues.at(p)->encodeValue()); + } transactonData.emplace_back(c.encodedData()); } diff --git a/mix/CodeHighlighter.cpp b/mix/CodeHighlighter.cpp index ab8a61ff5..c1ef39d5d 100644 --- a/mix/CodeHighlighter.cpp +++ b/mix/CodeHighlighter.cpp @@ -1,18 +1,18 @@ /* - This file is part of cpp-ethereum. + This file is part of cpp-ethereum. - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. + cpp-ethereum is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. + cpp-ethereum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . + You should have received a copy of the GNU General Public License + along with cpp-ethereum. If not, see . */ /** @file CodeHighlighter.cpp * @author Arkadiy Paronyan arkadiy@ethdev.com @@ -102,7 +102,8 @@ void CodeHighlighter::processAST(dev::solidity::ASTNode const& _ast) void CodeHighlighter::processError(dev::Exception const& _exception) { Location const* location = boost::get_error_info(_exception); - m_formats.push_back(FormatRange(CodeHighlighterSettings::CompilationError, *location)); + if (location) + m_formats.push_back(FormatRange(CodeHighlighterSettings::CompilationError, *location)); } void CodeHighlighter::processComments(std::string const& _source) diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index e3dcf9abb..4438c9387 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -35,6 +35,7 @@ using namespace dev::mix; bytes ContractCallDataEncoder::encodedData() { + qDebug() << " encoded data " << QString::fromStdString(toJS(m_encodedData)); return m_encodedData; } @@ -62,96 +63,16 @@ QList ContractCallDataEncoder::decode(QListtype().contains("real")) def = new QRealType(dec, QString()); + else if (dec->type().contains("bool")) + def = new QBoolType(dec, QString()); else if (dec->type().contains("string") || dec->type().contains("text")) def = new QStringType(dec, QString()); else if (dec->type().contains("hash") || dec->type().contains("address")) def = new QHashType(dec, QString()); - def->decodeValue(returnValue); r.push_back(def); - returnValue = returnValue.substr(def->length(), returnValue.length() - 1); - - /*QStringList tLength = typeLength(dec->type()); - - QRegExp intTest("(uint|int|hash|address)"); - QRegExp stringTest("(string|text)"); - QRegExp realTest("(real|ureal)"); - if (intTest.indexIn(dec->type()) != -1) - { - std::string rawParam = returnValue.substr(0, (tLength.first().toInt() / 8) * 2); - QString value = resolveNumber(QString::fromStdString(rawParam)); - r.append(new QVariableDefinition(dec, value)); - returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1); - } - else if (dec->type() == "bool") - { - std::string rawParam = returnValue.substr(0, 2); - std::string unpadded = unpadLeft(rawParam); - r.append(new QVariableDefinition(dec, QString::fromStdString(unpadded))); - returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1); - } - else if (stringTest.indexIn(dec->type()) != -1) - { - if (tLength.length() == 0) - { - QString strLength = QString::fromStdString(returnValue.substr(0, 2)); - returnValue = returnValue.substr(2, returnValue.length() - 1); - QString strValue = QString::fromStdString(returnValue.substr(0, strLength.toInt())); - r.append(new QVariableDefinition(dec, strValue)); - returnValue = returnValue.substr(strValue.length(), returnValue.length() - 1); - } - else - { - std::string rawParam = returnValue.substr(0, (tLength.first().toInt() / 8) * 2); - r.append(new QVariableDefinition(dec, QString::fromStdString(rawParam))); - returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1); - } - } - else if (realTest.indexIn(dec->type()) != -1) - { - QString value; - for (QString str: tLength) - { - std::string rawParam = returnValue.substr(0, (str.toInt() / 8) * 2); - QString value = resolveNumber(QString::fromStdString(rawParam)); - value += value + "x"; - returnValue = returnValue.substr(rawParam.length(), returnValue.length() - 1); - } - r.append(new QVariableDefinition(dec, value)); - }*/ + returnValue = returnValue.substr(32 * 2, returnValue.length() - 1); + qDebug() << "decoded return value : " << dec->type() << " " << def->value(); } return r; } - -QString ContractCallDataEncoder::resolveNumber(QString const& _rawParam) -{ - std::string unPadded = unpadLeft(_rawParam.toStdString()); - int x = std::stol(unPadded, nullptr, 16); - std::stringstream ss; - ss << std::dec << x; - return QString::fromStdString(ss.str()); -} - -QString ContractCallDataEncoder::convertToReadable(std::string _v, QVariableDeclaration* _dec) -{ - if (_dec->type().indexOf("int") != -1) - return convertToInt(_v); - else if (_dec->type().indexOf("bool") != -1) - return convertToBool(_v); - else - return QString::fromStdString(_v); -} - -QString ContractCallDataEncoder::convertToBool(std::string _v) -{ - return _v == "1" ? "true" : "false"; -} - -QString ContractCallDataEncoder::convertToInt(std::string _v) -{ - //TO DO to be improve to manage all int, uint size (128, 256, ...) in ethereum QML types task #612. - int x = std::stol(_v, nullptr, 16); - std::stringstream ss; - ss << std::dec << x; - return QString::fromStdString(ss.str()); -} diff --git a/mix/ContractCallDataEncoder.h b/mix/ContractCallDataEncoder.h index f92b25902..27baef8ee 100644 --- a/mix/ContractCallDataEncoder.h +++ b/mix/ContractCallDataEncoder.h @@ -41,33 +41,17 @@ class ContractCallDataEncoder { public: ContractCallDataEncoder() {} - /// Encode variable in order to be sent as parameter. - void encode(QVariableDeclaration const* _dec, QString _baseType, QStringList _length, QString _value); - /// Encode variable in order to be sent as parameter. - void encode(QVariableDeclaration const* _dec, QString _value); - /// Encode variable in order to be sent as parameter. - void encode(QVariableDeclaration const* _dec, bool _value); /// Encode hash of the function to call. void encode(QFunctionDefinition const* _function); /// Decode variable in order to be sent to QML view. QList decode(QList _dec, bytes _value); /// Get all encoded data encoded by encode function. bytes encodedData(); - /// Encode the given list of parameters (@a _p) - void encode(QVariableDefinition const* _dec); - /// Push the given @ _b to the current stored bytes. + /// Push the given @ _b to the current param context. void push(bytes _b); private: - //int padding(QString _type); bytes m_encodedData; - static bytes encodeNumber(QString _value, QString _length); - static QString convertToReadable(std::string _v, QVariableDeclaration* _dec); - static QString convertToBool(std::string _v); - static QString convertToInt(std::string _v); - static int integerPadding(int _bitValue); - static QString formatBool(bool _value); - static QString resolveNumber(QString const& _rawParams); }; } diff --git a/mix/QBigInt.h b/mix/QBigInt.h index e68b92259..0f5c88c43 100644 --- a/mix/QBigInt.h +++ b/mix/QBigInt.h @@ -28,7 +28,6 @@ #include #include #include -#include "QVariableDefinition.h" using namespace dev; @@ -76,6 +75,7 @@ public: QBigInt(dev::u256 const& _value, QObject* _parent = 0): QObject(_parent), m_internalValue(_value) { QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } QBigInt(dev::bigint const& _value, QObject* _parent = 0): QObject(_parent), m_internalValue(_value) { QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } QBigInt(BigIntVariant const& _value, QObject* _parent = 0): QObject(_parent), m_internalValue(_value){ QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } + QBigInt(QString const& _value, QObject* _parent = 0): QObject(_parent) { QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); setValue(_value); } ~QBigInt() {} /// @returns the current used big integer. diff --git a/mix/QFunctionDefinition.cpp b/mix/QFunctionDefinition.cpp index 1630ffe83..97ce0ff58 100644 --- a/mix/QFunctionDefinition.cpp +++ b/mix/QFunctionDefinition.cpp @@ -33,8 +33,6 @@ QFunctionDefinition::QFunctionDefinition(dev::solidity::FunctionDefinition const for (unsigned i = 0; i < parameters.size(); i++) m_parameters.append(new QVariableDeclaration(parameters.at(i).get())); - - std::vector> returnParameters = _f->getReturnParameters(); for (unsigned i = 0; i < returnParameters.size(); i++) m_returnParameters.append(new QVariableDeclaration(returnParameters.at(i).get())); diff --git a/mix/QVariableDeclaration.h b/mix/QVariableDeclaration.h index 78f97994f..08af30798 100644 --- a/mix/QVariableDeclaration.h +++ b/mix/QVariableDeclaration.h @@ -19,6 +19,7 @@ * @date 2014 */ +#include #include #include #include "QBasicNodeDefinition.h" @@ -39,13 +40,6 @@ public: QVariableDeclaration() {} QVariableDeclaration(solidity::VariableDeclaration const* _v): QBasicNodeDefinition(_v), m_type(QString::fromStdString(_v->getType()->toString())) {} Q_INVOKABLE QString type() const { return m_type; } - QStringList typeLength() - { - QRegExp rules("\\d"); - int pos = 0; - while ((pos = rules.indexIn(m_type, pos)) != -1) {} - return rules.capturedTexts(); - } private: QString m_type; diff --git a/mix/QVariableDefinition.cpp b/mix/QVariableDefinition.cpp index 3ac036222..4e29a3a2e 100644 --- a/mix/QVariableDefinition.cpp +++ b/mix/QVariableDefinition.cpp @@ -19,6 +19,7 @@ * @date 2014 */ +#include #include #include "QVariableDefinition.h" @@ -60,23 +61,25 @@ QVariableDefinition* QVariableDefinitionList::val(int _idx) */ dev::bytes QIntType::encodeValue() { + dev::bigint i(value().toStdString()); + if (i < 0) + i = i + dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + 1; std::ostringstream s; - s << std::hex << "0x" << value().toStdString(); - return padded(jsToBytes(s.str()), declaration()->typeLength().first().toInt() / 8); -} - -int QIntType::length() -{ - return (declaration()->typeLength().first().toInt() / 8) * 2; + s << std::hex << "0x" << i; + qDebug() << " int input " << QString::fromStdString(toJS(padded(jsToBytes(s.str()), 32))); + return padded(jsToBytes(s.str()), 32); } void QIntType::decodeValue(std::string const& _rawValue) { - std::string unPadded = unpadLeft(_rawValue); - int x = std::stol(unPadded, nullptr, 16); - std::stringstream ss; - ss << std::dec << x; - setValue(QString::fromStdString(ss.str())); + std::string rawParam = _rawValue.substr(0, 32 * 2); + dev::bigint bigint = dev::bigint("0x" + rawParam); + if (((bigint >> 32) & 1) == 1) + 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())); } /* @@ -84,17 +87,14 @@ void QIntType::decodeValue(std::string const& _rawValue) */ dev::bytes QHashType::encodeValue() { - return bytes(); -} - -int QHashType::length() -{ - return (declaration()->typeLength().first().toInt() / 8) * 2; + return padded(asBytes(value().toStdString()), 32); } void QHashType::decodeValue(std::string const& _rawValue) { - Q_UNUSED(_rawValue); + std::string rawParam = _rawValue.substr(0, 32 * 2); + std::string unPadded = unpadLeft(rawParam); + setValue(QString::fromStdString(unPadded)); } /* @@ -102,34 +102,12 @@ void QHashType::decodeValue(std::string const& _rawValue) */ dev::bytes QRealType::encodeValue() { - - std::ostringstream s; - s << std::hex << "0x" << value().split("x").first().toStdString(); - bytes first = padded(jsToBytes(s.str()), declaration()->typeLength().first().toInt() / 8); - s << std::hex << "0x" << value().split("x").last().toStdString(); - bytes second = padded(jsToBytes(s.str()), declaration()->typeLength().last().toInt() / 8); - first.insert(first.end(), second.begin(), second.end()); - return first; -} - -int QRealType::length() -{ - return (declaration()->typeLength().first().toInt() / 8) * 2 + (declaration()->typeLength().last().toInt() / 8) * 2; + return bytes(); } void QRealType::decodeValue(std::string const& _rawValue) { - QString value; - for (QString str: declaration()->typeLength()) - { - std::string rawParam = _rawValue.substr(0, (str.toInt() / 8) * 2); - std::string unPadded = unpadLeft(rawParam); - int x = std::stol(unPadded, nullptr, 16); - std::stringstream ss; - ss << std::dec << x; - value += QString::fromStdString(ss.str()) + "x"; - } - setValue(value); + Q_UNUSED(_rawValue); } /* @@ -137,30 +115,24 @@ void QRealType::decodeValue(std::string const& _rawValue) */ dev::bytes QStringType::encodeValue() { - return padded(jsToBytes(value().toStdString()), declaration()->typeLength().first().toInt() / 8); -} - -int QStringType::length() -{ - if (declaration()->typeLength().length() == 0) - return value().length() + 2; - else - return (declaration()->typeLength().first().toInt() / 8) * 2; + qDebug() << QString::fromStdString(toJS(paddedRight(asBytes(value().toStdString()), 32))); + return paddedRight(asBytes(value().toStdString()), 32); } void QStringType::decodeValue(std::string const& _rawValue) { - if (declaration()->typeLength().first().length() == 0) + std::string rawParam = _rawValue.substr(0, 32 * 2); + rawParam = unpadRight(rawParam); + std::string res; + res.reserve(rawParam.size() / 2); + for (unsigned int i = 0; i < rawParam.size(); i += 2) { - std::string strLength = _rawValue.substr(0, 2); - std::string strValue = _rawValue.substr(2, std::stoi(strLength)); - setValue(QString::fromStdString(strValue)); - } - else - { - std::string rawParam = _rawValue.substr(0, (declaration()->typeLength().first().toInt() / 8) * 2); - setValue(QString::fromStdString(rawParam)); + std::istringstream iss(rawParam.substr(i, 2)); + int temp; + iss >> std::hex >> temp; + res += static_cast(temp); } + setValue(QString::fromStdString(res)); } /* @@ -168,18 +140,13 @@ void QStringType::decodeValue(std::string const& _rawValue) */ dev::bytes QBoolType::encodeValue() { - return padded(jsToBytes(value().toStdString()), 1); -} - -int QBoolType::length() -{ - return 1; + qDebug() << QString::fromStdString(toJS(padded(jsToBytes(value().toStdString()), 32))); + return padded(jsToBytes(value().toStdString()), 32); } void QBoolType::decodeValue(std::string const& _rawValue) { - std::string rawParam = _rawValue.substr(0, 2); + std::string rawParam = _rawValue.substr(0, 32 * 2); std::string unpadded = unpadLeft(rawParam); setValue(QString::fromStdString(unpadded)); } - diff --git a/mix/QVariableDefinition.h b/mix/QVariableDefinition.h index 6f90e1da5..e58cc81f5 100644 --- a/mix/QVariableDefinition.h +++ b/mix/QVariableDefinition.h @@ -22,6 +22,7 @@ #pragma once #include +#include "QBigInt.h" #include "QVariableDeclaration.h" namespace dev @@ -48,7 +49,6 @@ public: Q_INVOKABLE void setDeclaration(QVariableDeclaration* _dec) { m_dec = _dec; } virtual bytes encodeValue() = 0; virtual void decodeValue(std::string const& _rawValue) = 0; - virtual int length() = 0; private: QString m_value; @@ -82,7 +82,7 @@ public: QIntType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} dev::bytes encodeValue() override; void decodeValue(std::string const& _rawValue) override; - int length() override; + QBigInt* toBigInt() { return new QBigInt(value()); } }; class QRealType: public QVariableDefinition @@ -94,7 +94,6 @@ public: QRealType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} dev::bytes encodeValue() override; void decodeValue(std::string const& _rawValue) override; - int length() override; }; class QStringType: public QVariableDefinition @@ -106,7 +105,6 @@ public: QStringType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} dev::bytes encodeValue() override; void decodeValue(std::string const& _rawValue) override; - int length() override; }; class QHashType: public QVariableDefinition @@ -118,7 +116,6 @@ public: QHashType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} dev::bytes encodeValue() override; void decodeValue(std::string const& _rawValue) override; - int length() override; }; class QBoolType: public QVariableDefinition @@ -130,13 +127,12 @@ public: QBoolType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} dev::bytes encodeValue() override; void decodeValue(std::string const& _rawValue) override; - int length() override; + bool toBool() { return value() != "0"; } }; } } -//Q_DECLARE_METATYPE(dev::mix::QVariableDefinition*) Q_DECLARE_METATYPE(dev::mix::QIntType*) Q_DECLARE_METATYPE(dev::mix::QStringType*) Q_DECLARE_METATYPE(dev::mix::QHashType*) diff --git a/mix/qml.qrc b/mix/qml.qrc index 730109c4a..558da9d45 100644 --- a/mix/qml.qrc +++ b/mix/qml.qrc @@ -41,7 +41,7 @@ qml/Ether.qml qml/EtherValue.qml qml/BigIntValue.qml - qml/QVariableDefinition.qml + qml/QVariableDefinition.qml qml/QBoolType.qml qml/QHashType.qml qml/QIntType.qml @@ -49,5 +49,11 @@ qml/js/QEtherHelper.js qml/js/TransactionHelper.js qml/Splitter.qml + qml/QStringType.qml + qml/QBoolTypeView.qml + qml/QIntTypeView.qml + qml/QRealTypeView.qml + qml/QStringTypeView.qml + qml/QHashTypeView.qml diff --git a/mix/qml/QBoolTypeView.qml b/mix/qml/QBoolTypeView.qml new file mode 100644 index 000000000..b71ec9cf4 --- /dev/null +++ b/mix/qml/QBoolTypeView.qml @@ -0,0 +1,30 @@ +import QtQuick 2.0 +import QtQuick.Controls 1.3 + +Item +{ + id: editRoot + property string text + Rectangle { + anchors.fill: parent + ComboBox + { + id: boolCombo + anchors.fill: parent + onCurrentIndexChanged: + { + text = coolComboModel.get(currentIndex).value; + editRoot.textChanged(); + } + model: ListModel + { + id: coolComboModel + ListElement { text: qsTr("True"); value: "1" } + ListElement { text: qsTr("False"); value: "0" } + } + } + } +} + + + diff --git a/mix/qml/QHashTypeView.qml b/mix/qml/QHashTypeView.qml new file mode 100644 index 000000000..3e09ca112 --- /dev/null +++ b/mix/qml/QHashTypeView.qml @@ -0,0 +1,22 @@ +import QtQuick 2.0 + +Item +{ + property alias text: textinput.text + id: editRoot + Rectangle { + anchors.fill: parent + TextInput { + id: textinput + text: text + anchors.fill: parent + onTextChanged: editRoot.textChanged() + MouseArea { + id: mouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: textinput.forceActiveFocus() + } + } + } +} diff --git a/mix/qml/QIntTypeView.qml b/mix/qml/QIntTypeView.qml new file mode 100644 index 000000000..d9156bf19 --- /dev/null +++ b/mix/qml/QIntTypeView.qml @@ -0,0 +1,25 @@ +import QtQuick 2.0 + +Item +{ + property alias text: textinput.text + id: editRoot + Rectangle { + anchors.fill: parent + TextInput { + id: textinput + text: text + anchors.fill: parent + onTextChanged: editRoot.textChanged() + MouseArea { + id: mouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: textinput.forceActiveFocus() + } + } + } +} + + + diff --git a/mix/qml/QRealTypeView.qml b/mix/qml/QRealTypeView.qml new file mode 100644 index 000000000..96db4de75 --- /dev/null +++ b/mix/qml/QRealTypeView.qml @@ -0,0 +1,15 @@ +import QtQuick 2.0 + +Component +{ + Rectangle { + anchors.fill: parent + Text{ + anchors.fill: parent + text: qsTr("Real") + } + } +} + + + diff --git a/mix/qml/QStringType.qml b/mix/qml/QStringType.qml new file mode 100644 index 000000000..ab8db4a42 --- /dev/null +++ b/mix/qml/QStringType.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 +import org.ethereum.qml.QStringType 1.0 + +QStringType +{ + property string view: "qrc:/qml/QStringTypeView.qml" +} + diff --git a/mix/qml/QStringTypeView.qml b/mix/qml/QStringTypeView.qml new file mode 100644 index 000000000..d9156bf19 --- /dev/null +++ b/mix/qml/QStringTypeView.qml @@ -0,0 +1,25 @@ +import QtQuick 2.0 + +Item +{ + property alias text: textinput.text + id: editRoot + Rectangle { + anchors.fill: parent + TextInput { + id: textinput + text: text + anchors.fill: parent + onTextChanged: editRoot.textChanged() + MouseArea { + id: mouseArea + anchors.fill: parent + hoverEnabled: true + onClicked: textinput.forceActiveFocus() + } + } + } +} + + + diff --git a/mix/qml/StateList.qml b/mix/qml/StateList.qml index 007a45d6a..c2722f69c 100644 --- a/mix/qml/StateList.qml +++ b/mix/qml/StateList.qml @@ -59,7 +59,6 @@ Rectangle { stateList.push(item); stateListModel.append(item); } - stateListModel.save(); } } diff --git a/mix/qml/TransactionDialog.qml b/mix/qml/TransactionDialog.qml index b1244ee0e..a98444b85 100644 --- a/mix/qml/TransactionDialog.qml +++ b/mix/qml/TransactionDialog.qml @@ -21,10 +21,12 @@ Window { property var itemParams; property bool isConstructorTransaction; property bool useTransactionDefaultValue: false + property var qType; signal accepted; function open(index, item) { + qType = []; rowFunction.visible = !useTransactionDefaultValue; rowValue.visible = !useTransactionDefaultValue; rowGas.visible = !useTransactionDefaultValue; @@ -39,8 +41,8 @@ Window { rowFunction.visible = !item.executeConstructor; itemParams = item.parameters !== undefined ? item.parameters : {}; - console.log("opening ..."); - console.log(JSON.stringify(itemParams)); + console.log("save parameters : "); + console.log(JSON.stringify(item.qType)); functionsModel.clear(); var functionIndex = -1; var functions = codeModel.code.contract.functions; @@ -70,8 +72,6 @@ Window { } function loadParameters() { - console.log("opening3 ..."); - console.log(JSON.stringify(itemParams)); if (!paramsModel) return; if (functionComboBox.currentIndex >= 0 && functionComboBox.currentIndex < functionsModel.count) { @@ -81,8 +81,7 @@ Window { var pname = parameters[p].name; var varComponent; var type = parameters[p].type; - console.log("type : " + type); - console.log("name : " + pname); + if (type.indexOf("int") !== -1) varComponent = Qt.createComponent("qrc:/qml/QIntType.qml"); else if (type.indexOf("real") !== -1) @@ -91,14 +90,16 @@ Window { varComponent = Qt.createComponent("qrc:/qml/QStringType.qml"); else if (type.indexOf("hash") !== -1 || type.indexOf("address") !== -1) varComponent = Qt.createComponent("qrc:/qml/QHashType.qml"); + else if (type.indexOf("bool") !== -1) + varComponent = Qt.createComponent("qrc:/qml/QBoolType.qml"); + var param = varComponent.createObject(modalTransactionDialog); - var value = itemParams[pname] !== undefined ? itemParams[pname].value : ""; + var value = itemParams[pname] !== undefined ? itemParams[pname] : ""; - console.log("loading parameters"); - console.log(JSON.stringify(itemParams)); param.setValue(value); param.setDeclaration(parameters[p]); - paramsModel.append({ internalValue: param, name: pname, type: parameters[p].type, value: itemParams[pname] !== undefined ? itemParams[pname].value : "" }); + qType.push({ name: pname, value: param }); + paramsModel.append({ name: pname, type: parameters[p].type, value: value }); } } } @@ -108,6 +109,15 @@ Window { visible = false; } + function getqTypeParam(name) + { + for (var k in qType) + { + if (qType[k].name === name) + return qType[k].value; + } + } + function getItem() { var item; @@ -132,18 +142,15 @@ Window { if (isConstructorTransaction) item.functionId = qsTr("Constructor"); + var orderedQType = []; for (var p = 0; p < transactionDialog.transactionParams.count; p++) { var parameter = transactionDialog.transactionParams.get(p); - //var intComponent = Qt.createComponent("qrc:/qml/BigIntValue.qml"); - //var param = intComponent.createObject(modalTransactionDialog); - //param.setValue(parameter.value); - //parameter.internalValue.setValue(parameter.value); - console.log("onget"); - console.log(JSON.stringify(parameter)); - item.parameters[parameter.name] = parameter; + getqTypeParam(parameter.name).setValue(parameter.value); + orderedQType.push(getqTypeParam(parameter.name)); + item.parameters[parameter.name] = parameter.value; } - console.log("return item"); - console.log(JSON.stringify(item)); + console.log(JSON.stringify(qType)); + item.qType = orderedQType; return item; } @@ -247,7 +254,6 @@ Window { TableView { model: paramsModel Layout.fillWidth: true - TableViewColumn { role: "name" title: "Name" @@ -264,7 +270,13 @@ Window { width: 120 } - itemDelegate: { + rowDelegate: + { + return rowDelegate + } + + itemDelegate: + { return editableDelegate; } } @@ -295,19 +307,15 @@ Window { } Component { - id: editableDelegate + id: rowDelegate Item { + height: 100 + } + } - Text { - width: parent.width - anchors.margins: 4 - anchors.left: parent.left - anchors.verticalCenter: parent.verticalCenter - elide: styleData.elideMode - text: styleData.value !== undefined ? styleData.value : "" - color: styleData.textColor - visible: !styleData.selected - } + Component { + id: editableDelegate + Item { Loader { id: loaderEditor anchors.fill: parent @@ -319,11 +327,73 @@ Window { paramsModel.setProperty(styleData.row, styleData.role, loaderEditor.item.text); } } - sourceComponent: (styleData.selected) ? editor : null + + sourceComponent: + { + if (styleData.role === "value") + { + if (paramsModel.get(styleData.row) === 'undefined') + return null; + if (paramsModel.get(styleData.row).type.indexOf("int") !== -1) + return intViewComp; + else if (paramsModel.get(styleData.row).type.indexOf("bool") !== -1) + return boolViewComp; + else if (paramsModel.get(styleData.row).type.indexOf("string") !== -1) + return stringViewComp; + else if (paramsModel.get(styleData.row).type.indexOf("hash") !== -1) + return hashViewComp; + } + else + return editor; + } + + Component + { + id: intViewComp + QIntTypeView + { + id: intView + text: styleData.value + } + } + + + Component + { + id: boolViewComp + QBoolTypeView + { + id: boolView + text: styleData.value + } + } + + Component + { + id: stringViewComp + QStringTypeView + { + id: stringView + text: styleData.value + } + } + + + Component + { + id: hashViewComp + QHashTypeView + { + id: hashView + text: styleData.value + } + } + Component { id: editor TextInput { id: textinput + readOnly: true color: styleData.textColor text: styleData.value MouseArea { From b0c3579e25f809ed77ba4f6110091e1a87c3a74d Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Fri, 30 Jan 2015 01:26:00 +0800 Subject: [PATCH 03/55] implement named arguments --- libsolidity/AST.cpp | 43 ++++++++++++++++++++++++++-- libsolidity/AST.h | 6 ++-- libsolidity/ExpressionCompiler.cpp | 32 +++++++++++++++++++-- libsolidity/Parser.cpp | 45 ++++++++++++++++++++++++++---- libsolidity/Parser.h | 3 +- 5 files changed, 116 insertions(+), 13 deletions(-) diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index d95a254e9..bda366aed 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -430,6 +430,8 @@ void FunctionCall::checkTypeRequirements() // number of non-mapping members if (m_arguments.size() != 1) BOOST_THROW_EXCEPTION(createTypeError("More than one argument for explicit type conversion.")); + if (!m_names.empty()) + BOOST_THROW_EXCEPTION(createTypeError("Type conversion can't allow named arguments.")); if (!m_arguments.front()->getType()->isExplicitlyConvertibleTo(*type.getActualType())) BOOST_THROW_EXCEPTION(createTypeError("Explicit type conversion not allowed.")); m_type = type.getActualType(); @@ -442,9 +444,44 @@ void FunctionCall::checkTypeRequirements() TypePointers const& parameterTypes = functionType->getParameterTypes(); if (parameterTypes.size() != m_arguments.size()) BOOST_THROW_EXCEPTION(createTypeError("Wrong argument count for function call.")); - for (size_t i = 0; i < m_arguments.size(); ++i) - if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*parameterTypes[i])) - BOOST_THROW_EXCEPTION(createTypeError("Invalid type for argument in function call.")); + + if (m_names.empty()) + { + for (size_t i = 0; i < m_arguments.size(); ++i) + if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*parameterTypes[i])) + BOOST_THROW_EXCEPTION(createTypeError("Invalid type for argument in function call.")); + } + else + { + auto const& parameterNames = functionType->getParameterNames(); + if (parameterNames.size() != m_names.size()) + BOOST_THROW_EXCEPTION(createTypeError("Some argument names are missing.")); + + // check duplicate names + for (size_t i = 0; i < m_names.size(); i++) { + for (size_t j = i + 1; j < m_names.size(); j++) { + if (m_names[i] == m_names[j]) + BOOST_THROW_EXCEPTION(createTypeError("Duplicate named argument.")); + } + } + + for (size_t i = 0; i < m_names.size(); i++) { + bool found = false; + for (size_t j = 0; j < parameterNames.size(); j++) { + if (parameterNames[j] == m_names[i]) { + // check type convertible + if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*parameterTypes[j])) + BOOST_THROW_EXCEPTION(createTypeError("Invalid type for argument in function call.")); + + found = true; + break; + } + } + if (!found) + BOOST_THROW_EXCEPTION(createTypeError("Named argument doesn't match function declaration.")); + } + } + // @todo actually the return type should be an anonymous struct, // but we change it to the type of the first return value until we have structs if (functionType->getReturnParameterTypes().empty()) diff --git a/libsolidity/AST.h b/libsolidity/AST.h index f3b18d392..cf86780d6 100755 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -983,14 +983,15 @@ class FunctionCall: public Expression { public: FunctionCall(Location const& _location, ASTPointer const& _expression, - std::vector> const& _arguments): - Expression(_location), m_expression(_expression), m_arguments(_arguments) {} + std::vector> const& _arguments, std::vector const& _names): + Expression(_location), m_expression(_expression), m_arguments(_arguments), m_names(_names) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; virtual void checkTypeRequirements() override; Expression const& getExpression() const { return *m_expression; } std::vector> getArguments() const { return {m_arguments.begin(), m_arguments.end()}; } + std::vector const& getNames() const { return m_names; } /// Returns true if this is not an actual function call, but an explicit type conversion /// or constructor call. @@ -999,6 +1000,7 @@ public: private: ASTPointer m_expression; std::vector> m_arguments; + std::vector m_names; }; /** diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index 5d44c86f3..62066ac69 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -193,6 +193,7 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) { //@todo struct construction solAssert(_functionCall.getArguments().size() == 1, ""); + solAssert(_functionCall.getNames().empty(), ""); Expression const& firstArgument = *_functionCall.getArguments().front(); firstArgument.accept(*this); appendTypeConversion(*firstArgument.getType(), *_functionCall.getType()); @@ -200,8 +201,35 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) else { FunctionType const& function = dynamic_cast(*_functionCall.getExpression().getType()); - vector> arguments = _functionCall.getArguments(); - solAssert(arguments.size() == function.getParameterTypes().size(), ""); + TypePointers const& parameterTypes = function.getParameterTypes(); + vector const& parameterNames = function.getParameterNames(); + vector> const& callArguments = _functionCall.getArguments(); + vector const& callArgumentNames = _functionCall.getNames(); + solAssert(callArguments.size() == parameterTypes.size(), ""); + + vector> arguments; + if (callArgumentNames.empty()) + { + // normal arguments + arguments = {callArguments.begin(), callArguments.end()}; + } + else + { + // named arguments + for (size_t i = 0; i < parameterNames.size(); i++) { + bool found = false; + for (size_t j = 0; j < callArgumentNames.size(); j++) { + if (parameterNames[i] == callArgumentNames[j]) { + // we found the actual parameter position + arguments.push_back(callArguments[j]); + + found = true; + break; + } + } + solAssert(found, ""); + } + } switch (function.getLocation()) { diff --git a/libsolidity/Parser.cpp b/libsolidity/Parser.cpp index 5cfc8f462..3d76eeecc 100644 --- a/libsolidity/Parser.cpp +++ b/libsolidity/Parser.cpp @@ -172,7 +172,7 @@ ASTPointer Parser::parseInheritanceSpecifier() if (m_scanner->getCurrentToken() == Token::LPAREN) { m_scanner->next(); - arguments = parseFunctionCallArguments(); + arguments = parseFunctionCallListArguments(); nodeFactory.markEndPosition(); expectToken(Token::RPAREN); } @@ -288,7 +288,7 @@ ASTPointer Parser::parseModifierInvocation() if (m_scanner->getCurrentToken() == Token::LPAREN) { m_scanner->next(); - arguments = parseFunctionCallArguments(); + arguments = parseFunctionCallListArguments(); nodeFactory.markEndPosition(); expectToken(Token::RPAREN); } @@ -621,10 +621,12 @@ ASTPointer Parser::parseLeftHandSideExpression() case Token::LPAREN: { m_scanner->next(); - vector> arguments = parseFunctionCallArguments(); + vector> arguments; + vector names; + parseFunctionCallArguments(arguments, names); nodeFactory.markEndPosition(); expectToken(Token::RPAREN); - expression = nodeFactory.createNode(expression, arguments); + expression = nodeFactory.createNode(expression, arguments, names); } break; default: @@ -677,7 +679,7 @@ ASTPointer Parser::parsePrimaryExpression() return expression; } -vector> Parser::parseFunctionCallArguments() +vector> Parser::parseFunctionCallListArguments() { vector> arguments; if (m_scanner->getCurrentToken() != Token::RPAREN) @@ -692,6 +694,39 @@ vector> Parser::parseFunctionCallArguments() return arguments; } +void Parser::parseFunctionCallArguments(vector>& _arguments, vector& _names) +{ + Token::Value token = m_scanner->getCurrentToken(); + if (token == Token::LBRACE) + { + // call({arg1 : 1, arg2 : 2 }) + expectToken(Token::LBRACE); + while (m_scanner->getCurrentToken() != Token::RBRACE) + { + string identifier = *expectIdentifierToken(); + expectToken(Token::COLON); + ASTPointer expression = parseExpression(); + + _arguments.push_back(expression); + _names.push_back(identifier); + + if (m_scanner->getCurrentToken() == Token::COMMA) + { + expectToken(Token::COMMA); + } + else + { + break; + } + } + expectToken(Token::RBRACE); + } + else + { + _arguments = parseFunctionCallListArguments(); + } +} + bool Parser::peekVariableDefinition() { diff --git a/libsolidity/Parser.h b/libsolidity/Parser.h index d3bff67e5..2a2f2312a 100644 --- a/libsolidity/Parser.h +++ b/libsolidity/Parser.h @@ -72,7 +72,8 @@ private: ASTPointer parseUnaryExpression(); ASTPointer parseLeftHandSideExpression(); ASTPointer parsePrimaryExpression(); - std::vector> parseFunctionCallArguments(); + std::vector> parseFunctionCallListArguments(); + void parseFunctionCallArguments(std::vector> & _arguments, std::vector & _names); ///@} ///@{ From a78c3668b5616d8eb65fa36b5902534b5ac73cbb Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 30 Jan 2015 00:12:29 +0100 Subject: [PATCH 04/55] - Cleaning. - Bug fix in hash decoding. --- libdevcore/CommonJS.cpp | 2 +- mix/AppContext.cpp | 1 - mix/ClientModel.cpp | 7 +---- mix/ContractCallDataEncoder.cpp | 1 - mix/QVariableDefinition.cpp | 5 +--- mix/QVariableDefinition.h | 8 +++++- mix/qml/QBoolType.qml | 1 - mix/qml/QBoolTypeView.qml | 18 ++++++++----- mix/qml/QHashType.qml | 1 - mix/qml/QHashTypeView.qml | 1 - mix/qml/QIntType.qml | 1 - mix/qml/QIntTypeView.qml | 1 - mix/qml/QRealType.qml | 1 - mix/qml/QStringType.qml | 1 - mix/qml/QStringTypeView.qml | 1 - mix/qml/TransactionDialog.qml | 47 ++++++++++++++++++--------------- 16 files changed, 48 insertions(+), 49 deletions(-) diff --git a/libdevcore/CommonJS.cpp b/libdevcore/CommonJS.cpp index 1a49d71ec..aa5ce2802 100644 --- a/libdevcore/CommonJS.cpp +++ b/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; diff --git a/mix/AppContext.cpp b/mix/AppContext.cpp index 49cf64c56..d280d421a 100644 --- a/mix/AppContext.cpp +++ b/mix/AppContext.cpp @@ -61,7 +61,6 @@ void AppContext::load() m_applicationEngine->rootContext()->setContextProperty("fileIo", m_fileIo.get()); qmlRegisterType("org.ethereum.qml.QEther", 1, 0, "QEther"); qmlRegisterType("org.ethereum.qml.QBigInt", 1, 0, "QBigInt"); - //qmlRegisterType("org.ethereum.qml.QVariableDefinition", 1, 0, "QVariableDefinition"); qmlRegisterType("org.ethereum.qml.QIntType", 1, 0, "QIntType"); qmlRegisterType("org.ethereum.qml.QRealType", 1, 0, "QRealType"); qmlRegisterType("org.ethereum.qml.QStringType", 1, 0, "QStringType"); diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index df489403b..6775817de 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -171,13 +171,8 @@ void ClientModel::executeSequence(std::vector 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()); } diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index 4438c9387..7358a91b3 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/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; } diff --git a/mix/QVariableDefinition.cpp b/mix/QVariableDefinition.cpp index 4e29a3a2e..ffa2c04aa 100644 --- a/mix/QVariableDefinition.cpp +++ b/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); } diff --git a/mix/QVariableDefinition.h b/mix/QVariableDefinition.h index e58cc81f5..a41a4a7ad 100644 --- a/mix/QVariableDefinition.h +++ b/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"; } }; diff --git a/mix/qml/QBoolType.qml b/mix/qml/QBoolType.qml index a6dc54035..9f5fe6fd7 100644 --- a/mix/qml/QBoolType.qml +++ b/mix/qml/QBoolType.qml @@ -3,6 +3,5 @@ import org.ethereum.qml.QBoolType 1.0 QBoolType { - property string view: "qrc:/qml/QBoolTypeView.qml" } diff --git a/mix/qml/QBoolTypeView.qml b/mix/qml/QBoolTypeView.qml index b71ec9cf4..4b17f5cc2 100644 --- a/mix/qml/QBoolTypeView.qml +++ b/mix/qml/QBoolTypeView.qml @@ -5,23 +5,29 @@ 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" } - ListElement { text: qsTr("False"); value: "0" } - } + id: comboModel + ListElement { text: qsTr("False"); value: "0" } + ListElement { text: qsTr("True"); value: "1" } + } } } } diff --git a/mix/qml/QHashType.qml b/mix/qml/QHashType.qml index a7913d414..cbd2618cf 100644 --- a/mix/qml/QHashType.qml +++ b/mix/qml/QHashType.qml @@ -3,6 +3,5 @@ import org.ethereum.qml.QHashType 1.0 QHashType { - property string view: "qrc:/qml/QHashTypeView.qml" } diff --git a/mix/qml/QHashTypeView.qml b/mix/qml/QHashTypeView.qml index 3e09ca112..7c77ae1c2 100644 --- a/mix/qml/QHashTypeView.qml +++ b/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 diff --git a/mix/qml/QIntType.qml b/mix/qml/QIntType.qml index 7533d367f..241bd4a12 100644 --- a/mix/qml/QIntType.qml +++ b/mix/qml/QIntType.qml @@ -3,6 +3,5 @@ import org.ethereum.qml.QIntType 1.0 QIntType { - property string view: "qrc:/qml/QIntTypeView.qml" } diff --git a/mix/qml/QIntTypeView.qml b/mix/qml/QIntTypeView.qml index d9156bf19..f794a3b2d 100644 --- a/mix/qml/QIntTypeView.qml +++ b/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 diff --git a/mix/qml/QRealType.qml b/mix/qml/QRealType.qml index ba3cf82bf..9a015b1c7 100644 --- a/mix/qml/QRealType.qml +++ b/mix/qml/QRealType.qml @@ -3,6 +3,5 @@ import org.ethereum.qml.QRealType 1.0 QRealType { - property string view: "qrc:/qml/QRealTypeView.qml" } diff --git a/mix/qml/QStringType.qml b/mix/qml/QStringType.qml index ab8db4a42..4113fec20 100644 --- a/mix/qml/QStringType.qml +++ b/mix/qml/QStringType.qml @@ -3,6 +3,5 @@ import org.ethereum.qml.QStringType 1.0 QStringType { - property string view: "qrc:/qml/QStringTypeView.qml" } diff --git a/mix/qml/QStringTypeView.qml b/mix/qml/QStringTypeView.qml index d9156bf19..f794a3b2d 100644 --- a/mix/qml/QStringTypeView.qml +++ b/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 diff --git a/mix/qml/TransactionDialog.qml b/mix/qml/TransactionDialog.qml index a98444b85..96b2e0e6b 100644 --- a/mix/qml/TransactionDialog.qml +++ b/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"); + } } } From eab72b22b35c015fa6c1013db44be98de6437745 Mon Sep 17 00:00:00 2001 From: yann300 Date: Fri, 30 Jan 2015 00:28:14 +0100 Subject: [PATCH 05/55] Cleaning --- libdevcore/CommonJS.h | 6 +++--- mix/ClientModel.cpp | 2 +- mix/ContractCallDataEncoder.cpp | 4 ++-- mix/ContractCallDataEncoder.h | 6 +++--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libdevcore/CommonJS.h b/libdevcore/CommonJS.h index 4f7ef8495..6b75d70dc 100644 --- a/libdevcore/CommonJS.h +++ b/libdevcore/CommonJS.h @@ -48,15 +48,15 @@ inline std::string toJS(dev::bytes const& _n) /// 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. +/// Add '0' on the head of @a _b until @a _l. bytes padded(bytes _b, unsigned _l); -/// Add '0' on the queue of _b until _l. +/// Add '0' on the queue of @a _b until @a _l. bytes paddedRight(bytes _b, unsigned _l); /// Remove all trailing '0' std::string unpadRight(std::string _b); /// 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. Returns 0 if _s contains only '0'. +/// Remove all '0' on the head of @a _s. Returns 0 if @a _s contains only '0'. std::string unpadLeft(std::string _s); /// 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); diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index 6775817de..393d08657 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -171,7 +171,7 @@ void ClientModel::executeSequence(std::vector const& _seque throw std::runtime_error("function " + t.functionId.toStdString() + " not found"); c.encode(f); - for (unsigned int p = 0; p < t.parameterValues.size(); p++) + for (int p = 0; p < t.parameterValues.size(); p++) c.push(t.parameterValues.at(p)->encodeValue()); transactonData.emplace_back(c.encodedData()); } diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index 7358a91b3..19e40936d 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -44,12 +44,12 @@ void ContractCallDataEncoder::encode(QFunctionDefinition const* _function) m_encodedData.insert(m_encodedData.end(), hash.begin(), hash.end()); } -void ContractCallDataEncoder::push(bytes _b) +void ContractCallDataEncoder::push(bytes const& _b) { m_encodedData.insert(m_encodedData.end(), _b.begin(), _b.end()); } -QList ContractCallDataEncoder::decode(QList _returnParameters, bytes _value) +QList ContractCallDataEncoder::decode(QList const& _returnParameters, bytes const& _value) { QList r; std::string returnValue = toJS(_value); diff --git a/mix/ContractCallDataEncoder.h b/mix/ContractCallDataEncoder.h index 27baef8ee..d64745052 100644 --- a/mix/ContractCallDataEncoder.h +++ b/mix/ContractCallDataEncoder.h @@ -44,11 +44,11 @@ public: /// Encode hash of the function to call. void encode(QFunctionDefinition const* _function); /// Decode variable in order to be sent to QML view. - QList decode(QList _dec, bytes _value); + QList decode(QList const& _dec, bytes const& _value); /// Get all encoded data encoded by encode function. bytes encodedData(); - /// Push the given @ _b to the current param context. - void push(bytes _b); + /// Push the given @a _b to the current param context. + void push(bytes const& _b); private: bytes m_encodedData; From 3fa0fd80c80cb3c2a69907c1b0b696a86eb2d0d0 Mon Sep 17 00:00:00 2001 From: arkpar Date: Sat, 31 Jan 2015 23:54:47 +0100 Subject: [PATCH 06/55] mix: proper mining --- libethereum/Executive.cpp | 2 +- mix/ClientModel.cpp | 12 ++++++++++-- mix/MixClient.cpp | 5 ++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index cea7d21f4..5208fc8bd 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -68,7 +68,7 @@ bool Executive::setup(bytesConstRef _rlp) if (m_t.gas() < gasCost) { - clog(StateDetail) << "Not enough gas to pay for the transaction: Require >" << gasCost << " Got" << m_t.gas(); + clog << "Not enough gas to pay for the transaction: Require >" << gasCost << " Got" << m_t.gas(); BOOST_THROW_EXCEPTION(OutOfGas() << RequirementError((bigint)gasCost, (bigint)m_t.gas())); } diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index 914edf52d..7fe514c09 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -93,8 +93,16 @@ ClientModel::~ClientModel() QString ClientModel::apiCall(QString const& _message) { - m_rpcConnector->OnRequest(_message.toStdString(), nullptr); - return m_rpcConnector->response(); + try + { + m_rpcConnector->OnRequest(_message.toStdString(), nullptr); + return m_rpcConnector->response(); + } + catch (...) + { + std::cerr << boost::current_exception_diagnostic_information(); + return QString(); + } } void ClientModel::mine() diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index b5f92b4f9..0e95fa429 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -50,7 +50,7 @@ void MixClient::resetState(u256 _balance) Guard fl(m_filterLock); m_filters.clear(); m_watches.clear(); - m_state = eth::State(m_userAccount.address(), m_stateDB, BaseState::Empty); + m_state = eth::State(m_userAccount.address(), m_stateDB, BaseState::Genesis); m_state.addBalance(m_userAccount.address(), _balance); Block genesis; genesis.state = m_state; @@ -161,7 +161,10 @@ void MixClient::mine() { WriteGuard l(x_state); Block& block = m_blocks.back(); + m_state.mine(0, true); m_state.completeMine(); + m_state.commitToMine(BlockChain()); + m_state.cleanup(true); block.state = m_state; block.info = m_state.info(); block.hash = block.info.hash; From c6c8a1ceebb4fd8b57df640c882c84b358a87675 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Fri, 30 Jan 2015 16:06:56 +0100 Subject: [PATCH 07/55] Adding mapping treatment to FunctionType Plus a TypeResolution test for it --- libsolidity/Types.cpp | 23 ++++++++++++++++++----- test/SolidityNameAndTypeResolution.cpp | 10 +++++++++- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index ab401332a..7fa4561e3 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -621,12 +621,25 @@ FunctionType::FunctionType(FunctionDefinition const& _function, bool _isInternal FunctionType::FunctionType(VariableDeclaration const& _varDecl): m_location(Location::EXTERNAL), m_isConstant(true), m_declaration(&_varDecl) { - TypePointers params({}); - vector paramNames({}); - TypePointers retParams({_varDecl.getType()}); - vector retParamNames({ _varDecl.getName()}); - // for now, no input parameters LTODO: change for some things like mapping + TypePointers params; + vector paramNames; + TypePointers retParams; + vector retParamNames; + TypePointer varDeclType = _varDecl.getType(); + auto mappingType = dynamic_cast(varDeclType.get()); + if (mappingType!= nullptr) + { + params.push_back(mappingType->getKeyType()); + paramNames.push_back(mappingType->getKeyType()->toString()); + retParams.push_back(mappingType->getValueType()); + retParamNames.push_back(mappingType->getValueType()->toString()); + } + else // elelemntary type + { + retParams.push_back(varDeclType); + retParamNames.push_back(_varDecl.getName()); + } swap(params, m_parameterTypes); swap(paramNames, m_parameterNames); swap(retParams, m_returnParameterTypes); diff --git a/test/SolidityNameAndTypeResolution.cpp b/test/SolidityNameAndTypeResolution.cpp index b9a7140f7..df0e07e1d 100644 --- a/test/SolidityNameAndTypeResolution.cpp +++ b/test/SolidityNameAndTypeResolution.cpp @@ -637,6 +637,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) " uint64(2);\n" " }\n" "uint256 foo;\n" + "mapping(uint=>string4) map;\n" "}\n"; ASTPointer source; @@ -644,10 +645,17 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) BOOST_CHECK_NO_THROW(source = parseTextAndResolveNamesWithChecks(text)); BOOST_REQUIRE((contract = retrieveContract(source, 0)) != nullptr); FunctionTypePointer function = retrieveFunctionBySignature(contract, "foo()"); - BOOST_REQUIRE(function->hasDeclaration()); + BOOST_REQUIRE(function && function->hasDeclaration()); auto returnParams = function->getReturnParameterTypeNames(); BOOST_CHECK_EQUAL(returnParams.at(0), "uint256"); BOOST_CHECK(function->isConstant()); + function = retrieveFunctionBySignature(contract, "map(uint256)"); + BOOST_REQUIRE(function && function->hasDeclaration()); + auto Params = function->getParameterTypeNames(); + BOOST_CHECK_EQUAL(returnParams.at(0), "uint256"); + returnParams = function->getReturnParameterTypeNames(); + BOOST_CHECK_EQUAL(returnParams.at(0), "string4"); + BOOST_CHECK(function->isConstant()); } BOOST_AUTO_TEST_CASE(function_clash_with_state_variable_accessor) From 4795991f2abadff12d80855ee82dd25c9ffaa0c3 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Sun, 1 Feb 2015 02:41:14 +0100 Subject: [PATCH 08/55] Code generation for mapping state variable accessor - Work in progress --- libsolidity/Compiler.cpp | 4 -- libsolidity/ExpressionCompiler.cpp | 75 ++++++++++++++++++++++++++---- libsolidity/ExpressionCompiler.h | 4 ++ test/SolidityEndToEndTest.cpp | 18 +++++++ 4 files changed, 89 insertions(+), 12 deletions(-) diff --git a/libsolidity/Compiler.cpp b/libsolidity/Compiler.cpp index 3c46d4552..389f826b7 100644 --- a/libsolidity/Compiler.cpp +++ b/libsolidity/Compiler.cpp @@ -240,10 +240,6 @@ bool Compiler::visit(VariableDeclaration const& _variableDeclaration) m_context << m_context.getFunctionEntryLabel(_variableDeclaration); ExpressionCompiler::appendStateVariableAccessor(m_context, _variableDeclaration); - unsigned sizeOnStack = _variableDeclaration.getType()->getSizeOnStack(); - solAssert(sizeOnStack <= 15, "Stack too deep."); - m_context << eth::dupInstruction(sizeOnStack + 1) << eth::Instruction::JUMP; - return false; } diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index 7d58ea2e2..edd04256f 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -823,26 +823,85 @@ unsigned ExpressionCompiler::appendArgumentCopyToMemory(TypePointers const& _typ return length; } -unsigned ExpressionCompiler::appendExpressionCopyToMemory(Type const& _expectedType, - Expression const& _expression, unsigned _memoryOffset) +unsigned ExpressionCompiler::appendTypeCopyToMemory(Type const& _expectedType, TypePointer const& _type, + Location const& _location, unsigned _memoryOffset) { - _expression.accept(*this); - appendTypeConversion(*_expression.getType(), _expectedType, true); + appendTypeConversion(*_type, _expectedType, true); unsigned const c_numBytes = CompilerUtils::getPaddedSize(_expectedType.getCalldataEncodedSize()); if (c_numBytes == 0 || c_numBytes > 32) BOOST_THROW_EXCEPTION(CompilerError() - << errinfo_sourceLocation(_expression.getLocation()) + << errinfo_sourceLocation(_location) << errinfo_comment("Type " + _expectedType.toString() + " not yet supported.")); bool const c_leftAligned = _expectedType.getCategory() == Type::Category::STRING; bool const c_padToWords = true; return CompilerUtils(m_context).storeInMemory(_memoryOffset, c_numBytes, c_leftAligned, c_padToWords); } +unsigned ExpressionCompiler::appendExpressionCopyToMemory(Type const& _expectedType, + Expression const& _expression, + unsigned _memoryOffset) +{ + _expression.accept(*this); + return appendTypeCopyToMemory(_expectedType, _expression.getType(), _expression.getLocation(), _memoryOffset); +} + void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& _varDecl) { - m_currentLValue.fromStateVariable(_varDecl, _varDecl.getType()); - solAssert(m_currentLValue.isInStorage(), ""); - m_currentLValue.retrieveValue(_varDecl.getType(), Location(), true); + auto mappingType = dynamic_cast(_varDecl.getType().get()); + unsigned sizeOnStack; + if (mappingType != nullptr) + { + // this copies from Compiler::visit(FunctionDefinition..) for argument reading + unsigned parameterSize = mappingType->getKeyType()->getSizeOnStack(); + m_context.adjustStackOffset(parameterSize); + m_context.addVariable(_varDecl, parameterSize); + // this copies from ExpressionCompiler::visit(IndexAccess .. ) for mapping access + TypePointer const& keyType = mappingType->getKeyType(); + unsigned length = appendTypeCopyToMemory(*keyType, mappingType->getValueType(), Location()); + solAssert(length == 32, "Mapping key has to take 32 bytes in memory (for now)."); + // @todo move this once we actually use memory + length += CompilerUtils(m_context).storeInMemory(length); + m_context << u256(length) << u256(0) << eth::Instruction::SHA3; + + m_currentLValue = LValue(m_context, LValue::STORAGE, *mappingType->getValueType()); + m_currentLValue.retrieveValue(mappingType->getValueType(), Location(), true); + + unsigned const c_argumentsSize = keyType->getSizeOnStack(); + unsigned const c_returnValuesSize = mappingType->getValueType()->getSizeOnStack(); + unsigned const c_localVariablesSize = 0; + + vector stackLayout; + stackLayout.push_back(c_returnValuesSize); // target of return address + stackLayout += vector(c_argumentsSize, -1); // discard all arguments + for (unsigned i = 0; i < c_returnValuesSize; ++i) + stackLayout.push_back(i); + stackLayout += vector(c_localVariablesSize, -1); + + while (stackLayout.back() != int(stackLayout.size() - 1)) + if (stackLayout.back() < 0) + { + m_context << eth::Instruction::POP; + stackLayout.pop_back(); + } + else + { + m_context << eth::swapInstruction(stackLayout.size() - stackLayout.back() - 1); + swap(stackLayout[stackLayout.back()], stackLayout.back()); + } + //@todo assert that everything is in place now + + m_context << eth::Instruction::JUMP; + } + else + { + m_currentLValue.fromStateVariable(_varDecl, _varDecl.getType()); + solAssert(m_currentLValue.isInStorage(), ""); + m_currentLValue.retrieveValue(_varDecl.getType(), Location(), true); + sizeOnStack = _varDecl.getType()->getSizeOnStack(); + solAssert(sizeOnStack <= 15, "Stack too deep."); + m_context << eth::dupInstruction(sizeOnStack + 1) << eth::Instruction::JUMP; + } + } ExpressionCompiler::LValue::LValue(CompilerContext& _compilerContext, LValueType _type, Type const& _dataType, diff --git a/libsolidity/ExpressionCompiler.h b/libsolidity/ExpressionCompiler.h index caecbfe8d..d93ab28ed 100644 --- a/libsolidity/ExpressionCompiler.h +++ b/libsolidity/ExpressionCompiler.h @@ -97,6 +97,10 @@ private: unsigned appendArgumentCopyToMemory(TypePointers const& _types, std::vector> const& _arguments, unsigned _memoryOffset = 0); + /// Appends code that copies a type to memory. + /// @returns the number of bytes copied to memory + unsigned appendTypeCopyToMemory(Type const& _expectedType, TypePointer const& _type, + Location const& _location, unsigned _memoryOffset = 0); /// Appends code that evaluates a single expression and copies it to memory (with optional offset). /// @returns the number of bytes copied to memory unsigned appendExpressionCopyToMemory(Type const& _expectedType, Expression const& _expression, diff --git a/test/SolidityEndToEndTest.cpp b/test/SolidityEndToEndTest.cpp index 7edc250c8..63a8ebcd3 100644 --- a/test/SolidityEndToEndTest.cpp +++ b/test/SolidityEndToEndTest.cpp @@ -919,6 +919,24 @@ BOOST_AUTO_TEST_CASE(multiple_elementary_accessors) BOOST_CHECK(callContractFunction("super_secret_data()") == bytes()); } +BOOST_AUTO_TEST_CASE(complex_accessors) +{ + char const* sourceCode = "contract test {\n" + " mapping(uint256 => string4) to_string_map;\n" + " mapping(uint256 => bool) to_bool_map;\n" + " mapping(uint256 => uint256) to_uint_map;\n" + " function test() {\n" + " to_string_map[42] = \"24\";\n" + " to_bool_map[42] = false;\n" + " to_uint_map[42] = 12;\n" + " }\n" + "}\n"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("to_string_map(uint256)", 42) == encodeArgs("24")); + BOOST_CHECK(callContractFunction("to_bool_map(uint256)", 42) == encodeArgs(false)); + BOOST_CHECK(callContractFunction("to_uint_map(uint256)", 42) == encodeArgs(12)); +} + BOOST_AUTO_TEST_CASE(balance) { char const* sourceCode = "contract test {\n" From 950305bb79f342d55c3955a5cd7d198ad05a7ad4 Mon Sep 17 00:00:00 2001 From: arkpar Date: Sun, 1 Feb 2015 16:43:24 +0100 Subject: [PATCH 09/55] fixed block generation on mine --- libethereum/Client.cpp | 5 +++-- libethereum/State.cpp | 43 ++++++++++++++++++++++-------------------- libethereum/State.h | 7 +++++-- mix/MixClient.cpp | 13 ++++++++++--- mix/MixClient.h | 1 + test/stateOriginal.cpp | 4 ++-- 6 files changed, 44 insertions(+), 29 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index e8aa0618e..260a81732 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -360,12 +360,13 @@ void Client::setupState(State& _s) cwork << "SETUP MINE"; _s = m_postMine; } + _s.setUncles(m_bc); if (m_paranoia) { if (_s.amIJustParanoid(m_bc)) { cnote << "I'm just paranoid. Block is fine."; - _s.commitToMine(m_bc); + _s.commitToMine(); } else { @@ -373,7 +374,7 @@ void Client::setupState(State& _s) } } else - _s.commitToMine(m_bc); + _s.commitToMine(); } void Client::transact(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice) diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 5232144c2..831696beb 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -639,7 +639,8 @@ void State::uncommitToMine() bool State::amIJustParanoid(BlockChain const& _bc) { - commitToMine(_bc); + setUncles(_bc); + commitToMine(); // Update difficulty according to timestamp. m_currentBlock.difficulty = m_currentBlock.calculateDifficulty(m_previousBlock); @@ -682,22 +683,8 @@ LogBloom State::logBloom() const return ret; } -// @returns the block that represents the difference between m_previousBlock and m_currentBlock. -// (i.e. all the transactions we executed). -void State::commitToMine(BlockChain const& _bc) +void State::setUncles(BlockChain const& _bc) { - uncommitToMine(); - -// cnote << "Committing to mine on block" << m_previousBlock.hash.abridged(); -#ifdef ETH_PARANOIA - commit(); - cnote << "Pre-reward stateRoot:" << m_state.root(); -#endif - - m_lastTx = m_db; - - Addresses uncleAddresses; - RLPStream unclesData; unsigned unclesCount = 0; if (m_previousBlock != BlockChain::genesis()) @@ -716,11 +703,26 @@ void State::commitToMine(BlockChain const& _bc) BlockInfo ubi(_bc.block(u)); ubi.streamRLP(unclesData, WithNonce); ++unclesCount; - uncleAddresses.push_back(ubi.coinbaseAddress); } } } + RLPStream(unclesCount).appendRaw(unclesData.out(), unclesCount).swapOut(m_currentUncles); + m_currentBlock.sha3Uncles = sha3(m_currentUncles); +} + +void State::commitToMine() +{ + uncommitToMine(); + +// cnote << "Committing to mine on block" << m_previousBlock.hash.abridged(); +#ifdef ETH_PARANOIA + commit(); + cnote << "Pre-reward stateRoot:" << m_state.root(); +#endif + + m_lastTx = m_db; + MemoryDB tm; GenericTrieDB transactionsTrie(&tm); transactionsTrie.init(); @@ -750,12 +752,13 @@ void State::commitToMine(BlockChain const& _bc) txs.swapOut(m_currentTxs); - RLPStream(unclesCount).appendRaw(unclesData.out(), unclesCount).swapOut(m_currentUncles); - m_currentBlock.transactionsRoot = transactionsTrie.root(); m_currentBlock.receiptsRoot = receiptsTrie.root(); m_currentBlock.logBloom = logBloom(); - m_currentBlock.sha3Uncles = sha3(m_currentUncles); + + Addresses uncleAddresses; + for (const auto& r: RLP(m_currentUncles)) + uncleAddresses.push_back(BlockInfo::fromHeader(r.data()).coinbaseAddress); // Apply rewards last of all. applyRewards(uncleAddresses); diff --git a/libethereum/State.h b/libethereum/State.h index 85abd9366..313cc5c44 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -105,13 +105,16 @@ public: /// @returns true if all is ok. If it's false, worry. bool amIJustParanoid(BlockChain const& _bc); + /// @brief Loads current block uncles from blockchain + void setUncles(BlockChain const& _bc); + /// Prepares the current state for mining. /// Commits all transactions into the trie, compiles uncles and transactions list, applies all /// rewards and populates the current block header with the appropriate hashes. /// The only thing left to do after this is to actually mine(). /// /// This may be called multiple times and without issue. - void commitToMine(BlockChain const& _bc); + void commitToMine(); /// Attempt to find valid nonce for block that this state represents. /// This function is thread-safe. You can safely have other interactions with this object while it is happening. @@ -123,7 +126,7 @@ public: * Typically looks like: * @code * // lock - * commitToMine(blockchain); + * commitToMine(); * // unlock * MineInfo info; * for (info.complete = false; !info.complete; info = mine()) {} diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index 0e95fa429..5c6917505 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -56,12 +56,16 @@ void MixClient::resetState(u256 _balance) genesis.state = m_state; Block open; m_blocks = Blocks { genesis, open }; //last block contains a list of pending transactions to be finalized + m_lastHashes.clear(); + m_lastHashes.resize(256); + m_lastHashes[0] = genesis.hash; } void MixClient::executeTransaction(Transaction const& _t, State& _state) { bytes rlp = _t.rlp(); - Executive execution(_state, LastHashes(), 0); + + Executive execution(_state, m_lastHashes, 0); execution.setup(&rlp); std::vector machineStates; std::vector levels; @@ -163,12 +167,15 @@ void MixClient::mine() Block& block = m_blocks.back(); m_state.mine(0, true); m_state.completeMine(); - m_state.commitToMine(BlockChain()); - m_state.cleanup(true); + m_state.commitToMine(); block.state = m_state; block.info = m_state.info(); block.hash = block.info.hash; + m_state.cleanup(true); m_blocks.push_back(Block()); + m_lastHashes.insert(m_lastHashes.begin(), block.hash); + m_lastHashes.resize(256); + h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter }; noteChanged(changed); } diff --git a/mix/MixClient.h b/mix/MixClient.h index fede1891e..dceb9ce7b 100644 --- a/mix/MixClient.h +++ b/mix/MixClient.h @@ -145,6 +145,7 @@ private: std::map m_filters; std::map m_watches; Blocks m_blocks; + eth::LastHashes m_lastHashes; }; } diff --git a/test/stateOriginal.cpp b/test/stateOriginal.cpp index a49c55061..f4804c43b 100644 --- a/test/stateOriginal.cpp +++ b/test/stateOriginal.cpp @@ -51,7 +51,7 @@ int stateTest() cout << s; // Mine to get some ether! - s.commitToMine(bc); + s.commitToMine(); while (!s.mine(100).completed) {} s.completeMine(); bc.attemptImport(s.blockData(), stateDB); @@ -74,7 +74,7 @@ int stateTest() cout << s; // Mine to get some ether and set in stone. - s.commitToMine(bc); + s.commitToMine(); while (!s.mine(100).completed) {} s.completeMine(); bc.attemptImport(s.blockData(), stateDB); From 622a358d1d0b03e7d3f00f0db0e7df6af3cd0b40 Mon Sep 17 00:00:00 2001 From: arkpar Date: Sun, 1 Feb 2015 17:20:52 +0100 Subject: [PATCH 10/55] reverted Executive.cpp --- libethereum/Executive.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 5208fc8bd..cea7d21f4 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -68,7 +68,7 @@ bool Executive::setup(bytesConstRef _rlp) if (m_t.gas() < gasCost) { - clog << "Not enough gas to pay for the transaction: Require >" << gasCost << " Got" << m_t.gas(); + clog(StateDetail) << "Not enough gas to pay for the transaction: Require >" << gasCost << " Got" << m_t.gas(); BOOST_THROW_EXCEPTION(OutOfGas() << RequirementError((bigint)gasCost, (bigint)m_t.gas())); } From a93319623a1df9ab64ed831356b9a8b6cdd93d6c Mon Sep 17 00:00:00 2001 From: yann300 Date: Sun, 1 Feb 2015 17:23:13 +0100 Subject: [PATCH 11/55] misc changes --- libdevcore/CommonJS.cpp | 28 ++++++-------- libdevcore/CommonJS.h | 6 +-- mix/ClientModel.cpp | 6 +++ mix/ContractCallDataEncoder.cpp | 13 ++++--- mix/ContractCallDataEncoder.h | 2 +- mix/QBigInt.h | 4 +- mix/QVariableDeclaration.h | 2 +- mix/QVariableDefinition.cpp | 65 ++++++++++++++++----------------- mix/QVariableDefinition.h | 28 +++++++++----- mix/qml/QBoolTypeView.qml | 14 +++++-- mix/qml/QHashTypeView.qml | 1 + mix/qml/QStringTypeView.qml | 1 + mix/qml/TransactionDialog.qml | 10 ++--- 13 files changed, 99 insertions(+), 81 deletions(-) diff --git a/libdevcore/CommonJS.cpp b/libdevcore/CommonJS.cpp index aa5ce2802..8cdb27954 100644 --- a/libdevcore/CommonJS.cpp +++ b/libdevcore/CommonJS.cpp @@ -47,9 +47,8 @@ bytes padded(bytes _b, unsigned _l) bytes paddedRight(bytes _b, unsigned _l) { - while (_b.size() < _l) - _b.insert(_b.end(), 0); - return asBytes(asString(_b).substr(_b.size() - std::max(_l, _l))); + _b.resize(_l); + return _b; } bytes unpadded(bytes _b) @@ -59,24 +58,21 @@ bytes unpadded(bytes _b) return _b; } -std::string unpadRight(std::string _b) +bytes unpadLeft(bytes _b) { + int i = 0; + if (_b.size() == 0) + return _b; while (true) { - auto p = _b.find_last_of("0"); - if (p == _b.size() - 1 && p != std::string::npos) - _b = _b.substr(0, _b.size() - 1); + if (_b.at(i) == byte(0)) + i++; else - return _b; + break; } -} - -std::string unpadLeft(std::string _b) -{ - auto p = _b.find_first_not_of('0'); - if (p == std::string::npos) - return "0"; - return _b.substr(p, _b.length() - 1); + if (i != 0) + _b.erase(_b.begin(), _b.begin() + i); + return _b; } std::string prettyU256(u256 _n) diff --git a/libdevcore/CommonJS.h b/libdevcore/CommonJS.h index 6b75d70dc..59e6c1d34 100644 --- a/libdevcore/CommonJS.h +++ b/libdevcore/CommonJS.h @@ -52,12 +52,10 @@ bytes jsToBytes(std::string const& _s); bytes padded(bytes _b, unsigned _l); /// Add '0' on the queue of @a _b until @a _l. bytes paddedRight(bytes _b, unsigned _l); -/// Remove all trailing '0' -std::string unpadRight(std::string _b); /// Removing all trailing '0'. Returns empty array if input contains only '0' char. bytes unpadded(bytes _s); -/// Remove all '0' on the head of @a _s. Returns 0 if @a _s contains only '0'. -std::string unpadLeft(std::string _s); +/// Remove all 0 byte on the head of @a _s. +bytes unpadLeft(bytes _s); /// 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 into user-readable string (by directly using std::string constructor). diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index 393d08657..e71280821 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -170,6 +170,12 @@ void ClientModel::executeSequence(std::vector const& _seque if (!f) throw std::runtime_error("function " + t.functionId.toStdString() + " not found"); + for (int k = 0; k < f->parametersList() .size(); k++) + { + if (f->parametersList().at(k)->type() != t.parameterValues.at(k)->declaration()->type()) + throw std::runtime_error("list of parameters has been changed. Need to update this transaction"); + } + c.encode(f); for (int p = 0; p < t.parameterValues.size(); p++) c.push(t.parameterValues.at(p)->encodeValue()); diff --git a/mix/ContractCallDataEncoder.cpp b/mix/ContractCallDataEncoder.cpp index 19e40936d..bdec95ca4 100644 --- a/mix/ContractCallDataEncoder.cpp +++ b/mix/ContractCallDataEncoder.cpp @@ -49,11 +49,9 @@ void ContractCallDataEncoder::push(bytes const& _b) m_encodedData.insert(m_encodedData.end(), _b.begin(), _b.end()); } -QList ContractCallDataEncoder::decode(QList const& _returnParameters, bytes const& _value) +QList ContractCallDataEncoder::decode(QList const& _returnParameters, bytes _value) { QList r; - std::string returnValue = toJS(_value); - returnValue = returnValue.substr(2, returnValue.length() - 1); for (int k = 0; k <_returnParameters.length(); k++) { QVariableDeclaration* dec = (QVariableDeclaration*)_returnParameters.at(k); @@ -68,9 +66,14 @@ QList ContractCallDataEncoder::decode(QListtype().contains("hash") || dec->type().contains("address")) def = new QHashType(dec, QString()); - def->decodeValue(returnValue); + else + BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Parameter declaration not found")); + + bytes rawParam(_value.begin(), _value.begin() + 32); + def->decodeValue(rawParam); r.push_back(def); - returnValue = returnValue.substr(32 * 2, returnValue.length() - 1); + if (_value.size() > 32) + _value = bytes(_value.begin() + 32, _value.end()); qDebug() << "decoded return value : " << dec->type() << " " << def->value(); } return r; diff --git a/mix/ContractCallDataEncoder.h b/mix/ContractCallDataEncoder.h index d64745052..718beb8e0 100644 --- a/mix/ContractCallDataEncoder.h +++ b/mix/ContractCallDataEncoder.h @@ -44,7 +44,7 @@ public: /// Encode hash of the function to call. void encode(QFunctionDefinition const* _function); /// Decode variable in order to be sent to QML view. - QList decode(QList const& _dec, bytes const& _value); + QList decode(QList const& _dec, bytes _value); /// Get all encoded data encoded by encode function. bytes encodedData(); /// Push the given @a _b to the current param context. diff --git a/mix/QBigInt.h b/mix/QBigInt.h index 0f5c88c43..c6ec72305 100644 --- a/mix/QBigInt.h +++ b/mix/QBigInt.h @@ -36,7 +36,7 @@ namespace dev namespace mix { -using BigIntVariant = boost::variant; +using BigIntVariant = boost::variant; struct add: public boost::static_visitor { @@ -75,7 +75,7 @@ public: QBigInt(dev::u256 const& _value, QObject* _parent = 0): QObject(_parent), m_internalValue(_value) { QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } QBigInt(dev::bigint const& _value, QObject* _parent = 0): QObject(_parent), m_internalValue(_value) { QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } QBigInt(BigIntVariant const& _value, QObject* _parent = 0): QObject(_parent), m_internalValue(_value){ QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } - QBigInt(QString const& _value, QObject* _parent = 0): QObject(_parent) { QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); setValue(_value); } + QBigInt(dev::s256 const& _value, QObject* _parent = 0): QObject(_parent), m_internalValue(_value) { QQmlEngine::setObjectOwnership(this, QQmlEngine::JavaScriptOwnership); } ~QBigInt() {} /// @returns the current used big integer. diff --git a/mix/QVariableDeclaration.h b/mix/QVariableDeclaration.h index 0d091b035..2670a4dc3 100644 --- a/mix/QVariableDeclaration.h +++ b/mix/QVariableDeclaration.h @@ -40,7 +40,7 @@ public: QVariableDeclaration() {} QVariableDeclaration(solidity::VariableDeclaration const* _v): QBasicNodeDefinition(_v), m_type(QString::fromStdString(_v->getType()->toString())) {} QVariableDeclaration(solidity::ParamDescription const& _v): QBasicNodeDefinition(_v.getName()), m_type(QString::fromStdString(_v.getType())) {} - Q_INVOKABLE QString type() const { return m_type; } + QString type() const { return m_type; } private: QString m_type; diff --git a/mix/QVariableDefinition.cpp b/mix/QVariableDefinition.cpp index ffa2c04aa..5049283da 100644 --- a/mix/QVariableDefinition.cpp +++ b/mix/QVariableDefinition.cpp @@ -59,25 +59,30 @@ QVariableDefinition* QVariableDefinitionList::val(int _idx) /* * QIntType */ +void QIntType::setValue(dev::bigint _value) +{ + m_bigIntvalue = _value; + std::stringstream str; + str << std::dec << m_bigIntvalue; + m_value = QString::fromStdString(str.str()); +} + dev::bytes QIntType::encodeValue() { dev::bigint i(value().toStdString()); if (i < 0) i = i + dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + 1; - std::ostringstream s; - s << std::hex << "0x" << i; - return padded(jsToBytes(s.str()), 32); + bytes ret(32); + toBigEndian(i, ret); + return ret; } -void QIntType::decodeValue(std::string const& _rawValue) +void QIntType::decodeValue(dev::bytes const& _rawValue) { - std::string rawParam = _rawValue.substr(0, 32 * 2); - dev::bigint bigint = dev::bigint("0x" + rawParam); + dev::bigint bigint = dev::fromBigEndian(_rawValue); if (((bigint >> 32) & 1) == 1) bigint = bigint - dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") - 1; - std::ostringstream s; - s << std::dec << bigint; - setValue(QString::fromStdString(s.str())); + setValue(bigint); } /* @@ -85,14 +90,15 @@ void QIntType::decodeValue(std::string const& _rawValue) */ dev::bytes QHashType::encodeValue() { - return padded(jsToBytes("0x" + value().toStdString()), 32); + QByteArray b = value().toUtf8(); + bytes r = bytes(b.begin(), b.end()); + return padded(r, 32); } -void QHashType::decodeValue(std::string const& _rawValue) +void QHashType::decodeValue(dev::bytes const& _rawValue) { - std::string rawParam = _rawValue.substr(0, 32 * 2); - std::string unPadded = unpadLeft(rawParam); - setValue(QString::fromStdString(unPadded)); + std::string _ret = asString(unpadLeft(_rawValue)); + setValue(QString::fromStdString(_ret)); } /* @@ -103,7 +109,7 @@ dev::bytes QRealType::encodeValue() return bytes(); } -void QRealType::decodeValue(std::string const& _rawValue) +void QRealType::decodeValue(dev::bytes const& _rawValue) { Q_UNUSED(_rawValue); } @@ -113,24 +119,14 @@ void QRealType::decodeValue(std::string const& _rawValue) */ dev::bytes QStringType::encodeValue() { - qDebug() << QString::fromStdString(toJS(paddedRight(asBytes(value().toStdString()), 32))); - return paddedRight(asBytes(value().toStdString()), 32); + QByteArray b = value().toUtf8(); + bytes r = bytes(b.begin(), b.end()); + return paddedRight(r, 32); } -void QStringType::decodeValue(std::string const& _rawValue) +void QStringType::decodeValue(dev::bytes const& _rawValue) { - std::string rawParam = _rawValue.substr(0, 32 * 2); - rawParam = unpadRight(rawParam); - std::string res; - res.reserve(rawParam.size() / 2); - for (unsigned int i = 0; i < rawParam.size(); i += 2) - { - std::istringstream iss(rawParam.substr(i, 2)); - int temp; - iss >> std::hex >> temp; - res += static_cast(temp); - } - setValue(QString::fromStdString(res)); + setValue(QString::fromUtf8((char*)_rawValue.data())); } /* @@ -141,9 +137,10 @@ dev::bytes QBoolType::encodeValue() return padded(jsToBytes(value().toStdString()), 32); } -void QBoolType::decodeValue(std::string const& _rawValue) +void QBoolType::decodeValue(dev::bytes const& _rawValue) { - std::string rawParam = _rawValue.substr(0, 32 * 2); - std::string unpadded = unpadLeft(rawParam); - setValue(QString::fromStdString(unpadded)); + byte ret = _rawValue.at(_rawValue.size() - 1); + bool boolRet = (ret == byte(1)); + m_boolValue = boolRet; + m_value = m_boolValue ? "1" : "0"; } diff --git a/mix/QVariableDefinition.h b/mix/QVariableDefinition.h index a41a4a7ad..ae9bf9459 100644 --- a/mix/QVariableDefinition.h +++ b/mix/QVariableDefinition.h @@ -52,10 +52,12 @@ public: /// 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; + virtual void decodeValue(dev::bytes const& _rawValue) = 0; -private: +protected: QString m_value; + +private: QVariableDeclaration* m_dec; }; @@ -85,9 +87,14 @@ public: QIntType() {} QIntType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} dev::bytes encodeValue() override; - void decodeValue(std::string const& _rawValue) override; + void decodeValue(dev::bytes const& _rawValue) override; /// @returns an instance of QBigInt for the current value. - QBigInt* toBigInt() { return new QBigInt(value()); } + QBigInt* toBigInt() { return new QBigInt(m_bigIntvalue); } + dev::bigint bigInt() { return m_bigIntvalue; } + void setValue(dev::bigint _value); + +private: + dev::bigint m_bigIntvalue; }; class QRealType: public QVariableDefinition @@ -98,7 +105,7 @@ public: QRealType() {} QRealType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} dev::bytes encodeValue() override; - void decodeValue(std::string const& _rawValue) override; + void decodeValue(dev::bytes const& _rawValue) override; }; class QStringType: public QVariableDefinition @@ -109,7 +116,7 @@ public: QStringType() {} QStringType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} dev::bytes encodeValue() override; - void decodeValue(std::string const& _rawValue) override; + void decodeValue(dev::bytes const& _rawValue) override; }; class QHashType: public QVariableDefinition @@ -120,7 +127,7 @@ public: QHashType() {} QHashType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} dev::bytes encodeValue() override; - void decodeValue(std::string const& _rawValue) override; + void decodeValue(dev::bytes const& _rawValue) override; }; class QBoolType: public QVariableDefinition @@ -131,9 +138,12 @@ public: QBoolType() {} QBoolType(QVariableDeclaration* _def, QString _value): QVariableDefinition(_def, _value) {} dev::bytes encodeValue() override; - void decodeValue(std::string const& _rawValue) override; + void decodeValue(dev::bytes const& _rawValue) override; /// @returns the boolean value for the current definition. - bool toBool() { return value() != "0"; } + bool toBool() { return m_boolValue; } + +private: + bool m_boolValue; }; } diff --git a/mix/qml/QBoolTypeView.qml b/mix/qml/QBoolTypeView.qml index 4b17f5cc2..a52601bdb 100644 --- a/mix/qml/QBoolTypeView.qml +++ b/mix/qml/QBoolTypeView.qml @@ -5,22 +5,28 @@ Item { id: editRoot property string text - property bool defaultValue + property string defaultValue + Rectangle { anchors.fill: parent ComboBox { + property bool inited: false Component.onCompleted: { - text = (defaultValue ? "1" : "0"); - currentIndex = parseInt(text); + if (text === "") + currentIndex = parseInt(defaultValue); + else + currentIndex = parseInt(text); + inited = true } id: boolCombo anchors.fill: parent onCurrentIndexChanged: { - text = comboModel.get(currentIndex).value; + if (inited) + text = comboModel.get(currentIndex).value; } model: ListModel { diff --git a/mix/qml/QHashTypeView.qml b/mix/qml/QHashTypeView.qml index 7c77ae1c2..e36514fab 100644 --- a/mix/qml/QHashTypeView.qml +++ b/mix/qml/QHashTypeView.qml @@ -10,6 +10,7 @@ Item id: textinput text: text anchors.fill: parent + wrapMode: Text.WrapAnywhere MouseArea { id: mouseArea anchors.fill: parent diff --git a/mix/qml/QStringTypeView.qml b/mix/qml/QStringTypeView.qml index f794a3b2d..a78fc1d26 100644 --- a/mix/qml/QStringTypeView.qml +++ b/mix/qml/QStringTypeView.qml @@ -10,6 +10,7 @@ Item id: textinput text: text anchors.fill: parent + wrapMode: Text.WrapAnywhere MouseArea { id: mouseArea anchors.fill: parent diff --git a/mix/qml/TransactionDialog.qml b/mix/qml/TransactionDialog.qml index 96b2e0e6b..f81de10a5 100644 --- a/mix/qml/TransactionDialog.qml +++ b/mix/qml/TransactionDialog.qml @@ -356,19 +356,19 @@ Window { } } - Component { id: boolViewComp QBoolTypeView { id: boolView - text: styleData.value - defaultValue: true + defaultValue: "1" Component.onCompleted: { - //default value - loaderEditor.updateValue(styleData.row, styleData.role, "1"); + loaderEditor.updateValue(styleData.row, styleData.role, + (paramsModel.get(styleData.row).value === "" ? defaultValue : + paramsModel.get(styleData.row).value)); + text = (paramsModel.get(styleData.row).value === "" ? defaultValue : paramsModel.get(styleData.row).value); } } } From a3a9762c96ad758cfea67857f384fa56fe136d96 Mon Sep 17 00:00:00 2001 From: yann300 Date: Sun, 1 Feb 2015 20:03:27 +0100 Subject: [PATCH 12/55] display return parameters in transaction list --- mix/ClientModel.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index b8f7c9a2b..ca7849412 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -207,15 +207,14 @@ void ClientModel::executeSequence(std::vector const& _seque if (!f) BOOST_THROW_EXCEPTION(FunctionNotFoundException() << FunctionName(transaction.functionId.toStdString())); - for (int k = 0; k < f->parametersList() .size(); k++) - { - if (f->parametersList().at(k)->type() != transaction.parameterValues.at(k)->declaration()->type()) - BOOST_THROW_EXCEPTION(ParameterChangedException() << FunctionName(f->parametersList().at(k)->type().toStdString())); - } - encoder.encode(f); for (int p = 0; p < transaction.parameterValues.size(); p++) + { + if (f->parametersList().at(p)->type() != transaction.parameterValues.at(p)->declaration()->type()) + BOOST_THROW_EXCEPTION(ParameterChangedException() << FunctionName(f->parametersList().at(p)->type().toStdString())); encoder.push(transaction.parameterValues.at(p)->encodeValue()); + } + if (transaction.functionId.isEmpty()) { @@ -229,10 +228,6 @@ void ClientModel::executeSequence(std::vector const& _seque else { callContract(m_contractAddress, encoder.encodedData(), transaction); - - // Used to log return values. TODO move this to QML. - ExecutionResult const& last = m_client->record().back().transactions.back(); - encoder.decode(f->returnParameters(), last.returnValue); } } onNewTransaction(); @@ -331,11 +326,6 @@ void ClientModel::onNewTransaction() bool creation = tr.contractAddress != 0; - if (creation) - returned = QString::fromStdString(toJS(tr.contractAddress)); - else - returned = QString::fromStdString(toJS(tr.returnValue)); - //TODO: handle value transfer FixedHash<4> functionHash; bool call = false; @@ -364,6 +354,10 @@ void ClientModel::onNewTransaction() function = QObject::tr(""); } + if (creation) + returned = QString::fromStdString(toJS(tr.contractAddress)); + + QList returnValues; if (m_contractAddress != 0 && (tr.address == m_contractAddress || tr.contractAddress == m_contractAddress)) { auto compilerRes = m_context->codeModel()->code(); @@ -373,7 +367,13 @@ void ClientModel::onNewTransaction() { QFunctionDefinition* funcDef = def->getFunction(functionHash); if (funcDef) + { function = funcDef->name(); + ContractCallDataEncoder encoder; + returnValues = encoder.decode(funcDef->returnParameters(), tr.returnValue); + for (auto const& var: returnValues) + returned += var->value() + " | "; + } } } From afa9b4337fa9ee35640e7ba2d6663bcbc98b3e43 Mon Sep 17 00:00:00 2001 From: yann300 Date: Sun, 1 Feb 2015 23:11:14 +0100 Subject: [PATCH 13/55] Integrate solidity type with project files. --- mix/AppContext.cpp | 1 + mix/ClientModel.cpp | 3 +- mix/QVariableDeclaration.h | 5 +++- mix/qml/QVariableDeclaration.qml | 7 +++++ mix/qml/StateListModel.qml | 47 ++++++++++++++++++++++++++++---- mix/res.qrc | 1 + 6 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 mix/qml/QVariableDeclaration.qml diff --git a/mix/AppContext.cpp b/mix/AppContext.cpp index 572ad7bbd..e27eac9fd 100644 --- a/mix/AppContext.cpp +++ b/mix/AppContext.cpp @@ -68,6 +68,7 @@ void AppContext::load() qmlRegisterType("org.ethereum.qml.QStringType", 1, 0, "QStringType"); qmlRegisterType("org.ethereum.qml.QHashType", 1, 0, "QHashType"); qmlRegisterType("org.ethereum.qml.QBoolType", 1, 0, "QBoolType"); + qmlRegisterType("org.ethereum.qml.QVariableDeclaration", 1, 0, "QVariableDeclaration"); QQmlComponent projectModelComponent(m_applicationEngine, QUrl("qrc:/qml/ProjectModel.qml")); QObject* projectModel = projectModelComponent.create(); if (projectModelComponent.isError()) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index ca7849412..93bcc7c92 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -357,7 +357,6 @@ void ClientModel::onNewTransaction() if (creation) returned = QString::fromStdString(toJS(tr.contractAddress)); - QList returnValues; if (m_contractAddress != 0 && (tr.address == m_contractAddress || tr.contractAddress == m_contractAddress)) { auto compilerRes = m_context->codeModel()->code(); @@ -370,7 +369,7 @@ void ClientModel::onNewTransaction() { function = funcDef->name(); ContractCallDataEncoder encoder; - returnValues = encoder.decode(funcDef->returnParameters(), tr.returnValue); + QList returnValues = encoder.decode(funcDef->returnParameters(), tr.returnValue); for (auto const& var: returnValues) returned += var->value() + " | "; } diff --git a/mix/QVariableDeclaration.h b/mix/QVariableDeclaration.h index 771f334e8..fcd83cb30 100644 --- a/mix/QVariableDeclaration.h +++ b/mix/QVariableDeclaration.h @@ -34,13 +34,14 @@ namespace mix class QVariableDeclaration: public QBasicNodeDefinition { Q_OBJECT - Q_PROPERTY(QString type READ type CONSTANT) + Q_PROPERTY(QString type READ type WRITE setType) public: QVariableDeclaration() {} QVariableDeclaration(solidity::VariableDeclaration const* _v): QBasicNodeDefinition(_v), m_type(QString::fromStdString(_v->getType()->toString())) {} QVariableDeclaration(std::string const& _name, std::string const& _type): QBasicNodeDefinition(_name), m_type(QString::fromStdString(_type)) {} QString type() const { return m_type; } + void setType(QString _type) { m_type = _type; } private: QString m_type; @@ -48,3 +49,5 @@ private: } } + +Q_DECLARE_METATYPE(dev::mix::QVariableDeclaration*) diff --git a/mix/qml/QVariableDeclaration.qml b/mix/qml/QVariableDeclaration.qml new file mode 100644 index 000000000..dc21d40a7 --- /dev/null +++ b/mix/qml/QVariableDeclaration.qml @@ -0,0 +1,7 @@ +import QtQuick 2.0 +import org.ethereum.qml.QVariableDeclaration 1.0 + +QVariableDeclaration +{ +} + diff --git a/mix/qml/StateListModel.qml b/mix/qml/StateListModel.qml index 5f4b7e20e..3d60414cc 100644 --- a/mix/qml/StateListModel.qml +++ b/mix/qml/StateListModel.qml @@ -31,12 +31,30 @@ Item { stdContract: t.stdContract, parameters: {} }; - for (var key in t.parameters) { - var intComponent = Qt.createComponent("qrc:/qml/BigIntValue.qml"); - var param = intComponent.createObject(); - param.setValue(t.parameters[key]); - r.parameters[key] = param; + var qType = []; + for (var key in t.parameters) + { + r.parameters[key] = t.parameters[key].value; + var type = t.parameters[key].type; + var varComponent; + if (type.indexOf("int") !== -1) + varComponent = Qt.createComponent("qrc:/qml/QIntType.qml"); + else if (type.indexOf("real") !== -1) + varComponent = Qt.createComponent("qrc:/qml/QRealType.qml"); + else if (type.indexOf("string") !== -1 || type.indexOf("text") !== -1) + varComponent = Qt.createComponent("qrc:/qml/QStringType.qml"); + else if (type.indexOf("hash") !== -1 || type.indexOf("address") !== -1) + varComponent = Qt.createComponent("qrc:/qml/QHashType.qml"); + else if (type.indexOf("bool") !== -1) + varComponent = Qt.createComponent("qrc:/qml/QBoolType.qml"); + + var param = varComponent.createObject(stateListModel); + var dec = Qt.createComponent("qrc:/qml/QVariableDeclaration.qml"); + param.setDeclaration(dec.createObject(stateListModel, { "type": type })); + param.setValue(r.parameters[key]); + qType.push(param); } + r.qType = qType; return r; } @@ -48,6 +66,16 @@ Item { }; } + function getParamType(param, params) + { + for (var k in params) + { + if (params[k].declaration.name === param) + return params[k].declaration.type; + } + return ''; + } + function toPlainTransactionItem(t) { var r = { functionId: t.functionId, @@ -60,7 +88,14 @@ Item { parameters: {} }; for (var key in t.parameters) - r.parameters[key] = t.parameters[key]; + { + var param = { + name: key, + value: t.parameters[key], + type: getParamType(key, t.qType) + } + r.parameters[key] = param; + } return r; } diff --git a/mix/res.qrc b/mix/res.qrc index 02b58bb8e..82f9456be 100644 --- a/mix/res.qrc +++ b/mix/res.qrc @@ -63,5 +63,6 @@ qml/TransactionLog.qml res/mix_256x256x32.png qml/CallStack.qml + qml/QVariableDeclaration.qml From a2f495c4bb12fc155b4016ed9011a4bd8b4c901b Mon Sep 17 00:00:00 2001 From: yann300 Date: Sun, 1 Feb 2015 23:24:03 +0100 Subject: [PATCH 14/55] fixed collision while merging --- mix/qml/StateList.qml | 58 ------------------------------------------- 1 file changed, 58 deletions(-) diff --git a/mix/qml/StateList.qml b/mix/qml/StateList.qml index ee5048e14..ad14cf30e 100644 --- a/mix/qml/StateList.qml +++ b/mix/qml/StateList.qml @@ -27,64 +27,6 @@ Rectangle { action: addStateAction } - StateDialog { - id: stateDialog - onAccepted: { - var item = stateDialog.getItem(); - if (stateDialog.stateIndex < stateListModel.count) { - stateList[stateDialog.stateIndex] = item; - stateListModel.set(stateDialog.stateIndex, item); - } else { - stateList.push(item); - stateListModel.append(item); - } - stateListModel.save(); - } - } - - ListModel { - id: stateListModel - - function addState() { - var ether = QEtherHelper.createEther("100000000000000000000000000", QEther.Wei); - var item = { - title: "", - balance: ether, - transactions: [] - }; - - var ctorTr = { - value: QEtherHelper.createEther("100", QEther.Wei), - functionId: qsTr("Constructor"), - gas: QEtherHelper.createEther("125000", QEther.Wei), - gasPrice: QEtherHelper.createEther("10000000000000", QEther.Wei), - executeConstructor: true - }; - - item.transactions.push(ctorTr); - stateDialog.open(stateListModel.count, item); - } - - function editState(index) { - stateDialog.open(index, stateList[index]); - } - - function runState(index) { - var item = stateList[index]; - clientModel.debugState(item); - } - - function deleteState(index) { - stateListModel.remove(index); - stateList.splice(index, 1); - save(); - } - - function save() { - projectModel.saveProject(); - } - } - Component { id: renderDelegate Item { From 780a7cfd262851715f044750c521165eedc8ea38 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 1 Feb 2015 22:48:52 -0800 Subject: [PATCH 15/55] Don't count same messages twice. --- test/whisperTopic.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/whisperTopic.cpp b/test/whisperTopic.cpp index 0162124b8..119373361 100644 --- a/test/whisperTopic.cpp +++ b/test/whisperTopic.cpp @@ -50,6 +50,7 @@ BOOST_AUTO_TEST_CASE(topic) auto w = wh->installWatch(BuildTopicMask("odd")); started = true; + set received; for (int iterout = 0, last = 0; iterout < 200 && last < 81; ++iterout) { @@ -57,6 +58,9 @@ BOOST_AUTO_TEST_CASE(topic) { Message msg = wh->envelope(i).open(wh->fullTopic(w)); last = RLP(msg.payload()).toInt(); + if (received.count(last)) + continue; + received.insert(last); cnote << "New message from:" << msg.from().abridged() << RLP(msg.payload()).toInt(); result += last; } From 4046debbc955d3bee697c50483684803215bbc8e Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 1 Feb 2015 22:51:14 -0800 Subject: [PATCH 16/55] Better HTML template in Mix. Use happened in JS. Debugging QML enabled. --- libjsqrc/ethereumjs/dist/ethereum.js | 3 +++ libjsqrc/ethereumjs/dist/ethereum.js.map | 4 ++-- libjsqrc/ethereumjs/dist/ethereum.min.js | 2 +- libjsqrc/ethereumjs/lib/filter.js | 3 +++ mix/CMakeLists.txt | 2 ++ mix/qml/js/ProjectModel.js | 4 ++-- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libjsqrc/ethereumjs/dist/ethereum.js b/libjsqrc/ethereumjs/dist/ethereum.js index 817b55852..0f30280f9 100644 --- a/libjsqrc/ethereumjs/dist/ethereum.js +++ b/libjsqrc/ethereumjs/dist/ethereum.js @@ -590,6 +590,9 @@ var Filter = function(options, impl) { Filter.prototype.arrived = function(callback) { this.changed(callback); }; +Filter.prototype.happened = function(callback) { + this.changed(callback); +}; /// gets called when there is new eth/shh message Filter.prototype.changed = function(callback) { diff --git a/libjsqrc/ethereumjs/dist/ethereum.js.map b/libjsqrc/ethereumjs/dist/ethereum.js.map index 81a7e3747..ae0d47200 100644 --- a/libjsqrc/ethereumjs/dist/ethereum.js.map +++ b/libjsqrc/ethereumjs/dist/ethereum.js.map @@ -17,7 +17,7 @@ "index.js" ], "names": [], - "mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/FA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1JA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClTA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA", + "mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1JA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClTA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA", "file": "generated.js", "sourceRoot": "", "sourcesContent": [ @@ -26,7 +26,7 @@ "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file const.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\n/// required to define ETH_BIGNUMBER_ROUNDING_MODE\nif (\"build\" !== 'build') {/*\n var BigNumber = require('bignumber.js'); // jshint ignore:line\n*/}\n\nmodule.exports = {\n ETH_PADDING: 32,\n ETH_SIGNATURE_LENGTH: 4,\n ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }\n};\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file contract.js\n * @authors:\n * Marek Kotewicz \n * @date 2014\n */\n\nvar web3 = require('./web3'); \nvar abi = require('./abi');\nvar utils = require('./utils');\nvar eventImpl = require('./event');\n\nvar exportNatspecGlobals = function (vars) {\n // it's used byt natspec.js\n // TODO: figure out better way to solve this\n web3._currentContractAbi = vars.abi;\n web3._currentContractAddress = vars.address;\n web3._currentContractMethodName = vars.method;\n web3._currentContractMethodParams = vars.params;\n};\n\nvar addFunctionRelatedPropertiesToContract = function (contract) {\n \n contract.call = function (options) {\n contract._isTransact = false;\n contract._options = options;\n return contract;\n };\n\n contract.transact = function (options) {\n contract._isTransact = true;\n contract._options = options;\n return contract;\n };\n\n contract._options = {};\n ['gas', 'gasPrice', 'value', 'from'].forEach(function(p) {\n contract[p] = function (v) {\n contract._options[p] = v;\n return contract;\n };\n });\n\n};\n\nvar addFunctionsToContract = function (contract, desc, address) {\n var inputParser = abi.inputParser(desc);\n var outputParser = abi.outputParser(desc);\n\n // create contract functions\n utils.filterFunctions(desc).forEach(function (method) {\n\n var displayName = utils.extractDisplayName(method.name);\n var typeName = utils.extractTypeName(method.name);\n\n var impl = function () {\n var params = Array.prototype.slice.call(arguments);\n var signature = abi.signatureFromAscii(method.name);\n var parsed = inputParser[displayName][typeName].apply(null, params);\n\n var options = contract._options || {};\n options.to = address;\n options.data = signature + parsed;\n \n var isTransact = contract._isTransact === true || (contract._isTransact !== false && !method.constant);\n var collapse = options.collapse !== false;\n \n // reset\n contract._options = {};\n contract._isTransact = null;\n\n if (isTransact) {\n \n exportNatspecGlobals({\n abi: desc,\n address: address,\n method: method.name,\n params: params\n });\n\n // transactions do not have any output, cause we do not know, when they will be processed\n web3.eth.transact(options);\n return;\n }\n \n var output = web3.eth.call(options);\n var ret = outputParser[displayName][typeName](output);\n if (collapse)\n {\n if (ret.length === 1)\n ret = ret[0];\n else if (ret.length === 0)\n ret = null;\n }\n return ret;\n };\n\n if (contract[displayName] === undefined) {\n contract[displayName] = impl;\n }\n\n contract[displayName][typeName] = impl;\n });\n};\n\nvar addEventRelatedPropertiesToContract = function (contract, desc, address) {\n contract.address = address;\n \n Object.defineProperty(contract, 'topic', {\n get: function() {\n return utils.filterEvents(desc).map(function (e) {\n return abi.eventSignatureFromAscii(e.name);\n });\n }\n });\n\n};\n\nvar addEventsToContract = function (contract, desc, address) {\n // create contract events\n utils.filterEvents(desc).forEach(function (e) {\n\n var impl = function () {\n var params = Array.prototype.slice.call(arguments);\n var signature = abi.eventSignatureFromAscii(e.name);\n var event = eventImpl(address, signature, e);\n var o = event.apply(null, params);\n return web3.eth.watch(o); \n };\n \n // this property should be used by eth.filter to check if object is an event\n impl._isEvent = true;\n\n var displayName = utils.extractDisplayName(e.name);\n var typeName = utils.extractTypeName(e.name);\n\n if (contract[displayName] === undefined) {\n contract[displayName] = impl;\n }\n\n contract[displayName][typeName] = impl;\n\n });\n};\n\n\n/**\n * This method should be called when we want to call / transact some solidity method from javascript\n * it returns an object which has same methods available as solidity contract description\n * usage example: \n *\n * var abi = [{\n * name: 'myMethod',\n * inputs: [{ name: 'a', type: 'string' }],\n * outputs: [{name: 'd', type: 'string' }]\n * }]; // contract abi\n *\n * var myContract = web3.eth.contract('0x0123123121', abi); // creation of contract object\n *\n * myContract.myMethod('this is test string param for call'); // myMethod call (implicit, default)\n * myContract.call().myMethod('this is test string param for call'); // myMethod call (explicit)\n * myContract.transact().myMethod('this is test string param for transact'); // myMethod transact\n *\n * @param address - address of the contract, which should be called\n * @param desc - abi json description of the contract, which is being created\n * @returns contract object\n */\n\nvar contract = function (address, desc) {\n\n // workaround for invalid assumption that method.name is the full anonymous prototype of the method.\n // it's not. it's just the name. the rest of the code assumes it's actually the anonymous\n // prototype, so we make it so as a workaround.\n // TODO: we may not want to modify input params, maybe use copy instead?\n desc.forEach(function (method) {\n if (method.name.indexOf('(') === -1) {\n var displayName = method.name;\n var typeName = method.inputs.map(function(i){return i.type; }).join();\n method.name = displayName + '(' + typeName + ')';\n }\n });\n\n var result = {};\n addFunctionRelatedPropertiesToContract(result);\n addFunctionsToContract(result, desc, address);\n addEventRelatedPropertiesToContract(result, desc, address);\n addEventsToContract(result, desc, address);\n\n return result;\n};\n\nmodule.exports = contract;\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file event.js\n * @authors:\n * Marek Kotewicz \n * @date 2014\n */\n\nvar abi = require('./abi');\nvar utils = require('./utils');\n\nvar inputWithName = function (inputs, name) {\n var index = utils.findIndex(inputs, function (input) {\n return input.name === name;\n });\n \n if (index === -1) {\n console.error('indexed param with name ' + name + ' not found');\n return undefined;\n }\n return inputs[index];\n};\n\nvar indexedParamsToTopics = function (event, indexed) {\n // sort keys?\n return Object.keys(indexed).map(function (key) {\n var inputs = [inputWithName(event.inputs, key)];\n\n var value = indexed[key];\n if (value instanceof Array) {\n return value.map(function (v) {\n return abi.formatInput(inputs, [v]);\n }); \n }\n return abi.formatInput(inputs, [value]);\n });\n};\n\nvar implementationOfEvent = function (address, signature, event) {\n \n // valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch'\n return function (indexed, options) {\n var o = options || {};\n o.address = address;\n o.topic = [];\n o.topic.push(signature);\n if (indexed) {\n o.topic = o.topic.concat(indexedParamsToTopics(event, indexed));\n }\n return o;\n };\n};\n\nmodule.exports = implementationOfEvent;\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file filter.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nvar web3 = require('./web3'); // jshint ignore:line\n\n/// should be used when we want to watch something\n/// it's using inner polling mechanism and is notified about changes\n/// TODO: change 'options' name cause it may be not the best matching one, since we have events\nvar Filter = function(options, impl) {\n\n if (typeof options !== \"string\") {\n\n // topics property is deprecated, warn about it!\n if (options.topics) {\n console.warn('\"topics\" is deprecated, use \"topic\" instead');\n }\n\n // evaluate lazy properties\n options = {\n to: options.to,\n topic: options.topic,\n earliest: options.earliest,\n latest: options.latest,\n max: options.max,\n skip: options.skip,\n address: options.address\n };\n\n }\n \n this.impl = impl;\n this.callbacks = [];\n\n this.id = impl.newFilter(options);\n web3.provider.startPolling({call: impl.changed, args: [this.id]}, this.id, this.trigger.bind(this));\n};\n\n/// alias for changed*\nFilter.prototype.arrived = function(callback) {\n this.changed(callback);\n};\n\n/// gets called when there is new eth/shh message\nFilter.prototype.changed = function(callback) {\n this.callbacks.push(callback);\n};\n\n/// trigger calling new message from people\nFilter.prototype.trigger = function(messages) {\n for (var i = 0; i < this.callbacks.length; i++) {\n for (var j = 0; j < messages.length; j++) {\n this.callbacks[i].call(this, messages[j]);\n }\n }\n};\n\n/// should be called to uninstall current filter\nFilter.prototype.uninstall = function() {\n this.impl.uninstallFilter(this.id);\n web3.provider.stopPolling(this.id);\n};\n\n/// should be called to manually trigger getting latest messages from the client\nFilter.prototype.messages = function() {\n return this.impl.getMessages(this.id);\n};\n\n/// alias for messages\nFilter.prototype.logs = function () {\n return this.messages();\n};\n\nmodule.exports = Filter;\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file filter.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nvar web3 = require('./web3'); // jshint ignore:line\n\n/// should be used when we want to watch something\n/// it's using inner polling mechanism and is notified about changes\n/// TODO: change 'options' name cause it may be not the best matching one, since we have events\nvar Filter = function(options, impl) {\n\n if (typeof options !== \"string\") {\n\n // topics property is deprecated, warn about it!\n if (options.topics) {\n console.warn('\"topics\" is deprecated, use \"topic\" instead');\n }\n\n // evaluate lazy properties\n options = {\n to: options.to,\n topic: options.topic,\n earliest: options.earliest,\n latest: options.latest,\n max: options.max,\n skip: options.skip,\n address: options.address\n };\n\n }\n \n this.impl = impl;\n this.callbacks = [];\n\n this.id = impl.newFilter(options);\n web3.provider.startPolling({call: impl.changed, args: [this.id]}, this.id, this.trigger.bind(this));\n};\n\n/// alias for changed*\nFilter.prototype.arrived = function(callback) {\n this.changed(callback);\n};\nFilter.prototype.happened = function(callback) {\n this.changed(callback);\n};\n\n/// gets called when there is new eth/shh message\nFilter.prototype.changed = function(callback) {\n this.callbacks.push(callback);\n};\n\n/// trigger calling new message from people\nFilter.prototype.trigger = function(messages) {\n for (var i = 0; i < this.callbacks.length; i++) {\n for (var j = 0; j < messages.length; j++) {\n this.callbacks[i].call(this, messages[j]);\n }\n }\n};\n\n/// should be called to uninstall current filter\nFilter.prototype.uninstall = function() {\n this.impl.uninstallFilter(this.id);\n web3.provider.stopPolling(this.id);\n};\n\n/// should be called to manually trigger getting latest messages from the client\nFilter.prototype.messages = function() {\n return this.impl.getMessages(this.id);\n};\n\n/// alias for messages\nFilter.prototype.logs = function () {\n return this.messages();\n};\n\nmodule.exports = Filter;\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file formatters.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\nif (\"build\" !== 'build') {/*\n var BigNumber = require('bignumber.js'); // jshint ignore:line\n*/}\n\nvar utils = require('./utils');\nvar c = require('./const');\n\n/// @param string string to be padded\n/// @param number of characters that result string should have\n/// @param sign, by default 0\n/// @returns right aligned string\nvar padLeft = function (string, chars, sign) {\n return new Array(chars - string.length + 1).join(sign ? sign : \"0\") + string;\n};\n\n/// Formats input value to byte representation of int\n/// If value is negative, return it's two's complement\n/// If the value is floating point, round it down\n/// @returns right-aligned byte representation of int\nvar formatInputInt = function (value) {\n var padding = c.ETH_PADDING * 2;\n if (value instanceof BigNumber || typeof value === 'number') {\n if (typeof value === 'number')\n value = new BigNumber(value);\n BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE);\n value = value.round();\n\n if (value.lessThan(0)) \n value = new BigNumber(\"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\", 16).plus(value).plus(1);\n value = value.toString(16);\n }\n else if (value.indexOf('0x') === 0)\n value = value.substr(2);\n else if (typeof value === 'string')\n value = formatInputInt(new BigNumber(value));\n else\n value = (+value).toString(16);\n return padLeft(value, padding);\n};\n\n/// Formats input value to byte representation of string\n/// @returns left-algined byte representation of string\nvar formatInputString = function (value) {\n return utils.fromAscii(value, c.ETH_PADDING).substr(2);\n};\n\n/// Formats input value to byte representation of bool\n/// @returns right-aligned byte representation bool\nvar formatInputBool = function (value) {\n return '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0');\n};\n\n/// Formats input value to byte representation of real\n/// Values are multiplied by 2^m and encoded as integers\n/// @returns byte representation of real\nvar formatInputReal = function (value) {\n return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); \n};\n\n\n/// Check if input value is negative\n/// @param value is hex format\n/// @returns true if it is negative, otherwise false\nvar signedIsNegative = function (value) {\n return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1';\n};\n\n/// Formats input right-aligned input bytes to int\n/// @returns right-aligned input bytes formatted to int\nvar formatOutputInt = function (value) {\n value = value || \"0\";\n // check if it's negative number\n // it it is, return two's complement\n if (signedIsNegative(value)) {\n return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1);\n }\n return new BigNumber(value, 16);\n};\n\n/// Formats big right-aligned input bytes to uint\n/// @returns right-aligned input bytes formatted to uint\nvar formatOutputUInt = function (value) {\n value = value || \"0\";\n return new BigNumber(value, 16);\n};\n\n/// @returns input bytes formatted to real\nvar formatOutputReal = function (value) {\n return formatOutputInt(value).dividedBy(new BigNumber(2).pow(128)); \n};\n\n/// @returns input bytes formatted to ureal\nvar formatOutputUReal = function (value) {\n return formatOutputUInt(value).dividedBy(new BigNumber(2).pow(128)); \n};\n\n/// @returns right-aligned input bytes formatted to hex\nvar formatOutputHash = function (value) {\n return \"0x\" + value;\n};\n\n/// @returns right-aligned input bytes formatted to bool\nvar formatOutputBool = function (value) {\n return value === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false;\n};\n\n/// @returns left-aligned input bytes formatted to ascii string\nvar formatOutputString = function (value) {\n return utils.toAscii(value);\n};\n\n/// @returns right-aligned input bytes formatted to address\nvar formatOutputAddress = function (value) {\n return \"0x\" + value.slice(value.length - 40, value.length);\n};\n\n\nmodule.exports = {\n formatInputInt: formatInputInt,\n formatInputString: formatInputString,\n formatInputBool: formatInputBool,\n formatInputReal: formatInputReal,\n formatOutputInt: formatOutputInt,\n formatOutputUInt: formatOutputUInt,\n formatOutputReal: formatOutputReal,\n formatOutputUReal: formatOutputUReal,\n formatOutputHash: formatOutputHash,\n formatOutputBool: formatOutputBool,\n formatOutputString: formatOutputString,\n formatOutputAddress: formatOutputAddress\n};\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file httpsync.js\n * @authors:\n * Marek Kotewicz \n * Marian Oancea \n * @date 2014\n */\n\nif (\"build\" !== 'build') {/*\n var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line\n*/}\n\nvar HttpSyncProvider = function (host) {\n this.handlers = [];\n this.host = host || 'http://localhost:8080';\n};\n\n/// Transforms inner message to proper jsonrpc object\n/// @param inner message object\n/// @returns jsonrpc object\nfunction formatJsonRpcObject(object) {\n return {\n jsonrpc: '2.0',\n method: object.call,\n params: object.args,\n id: object._id\n };\n}\n\n/// Transforms jsonrpc object to inner message\n/// @param incoming jsonrpc message \n/// @returns inner message object\nfunction formatJsonRpcMessage(message) {\n var object = JSON.parse(message);\n\n return {\n _id: object.id,\n data: object.result,\n error: object.error\n };\n}\n\nHttpSyncProvider.prototype.send = function (payload) {\n var data = formatJsonRpcObject(payload);\n \n var request = new XMLHttpRequest();\n request.open('POST', this.host, false);\n request.send(JSON.stringify(data));\n \n // check request.status\n return request.responseText;\n};\n\nmodule.exports = HttpSyncProvider;\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file providermanager.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nvar web3 = require('./web3'); // jshint ignore:line\n\n/**\n * Provider manager object prototype\n * It's responsible for passing messages to providers\n * If no provider is set it's responsible for queuing requests\n * It's also responsible for polling the ethereum node for incoming messages\n * Default poll timeout is 12 seconds\n * If we are running ethereum.js inside ethereum browser, there are backend based tools responsible for polling,\n * and provider manager polling mechanism is not used\n */\nvar ProviderManager = function() {\n this.polls = [];\n this.provider = undefined;\n this.id = 1;\n\n var self = this;\n var poll = function () {\n if (self.provider) {\n self.polls.forEach(function (data) {\n data.data._id = self.id;\n self.id++;\n var result = self.provider.send(data.data);\n \n result = JSON.parse(result);\n \n // dont call the callback if result is not an array, or empty one\n if (result.error || !(result.result instanceof Array) || result.result.length === 0) {\n return;\n }\n\n data.callback(result.result);\n });\n }\n setTimeout(poll, 1000);\n };\n poll();\n};\n\n/// sends outgoing requests\nProviderManager.prototype.send = function(data) {\n\n data.args = data.args || [];\n data._id = this.id++;\n\n if (this.provider === undefined) {\n console.error('provider is not set');\n return null; \n }\n\n //TODO: handle error here? \n var result = this.provider.send(data);\n result = JSON.parse(result);\n\n if (result.error) {\n console.log(result.error);\n return null;\n }\n\n return result.result;\n};\n\n/// setups provider, which will be used for sending messages\nProviderManager.prototype.set = function(provider) {\n this.provider = provider;\n};\n\n/// this method is only used, when we do not have native qt bindings and have to do polling on our own\n/// should be callled, on start watching for eth/shh changes\nProviderManager.prototype.startPolling = function (data, pollId, callback) {\n this.polls.push({data: data, id: pollId, callback: callback});\n};\n\n/// should be called to stop polling for certain watch changes\nProviderManager.prototype.stopPolling = function (pollId) {\n for (var i = this.polls.length; i--;) {\n var poll = this.polls[i];\n if (poll.id === pollId) {\n this.polls.splice(i, 1);\n }\n }\n};\n\nmodule.exports = ProviderManager;\n\n", diff --git a/libjsqrc/ethereumjs/dist/ethereum.min.js b/libjsqrc/ethereumjs/dist/ethereum.min.js index cc9b205d1..a745a5ed3 100644 --- a/libjsqrc/ethereumjs/dist/ethereum.min.js +++ b/libjsqrc/ethereumjs/dist/ethereum.min.js @@ -1 +1 @@ -require=function t(e,n,r){function i(a,u){if(!n[a]){if(!e[a]){var f="function"==typeof require&&require;if(!u&&f)return f(a,!0);if(o)return o(a,!0);var s=new Error("Cannot find module '"+a+"'");throw s.code="MODULE_NOT_FOUND",s}var c=n[a]={exports:{}};e[a][0].call(c.exports,function(t){var n=e[a][1][t];return i(n?n:t)},c,c.exports,t,e,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;av;v++)g.push(h(e.slice(0,r))),e=e.slice(r);n.push(g)}else i.prefixedType("string")(t[s].type)?(c=c.slice(r),n.push(h(e.slice(0,r))),e=e.slice(r)):(n.push(h(e.slice(0,r))),e=e.slice(r))}),n},d=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(){var e=Array.prototype.slice.call(arguments);return l(t.inputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},g=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(e){return h(t.outputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},v=function(t){return n.sha3(n.fromAscii(t)).slice(0,2+2*o.ETH_SIGNATURE_LENGTH)},y=function(t){return n.sha3(n.fromAscii(t))};e.exports={inputParser:d,outputParser:g,formatInput:l,formatOutput:h,signatureFromAscii:v,eventSignatureFromAscii:y}},{"./const":2,"./formatters":6,"./types":10,"./utils":11,"./web3":12}],2:[function(t,e){e.exports={ETH_PADDING:32,ETH_SIGNATURE_LENGTH:4,ETH_BIGNUMBER_ROUNDING_MODE:{ROUNDING_MODE:BigNumber.ROUND_DOWN}}},{}],3:[function(t,e){var n=t("./web3"),r=t("./abi"),i=t("./utils"),o=t("./event"),a=function(t){n._currentContractAbi=t.abi,n._currentContractAddress=t.address,n._currentContractMethodName=t.method,n._currentContractMethodParams=t.params},u=function(t){t.call=function(e){return t._isTransact=!1,t._options=e,t},t.transact=function(e){return t._isTransact=!0,t._options=e,t},t._options={},["gas","gasPrice","value","from"].forEach(function(e){t[e]=function(n){return t._options[e]=n,t}})},f=function(t,e,o){var u=r.inputParser(e),f=r.outputParser(e);i.filterFunctions(e).forEach(function(s){var c=i.extractDisplayName(s.name),l=i.extractTypeName(s.name),p=function(){var i=Array.prototype.slice.call(arguments),p=r.signatureFromAscii(s.name),m=u[c][l].apply(null,i),h=t._options||{};h.to=o,h.data=p+m;var d=t._isTransact===!0||t._isTransact!==!1&&!s.constant,g=h.collapse!==!1;if(t._options={},t._isTransact=null,d)return a({abi:e,address:o,method:s.name,params:i}),void n.eth.transact(h);var v=n.eth.call(h),y=f[c][l](v);return g&&(1===y.length?y=y[0]:0===y.length&&(y=null)),y};void 0===t[c]&&(t[c]=p),t[c][l]=p})},s=function(t,e,n){t.address=n,Object.defineProperty(t,"topic",{get:function(){return i.filterEvents(e).map(function(t){return r.eventSignatureFromAscii(t.name)})}})},c=function(t,e,a){i.filterEvents(e).forEach(function(e){var u=function(){var t=Array.prototype.slice.call(arguments),i=r.eventSignatureFromAscii(e.name),u=o(a,i,e),f=u.apply(null,t);return n.eth.watch(f)};u._isEvent=!0;var f=i.extractDisplayName(e.name),s=i.extractTypeName(e.name);void 0===t[f]&&(t[f]=u),t[f][s]=u})},l=function(t,e){e.forEach(function(t){if(-1===t.name.indexOf("(")){var e=t.name,n=t.inputs.map(function(t){return t.type}).join();t.name=e+"("+n+")"}});var n={};return u(n),f(n,e,t),s(n,e,t),c(n,e,t),n};e.exports=l},{"./abi":1,"./event":4,"./utils":11,"./web3":12}],4:[function(t,e){var n=t("./abi"),r=t("./utils"),i=function(t,e){var n=r.findIndex(t,function(t){return t.name===e});return-1===n?void console.error("indexed param with name "+e+" not found"):t[n]},o=function(t,e){return Object.keys(e).map(function(r){var o=[i(t.inputs,r)],a=e[r];return a instanceof Array?a.map(function(t){return n.formatInput(o,[t])}):n.formatInput(o,[a])})},a=function(t,e,n){return function(r,i){var a=i||{};return a.address=t,a.topic=[],a.topic.push(e),r&&(a.topic=a.topic.concat(o(n,r))),a}};e.exports=a},{"./abi":1,"./utils":11}],5:[function(t,e){var n=t("./web3"),r=function(t,e){"string"!=typeof t&&(t.topics&&console.warn('"topics" is deprecated, use "topic" instead'),t={to:t.to,topic:t.topic,earliest:t.earliest,latest:t.latest,max:t.max,skip:t.skip,address:t.address}),this.impl=e,this.callbacks=[],this.id=e.newFilter(t),n.provider.startPolling({call:e.changed,args:[this.id]},this.id,this.trigger.bind(this))};r.prototype.arrived=function(t){this.changed(t)},r.prototype.changed=function(t){this.callbacks.push(t)},r.prototype.trigger=function(t){for(var e=0;en;n+=2){var i=parseInt(t.substr(n,2),16);if(0===i)break;e+=String.fromCharCode(i)}return e},i=function(t){for(var e="",n=0;n2?t.substring(2):"0",new BigNumber(t,16).toString(10)},fromDecimal:function(t){return"0x"+new BigNumber(t).toString(16)},toEth:function(t){for(var e="string"==typeof t?0===t.indexOf("0x")?parseInt(t.substr(2),16):parseInt(t):t,n=0,i=r;e>3e3&&nv;v++)g.push(m(e.slice(0,r))),e=e.slice(r);n.push(g)}else i.prefixedType("string")(t[s].type)?(c=c.slice(r),n.push(m(e.slice(0,r))),e=e.slice(r)):(n.push(m(e.slice(0,r))),e=e.slice(r))}),n},d=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(){var e=Array.prototype.slice.call(arguments);return l(t.inputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},g=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(e){return m(t.outputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},v=function(t){return n.sha3(n.fromAscii(t)).slice(0,2+2*o.ETH_SIGNATURE_LENGTH)},y=function(t){return n.sha3(n.fromAscii(t))};e.exports={inputParser:d,outputParser:g,formatInput:l,formatOutput:m,signatureFromAscii:v,eventSignatureFromAscii:y}},{"./const":2,"./formatters":6,"./types":10,"./utils":11,"./web3":12}],2:[function(t,e){e.exports={ETH_PADDING:32,ETH_SIGNATURE_LENGTH:4,ETH_BIGNUMBER_ROUNDING_MODE:{ROUNDING_MODE:BigNumber.ROUND_DOWN}}},{}],3:[function(t,e){var n=t("./web3"),r=t("./abi"),i=t("./utils"),o=t("./event"),a=function(t){n._currentContractAbi=t.abi,n._currentContractAddress=t.address,n._currentContractMethodName=t.method,n._currentContractMethodParams=t.params},u=function(t){t.call=function(e){return t._isTransact=!1,t._options=e,t},t.transact=function(e){return t._isTransact=!0,t._options=e,t},t._options={},["gas","gasPrice","value","from"].forEach(function(e){t[e]=function(n){return t._options[e]=n,t}})},f=function(t,e,o){var u=r.inputParser(e),f=r.outputParser(e);i.filterFunctions(e).forEach(function(s){var c=i.extractDisplayName(s.name),l=i.extractTypeName(s.name),p=function(){var i=Array.prototype.slice.call(arguments),p=r.signatureFromAscii(s.name),h=u[c][l].apply(null,i),m=t._options||{};m.to=o,m.data=p+h;var d=t._isTransact===!0||t._isTransact!==!1&&!s.constant,g=m.collapse!==!1;if(t._options={},t._isTransact=null,d)return a({abi:e,address:o,method:s.name,params:i}),void n.eth.transact(m);var v=n.eth.call(m),y=f[c][l](v);return g&&(1===y.length?y=y[0]:0===y.length&&(y=null)),y};void 0===t[c]&&(t[c]=p),t[c][l]=p})},s=function(t,e,n){t.address=n,Object.defineProperty(t,"topic",{get:function(){return i.filterEvents(e).map(function(t){return r.eventSignatureFromAscii(t.name)})}})},c=function(t,e,a){i.filterEvents(e).forEach(function(e){var u=function(){var t=Array.prototype.slice.call(arguments),i=r.eventSignatureFromAscii(e.name),u=o(a,i,e),f=u.apply(null,t);return n.eth.watch(f)};u._isEvent=!0;var f=i.extractDisplayName(e.name),s=i.extractTypeName(e.name);void 0===t[f]&&(t[f]=u),t[f][s]=u})},l=function(t,e){e.forEach(function(t){if(-1===t.name.indexOf("(")){var e=t.name,n=t.inputs.map(function(t){return t.type}).join();t.name=e+"("+n+")"}});var n={};return u(n),f(n,e,t),s(n,e,t),c(n,e,t),n};e.exports=l},{"./abi":1,"./event":4,"./utils":11,"./web3":12}],4:[function(t,e){var n=t("./abi"),r=t("./utils"),i=function(t,e){var n=r.findIndex(t,function(t){return t.name===e});return-1===n?void console.error("indexed param with name "+e+" not found"):t[n]},o=function(t,e){return Object.keys(e).map(function(r){var o=[i(t.inputs,r)],a=e[r];return a instanceof Array?a.map(function(t){return n.formatInput(o,[t])}):n.formatInput(o,[a])})},a=function(t,e,n){return function(r,i){var a=i||{};return a.address=t,a.topic=[],a.topic.push(e),r&&(a.topic=a.topic.concat(o(n,r))),a}};e.exports=a},{"./abi":1,"./utils":11}],5:[function(t,e){var n=t("./web3"),r=function(t,e){"string"!=typeof t&&(t.topics&&console.warn('"topics" is deprecated, use "topic" instead'),t={to:t.to,topic:t.topic,earliest:t.earliest,latest:t.latest,max:t.max,skip:t.skip,address:t.address}),this.impl=e,this.callbacks=[],this.id=e.newFilter(t),n.provider.startPolling({call:e.changed,args:[this.id]},this.id,this.trigger.bind(this))};r.prototype.arrived=function(t){this.changed(t)},r.prototype.happened=function(t){this.changed(t)},r.prototype.changed=function(t){this.callbacks.push(t)},r.prototype.trigger=function(t){for(var e=0;en;n+=2){var i=parseInt(t.substr(n,2),16);if(0===i)break;e+=String.fromCharCode(i)}return e},i=function(t){for(var e="",n=0;n2?t.substring(2):"0",new BigNumber(t,16).toString(10)},fromDecimal:function(t){return"0x"+new BigNumber(t).toString(16)},toEth:function(t){for(var e="string"==typeof t?0===t.indexOf("0x")?parseInt(t.substr(2),16):parseInt(t):t,n=0,i=r;e>3e3&&n"); - fileIo.writeFile(dirPath + contractsFile, "contract MyContract {\n}\n"); + fileIo.writeFile(dirPath + indexFile, "\n\n\n\n\n\n\n"); + fileIo.writeFile(dirPath + contractsFile, "contract Contract {\n}\n"); newProject(projectData); var json = JSON.stringify(projectData, null, "\t"); fileIo.writeFile(projectFile, json); From df87d732f0536c52a2da0a107afb4849d5f1ee85 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 1 Feb 2015 22:52:11 -0800 Subject: [PATCH 17/55] Less verbose. --- mix/Web3Server.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/mix/Web3Server.cpp b/mix/Web3Server.cpp index ead2c792f..edac252fe 100644 --- a/mix/Web3Server.cpp +++ b/mix/Web3Server.cpp @@ -57,8 +57,6 @@ void Web3Server::put(std::string const& _name, std::string const& _key, std::str Json::Value Web3Server::eth_changed(int const& _id) { - cnote << "eth_changed(" << _id << ") ->" << client()->peekWatch(_id).size(); - return WebThreeStubServerBase::eth_changed(_id); } From 1592bb2651d3eb43e656177cc895720f3c69b294 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 2 Feb 2015 10:06:34 +0100 Subject: [PATCH 18/55] Coding standards. --- libdevcore/CommonJS.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libdevcore/CommonJS.cpp b/libdevcore/CommonJS.cpp index 8cdb27954..9c20bdd53 100644 --- a/libdevcore/CommonJS.cpp +++ b/libdevcore/CommonJS.cpp @@ -63,13 +63,13 @@ bytes unpadLeft(bytes _b) int i = 0; if (_b.size() == 0) return _b; + while (true) - { if (_b.at(i) == byte(0)) i++; else break; - } + if (i != 0) _b.erase(_b.begin(), _b.begin() + i); return _b; From 1cd85e9cc9a7fb004e3caab14e59a51425a8278e Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 2 Feb 2015 12:15:42 +0100 Subject: [PATCH 19/55] ux improvements --- mix/main.cpp | 2 + mix/qml/MainContent.qml | 215 +++++++++++++++++-------------------- mix/qml/ProjectList.qml | 2 +- mix/qml/ProjectModel.qml | 3 +- mix/qml/StateListModel.qml | 2 +- mix/qml/WebPreview.qml | 2 +- mix/qml/html/codeeditor.js | 1 + mix/qml/js/ProjectModel.js | 3 +- mix/qml/main.qml | 39 ++++--- 9 files changed, 133 insertions(+), 136 deletions(-) diff --git a/mix/main.cpp b/mix/main.cpp index f7213f0fc..b24b8a549 100644 --- a/mix/main.cpp +++ b/mix/main.cpp @@ -35,6 +35,8 @@ int main(int _argc, char* _argv[]) //work around ubuntu appmenu-qt5 bug //https://bugs.launchpad.net/ubuntu/+source/appmenu-qt5/+bug/1323853 putenv((char*)"QT_QPA_PLATFORMTHEME="); + putenv((char*)"QSG_RENDER_LOOP=threaded"); + putenv((char*)"QT_IM_MODULE="); #endif try { diff --git a/mix/qml/MainContent.qml b/mix/qml/MainContent.qml index 1ed1c11d2..247de143f 100644 --- a/mix/qml/MainContent.qml +++ b/mix/qml/MainContent.qml @@ -23,14 +23,20 @@ Rectangle { property alias rightViewVisible : rightView.visible property alias webViewVisible : webPreview.visible + property alias projectViewVisible : projectList.visible + property alias runOnProjectLoad : mainSettings.runOnProjectLoad property bool webViewHorizontal : codeWebSplitter.orientation === Qt.Vertical //vertical splitter positions elements vertically, splits screen horizontally - - onWidthChanged: - { - if (rightView.visible) - contentView.width = parent.width - projectList.width - rightView.width; - else - contentView.width = parent.width - projectList.width; + property bool firstCompile: true + + Connections { + target: codeModel + onCompilationComplete: { + if (firstCompile) { + firstCompile = false; + if (codeModel.code.successful && runOnProjectLoad) + startQuickDebugging(); + } + } } function startQuickDebugging() @@ -40,15 +46,11 @@ Rectangle { } function toggleRightView() { - if (!rightView.visible) - rightView.show(); - else - rightView.hide(); + rightView.visible = !rightView.visible; } function ensureRightView() { - if (!rightView.visible) - rightView.show(); + rightView.visible = true; } function rightViewIsVisible() @@ -65,6 +67,10 @@ Rectangle { webPreview.visible = !webPreview.visible; } + function toggleProjectView() { + projectList.visible = !projectList.visible; + } + function toggleWebPreviewOrientation() { codeWebSplitter.orientation = (codeWebSplitter.orientation === Qt.Vertical ? Qt.Horizontal : Qt.Vertical); } @@ -75,19 +81,18 @@ Rectangle { } Settings { - id: mainLayoutSettings + id: mainSettings property alias codeWebOrientation: codeWebSplitter.orientation property alias webWidth: webPreview.width property alias webHeight: webPreview.height + property alias showProjectView: projectList.visible + property bool runOnProjectLoad: false } - GridLayout + ColumnLayout { anchors.fill: parent - rows: 2 - flow: GridLayout.TopToBottom - columnSpacing: 0 - rowSpacing: 0 + spacing: 0 Rectangle { width: parent.width height: 50 @@ -128,116 +133,90 @@ Rectangle { property alias rightViewWidth: rightView.width } - ProjectList { - anchors.left: parent.left - id: projectList - width: 200 - height: parent.height - Layout.minimumWidth: 200 - } - - Splitter + SplitView { - id: resizeLeft - itemToStick: projectList - itemMinimumWidth: projectList.Layout.minimumWidth - direction: "right" - brother: contentView - color: "#a2a2a2" - } - - Rectangle { - anchors.left: projectList.right - id: contentView - width: parent.width - projectList.width - height: parent.height - SplitView { - handleDelegate: Rectangle { - width: 4 - height: 4 - color: "#cccccc" - } - id: codeWebSplitter - anchors.fill: parent - orientation: Qt.Vertical - CodeEditorView { - height: parent.height * 0.6 - anchors.top: parent.top - Layout.fillWidth: true - Layout.fillHeight: true - } - WebPreview { - id: webPreview - height: parent.height * 0.4 - Layout.fillWidth: codeWebSplitter.orientation === Qt.Vertical - Layout.fillHeight: codeWebSplitter.orientation === Qt.Horizontal - Layout.minimumHeight: 200 - Layout.minimumWidth: 200 - } + anchors.fill: parent + handleDelegate: Rectangle { + width: 4 + height: 4 + color: "#cccccc" } - } - - Splitter - { - id: resizeRight - visible: false; - itemToStick: rightView - itemMinimumWidth: rightView.Layout.minimumWidth - direction: "left" - brother: contentView - color: "#a2a2a2" - } - - Rectangle { - visible: false; - id: rightView; + orientation: Qt.Horizontal - Keys.onEscapePressed: hide() - - function show() { - visible = true; - resizeRight.visible = true; - contentView.width = parent.width - projectList.width - rightView.width; + ProjectList { + id: projectList + width: 200 + Layout.minimumWidth: 180 + Layout.fillHeight: true } - - function hide() { - resizeRight.visible = false; - visible = false; - contentView.width = parent.width - projectList.width; + Rectangle { + id: contentView + Layout.fillHeight: true + Layout.fillWidth: true + SplitView { + handleDelegate: Rectangle { + width: 4 + height: 4 + color: "#cccccc" + } + id: codeWebSplitter + anchors.fill: parent + orientation: Qt.Vertical + CodeEditorView { + height: parent.height * 0.6 + anchors.top: parent.top + Layout.fillWidth: true + Layout.fillHeight: true + } + WebPreview { + id: webPreview + height: parent.height * 0.4 + Layout.fillWidth: codeWebSplitter.orientation === Qt.Vertical + Layout.fillHeight: codeWebSplitter.orientation === Qt.Horizontal + Layout.minimumHeight: 200 + Layout.minimumWidth: 200 + } + } } - height: parent.height; - width: 515 - Layout.minimumWidth: 515 - anchors.right: parent.right Rectangle { - anchors.fill: parent; - id: rightPaneView - TabView { - id: rightPaneTabs - tabsVisible: true - antialiasing: true - anchors.fill: parent - style: TabViewStyle { - frameOverlap: 1 - tabBar: - Rectangle { + visible: false; + id: rightView; + Layout.fillHeight: true + Keys.onEscapePressed: visible = false + height: parent.height; + width: 515 + Layout.minimumWidth: 515 + anchors.right: parent.right + Rectangle { + anchors.fill: parent; + id: rightPaneView + TabView { + id: rightPaneTabs + tabsVisible: true + antialiasing: true + anchors.fill: parent + style: TabViewStyle { + frameOverlap: 1 + tabBar: + Rectangle { + color: "#ededed" + id: background + } + tab: Rectangle { color: "#ededed" - id: background + implicitWidth: 80 + implicitHeight: 20 + radius: 2 + Text { + anchors.centerIn: parent + text: styleData.title + color: styleData.selected ? "#7da4cd" : "#202020" + } } - tab: Rectangle { - color: "#ededed" - implicitWidth: 80 - implicitHeight: 20 - radius: 2 - Text { - anchors.centerIn: parent - text: styleData.title - color: styleData.selected ? "#7da4cd" : "#202020" + frame: Rectangle { } } - frame: Rectangle { - } } } } diff --git a/mix/qml/ProjectList.qml b/mix/qml/ProjectList.qml index 30f945706..e4e57455d 100644 --- a/mix/qml/ProjectList.qml +++ b/mix/qml/ProjectList.qml @@ -3,7 +3,7 @@ import QtQuick.Window 2.0 import QtQuick.Layouts 1.0 import QtQuick.Controls 1.0 -Item { +Rectangle { property bool renameMode: false; ColumnLayout { anchors.fill: parent diff --git a/mix/qml/ProjectModel.qml b/mix/qml/ProjectModel.qml index 14716483c..49e63e184 100644 --- a/mix/qml/ProjectModel.qml +++ b/mix/qml/ProjectModel.qml @@ -10,7 +10,8 @@ Item { id: projectModel signal projectClosed - signal projectLoaded(var projectData) + signal projectLoading(var projectData) + signal projectLoaded() signal documentOpened(var document) signal documentRemoved(var documentId) signal documentUpdated(var documentId) //renamed diff --git a/mix/qml/StateListModel.qml b/mix/qml/StateListModel.qml index c158112e1..6f8fd3a1a 100644 --- a/mix/qml/StateListModel.qml +++ b/mix/qml/StateListModel.qml @@ -70,7 +70,7 @@ Item { stateListModel.clear(); stateList = []; } - onProjectLoaded: { + onProjectLoading: { if (!projectData.states) projectData.states = []; if (projectData.defaultStateIndex !== undefined) diff --git a/mix/qml/WebPreview.qml b/mix/qml/WebPreview.qml index bd48210ef..e95a85fde 100644 --- a/mix/qml/WebPreview.qml +++ b/mix/qml/WebPreview.qml @@ -86,7 +86,7 @@ Item { updateDocument(documentId, function(i) { pageListModel.set(i, projectModel.getDocument(documentId)) } ) } - onProjectLoaded: { + onProjectLoading: { for (var i = 0; i < target.listModel.count; i++) { var document = target.listModel.get(i); if (document.isHtml) { diff --git a/mix/qml/html/codeeditor.js b/mix/qml/html/codeeditor.js index 2cebc121e..5b3e5450f 100644 --- a/mix/qml/html/codeeditor.js +++ b/mix/qml/html/codeeditor.js @@ -31,6 +31,7 @@ getText = function() { setTextBase64 = function(text) { editor.setValue(window.atob(text)); + editor.getDoc().clearHistory(); editor.focus(); }; diff --git a/mix/qml/js/ProjectModel.js b/mix/qml/js/ProjectModel.js index ed7ebd3ce..7e1050385 100644 --- a/mix/qml/js/ProjectModel.js +++ b/mix/qml/js/ProjectModel.js @@ -73,7 +73,8 @@ function loadProject(path) { addFile(projectData.files[i]); } projectSettings.lastProjectPath = path; - projectLoaded(projectData); + projectLoading(projectData); + projectLoaded() } function addExistingFile() { diff --git a/mix/qml/main.qml b/mix/qml/main.qml index a0a4ba423..b2fc38b0a 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -36,14 +36,16 @@ ApplicationWindow { Menu { title: qsTr("Debug") MenuItem { action: debugRunAction } - MenuItem { action: debugResetStateAction } MenuItem { action: mineAction } + MenuSeparator {} + MenuItem { action: toggleRunOnLoadAction } } Menu { title: qsTr("Windows") MenuItem { action: openNextDocumentAction } MenuItem { action: openPrevDocumentAction } MenuSeparator {} + MenuItem { action: toggleProjectNavigatorAction } MenuItem { action: showHideRightPanelAction } MenuItem { action: toggleWebPreviewAction } MenuItem { action: toggleWebPreviewOrientationAction } @@ -82,47 +84,58 @@ ApplicationWindow { Action { id: mineAction - text: "Mine" + text: qsTr("Mine") shortcut: "Ctrl+M" onTriggered: clientModel.mine(); enabled: codeModel.hasContract && !clientModel.running } Action { id: debugRunAction - text: "&Run" + text: qsTr("Run") shortcut: "F5" onTriggered: mainContent.startQuickDebugging() enabled: codeModel.hasContract && !clientModel.running } - Action { - id: debugResetStateAction - text: "Reset &State" - shortcut: "F6" - onTriggered: clientModel.resetState(); - } - Action { id: toggleWebPreviewAction - text: "Show Web View" + text: qsTr("Show Web View") shortcut: "F2" checkable: true checked: mainContent.webViewVisible onTriggered: mainContent.toggleWebPreview(); } + Action { + id: toggleProjectNavigatorAction + text: qsTr("Show Project Navigator") + shortcut: "Alt+0" + checkable: true + checked: mainContent.projectViewVisible + onTriggered: mainContent.toggleProjectView(); + } + Action { id: toggleWebPreviewOrientationAction - text: "Horizontal Web View" + text: qsTr("Horizontal Web View") shortcut: "" checkable: true checked: mainContent.webViewHorizontal onTriggered: mainContent.toggleWebPreviewOrientation(); } + Action { + id: toggleRunOnLoadAction + text: qsTr("Load State on Startup") + shortcut: "" + checkable: true + checked: mainContent.runOnProjectLoad + onTriggered: mainContent.runOnProjectLoad = !mainContent.runOnProjectLoad + } + Action { id: showHideRightPanelAction - text: "Show Right View" + text: qsTr("Show Right View") shortcut: "F7" checkable: true checked: mainContent.rightViewVisible From 6441a1d93d51b2f0ae896d16daf447389cc9f164 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 2 Feb 2015 15:03:44 +0100 Subject: [PATCH 20/55] Simple mapping accessors working --- libsolidity/ExpressionCompiler.cpp | 53 ++++++++---------------------- libsolidity/ExpressionCompiler.h | 4 +-- 2 files changed, 16 insertions(+), 41 deletions(-) diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index edd04256f..722ac9895 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -823,10 +823,10 @@ unsigned ExpressionCompiler::appendArgumentCopyToMemory(TypePointers const& _typ return length; } -unsigned ExpressionCompiler::appendTypeCopyToMemory(Type const& _expectedType, TypePointer const& _type, - Location const& _location, unsigned _memoryOffset) +unsigned ExpressionCompiler::appendTypeConversionAndMoveToMemory(Type const& _expectedType, Type const& _type, + Location const& _location, unsigned _memoryOffset) { - appendTypeConversion(*_type, _expectedType, true); + appendTypeConversion(_type, _expectedType, true); unsigned const c_numBytes = CompilerUtils::getPaddedSize(_expectedType.getCalldataEncodedSize()); if (c_numBytes == 0 || c_numBytes > 32) BOOST_THROW_EXCEPTION(CompilerError() @@ -842,65 +842,40 @@ unsigned ExpressionCompiler::appendExpressionCopyToMemory(Type const& _expectedT unsigned _memoryOffset) { _expression.accept(*this); - return appendTypeCopyToMemory(_expectedType, _expression.getType(), _expression.getLocation(), _memoryOffset); + return appendTypeConversionAndMoveToMemory(_expectedType, *_expression.getType(), _expression.getLocation(), _memoryOffset); } void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& _varDecl) { - auto mappingType = dynamic_cast(_varDecl.getType().get()); + TypePointer resultType = _varDecl.getType(); + auto mappingType = dynamic_cast(resultType.get()); unsigned sizeOnStack; + if (mappingType != nullptr) { - // this copies from Compiler::visit(FunctionDefinition..) for argument reading - unsigned parameterSize = mappingType->getKeyType()->getSizeOnStack(); - m_context.adjustStackOffset(parameterSize); - m_context.addVariable(_varDecl, parameterSize); // this copies from ExpressionCompiler::visit(IndexAccess .. ) for mapping access TypePointer const& keyType = mappingType->getKeyType(); - unsigned length = appendTypeCopyToMemory(*keyType, mappingType->getValueType(), Location()); + unsigned length = appendTypeConversionAndMoveToMemory(*keyType, *keyType, Location()); solAssert(length == 32, "Mapping key has to take 32 bytes in memory (for now)."); // @todo move this once we actually use memory + m_context << m_context.getStorageLocationOfVariable(_varDecl); length += CompilerUtils(m_context).storeInMemory(length); m_context << u256(length) << u256(0) << eth::Instruction::SHA3; - m_currentLValue = LValue(m_context, LValue::STORAGE, *mappingType->getValueType()); m_currentLValue.retrieveValue(mappingType->getValueType(), Location(), true); + m_currentLValue.reset(); - unsigned const c_argumentsSize = keyType->getSizeOnStack(); - unsigned const c_returnValuesSize = mappingType->getValueType()->getSizeOnStack(); - unsigned const c_localVariablesSize = 0; - - vector stackLayout; - stackLayout.push_back(c_returnValuesSize); // target of return address - stackLayout += vector(c_argumentsSize, -1); // discard all arguments - for (unsigned i = 0; i < c_returnValuesSize; ++i) - stackLayout.push_back(i); - stackLayout += vector(c_localVariablesSize, -1); - - while (stackLayout.back() != int(stackLayout.size() - 1)) - if (stackLayout.back() < 0) - { - m_context << eth::Instruction::POP; - stackLayout.pop_back(); - } - else - { - m_context << eth::swapInstruction(stackLayout.size() - stackLayout.back() - 1); - swap(stackLayout[stackLayout.back()], stackLayout.back()); - } - //@todo assert that everything is in place now - - m_context << eth::Instruction::JUMP; + resultType = mappingType->getValueType(); } else { m_currentLValue.fromStateVariable(_varDecl, _varDecl.getType()); solAssert(m_currentLValue.isInStorage(), ""); m_currentLValue.retrieveValue(_varDecl.getType(), Location(), true); - sizeOnStack = _varDecl.getType()->getSizeOnStack(); - solAssert(sizeOnStack <= 15, "Stack too deep."); - m_context << eth::dupInstruction(sizeOnStack + 1) << eth::Instruction::JUMP; } + sizeOnStack = _varDecl.getType()->getSizeOnStack(); + solAssert(sizeOnStack <= 15, "Stack too deep."); + m_context << eth::dupInstruction(sizeOnStack + 1) << eth::Instruction::JUMP; } diff --git a/libsolidity/ExpressionCompiler.h b/libsolidity/ExpressionCompiler.h index d93ab28ed..7de577e6c 100644 --- a/libsolidity/ExpressionCompiler.h +++ b/libsolidity/ExpressionCompiler.h @@ -99,8 +99,8 @@ private: unsigned _memoryOffset = 0); /// Appends code that copies a type to memory. /// @returns the number of bytes copied to memory - unsigned appendTypeCopyToMemory(Type const& _expectedType, TypePointer const& _type, - Location const& _location, unsigned _memoryOffset = 0); + unsigned appendTypeConversionAndMoveToMemory(Type const& _expectedType, Type const& _type, + Location const& _location, unsigned _memoryOffset = 0); /// Appends code that evaluates a single expression and copies it to memory (with optional offset). /// @returns the number of bytes copied to memory unsigned appendExpressionCopyToMemory(Type const& _expectedType, Expression const& _expression, From b7070ec12f4d112edfea9f5df79cd6b33656fc16 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 2 Feb 2015 15:30:33 +0100 Subject: [PATCH 21/55] bug fixes https://www.pivotaltracker.com/n/projects/1265056/stories/87395458 --- mix/qml/StateDialog.qml | 1 + mix/qml/StateList.qml | 1 + mix/qml/StateListModel.qml | 5 +++++ 3 files changed, 7 insertions(+) diff --git a/mix/qml/StateDialog.qml b/mix/qml/StateDialog.qml index c00e3226f..37e36621e 100644 --- a/mix/qml/StateDialog.qml +++ b/mix/qml/StateDialog.qml @@ -167,6 +167,7 @@ Window { onClicked: transactionsModel.editTransaction(index) } ToolButton { + visible: !transactionsModel.get(index).executeConstructor text: qsTr("Delete"); Layout.fillHeight: true onClicked: transactionsModel.deleteTransaction(index) diff --git a/mix/qml/StateList.qml b/mix/qml/StateList.qml index ad14cf30e..c20d1379d 100644 --- a/mix/qml/StateList.qml +++ b/mix/qml/StateList.qml @@ -48,6 +48,7 @@ Rectangle { onClicked: list.model.editState(index); } ToolButton { + visible: !list.model.isDefaultState(index) text: qsTr("Delete"); Layout.fillHeight: true onClicked: list.model.deleteState(index); diff --git a/mix/qml/StateListModel.qml b/mix/qml/StateListModel.qml index c158112e1..5a4722e84 100644 --- a/mix/qml/StateListModel.qml +++ b/mix/qml/StateListModel.qml @@ -176,6 +176,11 @@ Item { runState(defaultStateIndex); } + function isDefaultState(index) + { + return index === defaultStateIndex; + } + function runState(index) { var item = stateList[index]; clientModel.setupState(item); From d60b578de8f80f6ec873c015be6683bae66789ea Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Mon, 2 Feb 2015 15:58:01 +0100 Subject: [PATCH 22/55] mix on osx --- cmake/EthExecutableHelper.cmake | 3 ++- macdeployfix.sh | 38 +++++++++++++++++++++++++++++++++ mix/qml/main.qml | 1 + 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 macdeployfix.sh diff --git a/cmake/EthExecutableHelper.cmake b/cmake/EthExecutableHelper.cmake index 88e2a3e16..be45031ce 100644 --- a/cmake/EthExecutableHelper.cmake +++ b/cmake/EthExecutableHelper.cmake @@ -71,8 +71,9 @@ macro(eth_install_executable EXECUTABLE) if (APPLE) # First have qt5 install plugins and frameworks add_custom_command(TARGET ${EXECUTABLE} POST_BUILD - COMMAND ${MACDEPLOYQT_APP} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${EXECUTABLE}.app ${eth_qml_dir} + COMMAND ${MACDEPLOYQT_APP} ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${EXECUTABLE}.app -executable=${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${EXECUTABLE}.app/Contents/MacOS/${EXECUTABLE} ${eth_qml_dir} WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + COMMAND sh ${CMAKE_SOURCE_DIR}/macdeployfix.sh ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${EXECUTABLE}.app/Contents ) # This tool and next will inspect linked libraries in order to determine which dependencies are required diff --git a/macdeployfix.sh b/macdeployfix.sh new file mode 100644 index 000000000..0ff547d35 --- /dev/null +++ b/macdeployfix.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# solves problem with macdeployqt on Qt 5.4 RC +# http://qt-project.org/forums/viewthread/50118 + +BUILD_FOLDER_PATH=$1 +BUILD_QML_FOLDER_PATH="$BUILD_FOLDER_PATH/Resources/qml" +BUILD_PLUGINS_FOLDER_PATH="$BUILD_FOLDER_PATH/PlugIns" + +declare -a BROKEN_FILES; +k=0; +for j in $(find ${BUILD_QML_FOLDER_PATH} -name *.dylib); do + BROKEN_FILES[${k}]=$j + + ((k=k+1)) +done + + +for i in "${BROKEN_FILES[@]}"; do + REPLACE_STRING="$BUILD_FOLDER_PATH/" + APP_CONTENT_FILE=${i//$REPLACE_STRING/""} + IFS='/' read -a array <<< "$APP_CONTENT_FILE" + LENGTH=${#array[@]} + LAST_ITEM_INDEX=$((LENGTH-1)) + FILE=${array[${LENGTH} - 1]} + + ORIGINE_PATH=$(find ${BUILD_PLUGINS_FOLDER_PATH} -name ${FILE}) + ORIGINE_PATH=${ORIGINE_PATH//$REPLACE_STRING/""} + s="" + for((l=0;l<${LAST_ITEM_INDEX};l++)) do + s=$s"../" + done + s=$s$ORIGINE_PATH + echo "s: $s" + + REMOVE_BROKEN_ALIAS=$(rm -rf $i) + RESULT=$(ln -s $s $i) +done diff --git a/mix/qml/main.qml b/mix/qml/main.qml index a0a4ba423..657801b4b 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -4,6 +4,7 @@ import QtQuick.Controls.Styles 1.1 import QtQuick.Dialogs 1.1 import QtQuick.Layouts 1.1 import QtQuick.Window 2.1 +import QtQuick.PrivateWidgets 1.1 import Qt.labs.settings 1.0 import org.ethereum.qml.QEther 1.0 From fca289876fce4f3cf4a8d0b27fa0e7148bf9cc9f Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 2 Feb 2015 16:47:18 +0100 Subject: [PATCH 23/55] removed splitter.qml --- libjsqrc/ethereumjs/dist/ethereum.js | 7 ++--- mix/qml/Splitter.qml | 47 ---------------------------- mix/res.qrc | 1 - 3 files changed, 3 insertions(+), 52 deletions(-) delete mode 100644 mix/qml/Splitter.qml diff --git a/libjsqrc/ethereumjs/dist/ethereum.js b/libjsqrc/ethereumjs/dist/ethereum.js index 0f30280f9..5c912dbba 100644 --- a/libjsqrc/ethereumjs/dist/ethereum.js +++ b/libjsqrc/ethereumjs/dist/ethereum.js @@ -903,9 +903,8 @@ var ProviderManager = function() { data.data._id = self.id; self.id++; var result = self.provider.send(data.data); - - result = JSON.parse(result); - + result = JSON.parse(result); + // dont call the callback if result is not an array, or empty one if (result.error || !(result.result instanceof Array) || result.result.length === 0) { return; @@ -1520,4 +1519,4 @@ module.exports = web3; },{"./lib/abi":1,"./lib/contract":3,"./lib/filter":5,"./lib/httpsync":7,"./lib/providermanager":8,"./lib/qtsync":9,"./lib/web3":12}]},{},["web3"]) -//# sourceMappingURL=ethereum.js.map \ No newline at end of file +//# sourceMappingURL=ethereum.js.map diff --git a/mix/qml/Splitter.qml b/mix/qml/Splitter.qml deleted file mode 100644 index 341dc4450..000000000 --- a/mix/qml/Splitter.qml +++ /dev/null @@ -1,47 +0,0 @@ -import QtQuick 2.2 - -Rectangle { - property variant itemToStick; - property int itemMinimumWidth; - property string direction; - property variant brother; - - Component.onCompleted: - { - if (direction === "left") - anchors.right = itemToStick.left; - else if (direction === "right") - anchors.left = itemToStick.right; - } - - width: 5 - height: parent.height - anchors.top: parent.top; - MouseArea - { - property int startX: 0; - anchors.fill: parent - onPressed: startX = mouseX; - onPositionChanged: - { - parent.x += mouseX; - var diff = 0; - if (direction == "left") - diff = mouseX - startX; - else if (direction == "right") - diff = -(mouseX - startX); - - if (itemMinimumWidth > itemToStick.width - diff) - { - brother.width = brother.width + diff; - itemToStick.width = itemMinimumWidth; - } - else - { - brother.width = brother.width + diff; - itemToStick.width = itemToStick.width - diff; - } - } - cursorShape: Qt.SizeHorCursor - } -} diff --git a/mix/res.qrc b/mix/res.qrc index 639881e6a..b511217e6 100644 --- a/mix/res.qrc +++ b/mix/res.qrc @@ -44,7 +44,6 @@ qml/BigIntValue.qml qml/js/QEtherHelper.js qml/js/TransactionHelper.js - qml/Splitter.qml qml/ContractLibrary.qml stdc/config.sol stdc/namereg.sol From 76da204e17b54959aebba5feb0d02d516e319168 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 2 Feb 2015 17:24:09 +0100 Subject: [PATCH 24/55] Visibility specifiers. --- libsolidity/AST.cpp | 2 +- libsolidity/AST.h | 35 +++++++----- libsolidity/Parser.cpp | 49 +++++++++++----- libsolidity/Parser.h | 4 +- libsolidity/Token.h | 2 + libsolidity/grammar.txt | 7 ++- test/SolidityEndToEndTest.cpp | 14 ++--- test/SolidityNameAndTypeResolution.cpp | 77 ++++++++++++++++++++++++-- test/SolidityParser.cpp | 31 +++++++++-- 9 files changed, 169 insertions(+), 52 deletions(-) diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index 10464726e..b07959b39 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -133,7 +133,7 @@ void ContractDefinition::checkIllegalOverrides() const FunctionDefinition const*& override = functions[name]; if (!override) override = function.get(); - else if (override->isPublic() != function->isPublic() || + else if (override->getVisibility() != function->getVisibility() || override->isDeclaredConst() != function->isDeclaredConst() || FunctionType(*override) != FunctionType(*function)) BOOST_THROW_EXCEPTION(override->createTypeError("Override changes extended function signature.")); diff --git a/libsolidity/AST.h b/libsolidity/AST.h index 950553cd4..8e8641c78 100755 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -133,12 +133,17 @@ class Declaration: public ASTNode { public: enum class LValueType { NONE, LOCAL, STORAGE }; + enum class Visibility { DEFAULT, PUBLIC, PROTECTED, PRIVATE }; - Declaration(Location const& _location, ASTPointer const& _name): - ASTNode(_location), m_name(_name), m_scope(nullptr) {} + Declaration(Location const& _location, ASTPointer const& _name, + Visibility _visibility = Visibility::DEFAULT): + ASTNode(_location), m_name(_name), m_visibility(_visibility), m_scope(nullptr) {} /// @returns the declared name. ASTString const& getName() const { return *m_name; } + Visibility getVisibility() const { return m_visibility == Visibility::DEFAULT ? getDefaultVisibility() : m_visibility; } + bool isPublic() const { return getVisibility() == Visibility::PUBLIC; } + /// @returns the scope this declaration resides in. Can be nullptr if it is the global scope. /// Available only after name and type resolution step. Declaration const* getScope() const { return m_scope; } @@ -151,8 +156,12 @@ public: /// @returns the lvalue type of expressions referencing this declaration virtual LValueType getLValueType() const { return LValueType::NONE; } +protected: + virtual Visibility getDefaultVisibility() const { return Visibility::PUBLIC; } + private: ASTPointer m_name; + Visibility m_visibility; Declaration const* m_scope; }; @@ -330,16 +339,15 @@ class FunctionDefinition: public Declaration, public VariableScope, public Docum { public: FunctionDefinition(Location const& _location, ASTPointer const& _name, - bool _isPublic, - bool _isConstructor, + Declaration::Visibility _visibility, bool _isConstructor, ASTPointer const& _documentation, ASTPointer const& _parameters, bool _isDeclaredConst, std::vector> const& _modifiers, ASTPointer const& _returnParameters, ASTPointer const& _body): - Declaration(_location, _name), Documented(_documentation), - m_isPublic(_isPublic), m_isConstructor(_isConstructor), + Declaration(_location, _name, _visibility), Documented(_documentation), + m_isConstructor(_isConstructor), m_parameters(_parameters), m_isDeclaredConst(_isDeclaredConst), m_functionModifiers(_modifiers), @@ -350,7 +358,6 @@ public: virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; - bool isPublic() const { return m_isPublic; } bool isConstructor() const { return m_isConstructor; } bool isDeclaredConst() const { return m_isDeclaredConst; } std::vector> const& getModifiers() const { return m_functionModifiers; } @@ -371,7 +378,6 @@ public: std::string getCanonicalSignature() const; private: - bool m_isPublic; bool m_isConstructor; ASTPointer m_parameters; bool m_isDeclaredConst; @@ -388,10 +394,10 @@ class VariableDeclaration: public Declaration { public: VariableDeclaration(Location const& _location, ASTPointer const& _type, - ASTPointer const& _name, bool _isPublic, bool _isStateVar = false, - bool _isIndexed = false): - Declaration(_location, _name), m_typeName(_type), - m_isPublic(_isPublic), m_isStateVariable(_isStateVar), m_isIndexed(_isIndexed) {} + ASTPointer const& _name, Visibility _visibility, + bool _isStateVar = false, bool _isIndexed = false): + Declaration(_location, _name, _visibility), m_typeName(_type), + m_isStateVariable(_isStateVar), m_isIndexed(_isIndexed) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; @@ -404,13 +410,14 @@ public: virtual LValueType getLValueType() const override; bool isLocalVariable() const { return !!dynamic_cast(getScope()); } - bool isPublic() const { return m_isPublic; } bool isStateVariable() const { return m_isStateVariable; } bool isIndexed() const { return m_isIndexed; } +protected: + Visibility getDefaultVisibility() const override { return Visibility::PROTECTED; } + private: ASTPointer m_typeName; ///< can be empty ("var") - bool m_isPublic; ///< Whether there is an accessor for it or not bool m_isStateVariable; ///< Whether or not this is a contract state variable bool m_isIndexed; ///< Whether this is an indexed variable (used by events). diff --git a/libsolidity/Parser.cpp b/libsolidity/Parser.cpp index d2e888a8d..cc75fc0a2 100644 --- a/libsolidity/Parser.cpp +++ b/libsolidity/Parser.cpp @@ -131,27 +131,19 @@ ASTPointer Parser::parseContractDefinition() } while (m_scanner->getCurrentToken() == Token::COMMA); expectToken(Token::LBRACE); - bool visibilityIsPublic = true; while (true) { Token::Value currentToken = m_scanner->getCurrentToken(); if (currentToken == Token::RBRACE) break; - else if (currentToken == Token::PUBLIC || currentToken == Token::PRIVATE) - { - visibilityIsPublic = (m_scanner->getCurrentToken() == Token::PUBLIC); - m_scanner->next(); - expectToken(Token::COLON); - } else if (currentToken == Token::FUNCTION) - functions.push_back(parseFunctionDefinition(visibilityIsPublic, name.get())); + functions.push_back(parseFunctionDefinition(name.get())); else if (currentToken == Token::STRUCT) structs.push_back(parseStructDefinition()); else if (currentToken == Token::IDENTIFIER || currentToken == Token::MAPPING || Token::isElementaryTypeName(currentToken)) { VarDeclParserOptions options; - options.isPublic = visibilityIsPublic; options.isStateVariable = true; stateVariables.push_back(parseVariableDeclaration(options)); expectToken(Token::SEMICOLON); @@ -186,7 +178,22 @@ ASTPointer Parser::parseInheritanceSpecifier() return nodeFactory.createNode(name, arguments); } -ASTPointer Parser::parseFunctionDefinition(bool _isPublic, ASTString const* _contractName) +Declaration::Visibility Parser::parseVisibilitySpecifier(Token::Value _token) +{ + Declaration::Visibility visibility; + if (_token == Token::PUBLIC) + visibility = Declaration::Visibility::PUBLIC; + else if (_token == Token::PROTECTED) + visibility = Declaration::Visibility::PROTECTED; + else if (_token == Token::PRIVATE) + visibility = Declaration::Visibility::PRIVATE; + else + solAssert(false, "Invalid visibility specifier."); + m_scanner->next(); + return visibility; +} + +ASTPointer Parser::parseFunctionDefinition(ASTString const* _contractName) { ASTNodeFactory nodeFactory(*this); ASTPointer docstring; @@ -201,16 +208,24 @@ ASTPointer Parser::parseFunctionDefinition(bool _isPublic, A name = expectIdentifierToken(); ASTPointer parameters(parseParameterList()); bool isDeclaredConst = false; + Declaration::Visibility visibility(Declaration::Visibility::DEFAULT); vector> modifiers; while (true) { - if (m_scanner->getCurrentToken() == Token::CONST) + Token::Value token = m_scanner->getCurrentToken(); + if (token == Token::CONST) { isDeclaredConst = true; m_scanner->next(); } - else if (m_scanner->getCurrentToken() == Token::IDENTIFIER) + else if (token == Token::IDENTIFIER) modifiers.push_back(parseModifierInvocation()); + else if (Token::isVisibilitySpecifier(token)) + { + if (visibility != Declaration::Visibility::DEFAULT) + BOOST_THROW_EXCEPTION(createParserError("Multiple visibility specifiers.")); + visibility = parseVisibilitySpecifier(token); + } else break; } @@ -226,7 +241,7 @@ ASTPointer Parser::parseFunctionDefinition(bool _isPublic, A ASTPointer block = parseBlock(); nodeFactory.setEndPositionFromNode(block); bool const c_isConstructor = (_contractName && *name == *_contractName); - return nodeFactory.createNode(name, _isPublic, c_isConstructor, docstring, + return nodeFactory.createNode(name, visibility, c_isConstructor, docstring, parameters, isDeclaredConst, modifiers, returnParameters, block); } @@ -253,14 +268,18 @@ ASTPointer Parser::parseVariableDeclaration(VarDeclParserOp ASTNodeFactory nodeFactory(*this); ASTPointer type = parseTypeName(_options.allowVar); bool isIndexed = false; - if (_options.allowIndexed && m_scanner->getCurrentToken() == Token::INDEXED) + Token::Value token = m_scanner->getCurrentToken(); + if (_options.allowIndexed && token == Token::INDEXED) { isIndexed = true; m_scanner->next(); } + Declaration::Visibility visibility(Declaration::Visibility::DEFAULT); + if (_options.isStateVariable && Token::isVisibilitySpecifier(token)) + visibility = parseVisibilitySpecifier(token); nodeFactory.markEndPosition(); return nodeFactory.createNode(type, expectIdentifierToken(), - _options.isPublic, _options.isStateVariable, + visibility, _options.isStateVariable, isIndexed); } diff --git a/libsolidity/Parser.h b/libsolidity/Parser.h index 413a2711e..388fd7a96 100644 --- a/libsolidity/Parser.h +++ b/libsolidity/Parser.h @@ -48,7 +48,6 @@ private: struct VarDeclParserOptions { VarDeclParserOptions() {} bool allowVar = false; - bool isPublic = false; bool isStateVariable = false; bool allowIndexed = false; }; @@ -58,7 +57,8 @@ private: ASTPointer parseImportDirective(); ASTPointer parseContractDefinition(); ASTPointer parseInheritanceSpecifier(); - ASTPointer parseFunctionDefinition(bool _isPublic, ASTString const* _contractName); + Declaration::Visibility parseVisibilitySpecifier(Token::Value _token); + ASTPointer parseFunctionDefinition(ASTString const* _contractName); ASTPointer parseStructDefinition(); ASTPointer parseVariableDeclaration(VarDeclParserOptions const& _options = VarDeclParserOptions()); ASTPointer parseModifierDefinition(); diff --git a/libsolidity/Token.h b/libsolidity/Token.h index ed42f90cc..76e504499 100644 --- a/libsolidity/Token.h +++ b/libsolidity/Token.h @@ -165,6 +165,7 @@ namespace solidity K(NEW, "new", 0) \ K(PUBLIC, "public", 0) \ K(PRIVATE, "private", 0) \ + K(PROTECTED, "protected", 0) \ K(RETURN, "return", 0) \ K(RETURNS, "returns", 0) \ K(STRUCT, "struct", 0) \ @@ -376,6 +377,7 @@ public: static bool isUnaryOp(Value op) { return (NOT <= op && op <= DELETE) || op == ADD || op == SUB; } static bool isCountOp(Value op) { return op == INC || op == DEC; } static bool isShiftOp(Value op) { return (SHL <= op) && (op <= SHR); } + static bool isVisibilitySpecifier(Value op) { return op == PUBLIC || op == PRIVATE || op == PROTECTED; } // Returns a string corresponding to the JS token string // (.e., "<" for the token LT) or NULL if the token doesn't diff --git a/libsolidity/grammar.txt b/libsolidity/grammar.txt index b97dac5db..1785b516c 100644 --- a/libsolidity/grammar.txt +++ b/libsolidity/grammar.txt @@ -1,14 +1,15 @@ ContractDefinition = 'contract' Identifier ( 'is' InheritanceSpecifier (',' InheritanceSpecifier )* )? '{' ContractPart* '}' -ContractPart = VariableDeclaration ';' | StructDefinition | ModifierDefinition | - FunctionDefinition | 'public:' | 'private:' +ContractPart = StateVariableDeclaration | StructDefinition | ModifierDefinition | FunctionDefinition InheritanceSpecifier = Identifier ( '(' Expression ( ',' Expression )* ')' )? StructDefinition = 'struct' Identifier '{' ( VariableDeclaration (';' VariableDeclaration)* )? '} +StateVariableDeclaration = TypeName ( 'public' | 'protected' | 'private' )? Identifier ';' ModifierDefinition = 'modifier' Identifier ParameterList? Block -FunctionDefinition = 'function' Identifier ParameterList ( Identifier | 'constant' )* +FunctionDefinition = 'function' Identifier ParameterList + ( Identifier | 'constant' | 'public' | 'protected' | 'private' )* ( 'returns' ParameterList )? Block ParameterList = '(' ( VariableDeclaration (',' VariableDeclaration)* )? ')' // semantic restriction: mappings and structs (recursively) containing mappings diff --git a/test/SolidityEndToEndTest.cpp b/test/SolidityEndToEndTest.cpp index 7edc250c8..7166b95fb 100644 --- a/test/SolidityEndToEndTest.cpp +++ b/test/SolidityEndToEndTest.cpp @@ -885,7 +885,7 @@ BOOST_AUTO_TEST_CASE(constructor) BOOST_AUTO_TEST_CASE(simple_accessor) { char const* sourceCode = "contract test {\n" - " uint256 data;\n" + " uint256 public data;\n" " function test() {\n" " data = 8;\n" " }\n" @@ -897,10 +897,10 @@ BOOST_AUTO_TEST_CASE(simple_accessor) BOOST_AUTO_TEST_CASE(multiple_elementary_accessors) { char const* sourceCode = "contract test {\n" - " uint256 data;\n" - " string6 name;\n" - " hash a_hash;\n" - " address an_address;\n" + " uint256 public data;\n" + " string6 public name;\n" + " hash public a_hash;\n" + " address public an_address;\n" " function test() {\n" " data = 8;\n" " name = \"Celina\";\n" @@ -908,7 +908,6 @@ BOOST_AUTO_TEST_CASE(multiple_elementary_accessors) " an_address = address(0x1337);\n" " super_secret_data = 42;\n" " }\n" - " private:" " uint256 super_secret_data;" "}\n"; compileAndRun(sourceCode); @@ -1490,8 +1489,7 @@ BOOST_AUTO_TEST_CASE(functions_called_by_constructor) setName("abc"); } function getName() returns (string3 ret) { return name; } - private: - function setName(string3 _name) { name = _name; } + function setName(string3 _name) private { name = _name; } })"; compileAndRun(sourceCode); BOOST_REQUIRE(callContractFunction("getName()") == encodeArgs("abc")); diff --git a/test/SolidityNameAndTypeResolution.cpp b/test/SolidityNameAndTypeResolution.cpp index b9a7140f7..4e01d02d0 100644 --- a/test/SolidityNameAndTypeResolution.cpp +++ b/test/SolidityNameAndTypeResolution.cpp @@ -467,6 +467,24 @@ BOOST_AUTO_TEST_CASE(illegal_override_indirect) BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); } +BOOST_AUTO_TEST_CASE(illegal_override_visibility) +{ + char const* text = R"( + contract B { function f() protected {} } + contract C is B { function f() public {} } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); +} + +BOOST_AUTO_TEST_CASE(illegal_override_constness) +{ + char const* text = R"( + contract B { function f() constant {} } + contract C is B { function f() {} } + )"; + BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); +} + BOOST_AUTO_TEST_CASE(complex_inheritance) { char const* text = R"( @@ -636,7 +654,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) " function fun() {\n" " uint64(2);\n" " }\n" - "uint256 foo;\n" + "uint256 public foo;\n" "}\n"; ASTPointer source; @@ -668,16 +686,19 @@ BOOST_AUTO_TEST_CASE(private_state_variable) " function fun() {\n" " uint64(2);\n" " }\n" - "private:\n" - "uint256 foo;\n" + "uint256 private foo;\n" + "uint256 protected bar;\n" "}\n"; ASTPointer source; ContractDefinition const* contract; BOOST_CHECK_NO_THROW(source = parseTextAndResolveNamesWithChecks(text)); BOOST_CHECK((contract = retrieveContract(source, 0)) != nullptr); - FunctionTypePointer function = retrieveFunctionBySignature(contract, "foo()"); + FunctionTypePointer function; + function = retrieveFunctionBySignature(contract, "foo()"); BOOST_CHECK_MESSAGE(function == nullptr, "Accessor function of a private variable should not exist"); + function = retrieveFunctionBySignature(contract, "bar()"); + BOOST_CHECK_MESSAGE(function == nullptr, "Accessor function of a protected variable should not exist"); } BOOST_AUTO_TEST_CASE(fallback_function) @@ -780,6 +801,54 @@ BOOST_AUTO_TEST_CASE(multiple_events_argument_clash) BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); } +BOOST_AUTO_TEST_CASE(access_to_default_function_visibility) +{ + char const* text = R"( + contract c { + function f() {} + } + contract d { + function g() { c(0).f(); } + })"; + BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); +} + +BOOST_AUTO_TEST_CASE(access_to_protected_function) +{ + char const* text = R"( + contract c { + function f() protected {} + } + contract d { + function g() { c(0).f(); } + })"; + BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); +} + +BOOST_AUTO_TEST_CASE(access_to_default_state_variable_visibility) +{ + char const* text = R"( + contract c { + uint a; + } + contract d { + function g() { c(0).a(); } + })"; + BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError); +} + +BOOST_AUTO_TEST_CASE(access_to_protected_state_variable) +{ + char const* text = R"( + contract c { + uint public a; + } + contract d { + function g() { c(0).a(); } + })"; + BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text)); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/SolidityParser.cpp b/test/SolidityParser.cpp index 4adee9c66..4ccdcd57a 100644 --- a/test/SolidityParser.cpp +++ b/test/SolidityParser.cpp @@ -129,9 +129,7 @@ BOOST_AUTO_TEST_CASE(function_natspec_documentation) ASTPointer contract; ASTPointer function; char const* text = "contract test {\n" - " private:\n" - " uint256 stateVar;\n" - " public:\n" + " uint256 stateVar;\n" " /// This is a test function\n" " function functionName(hash hashin) returns (hash hashout) {}\n" "}\n"; @@ -162,9 +160,7 @@ BOOST_AUTO_TEST_CASE(multiple_functions_natspec_documentation) ASTPointer contract; ASTPointer function; char const* text = "contract test {\n" - " private:\n" " uint256 stateVar;\n" - " public:\n" " /// This is test function 1\n" " function functionName1(hash hashin) returns (hash hashout) {}\n" " /// This is test function 2\n" @@ -621,6 +617,31 @@ BOOST_AUTO_TEST_CASE(event_arguments_indexed) BOOST_CHECK_NO_THROW(parseText(text)); } +BOOST_AUTO_TEST_CASE(visibility_specifiers) +{ + char const* text = R"( + contract c { + uint private a; + uint protected b; + uint public c; + uint d; + function f() {} + function f_priv() private {} + function f_public() public {} + function f_protected() protected {} + })"; + BOOST_CHECK_NO_THROW(parseText(text)); +} + +BOOST_AUTO_TEST_CASE(multiple_visibility_specifiers) +{ + char const* text = R"( + contract c { + uint private protected a; + })"; + BOOST_CHECK_THROW(parseText(text), ParserError); +} + BOOST_AUTO_TEST_SUITE_END() } From 6c5120978ececc5dc015721a0554c3a360e68827 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 2 Feb 2015 17:52:50 +0100 Subject: [PATCH 25/55] Accessors for multiple mappings implemented --- libsolidity/ExpressionCompiler.cpp | 45 +++++++++++++------------- libsolidity/Types.cpp | 22 ++++++------- test/SolidityEndToEndTest.cpp | 3 ++ test/SolidityNameAndTypeResolution.cpp | 15 +++++++-- 4 files changed, 49 insertions(+), 36 deletions(-) diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index 722ac9895..45e0e80b0 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -847,36 +848,34 @@ unsigned ExpressionCompiler::appendExpressionCopyToMemory(Type const& _expectedT void ExpressionCompiler::appendStateVariableAccessor(VariableDeclaration const& _varDecl) { - TypePointer resultType = _varDecl.getType(); - auto mappingType = dynamic_cast(resultType.get()); + FunctionType thisType(_varDecl); + solAssert(thisType.getReturnParameterTypes().size() == 1, ""); + TypePointer const& resultType = thisType.getReturnParameterTypes().front(); unsigned sizeOnStack; - if (mappingType != nullptr) - { - // this copies from ExpressionCompiler::visit(IndexAccess .. ) for mapping access - TypePointer const& keyType = mappingType->getKeyType(); - unsigned length = appendTypeConversionAndMoveToMemory(*keyType, *keyType, Location()); - solAssert(length == 32, "Mapping key has to take 32 bytes in memory (for now)."); - // @todo move this once we actually use memory - m_context << m_context.getStorageLocationOfVariable(_varDecl); - length += CompilerUtils(m_context).storeInMemory(length); - m_context << u256(length) << u256(0) << eth::Instruction::SHA3; - m_currentLValue = LValue(m_context, LValue::STORAGE, *mappingType->getValueType()); - m_currentLValue.retrieveValue(mappingType->getValueType(), Location(), true); - m_currentLValue.reset(); + unsigned length = 0; + TypePointers const& params = thisType.getParameterTypes(); + // move arguments to memory + for (TypePointer const& param: boost::adaptors::reverse(params)) + length += appendTypeConversionAndMoveToMemory(*param, *param, Location(), length); - resultType = mappingType->getValueType(); - } - else + // retrieve the position of the mapping + m_context << m_context.getStorageLocationOfVariable(_varDecl); + + for (TypePointer const& param: params) { - m_currentLValue.fromStateVariable(_varDecl, _varDecl.getType()); - solAssert(m_currentLValue.isInStorage(), ""); - m_currentLValue.retrieveValue(_varDecl.getType(), Location(), true); + // move offset to memory + CompilerUtils(m_context).storeInMemory(length); + unsigned argLen = CompilerUtils::getPaddedSize(param->getCalldataEncodedSize()); + length -= argLen; + m_context << u256(argLen + 32) << u256(length) << eth::Instruction::SHA3; } - sizeOnStack = _varDecl.getType()->getSizeOnStack(); + + m_currentLValue = LValue(m_context, LValue::STORAGE, *resultType); + m_currentLValue.retrieveValue(resultType, Location(), true); + sizeOnStack = resultType->getSizeOnStack(); solAssert(sizeOnStack <= 15, "Stack too deep."); m_context << eth::dupInstruction(sizeOnStack + 1) << eth::Instruction::JUMP; - } ExpressionCompiler::LValue::LValue(CompilerContext& _compilerContext, LValueType _type, Type const& _dataType, diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index 7fa4561e3..cfb852c2f 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -626,20 +626,20 @@ FunctionType::FunctionType(VariableDeclaration const& _varDecl): TypePointers retParams; vector retParamNames; TypePointer varDeclType = _varDecl.getType(); - auto mappingType = dynamic_cast(varDeclType.get()); - if (mappingType!= nullptr) - { - params.push_back(mappingType->getKeyType()); - paramNames.push_back(mappingType->getKeyType()->toString()); + auto mappingType = dynamic_cast(varDeclType.get()); + auto returnType = varDeclType; - retParams.push_back(mappingType->getValueType()); - retParamNames.push_back(mappingType->getValueType()->toString()); - } - else // elelemntary type + while (mappingType!= nullptr) { - retParams.push_back(varDeclType); - retParamNames.push_back(_varDecl.getName()); + params.push_back(mappingType->getKeyType()); + paramNames.push_back(""); + returnType = mappingType->getValueType(); + mappingType = dynamic_cast(mappingType->getValueType().get()); } + + retParams.push_back(returnType); + retParamNames.push_back(""); + swap(params, m_parameterTypes); swap(paramNames, m_parameterNames); swap(retParams, m_returnParameterTypes); diff --git a/test/SolidityEndToEndTest.cpp b/test/SolidityEndToEndTest.cpp index 63a8ebcd3..9a04e02d3 100644 --- a/test/SolidityEndToEndTest.cpp +++ b/test/SolidityEndToEndTest.cpp @@ -925,16 +925,19 @@ BOOST_AUTO_TEST_CASE(complex_accessors) " mapping(uint256 => string4) to_string_map;\n" " mapping(uint256 => bool) to_bool_map;\n" " mapping(uint256 => uint256) to_uint_map;\n" + " mapping(uint256 => mapping(uint256 => uint256)) to_multiple_map;\n" " function test() {\n" " to_string_map[42] = \"24\";\n" " to_bool_map[42] = false;\n" " to_uint_map[42] = 12;\n" + " to_multiple_map[42][23] = 31;\n" " }\n" "}\n"; compileAndRun(sourceCode); BOOST_CHECK(callContractFunction("to_string_map(uint256)", 42) == encodeArgs("24")); BOOST_CHECK(callContractFunction("to_bool_map(uint256)", 42) == encodeArgs(false)); BOOST_CHECK(callContractFunction("to_uint_map(uint256)", 42) == encodeArgs(12)); + BOOST_CHECK(callContractFunction("to_multiple_map(uint256,uint256)", 42, 23) == encodeArgs(31)); } BOOST_AUTO_TEST_CASE(balance) diff --git a/test/SolidityNameAndTypeResolution.cpp b/test/SolidityNameAndTypeResolution.cpp index df0e07e1d..2fe3288ad 100644 --- a/test/SolidityNameAndTypeResolution.cpp +++ b/test/SolidityNameAndTypeResolution.cpp @@ -638,6 +638,7 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) " }\n" "uint256 foo;\n" "mapping(uint=>string4) map;\n" + "mapping(uint=>mapping(uint=>string4)) multiple_map;\n" "}\n"; ASTPointer source; @@ -649,10 +650,20 @@ BOOST_AUTO_TEST_CASE(state_variable_accessors) auto returnParams = function->getReturnParameterTypeNames(); BOOST_CHECK_EQUAL(returnParams.at(0), "uint256"); BOOST_CHECK(function->isConstant()); + function = retrieveFunctionBySignature(contract, "map(uint256)"); BOOST_REQUIRE(function && function->hasDeclaration()); - auto Params = function->getParameterTypeNames(); - BOOST_CHECK_EQUAL(returnParams.at(0), "uint256"); + auto params = function->getParameterTypeNames(); + BOOST_CHECK_EQUAL(params.at(0), "uint256"); + returnParams = function->getReturnParameterTypeNames(); + BOOST_CHECK_EQUAL(returnParams.at(0), "string4"); + BOOST_CHECK(function->isConstant()); + + function = retrieveFunctionBySignature(contract, "multiple_map(uint256,uint256)"); + BOOST_REQUIRE(function && function->hasDeclaration()); + params = function->getParameterTypeNames(); + BOOST_CHECK_EQUAL(params.at(0), "uint256"); + BOOST_CHECK_EQUAL(params.at(1), "uint256"); returnParams = function->getReturnParameterTypeNames(); BOOST_CHECK_EQUAL(returnParams.at(0), "string4"); BOOST_CHECK(function->isConstant()); From 6a6917607b92c0b2a0d5c84683486033019d8341 Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 2 Feb 2015 18:09:14 +0100 Subject: [PATCH 26/55] fixed msvc build --- mix/AssemblyDebuggerControl.cpp | 1 - mix/MachineStates.h | 79 +++++++++++++++++++++++++++++++++ mix/MixClient.h | 41 +---------------- 3 files changed, 80 insertions(+), 41 deletions(-) create mode 100644 mix/MachineStates.h diff --git a/mix/AssemblyDebuggerControl.cpp b/mix/AssemblyDebuggerControl.cpp index e065513a8..7bf177981 100644 --- a/mix/AssemblyDebuggerControl.cpp +++ b/mix/AssemblyDebuggerControl.cpp @@ -20,7 +20,6 @@ #include #include #include -#include "AppContext.h" #include "ClientModel.h" #include "AssemblyDebuggerControl.h" diff --git a/mix/MachineStates.h b/mix/MachineStates.h new file mode 100644 index 000000000..d19fd9b74 --- /dev/null +++ b/mix/MachineStates.h @@ -0,0 +1,79 @@ +/* +This file is part of cpp-ethereum. + +cpp-ethereum is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +cpp-ethereum is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with cpp-ethereum. If not, see . +*/ +/** @file MixClient.h +* @author Yann yann@ethdev.com +* @author Arkadiy Paronyan arkadiy@ethdev.com +* @date 2015 +* Ethereum IDE client. +*/ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace dev +{ +namespace mix +{ + + /** + * @brief Store information about a machine state. + */ + struct MachineState + { + uint64_t steps; + dev::Address address; + dev::u256 curPC; + dev::eth::Instruction inst; + dev::bigint newMemSize; + dev::u256 gas; + dev::u256s stack; + dev::bytes memory; + dev::bigint gasCost; + std::map storage; + std::vector levels; + unsigned codeIndex; + unsigned dataIndex; + }; + + /** + * @brief Store information about a machine states. + */ + struct ExecutionResult + { + ExecutionResult() : receipt(dev::h256(), dev::h256(), dev::eth::LogEntries()) {} + + std::vector machineStates; + std::vector transactionData; + std::vector executionCode; + bytes returnValue; + dev::Address address; + dev::Address sender; + dev::Address contractAddress; + dev::u256 value; + dev::eth::TransactionReceipt receipt; + }; + + using ExecutionResults = std::vector; +} +} \ No newline at end of file diff --git a/mix/MixClient.h b/mix/MixClient.h index dceb9ce7b..6118613ed 100644 --- a/mix/MixClient.h +++ b/mix/MixClient.h @@ -26,52 +26,13 @@ #include #include #include +#include "MachineStates.h" namespace dev { namespace mix { -/** - * @brief Store information about a machine state. - */ -struct MachineState -{ - uint64_t steps; - dev::Address address; - dev::u256 curPC; - dev::eth::Instruction inst; - dev::bigint newMemSize; - dev::u256 gas; - dev::u256s stack; - dev::bytes memory; - dev::bigint gasCost; - std::map storage; - std::vector levels; - unsigned codeIndex; - unsigned dataIndex; -}; - -/** - * @brief Store information about a machine states. - */ -struct ExecutionResult -{ - ExecutionResult(): receipt(dev::h256(), dev::h256(), dev::eth::LogEntries()) {} - - std::vector machineStates; - std::vector transactionData; - std::vector executionCode; - bytes returnValue; - dev::Address address; - dev::Address sender; - dev::Address contractAddress; - dev::u256 value; - dev::eth::TransactionReceipt receipt; -}; - -using ExecutionResults = std::vector; - struct Block { ExecutionResults transactions; From 921e92474e71d6d1fc18eaa60640f7c2f3eb6c6f Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 2 Feb 2015 18:20:43 +0100 Subject: [PATCH 27/55] reverted ethereum.js --- libjsqrc/ethereumjs/dist/ethereum.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libjsqrc/ethereumjs/dist/ethereum.js b/libjsqrc/ethereumjs/dist/ethereum.js index 5c912dbba..0f30280f9 100644 --- a/libjsqrc/ethereumjs/dist/ethereum.js +++ b/libjsqrc/ethereumjs/dist/ethereum.js @@ -903,8 +903,9 @@ var ProviderManager = function() { data.data._id = self.id; self.id++; var result = self.provider.send(data.data); - result = JSON.parse(result); - + + result = JSON.parse(result); + // dont call the callback if result is not an array, or empty one if (result.error || !(result.result instanceof Array) || result.result.length === 0) { return; @@ -1519,4 +1520,4 @@ module.exports = web3; },{"./lib/abi":1,"./lib/contract":3,"./lib/filter":5,"./lib/httpsync":7,"./lib/providermanager":8,"./lib/qtsync":9,"./lib/web3":12}]},{},["web3"]) -//# sourceMappingURL=ethereum.js.map +//# sourceMappingURL=ethereum.js.map \ No newline at end of file From ccb6b58e7185ec82b5d830c5812e1d04f5d5e45f Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 2 Feb 2015 18:21:47 +0100 Subject: [PATCH 28/55] - Coding Standards. - Encode/Decode bigint behavior. --- mix/ClientModel.cpp | 3 --- mix/QVariableDefinition.cpp | 17 ++++++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index 93bcc7c92..a66335b5a 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -215,7 +215,6 @@ void ClientModel::executeSequence(std::vector const& _seque encoder.push(transaction.parameterValues.at(p)->encodeValue()); } - if (transaction.functionId.isEmpty()) { Address newAddress = deployContract(contractCode, transaction); @@ -226,9 +225,7 @@ void ClientModel::executeSequence(std::vector const& _seque } } else - { callContract(m_contractAddress, encoder.encodedData(), transaction); - } } onNewTransaction(); } diff --git a/mix/QVariableDefinition.cpp b/mix/QVariableDefinition.cpp index 5049283da..a76388d68 100644 --- a/mix/QVariableDefinition.cpp +++ b/mix/QVariableDefinition.cpp @@ -70,19 +70,18 @@ void QIntType::setValue(dev::bigint _value) dev::bytes QIntType::encodeValue() { dev::bigint i(value().toStdString()); - if (i < 0) - i = i + dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") + 1; bytes ret(32); - toBigEndian(i, ret); + toBigEndian((u256)i, ret); return ret; } void QIntType::decodeValue(dev::bytes const& _rawValue) { - dev::bigint bigint = dev::fromBigEndian(_rawValue); - if (((bigint >> 32) & 1) == 1) - bigint = bigint - dev::bigint("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") - 1; - setValue(bigint); + dev::u256 un = dev::fromBigEndian(_rawValue); + if (un >> 255) + setValue(-s256(~un + 1)); + else + setValue(un); } /* @@ -90,8 +89,8 @@ void QIntType::decodeValue(dev::bytes const& _rawValue) */ dev::bytes QHashType::encodeValue() { - QByteArray b = value().toUtf8(); - bytes r = bytes(b.begin(), b.end()); + QByteArray bytesAr = value().toLocal8Bit(); + bytes r = bytes(bytesAr.begin(), bytesAr.end()); return padded(r, 32); } From f0bfbf797a9bf13c92e164e34ba275af7e51645e Mon Sep 17 00:00:00 2001 From: arkpar Date: Mon, 2 Feb 2015 18:24:04 +0100 Subject: [PATCH 29/55] reverted some changes --- mix/main.cpp | 1 - mix/qml/ProjectList.qml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/mix/main.cpp b/mix/main.cpp index b24b8a549..d0a19cfb5 100644 --- a/mix/main.cpp +++ b/mix/main.cpp @@ -36,7 +36,6 @@ int main(int _argc, char* _argv[]) //https://bugs.launchpad.net/ubuntu/+source/appmenu-qt5/+bug/1323853 putenv((char*)"QT_QPA_PLATFORMTHEME="); putenv((char*)"QSG_RENDER_LOOP=threaded"); - putenv((char*)"QT_IM_MODULE="); #endif try { diff --git a/mix/qml/ProjectList.qml b/mix/qml/ProjectList.qml index e4e57455d..30f945706 100644 --- a/mix/qml/ProjectList.qml +++ b/mix/qml/ProjectList.qml @@ -3,7 +3,7 @@ import QtQuick.Window 2.0 import QtQuick.Layouts 1.0 import QtQuick.Controls 1.0 -Rectangle { +Item { property bool renameMode: false; ColumnLayout { anchors.fill: parent From d5e3f6f098f8c53b650b258df10643a502429f96 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 2 Feb 2015 19:37:38 +0100 Subject: [PATCH 30/55] bug fixes --- libdevcore/CommonJS.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/libdevcore/CommonJS.cpp b/libdevcore/CommonJS.cpp index 9c20bdd53..980cb9081 100644 --- a/libdevcore/CommonJS.cpp +++ b/libdevcore/CommonJS.cpp @@ -60,15 +60,12 @@ bytes unpadded(bytes _b) bytes unpadLeft(bytes _b) { - int i = 0; + unsigned int i = 0; if (_b.size() == 0) return _b; - while (true) - if (_b.at(i) == byte(0)) - i++; - else - break; + while (i < _b.size() && _b[i] == byte(0)) + i++; if (i != 0) _b.erase(_b.begin(), _b.begin() + i); From 114db8ab36bc25e666702abdece63d607597b7d2 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 2 Feb 2015 17:07:15 -0800 Subject: [PATCH 31/55] Revert State class changes for Mix. --- alethzero/MainWin.cpp | 7 ++++--- libethcore/CommonEth.cpp | 21 ++++++++++++++------ libethcore/CommonEth.h | 2 +- libethereum/Client.cpp | 7 +++---- libethereum/State.cpp | 41 ++++++++++++++++++---------------------- libethereum/State.h | 10 +++++----- mix/MixClient.cpp | 15 ++++++--------- mix/MixClient.h | 1 - test/stateOriginal.cpp | 7 ++++--- 9 files changed, 56 insertions(+), 55 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 3c87f649a..1921e80cd 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -1209,8 +1209,9 @@ string Main::renderDiff(StateDiff const& _d) const if (ad.balance) { - s << "
" << indent << "Balance " << dec << formatBalance(ad.balance.to()); - s << " " << showpos << (((dev::bigint)ad.balance.to()) - ((dev::bigint)ad.balance.from())) << noshowpos << ""; + s << "
" << indent << "Balance " << dec << ad.balance.to() << " [=" << formatBalance(ad.balance.to()) << "]"; + auto d = (((dev::bigint)ad.balance.to()) - ((dev::bigint)ad.balance.from())); + s << " " << showpos << dec << d << " [=" << formatBalance(d) << "]" << noshowpos << ""; } if (ad.nonce) { @@ -1219,7 +1220,7 @@ string Main::renderDiff(StateDiff const& _d) const } if (ad.code) { - s << "
" << indent << "Code " << hex << ad.code.to().size() << " bytes"; + s << "
" << indent << "Code " << dec << ad.code.to().size() << " bytes"; if (ad.code.from().size()) s << " (" << ad.code.from().size() << " bytes)"; } diff --git a/libethcore/CommonEth.cpp b/libethcore/CommonEth.cpp index 8de20c21d..c530beef1 100644 --- a/libethcore/CommonEth.cpp +++ b/libethcore/CommonEth.cpp @@ -63,22 +63,31 @@ vector> const& units() return g_units; } -std::string formatBalance(u256 _b) +std::string formatBalance(bigint const& _b) { ostringstream ret; - if (_b > g_units[0].first * 10000) + u256 b; + if (_b < 0) { - ret << (_b / g_units[0].first) << " " << g_units[0].second; + ret << "-"; + b = (u256)-_b; + } + else + b = (u256)_b; + + if (b > g_units[0].first * 10000) + { + ret << (b / g_units[0].first) << " " << g_units[0].second; return ret.str(); } ret << setprecision(5); for (auto const& i: g_units) - if (i.first != 1 && _b >= i.first * 100) + if (i.first != 1 && b >= i.first * 100) { - ret << (double(_b / (i.first / 1000)) / 1000.0) << " " << i.second; + ret << (double(b / (i.first / 1000)) / 1000.0) << " " << i.second; return ret.str(); } - ret << _b << " wei"; + ret << b << " wei"; return ret.str(); } diff --git a/libethcore/CommonEth.h b/libethcore/CommonEth.h index 704e354a2..966794953 100644 --- a/libethcore/CommonEth.h +++ b/libethcore/CommonEth.h @@ -39,7 +39,7 @@ extern const unsigned c_protocolVersion; extern const unsigned c_databaseVersion; /// User-friendly string representation of the amount _b in wei. -std::string formatBalance(u256 _b); +std::string formatBalance(bigint const& _b); /// Get information concerning the currency denominations. std::vector> const& units(); diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index ccff335b6..9cfd18b2d 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -226,7 +226,7 @@ void Client::uninstallWatch(unsigned _i) void Client::noteChanged(h256Set const& _filters) { Guard l(m_filterLock); - cnote << "noteChanged(" << _filters << ")"; +// cnote << "noteChanged(" << _filters << ")"; // accrue all changes left in each filter into the watches. for (auto& i: m_watches) if (_filters.count(i.second.id)) @@ -361,13 +361,12 @@ void Client::setupState(State& _s) cwork << "SETUP MINE"; _s = m_postMine; } - _s.setUncles(m_bc); if (m_paranoia) { if (_s.amIJustParanoid(m_bc)) { cnote << "I'm just paranoid. Block is fine."; - _s.commitToMine(); + _s.commitToMine(m_bc); } else { @@ -375,7 +374,7 @@ void Client::setupState(State& _s) } } else - _s.commitToMine(); + _s.commitToMine(m_bc); } void Client::transact(Secret _secret, u256 _value, Address _dest, bytes const& _data, u256 _gas, u256 _gasPrice) diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 831696beb..ecb5b2606 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -639,8 +639,7 @@ void State::uncommitToMine() bool State::amIJustParanoid(BlockChain const& _bc) { - setUncles(_bc); - commitToMine(); + commitToMine(_bc); // Update difficulty according to timestamp. m_currentBlock.difficulty = m_currentBlock.calculateDifficulty(m_previousBlock); @@ -683,8 +682,20 @@ LogBloom State::logBloom() const return ret; } -void State::setUncles(BlockChain const& _bc) +void State::commitToMine(BlockChain const& _bc) { + uncommitToMine(); + +// cnote << "Committing to mine on block" << m_previousBlock.hash.abridged(); +#ifdef ETH_PARANOIA + commit(); + cnote << "Pre-reward stateRoot:" << m_state.root(); +#endif + + m_lastTx = m_db; + + Addresses uncleAddresses; + RLPStream unclesData; unsigned unclesCount = 0; if (m_previousBlock != BlockChain::genesis()) @@ -703,26 +714,11 @@ void State::setUncles(BlockChain const& _bc) BlockInfo ubi(_bc.block(u)); ubi.streamRLP(unclesData, WithNonce); ++unclesCount; + uncleAddresses.push_back(ubi.coinbaseAddress); } } } - RLPStream(unclesCount).appendRaw(unclesData.out(), unclesCount).swapOut(m_currentUncles); - m_currentBlock.sha3Uncles = sha3(m_currentUncles); -} - -void State::commitToMine() -{ - uncommitToMine(); - -// cnote << "Committing to mine on block" << m_previousBlock.hash.abridged(); -#ifdef ETH_PARANOIA - commit(); - cnote << "Pre-reward stateRoot:" << m_state.root(); -#endif - - m_lastTx = m_db; - MemoryDB tm; GenericTrieDB transactionsTrie(&tm); transactionsTrie.init(); @@ -752,13 +748,12 @@ void State::commitToMine() txs.swapOut(m_currentTxs); + RLPStream(unclesCount).appendRaw(unclesData.out(), unclesCount).swapOut(m_currentUncles); + m_currentBlock.transactionsRoot = transactionsTrie.root(); m_currentBlock.receiptsRoot = receiptsTrie.root(); m_currentBlock.logBloom = logBloom(); - - Addresses uncleAddresses; - for (const auto& r: RLP(m_currentUncles)) - uncleAddresses.push_back(BlockInfo::fromHeader(r.data()).coinbaseAddress); + m_currentBlock.sha3Uncles = sha3(m_currentUncles); // Apply rewards last of all. applyRewards(uncleAddresses); diff --git a/libethereum/State.h b/libethereum/State.h index 313cc5c44..0a288238d 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -105,16 +105,13 @@ public: /// @returns true if all is ok. If it's false, worry. bool amIJustParanoid(BlockChain const& _bc); - /// @brief Loads current block uncles from blockchain - void setUncles(BlockChain const& _bc); - /// Prepares the current state for mining. /// Commits all transactions into the trie, compiles uncles and transactions list, applies all /// rewards and populates the current block header with the appropriate hashes. /// The only thing left to do after this is to actually mine(). /// /// This may be called multiple times and without issue. - void commitToMine(); + void commitToMine(BlockChain const& _bc); /// Attempt to find valid nonce for block that this state represents. /// This function is thread-safe. You can safely have other interactions with this object while it is happening. @@ -125,11 +122,14 @@ public: /** Commit to DB and build the final block if the previous call to mine()'s result is completion. * Typically looks like: * @code + * while (notYetMined) + * { * // lock - * commitToMine(); + * commitToMine(_blockChain); // will call uncommitToMine if a repeat. * // unlock * MineInfo info; * for (info.complete = false; !info.complete; info = mine()) {} + * } * // lock * completeMine(); * // unlock diff --git a/mix/MixClient.cpp b/mix/MixClient.cpp index 293d4036e..a6c833532 100644 --- a/mix/MixClient.cpp +++ b/mix/MixClient.cpp @@ -56,16 +56,15 @@ void MixClient::resetState(u256 _balance) genesis.state = m_state; Block open; m_blocks = Blocks { genesis, open }; //last block contains a list of pending transactions to be finalized - m_lastHashes.clear(); - m_lastHashes.resize(256); - m_lastHashes[0] = genesis.hash; +// m_lastHashes.clear(); +// m_lastHashes.resize(256); +// m_lastHashes[0] = genesis.hash; } void MixClient::executeTransaction(Transaction const& _t, State& _state) { bytes rlp = _t.rlp(); - - Executive execution(_state, m_lastHashes, 0); + Executive execution(_state, LastHashes(), 0); execution.setup(&rlp); std::vector machineStates; std::vector levels; @@ -165,14 +164,12 @@ void MixClient::mine() Block& block = m_blocks.back(); m_state.mine(0, true); m_state.completeMine(); - m_state.commitToMine(); + m_state.commitToMine(BlockChain()); + m_state.cleanup(true); block.state = m_state; block.info = m_state.info(); block.hash = block.info.hash; - m_state.cleanup(true); m_blocks.push_back(Block()); - m_lastHashes.insert(m_lastHashes.begin(), block.hash); - m_lastHashes.resize(256); h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter }; noteChanged(changed); diff --git a/mix/MixClient.h b/mix/MixClient.h index dceb9ce7b..fede1891e 100644 --- a/mix/MixClient.h +++ b/mix/MixClient.h @@ -145,7 +145,6 @@ private: std::map m_filters; std::map m_watches; Blocks m_blocks; - eth::LastHashes m_lastHashes; }; } diff --git a/test/stateOriginal.cpp b/test/stateOriginal.cpp index f4804c43b..b1a7c0d8e 100644 --- a/test/stateOriginal.cpp +++ b/test/stateOriginal.cpp @@ -51,7 +51,7 @@ int stateTest() cout << s; // Mine to get some ether! - s.commitToMine(); + s.commitToMine(bc); while (!s.mine(100).completed) {} s.completeMine(); bc.attemptImport(s.blockData(), stateDB); @@ -74,8 +74,9 @@ int stateTest() cout << s; // Mine to get some ether and set in stone. - s.commitToMine(); - while (!s.mine(100).completed) {} + s.commitToMine(bc); + s.commitToMine(bc); + while (!s.mine(50).completed) { s.commitToMine(bc); } s.completeMine(); bc.attemptImport(s.blockData(), stateDB); From 7ff02f022996499df9c1a4b4b556a1ca978a4bbf Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 3 Feb 2015 09:34:57 +0100 Subject: [PATCH 32/55] fixed shell script error, when we were building target without qml files --- macdeployfix.sh | 7 +++++++ 1 file changed, 7 insertions(+) mode change 100644 => 100755 macdeployfix.sh diff --git a/macdeployfix.sh b/macdeployfix.sh old mode 100644 new mode 100755 index 0ff547d35..9a6ce1ebc --- a/macdeployfix.sh +++ b/macdeployfix.sh @@ -7,6 +7,12 @@ BUILD_FOLDER_PATH=$1 BUILD_QML_FOLDER_PATH="$BUILD_FOLDER_PATH/Resources/qml" BUILD_PLUGINS_FOLDER_PATH="$BUILD_FOLDER_PATH/PlugIns" +if [ ! -d ${BUILD_QML_FOLDER_PATH} ]; then + # we are not using any qml files + # gracefully exit + exit 0 +fi + declare -a BROKEN_FILES; k=0; for j in $(find ${BUILD_QML_FOLDER_PATH} -name *.dylib); do @@ -36,3 +42,4 @@ for i in "${BROKEN_FILES[@]}"; do REMOVE_BROKEN_ALIAS=$(rm -rf $i) RESULT=$(ln -s $s $i) done + From 51e2c1424d75317c791755e8ecf696f0b59c3729 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 3 Feb 2015 11:38:25 +0100 Subject: [PATCH 33/55] Change behavior when running/deleting the default state. --- mix/qml/StateDialog.qml | 14 ++------ mix/qml/StateList.qml | 2 +- mix/qml/StateListModel.qml | 65 ++++++++++++++++++++------------------ mix/qml/main.qml | 17 ++++++++-- 4 files changed, 53 insertions(+), 45 deletions(-) diff --git a/mix/qml/StateDialog.qml b/mix/qml/StateDialog.qml index 37e36621e..9e5c60d3d 100644 --- a/mix/qml/StateDialog.qml +++ b/mix/qml/StateDialog.qml @@ -17,12 +17,11 @@ Window { property alias stateTitle: titleField.text property alias stateBalance: balanceField.value - property alias isDefault: defaultCheckBox.checked property int stateIndex property var stateTransactions: [] signal accepted - function open(index, item, setDefault) { + function open(index, item) { stateIndex = index; stateTitle = item.title; balanceField.value = item.balance; @@ -33,7 +32,6 @@ Window { transactionsModel.append(item.transactions[t]); stateTransactions.push(item.transactions[t]); } - isDefault = setDefault; visible = true; titleField.focus = true; } @@ -79,14 +77,6 @@ Window { Layout.fillWidth: true } - Label { - text: qsTr("Default") - } - CheckBox { - id: defaultCheckBox - Layout.fillWidth: true - } - Label { text: qsTr("Transactions") } @@ -167,7 +157,7 @@ Window { onClicked: transactionsModel.editTransaction(index) } ToolButton { - visible: !transactionsModel.get(index).executeConstructor + visible: index >= 0 ? !transactionsModel.get(index).executeConstructor : false text: qsTr("Delete"); Layout.fillHeight: true onClicked: transactionsModel.deleteTransaction(index) diff --git a/mix/qml/StateList.qml b/mix/qml/StateList.qml index c20d1379d..3674e0dbc 100644 --- a/mix/qml/StateList.qml +++ b/mix/qml/StateList.qml @@ -48,7 +48,7 @@ Rectangle { onClicked: list.model.editState(index); } ToolButton { - visible: !list.model.isDefaultState(index) + visible: list.model.count - 1 != index text: qsTr("Delete"); Layout.fillHeight: true onClicked: list.model.deleteState(index); diff --git a/mix/qml/StateListModel.qml b/mix/qml/StateListModel.qml index 5a4722e84..0b5645d37 100644 --- a/mix/qml/StateListModel.qml +++ b/mix/qml/StateListModel.qml @@ -8,7 +8,7 @@ import "js/QEtherHelper.js" as QEtherHelper Item { - property int defaultStateIndex: -1 + property int defaultStateIndex: 0 property alias model: stateListModel property var stateList: [] @@ -70,20 +70,7 @@ Item { stateListModel.clear(); stateList = []; } - onProjectLoaded: { - if (!projectData.states) - projectData.states = []; - if (projectData.defaultStateIndex !== undefined) - defaultStateIndex = projectData.defaultStateIndex; - else - defaultStateIndex = -1; - var items = projectData.states; - for(var i = 0; i < items.length; i++) { - var item = fromPlainStateItem(items[i]); - stateListModel.append(item); - stateList.push(item); - } - } + onProjectLoaded: stateListModel.loadStatesFromProject(projectData); onProjectSaving: { projectData.states = [] for(var i = 0; i < stateListModel.count; i++) { @@ -103,18 +90,16 @@ Item { id: stateDialog onAccepted: { var item = stateDialog.getItem(); - if (stateDialog.stateIndex < stateListModel.count) { - if (stateDialog.isDefault) - defaultStateIndex = stateIndex; + if (stateDialog.stateIndex < stateListModel.count) + { stateList[stateDialog.stateIndex] = item; stateListModel.set(stateDialog.stateIndex, item); - } else { - if (stateDialog.isDefault) - defaultStateIndex = 0; + } + else + { stateList.push(item); stateListModel.append(item); } - stateListModel.save(); } } @@ -126,6 +111,9 @@ Item { ListModel { id: stateListModel + signal defaultStateChanged; + signal stateListModelReady; + function defaultTransactionItem() { return { value: QEtherHelper.createEther("100", QEther.Wei), @@ -164,11 +152,11 @@ Item { function addState() { var item = createDefaultState(); - stateDialog.open(stateListModel.count, item, defaultStateIndex === -1); + stateDialog.open(stateListModel.count, item); } function editState(index) { - stateDialog.open(index, stateList[index], defaultStateIndex === index); + stateDialog.open(index, stateList[index]); } function debugDefaultState() { @@ -176,11 +164,6 @@ Item { runState(defaultStateIndex); } - function isDefaultState(index) - { - return index === defaultStateIndex; - } - function runState(index) { var item = stateList[index]; clientModel.setupState(item); @@ -190,12 +173,34 @@ Item { stateListModel.remove(index); stateList.splice(index, 1); if (index === defaultStateIndex) - defaultStateIndex = -1; + defaultStateChanged(); save(); } function save() { projectModel.saveProject(); } + + function defaultStateName() + { + return stateList[defaultStateIndex].title; + } + + function loadStatesFromProject(projectData) + { + if (!projectData.states) + projectData.states = []; + if (projectData.defaultStateIndex !== undefined) + defaultStateIndex = projectData.defaultStateIndex; + else + defaultStateIndex = 0; + var items = projectData.states; + for(var i = 0; i < items.length; i++) { + var item = fromPlainStateItem(items[i]); + stateListModel.append(item); + stateList.push(item); + } + stateListModelReady(); + } } } diff --git a/mix/qml/main.qml b/mix/qml/main.qml index a0a4ba423..2e939fa12 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -34,7 +34,7 @@ ApplicationWindow { MenuItem { action: exitAppAction } } Menu { - title: qsTr("Debug") + title: qsTr("Deploy") MenuItem { action: debugRunAction } MenuItem { action: debugResetStateAction } MenuItem { action: mineAction } @@ -87,9 +87,22 @@ ApplicationWindow { onTriggered: clientModel.mine(); enabled: codeModel.hasContract && !clientModel.running } + + Connections { + target: projectModel.stateListModel + onDefaultStateChanged: + { + debugRunAction.text = "&Deploy" + " \"" + projectModel.stateListModel.defaultStateName() + "\""; + } + onStateListModelReady: + { + debugRunAction.text = "&Deploy" + " \"" + projectModel.stateListModel.defaultStateName() + "\""; + } + } + Action { id: debugRunAction - text: "&Run" + text: "&Deploy" shortcut: "F5" onTriggered: mainContent.startQuickDebugging() enabled: codeModel.hasContract && !clientModel.running From edea2145f9e62adbb94ea717cd49a807ba0c4f53 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 3 Feb 2015 15:08:09 +0100 Subject: [PATCH 34/55] misc --- mix/qml/main.qml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mix/qml/main.qml b/mix/qml/main.qml index 2ca2bc133..a90c90feb 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -94,11 +94,11 @@ ApplicationWindow { target: projectModel.stateListModel onDefaultStateChanged: { - debugRunAction.text = "&Deploy" + " \"" + projectModel.stateListModel.defaultStateName() + "\""; + debugRunAction.text = qsTr("Deploy") + " \"" + projectModel.stateListModel.defaultStateName() + "\""; } onStateListModelReady: { - debugRunAction.text = "&Deploy" + " \"" + projectModel.stateListModel.defaultStateName() + "\""; + debugRunAction.text = qsTr("Deploy") + " \"" + projectModel.stateListModel.defaultStateName() + "\""; } } From 068d8e4ebb46b7a96567130717b046a262634820 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 3 Feb 2015 15:40:34 +0100 Subject: [PATCH 35/55] verify_app instead of fixup_bundle --- cmake/EthExecutableHelper.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/EthExecutableHelper.cmake b/cmake/EthExecutableHelper.cmake index be45031ce..b8276fe54 100644 --- a/cmake/EthExecutableHelper.cmake +++ b/cmake/EthExecutableHelper.cmake @@ -86,8 +86,8 @@ macro(eth_install_executable EXECUTABLE) # TODO check, how fixup_bundle works and if it is required install(CODE " include(BundleUtilities) - set(BU_CHMOD_BUNDLE_ITEMS 1) - fixup_bundle(\"${APP_BUNDLE_PATH}\" \"${BUNDLELIBS}\" \"../libqethereum ../libethereum ../secp256k1\") + set(BU_CHMOD_BUNDLE_ITEMS 1) + verify_app(\"${APP_BUNDLE_PATH}\") " COMPONENT RUNTIME ) # Cleanup duplicate libs from macdeployqt install(CODE " From 1e60fb5d095d59e2bf9ab00182089227b0dbcce2 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 3 Feb 2015 16:05:52 +0100 Subject: [PATCH 36/55] add checkbox in statedialog. --- mix/qml/StateDialog.qml | 15 ++++++++++++++- mix/qml/StateListModel.qml | 20 +++++++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/mix/qml/StateDialog.qml b/mix/qml/StateDialog.qml index 9e5c60d3d..a2f9b7fa8 100644 --- a/mix/qml/StateDialog.qml +++ b/mix/qml/StateDialog.qml @@ -17,11 +17,12 @@ Window { property alias stateTitle: titleField.text property alias stateBalance: balanceField.value + property alias isDefault: defaultCheckBox.checked property int stateIndex property var stateTransactions: [] signal accepted - function open(index, item) { + function open(index, item, setDefault) { stateIndex = index; stateTitle = item.title; balanceField.value = item.balance; @@ -33,7 +34,10 @@ Window { stateTransactions.push(item.transactions[t]); } visible = true; + isDefault = setDefault; titleField.focus = true; + defaultCheckBox.enabled = !isDefault; + } function close() { @@ -77,6 +81,15 @@ Window { Layout.fillWidth: true } + Label { + text: qsTr("Default") + } + CheckBox { + id: defaultCheckBox + Layout.fillWidth: true + } + + Label { text: qsTr("Transactions") } diff --git a/mix/qml/StateListModel.qml b/mix/qml/StateListModel.qml index f87ecbea0..a1b24fe0f 100644 --- a/mix/qml/StateListModel.qml +++ b/mix/qml/StateListModel.qml @@ -125,16 +125,19 @@ Item { id: stateDialog onAccepted: { var item = stateDialog.getItem(); - if (stateDialog.stateIndex < stateListModel.count) - { + if (stateDialog.stateIndex < stateListModel.count) { + if (stateDialog.isDefault) + defaultStateIndex = stateIndex; stateList[stateDialog.stateIndex] = item; stateListModel.set(stateDialog.stateIndex, item); - } - else - { + } else { + if (stateDialog.isDefault) + defaultStateIndex = 0; stateList.push(item); stateListModel.append(item); } + if (stateDialog.isDefault) + stateListModel.defaultStateChanged(); stateListModel.save(); } } @@ -187,11 +190,11 @@ Item { function addState() { var item = createDefaultState(); - stateDialog.open(stateListModel.count, item); + stateDialog.open(stateListModel.count, item, false); } function editState(index) { - stateDialog.open(index, stateList[index]); + stateDialog.open(index, stateList[index], defaultStateIndex === index); } function debugDefaultState() { @@ -208,7 +211,10 @@ Item { stateListModel.remove(index); stateList.splice(index, 1); if (index === defaultStateIndex) + { + defaultStateIndex = 0; defaultStateChanged(); + } save(); } From 699bed10c09a86983f357d3c2fd421c2dc28a2f6 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 3 Feb 2015 16:31:18 +0100 Subject: [PATCH 37/55] Squashed 'libjsqrc/ethereumjs/' changes from d516691..f1a5cf9 f1a5cf9 Merge branch 'develop' into cpp a5909d8 parsing events output 1860b3d gulp 03faec9 event outputParser && tests 4bb5ba7 reverted ethereum.js 9d9c23e common cleanup 1a6b7de removed splitter.qml 011fdd9 event_inc example 0994efa Better HTML template in Mix. Use happened in JS. Debugging QML enabled. git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: f1a5cf9128170b85428259c8b0ecfaed5b3e17d1 --- dist/ethereum.js | 199 ++++++++++++++++++++++++++----------- dist/ethereum.js.map | 14 +-- dist/ethereum.min.js | 2 +- example/event_inc.html | 66 ++++++++++++ lib/const.js | 23 +++++ lib/contract.js | 11 +- lib/event.js | 72 +++++++++++++- lib/filter.js | 8 +- lib/utils.js | 31 +++++- lib/web3.js | 52 +--------- test/event.inputParser.js | 125 +++++++++++++++++++++++ test/event.js | 124 ----------------------- test/event.outputParser.js | 81 +++++++++++++++ 13 files changed, 561 insertions(+), 247 deletions(-) create mode 100644 example/event_inc.html create mode 100644 test/event.inputParser.js delete mode 100644 test/event.js create mode 100644 test/event.outputParser.js diff --git a/dist/ethereum.js b/dist/ethereum.js index 817b55852..0a83a3c50 100644 --- a/dist/ethereum.js +++ b/dist/ethereum.js @@ -238,9 +238,32 @@ if ("build" !== 'build') {/* var BigNumber = require('bignumber.js'); // jshint ignore:line */} +var ETH_UNITS = [ + 'wei', + 'Kwei', + 'Mwei', + 'Gwei', + 'szabo', + 'finney', + 'ether', + 'grand', + 'Mether', + 'Gether', + 'Tether', + 'Pether', + 'Eether', + 'Zether', + 'Yether', + 'Nether', + 'Dether', + 'Vether', + 'Uether' +]; + module.exports = { ETH_PADDING: 32, ETH_SIGNATURE_LENGTH: 4, + ETH_UNITS: ETH_UNITS, ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN } }; @@ -368,6 +391,11 @@ var addFunctionsToContract = function (contract, desc, address) { var addEventRelatedPropertiesToContract = function (contract, desc, address) { contract.address = address; + contract._onWatchEventResult = function (data) { + var matchingEvent = event.getMatchingEvent(utils.filterEvents(desc)); + var parser = eventImpl.outputParser(matchingEvent); + return parser(data); + }; Object.defineProperty(contract, 'topic', { get: function() { @@ -386,8 +414,12 @@ var addEventsToContract = function (contract, desc, address) { var impl = function () { var params = Array.prototype.slice.call(arguments); var signature = abi.eventSignatureFromAscii(e.name); - var event = eventImpl(address, signature, e); + var event = eventImpl.inputParser(address, signature, e); var o = event.apply(null, params); + o._onWatchEventResult = function (data) { + var parser = eventImpl.outputParser(e); + return parser(data); + }; return web3.eth.watch(o); }; @@ -481,6 +513,16 @@ module.exports = contract; var abi = require('./abi'); var utils = require('./utils'); +/// filter inputs array && returns only indexed (or not) inputs +/// @param inputs array +/// @param bool if result should be an array of indexed params on not +/// @returns array of (not?) indexed params +var filterInputs = function (inputs, indexed) { + return inputs.filter(function (current) { + return current.indexed === indexed; + }); +}; + var inputWithName = function (inputs, name) { var index = utils.findIndex(inputs, function (input) { return input.name === name; @@ -496,7 +538,7 @@ var inputWithName = function (inputs, name) { var indexedParamsToTopics = function (event, indexed) { // sort keys? return Object.keys(indexed).map(function (key) { - var inputs = [inputWithName(event.inputs, key)]; + var inputs = [inputWithName(filterInputs(event.inputs, true), key)]; var value = indexed[key]; if (value instanceof Array) { @@ -508,7 +550,7 @@ var indexedParamsToTopics = function (event, indexed) { }); }; -var implementationOfEvent = function (address, signature, event) { +var inputParser = function (address, signature, event) { // valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch' return function (indexed, options) { @@ -523,7 +565,63 @@ var implementationOfEvent = function (address, signature, event) { }; }; -module.exports = implementationOfEvent; +var getArgumentsObject = function (inputs, indexed, notIndexed) { + var indexedCopy = indexed.slice(); + var notIndexedCopy = notIndexed.slice(); + return inputs.reduce(function (acc, current) { + var value; + if (current.indexed) + value = indexed.splice(0, 1)[0]; + else + value = notIndexed.splice(0, 1)[0]; + + acc[current.name] = value; + return acc; + }, {}); +}; + +var outputParser = function (event) { + + return function (output) { + var result = { + event: utils.extractDisplayName(event.name), + number: output.number, + args: {} + }; + + if (!output.topic) { + return result; + } + + var indexedOutputs = filterInputs(event.inputs, true); + var indexedData = "0x" + output.topic.slice(1, output.topic.length).map(function (topic) { return topic.slice(2); }).join(""); + var indexedRes = abi.formatOutput(indexedOutputs, indexedData); + + var notIndexedOutputs = filterInputs(event.inputs, false); + var notIndexedRes = abi.formatOutput(notIndexedOutputs, output.data); + + result.args = getArgumentsObject(event.inputs, indexedRes, notIndexedRes); + + return result; + }; +}; + +var getMatchingEvent = function (events, payload) { + for (var i = 0; i < events.length; i++) { + var signature = abi.eventSignatureFromAscii(events[i].name); + if (signature === payload.topic[0]) { + return events[i]; + } + } + return undefined; +}; + + +module.exports = { + inputParser: inputParser, + outputParser: outputParser, + getMatchingEvent: getMatchingEvent +}; },{"./abi":1,"./utils":11}],5:[function(require,module,exports){ @@ -565,6 +663,8 @@ var Filter = function(options, impl) { if (options.topics) { console.warn('"topics" is deprecated, use "topic" instead'); } + + this._onWatchResult = options._onWatchEventResult; // evaluate lazy properties options = { @@ -590,6 +690,9 @@ var Filter = function(options, impl) { Filter.prototype.arrived = function(callback) { this.changed(callback); }; +Filter.prototype.happened = function(callback) { + this.changed(callback); +}; /// gets called when there is new eth/shh message Filter.prototype.changed = function(callback) { @@ -600,7 +703,8 @@ Filter.prototype.changed = function(callback) { Filter.prototype.trigger = function(messages) { for (var i = 0; i < this.callbacks.length; i++) { for (var j = 0; j < messages.length; j++) { - this.callbacks[i].call(this, messages[j]); + var message = this._onWatchResult ? this._onWatchResult(messages[j]) : messages[j]; + this.callbacks[i].call(this, message); } } }; @@ -1101,6 +1205,8 @@ module.exports = { * @date 2015 */ +var c = require('./const'); + /// Finds first index of array element matching pattern /// @param array /// @param callback pattern @@ -1182,6 +1288,32 @@ var filterEvents = function (json) { }); }; +/// used to transform value/string to eth string +/// TODO: use BigNumber.js to parse int +/// TODO: add tests for it! +var toEth = function (str) { + var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str; + var unit = 0; + var units = c.ETH_UNITS; + while (val > 3000 && unit < units.length - 1) + { + val /= 1000; + unit++; + } + var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2); + var replaceFunction = function($0, $1, $2) { + return $1 + ',' + $2; + }; + + while (true) { + var o = s; + s = s.replace(/(\d)(\d\d\d[\.\,])/, replaceFunction); + if (o === s) + break; + } + return s + ' ' + units[unit]; +}; + module.exports = { findIndex: findIndex, toAscii: toAscii, @@ -1189,11 +1321,12 @@ module.exports = { extractDisplayName: extractDisplayName, extractTypeName: extractTypeName, filterFunctions: filterFunctions, - filterEvents: filterEvents + filterEvents: filterEvents, + toEth: toEth }; -},{}],12:[function(require,module,exports){ +},{"./const":2}],12:[function(require,module,exports){ /* This file is part of ethereum.js. @@ -1225,28 +1358,6 @@ if ("build" !== 'build') {/* var utils = require('./utils'); -var ETH_UNITS = [ - 'wei', - 'Kwei', - 'Mwei', - 'Gwei', - 'szabo', - 'finney', - 'ether', - 'grand', - 'Mether', - 'Gether', - 'Tether', - 'Pether', - 'Eether', - 'Zether', - 'Yether', - 'Nether', - 'Dether', - 'Vether', - 'Uether' -]; - /// @returns an array of objects describing web3 api methods var web3Methods = function () { return [ @@ -1409,29 +1520,7 @@ var web3 = { }, /// used to transform value/string to eth string - /// TODO: use BigNumber.js to parse int - toEth: function(str) { - var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str; - var unit = 0; - var units = ETH_UNITS; - while (val > 3000 && unit < units.length - 1) - { - val /= 1000; - unit++; - } - var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2); - var replaceFunction = function($0, $1, $2) { - return $1 + ',' + $2; - }; - - while (true) { - var o = s; - s = s.replace(/(\d)(\d\d\d[\.\,])/, replaceFunction); - if (o === s) - break; - } - return s + ' ' + units[unit]; - }, + toEth: utils.toEth, /// eth object prototype eth: { @@ -1467,11 +1556,6 @@ var web3 = { return new web3.filter(filter, shhWatch); } }, - - /// @returns true if provider is installed - haveProvider: function() { - return !!web3.provider.provider; - } }; /// setups all api methods @@ -1494,7 +1578,6 @@ var shhWatch = { setupMethods(shhWatch, shhWatchMethods()); web3.setProvider = function(provider) { - //provider.onmessage = messageHandler; // there will be no async calls, to remove web3.provider.set(provider); }; diff --git a/dist/ethereum.js.map b/dist/ethereum.js.map index 81a7e3747..2c1bebd75 100644 --- a/dist/ethereum.js.map +++ b/dist/ethereum.js.map @@ -17,23 +17,23 @@ "index.js" ], "names": [], - "mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/FA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1JA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClTA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA", + "mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1JA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9IA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA", "file": "generated.js", "sourceRoot": "", "sourcesContent": [ "(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o.\n*/\n/** @file abi.js\n * @authors:\n * Marek Kotewicz \n * Gav Wood \n * @date 2014\n */\n\nvar web3 = require('./web3'); \nvar utils = require('./utils');\nvar types = require('./types');\nvar c = require('./const');\nvar f = require('./formatters');\n\nvar displayTypeError = function (type) {\n console.error('parser does not support type: ' + type);\n};\n\n/// This method should be called if we want to check if givent type is an array type\n/// @returns true if it is, otherwise false\nvar arrayType = function (type) {\n return type.slice(-2) === '[]';\n};\n\nvar dynamicTypeBytes = function (type, value) {\n // TODO: decide what to do with array of strings\n if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length.\n return f.formatInputInt(value.length); \n return \"\";\n};\n\nvar inputTypes = types.inputTypes(); \n\n/// Formats input params to bytes\n/// @param abi contract method inputs\n/// @param array of params that will be formatted to bytes\n/// @returns bytes representation of input params\nvar formatInput = function (inputs, params) {\n var bytes = \"\";\n var padding = c.ETH_PADDING * 2;\n\n /// first we iterate in search for dynamic \n inputs.forEach(function (input, index) {\n bytes += dynamicTypeBytes(input.type, params[index]);\n });\n\n inputs.forEach(function (input, i) {\n var typeMatch = false;\n for (var j = 0; j < inputTypes.length && !typeMatch; j++) {\n typeMatch = inputTypes[j].type(inputs[i].type, params[i]);\n }\n if (!typeMatch) {\n displayTypeError(inputs[i].type);\n }\n\n var formatter = inputTypes[j - 1].format;\n var toAppend = \"\";\n\n if (arrayType(inputs[i].type))\n toAppend = params[i].reduce(function (acc, curr) {\n return acc + formatter(curr);\n }, \"\");\n else\n toAppend = formatter(params[i]);\n\n bytes += toAppend; \n });\n return bytes;\n};\n\nvar dynamicBytesLength = function (type) {\n if (arrayType(type) || type === 'string') // only string itself that is dynamic; stringX is static length.\n return c.ETH_PADDING * 2;\n return 0;\n};\n\nvar outputTypes = types.outputTypes(); \n\n/// Formats output bytes back to param list\n/// @param contract abi method outputs\n/// @param bytes representtion of output \n/// @returns array of output params \nvar formatOutput = function (outs, output) {\n \n output = output.slice(2);\n var result = [];\n var padding = c.ETH_PADDING * 2;\n\n var dynamicPartLength = outs.reduce(function (acc, curr) {\n return acc + dynamicBytesLength(curr.type);\n }, 0);\n \n var dynamicPart = output.slice(0, dynamicPartLength);\n output = output.slice(dynamicPartLength);\n\n outs.forEach(function (out, i) {\n var typeMatch = false;\n for (var j = 0; j < outputTypes.length && !typeMatch; j++) {\n typeMatch = outputTypes[j].type(outs[i].type);\n }\n\n if (!typeMatch) {\n displayTypeError(outs[i].type);\n }\n\n var formatter = outputTypes[j - 1].format;\n if (arrayType(outs[i].type)) {\n var size = f.formatOutputUInt(dynamicPart.slice(0, padding));\n dynamicPart = dynamicPart.slice(padding);\n var array = [];\n for (var k = 0; k < size; k++) {\n array.push(formatter(output.slice(0, padding))); \n output = output.slice(padding);\n }\n result.push(array);\n }\n else if (types.prefixedType('string')(outs[i].type)) {\n dynamicPart = dynamicPart.slice(padding); \n result.push(formatter(output.slice(0, padding)));\n output = output.slice(padding);\n } else {\n result.push(formatter(output.slice(0, padding)));\n output = output.slice(padding);\n }\n });\n\n return result;\n};\n\n/// @param json abi for contract\n/// @returns input parser object for given json abi\n/// TODO: refactor creating the parser, do not double logic from contract\nvar inputParser = function (json) {\n var parser = {};\n json.forEach(function (method) {\n var displayName = utils.extractDisplayName(method.name); \n var typeName = utils.extractTypeName(method.name);\n\n var impl = function () {\n var params = Array.prototype.slice.call(arguments);\n return formatInput(method.inputs, params);\n };\n \n if (parser[displayName] === undefined) {\n parser[displayName] = impl;\n }\n\n parser[displayName][typeName] = impl;\n });\n\n return parser;\n};\n\n/// @param json abi for contract\n/// @returns output parser for given json abi\nvar outputParser = function (json) {\n var parser = {};\n json.forEach(function (method) {\n\n var displayName = utils.extractDisplayName(method.name); \n var typeName = utils.extractTypeName(method.name);\n\n var impl = function (output) {\n return formatOutput(method.outputs, output);\n };\n\n if (parser[displayName] === undefined) {\n parser[displayName] = impl;\n }\n\n parser[displayName][typeName] = impl;\n });\n\n return parser;\n};\n\n/// @param function/event name for which we want to get signature\n/// @returns signature of function/event with given name\nvar signatureFromAscii = function (name) {\n return web3.sha3(web3.fromAscii(name)).slice(0, 2 + c.ETH_SIGNATURE_LENGTH * 2);\n};\n\nvar eventSignatureFromAscii = function (name) {\n return web3.sha3(web3.fromAscii(name));\n};\n\nmodule.exports = {\n inputParser: inputParser,\n outputParser: outputParser,\n formatInput: formatInput,\n formatOutput: formatOutput,\n signatureFromAscii: signatureFromAscii,\n eventSignatureFromAscii: eventSignatureFromAscii\n};\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file const.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\n/// required to define ETH_BIGNUMBER_ROUNDING_MODE\nif (\"build\" !== 'build') {/*\n var BigNumber = require('bignumber.js'); // jshint ignore:line\n*/}\n\nmodule.exports = {\n ETH_PADDING: 32,\n ETH_SIGNATURE_LENGTH: 4,\n ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }\n};\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file contract.js\n * @authors:\n * Marek Kotewicz \n * @date 2014\n */\n\nvar web3 = require('./web3'); \nvar abi = require('./abi');\nvar utils = require('./utils');\nvar eventImpl = require('./event');\n\nvar exportNatspecGlobals = function (vars) {\n // it's used byt natspec.js\n // TODO: figure out better way to solve this\n web3._currentContractAbi = vars.abi;\n web3._currentContractAddress = vars.address;\n web3._currentContractMethodName = vars.method;\n web3._currentContractMethodParams = vars.params;\n};\n\nvar addFunctionRelatedPropertiesToContract = function (contract) {\n \n contract.call = function (options) {\n contract._isTransact = false;\n contract._options = options;\n return contract;\n };\n\n contract.transact = function (options) {\n contract._isTransact = true;\n contract._options = options;\n return contract;\n };\n\n contract._options = {};\n ['gas', 'gasPrice', 'value', 'from'].forEach(function(p) {\n contract[p] = function (v) {\n contract._options[p] = v;\n return contract;\n };\n });\n\n};\n\nvar addFunctionsToContract = function (contract, desc, address) {\n var inputParser = abi.inputParser(desc);\n var outputParser = abi.outputParser(desc);\n\n // create contract functions\n utils.filterFunctions(desc).forEach(function (method) {\n\n var displayName = utils.extractDisplayName(method.name);\n var typeName = utils.extractTypeName(method.name);\n\n var impl = function () {\n var params = Array.prototype.slice.call(arguments);\n var signature = abi.signatureFromAscii(method.name);\n var parsed = inputParser[displayName][typeName].apply(null, params);\n\n var options = contract._options || {};\n options.to = address;\n options.data = signature + parsed;\n \n var isTransact = contract._isTransact === true || (contract._isTransact !== false && !method.constant);\n var collapse = options.collapse !== false;\n \n // reset\n contract._options = {};\n contract._isTransact = null;\n\n if (isTransact) {\n \n exportNatspecGlobals({\n abi: desc,\n address: address,\n method: method.name,\n params: params\n });\n\n // transactions do not have any output, cause we do not know, when they will be processed\n web3.eth.transact(options);\n return;\n }\n \n var output = web3.eth.call(options);\n var ret = outputParser[displayName][typeName](output);\n if (collapse)\n {\n if (ret.length === 1)\n ret = ret[0];\n else if (ret.length === 0)\n ret = null;\n }\n return ret;\n };\n\n if (contract[displayName] === undefined) {\n contract[displayName] = impl;\n }\n\n contract[displayName][typeName] = impl;\n });\n};\n\nvar addEventRelatedPropertiesToContract = function (contract, desc, address) {\n contract.address = address;\n \n Object.defineProperty(contract, 'topic', {\n get: function() {\n return utils.filterEvents(desc).map(function (e) {\n return abi.eventSignatureFromAscii(e.name);\n });\n }\n });\n\n};\n\nvar addEventsToContract = function (contract, desc, address) {\n // create contract events\n utils.filterEvents(desc).forEach(function (e) {\n\n var impl = function () {\n var params = Array.prototype.slice.call(arguments);\n var signature = abi.eventSignatureFromAscii(e.name);\n var event = eventImpl(address, signature, e);\n var o = event.apply(null, params);\n return web3.eth.watch(o); \n };\n \n // this property should be used by eth.filter to check if object is an event\n impl._isEvent = true;\n\n var displayName = utils.extractDisplayName(e.name);\n var typeName = utils.extractTypeName(e.name);\n\n if (contract[displayName] === undefined) {\n contract[displayName] = impl;\n }\n\n contract[displayName][typeName] = impl;\n\n });\n};\n\n\n/**\n * This method should be called when we want to call / transact some solidity method from javascript\n * it returns an object which has same methods available as solidity contract description\n * usage example: \n *\n * var abi = [{\n * name: 'myMethod',\n * inputs: [{ name: 'a', type: 'string' }],\n * outputs: [{name: 'd', type: 'string' }]\n * }]; // contract abi\n *\n * var myContract = web3.eth.contract('0x0123123121', abi); // creation of contract object\n *\n * myContract.myMethod('this is test string param for call'); // myMethod call (implicit, default)\n * myContract.call().myMethod('this is test string param for call'); // myMethod call (explicit)\n * myContract.transact().myMethod('this is test string param for transact'); // myMethod transact\n *\n * @param address - address of the contract, which should be called\n * @param desc - abi json description of the contract, which is being created\n * @returns contract object\n */\n\nvar contract = function (address, desc) {\n\n // workaround for invalid assumption that method.name is the full anonymous prototype of the method.\n // it's not. it's just the name. the rest of the code assumes it's actually the anonymous\n // prototype, so we make it so as a workaround.\n // TODO: we may not want to modify input params, maybe use copy instead?\n desc.forEach(function (method) {\n if (method.name.indexOf('(') === -1) {\n var displayName = method.name;\n var typeName = method.inputs.map(function(i){return i.type; }).join();\n method.name = displayName + '(' + typeName + ')';\n }\n });\n\n var result = {};\n addFunctionRelatedPropertiesToContract(result);\n addFunctionsToContract(result, desc, address);\n addEventRelatedPropertiesToContract(result, desc, address);\n addEventsToContract(result, desc, address);\n\n return result;\n};\n\nmodule.exports = contract;\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file event.js\n * @authors:\n * Marek Kotewicz \n * @date 2014\n */\n\nvar abi = require('./abi');\nvar utils = require('./utils');\n\nvar inputWithName = function (inputs, name) {\n var index = utils.findIndex(inputs, function (input) {\n return input.name === name;\n });\n \n if (index === -1) {\n console.error('indexed param with name ' + name + ' not found');\n return undefined;\n }\n return inputs[index];\n};\n\nvar indexedParamsToTopics = function (event, indexed) {\n // sort keys?\n return Object.keys(indexed).map(function (key) {\n var inputs = [inputWithName(event.inputs, key)];\n\n var value = indexed[key];\n if (value instanceof Array) {\n return value.map(function (v) {\n return abi.formatInput(inputs, [v]);\n }); \n }\n return abi.formatInput(inputs, [value]);\n });\n};\n\nvar implementationOfEvent = function (address, signature, event) {\n \n // valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch'\n return function (indexed, options) {\n var o = options || {};\n o.address = address;\n o.topic = [];\n o.topic.push(signature);\n if (indexed) {\n o.topic = o.topic.concat(indexedParamsToTopics(event, indexed));\n }\n return o;\n };\n};\n\nmodule.exports = implementationOfEvent;\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file filter.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nvar web3 = require('./web3'); // jshint ignore:line\n\n/// should be used when we want to watch something\n/// it's using inner polling mechanism and is notified about changes\n/// TODO: change 'options' name cause it may be not the best matching one, since we have events\nvar Filter = function(options, impl) {\n\n if (typeof options !== \"string\") {\n\n // topics property is deprecated, warn about it!\n if (options.topics) {\n console.warn('\"topics\" is deprecated, use \"topic\" instead');\n }\n\n // evaluate lazy properties\n options = {\n to: options.to,\n topic: options.topic,\n earliest: options.earliest,\n latest: options.latest,\n max: options.max,\n skip: options.skip,\n address: options.address\n };\n\n }\n \n this.impl = impl;\n this.callbacks = [];\n\n this.id = impl.newFilter(options);\n web3.provider.startPolling({call: impl.changed, args: [this.id]}, this.id, this.trigger.bind(this));\n};\n\n/// alias for changed*\nFilter.prototype.arrived = function(callback) {\n this.changed(callback);\n};\n\n/// gets called when there is new eth/shh message\nFilter.prototype.changed = function(callback) {\n this.callbacks.push(callback);\n};\n\n/// trigger calling new message from people\nFilter.prototype.trigger = function(messages) {\n for (var i = 0; i < this.callbacks.length; i++) {\n for (var j = 0; j < messages.length; j++) {\n this.callbacks[i].call(this, messages[j]);\n }\n }\n};\n\n/// should be called to uninstall current filter\nFilter.prototype.uninstall = function() {\n this.impl.uninstallFilter(this.id);\n web3.provider.stopPolling(this.id);\n};\n\n/// should be called to manually trigger getting latest messages from the client\nFilter.prototype.messages = function() {\n return this.impl.getMessages(this.id);\n};\n\n/// alias for messages\nFilter.prototype.logs = function () {\n return this.messages();\n};\n\nmodule.exports = Filter;\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file const.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\n/// required to define ETH_BIGNUMBER_ROUNDING_MODE\nif (\"build\" !== 'build') {/*\n var BigNumber = require('bignumber.js'); // jshint ignore:line\n*/}\n\nvar ETH_UNITS = [ \n 'wei', \n 'Kwei', \n 'Mwei', \n 'Gwei', \n 'szabo', \n 'finney', \n 'ether', \n 'grand', \n 'Mether', \n 'Gether', \n 'Tether', \n 'Pether', \n 'Eether', \n 'Zether', \n 'Yether', \n 'Nether', \n 'Dether', \n 'Vether', \n 'Uether' \n];\n\nmodule.exports = {\n ETH_PADDING: 32,\n ETH_SIGNATURE_LENGTH: 4,\n ETH_UNITS: ETH_UNITS,\n ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }\n};\n\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file contract.js\n * @authors:\n * Marek Kotewicz \n * @date 2014\n */\n\nvar web3 = require('./web3'); \nvar abi = require('./abi');\nvar utils = require('./utils');\nvar eventImpl = require('./event');\n\nvar exportNatspecGlobals = function (vars) {\n // it's used byt natspec.js\n // TODO: figure out better way to solve this\n web3._currentContractAbi = vars.abi;\n web3._currentContractAddress = vars.address;\n web3._currentContractMethodName = vars.method;\n web3._currentContractMethodParams = vars.params;\n};\n\nvar addFunctionRelatedPropertiesToContract = function (contract) {\n \n contract.call = function (options) {\n contract._isTransact = false;\n contract._options = options;\n return contract;\n };\n\n contract.transact = function (options) {\n contract._isTransact = true;\n contract._options = options;\n return contract;\n };\n\n contract._options = {};\n ['gas', 'gasPrice', 'value', 'from'].forEach(function(p) {\n contract[p] = function (v) {\n contract._options[p] = v;\n return contract;\n };\n });\n\n};\n\nvar addFunctionsToContract = function (contract, desc, address) {\n var inputParser = abi.inputParser(desc);\n var outputParser = abi.outputParser(desc);\n\n // create contract functions\n utils.filterFunctions(desc).forEach(function (method) {\n\n var displayName = utils.extractDisplayName(method.name);\n var typeName = utils.extractTypeName(method.name);\n\n var impl = function () {\n var params = Array.prototype.slice.call(arguments);\n var signature = abi.signatureFromAscii(method.name);\n var parsed = inputParser[displayName][typeName].apply(null, params);\n\n var options = contract._options || {};\n options.to = address;\n options.data = signature + parsed;\n \n var isTransact = contract._isTransact === true || (contract._isTransact !== false && !method.constant);\n var collapse = options.collapse !== false;\n \n // reset\n contract._options = {};\n contract._isTransact = null;\n\n if (isTransact) {\n \n exportNatspecGlobals({\n abi: desc,\n address: address,\n method: method.name,\n params: params\n });\n\n // transactions do not have any output, cause we do not know, when they will be processed\n web3.eth.transact(options);\n return;\n }\n \n var output = web3.eth.call(options);\n var ret = outputParser[displayName][typeName](output);\n if (collapse)\n {\n if (ret.length === 1)\n ret = ret[0];\n else if (ret.length === 0)\n ret = null;\n }\n return ret;\n };\n\n if (contract[displayName] === undefined) {\n contract[displayName] = impl;\n }\n\n contract[displayName][typeName] = impl;\n });\n};\n\nvar addEventRelatedPropertiesToContract = function (contract, desc, address) {\n contract.address = address;\n contract._onWatchEventResult = function (data) {\n var matchingEvent = event.getMatchingEvent(utils.filterEvents(desc));\n var parser = eventImpl.outputParser(matchingEvent);\n return parser(data);\n };\n \n Object.defineProperty(contract, 'topic', {\n get: function() {\n return utils.filterEvents(desc).map(function (e) {\n return abi.eventSignatureFromAscii(e.name);\n });\n }\n });\n\n};\n\nvar addEventsToContract = function (contract, desc, address) {\n // create contract events\n utils.filterEvents(desc).forEach(function (e) {\n\n var impl = function () {\n var params = Array.prototype.slice.call(arguments);\n var signature = abi.eventSignatureFromAscii(e.name);\n var event = eventImpl.inputParser(address, signature, e);\n var o = event.apply(null, params);\n o._onWatchEventResult = function (data) {\n var parser = eventImpl.outputParser(e);\n return parser(data);\n };\n return web3.eth.watch(o); \n };\n \n // this property should be used by eth.filter to check if object is an event\n impl._isEvent = true;\n\n var displayName = utils.extractDisplayName(e.name);\n var typeName = utils.extractTypeName(e.name);\n\n if (contract[displayName] === undefined) {\n contract[displayName] = impl;\n }\n\n contract[displayName][typeName] = impl;\n\n });\n};\n\n\n/**\n * This method should be called when we want to call / transact some solidity method from javascript\n * it returns an object which has same methods available as solidity contract description\n * usage example: \n *\n * var abi = [{\n * name: 'myMethod',\n * inputs: [{ name: 'a', type: 'string' }],\n * outputs: [{name: 'd', type: 'string' }]\n * }]; // contract abi\n *\n * var myContract = web3.eth.contract('0x0123123121', abi); // creation of contract object\n *\n * myContract.myMethod('this is test string param for call'); // myMethod call (implicit, default)\n * myContract.call().myMethod('this is test string param for call'); // myMethod call (explicit)\n * myContract.transact().myMethod('this is test string param for transact'); // myMethod transact\n *\n * @param address - address of the contract, which should be called\n * @param desc - abi json description of the contract, which is being created\n * @returns contract object\n */\n\nvar contract = function (address, desc) {\n\n // workaround for invalid assumption that method.name is the full anonymous prototype of the method.\n // it's not. it's just the name. the rest of the code assumes it's actually the anonymous\n // prototype, so we make it so as a workaround.\n // TODO: we may not want to modify input params, maybe use copy instead?\n desc.forEach(function (method) {\n if (method.name.indexOf('(') === -1) {\n var displayName = method.name;\n var typeName = method.inputs.map(function(i){return i.type; }).join();\n method.name = displayName + '(' + typeName + ')';\n }\n });\n\n var result = {};\n addFunctionRelatedPropertiesToContract(result);\n addFunctionsToContract(result, desc, address);\n addEventRelatedPropertiesToContract(result, desc, address);\n addEventsToContract(result, desc, address);\n\n return result;\n};\n\nmodule.exports = contract;\n\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file event.js\n * @authors:\n * Marek Kotewicz \n * @date 2014\n */\n\nvar abi = require('./abi');\nvar utils = require('./utils');\n\n/// filter inputs array && returns only indexed (or not) inputs\n/// @param inputs array\n/// @param bool if result should be an array of indexed params on not\n/// @returns array of (not?) indexed params\nvar filterInputs = function (inputs, indexed) {\n return inputs.filter(function (current) {\n return current.indexed === indexed;\n });\n};\n\nvar inputWithName = function (inputs, name) {\n var index = utils.findIndex(inputs, function (input) {\n return input.name === name;\n });\n \n if (index === -1) {\n console.error('indexed param with name ' + name + ' not found');\n return undefined;\n }\n return inputs[index];\n};\n\nvar indexedParamsToTopics = function (event, indexed) {\n // sort keys?\n return Object.keys(indexed).map(function (key) {\n var inputs = [inputWithName(filterInputs(event.inputs, true), key)];\n\n var value = indexed[key];\n if (value instanceof Array) {\n return value.map(function (v) {\n return abi.formatInput(inputs, [v]);\n }); \n }\n return abi.formatInput(inputs, [value]);\n });\n};\n\nvar inputParser = function (address, signature, event) {\n \n // valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch'\n return function (indexed, options) {\n var o = options || {};\n o.address = address;\n o.topic = [];\n o.topic.push(signature);\n if (indexed) {\n o.topic = o.topic.concat(indexedParamsToTopics(event, indexed));\n }\n return o;\n };\n};\n\nvar getArgumentsObject = function (inputs, indexed, notIndexed) {\n var indexedCopy = indexed.slice();\n var notIndexedCopy = notIndexed.slice();\n return inputs.reduce(function (acc, current) {\n var value;\n if (current.indexed)\n value = indexed.splice(0, 1)[0];\n else\n value = notIndexed.splice(0, 1)[0];\n\n acc[current.name] = value;\n return acc;\n }, {}); \n};\n \nvar outputParser = function (event) {\n \n return function (output) {\n var result = {\n event: utils.extractDisplayName(event.name),\n number: output.number,\n args: {}\n };\n\n if (!output.topic) {\n return result;\n }\n \n var indexedOutputs = filterInputs(event.inputs, true);\n var indexedData = \"0x\" + output.topic.slice(1, output.topic.length).map(function (topic) { return topic.slice(2); }).join(\"\");\n var indexedRes = abi.formatOutput(indexedOutputs, indexedData);\n\n var notIndexedOutputs = filterInputs(event.inputs, false);\n var notIndexedRes = abi.formatOutput(notIndexedOutputs, output.data);\n\n result.args = getArgumentsObject(event.inputs, indexedRes, notIndexedRes);\n\n return result;\n };\n};\n\nvar getMatchingEvent = function (events, payload) {\n for (var i = 0; i < events.length; i++) {\n var signature = abi.eventSignatureFromAscii(events[i].name); \n if (signature === payload.topic[0]) {\n return events[i];\n }\n }\n return undefined;\n};\n\n\nmodule.exports = {\n inputParser: inputParser,\n outputParser: outputParser,\n getMatchingEvent: getMatchingEvent\n};\n\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file filter.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nvar web3 = require('./web3'); // jshint ignore:line\n\n/// should be used when we want to watch something\n/// it's using inner polling mechanism and is notified about changes\n/// TODO: change 'options' name cause it may be not the best matching one, since we have events\nvar Filter = function(options, impl) {\n\n if (typeof options !== \"string\") {\n\n // topics property is deprecated, warn about it!\n if (options.topics) {\n console.warn('\"topics\" is deprecated, use \"topic\" instead');\n }\n \n this._onWatchResult = options._onWatchEventResult;\n\n // evaluate lazy properties\n options = {\n to: options.to,\n topic: options.topic,\n earliest: options.earliest,\n latest: options.latest,\n max: options.max,\n skip: options.skip,\n address: options.address\n };\n\n }\n \n this.impl = impl;\n this.callbacks = [];\n\n this.id = impl.newFilter(options);\n web3.provider.startPolling({call: impl.changed, args: [this.id]}, this.id, this.trigger.bind(this));\n};\n\n/// alias for changed*\nFilter.prototype.arrived = function(callback) {\n this.changed(callback);\n};\nFilter.prototype.happened = function(callback) {\n this.changed(callback);\n};\n\n/// gets called when there is new eth/shh message\nFilter.prototype.changed = function(callback) {\n this.callbacks.push(callback);\n};\n\n/// trigger calling new message from people\nFilter.prototype.trigger = function(messages) {\n for (var i = 0; i < this.callbacks.length; i++) {\n for (var j = 0; j < messages.length; j++) {\n var message = this._onWatchResult ? this._onWatchResult(messages[j]) : messages[j];\n this.callbacks[i].call(this, message);\n }\n }\n};\n\n/// should be called to uninstall current filter\nFilter.prototype.uninstall = function() {\n this.impl.uninstallFilter(this.id);\n web3.provider.stopPolling(this.id);\n};\n\n/// should be called to manually trigger getting latest messages from the client\nFilter.prototype.messages = function() {\n return this.impl.getMessages(this.id);\n};\n\n/// alias for messages\nFilter.prototype.logs = function () {\n return this.messages();\n};\n\nmodule.exports = Filter;\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file formatters.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\nif (\"build\" !== 'build') {/*\n var BigNumber = require('bignumber.js'); // jshint ignore:line\n*/}\n\nvar utils = require('./utils');\nvar c = require('./const');\n\n/// @param string string to be padded\n/// @param number of characters that result string should have\n/// @param sign, by default 0\n/// @returns right aligned string\nvar padLeft = function (string, chars, sign) {\n return new Array(chars - string.length + 1).join(sign ? sign : \"0\") + string;\n};\n\n/// Formats input value to byte representation of int\n/// If value is negative, return it's two's complement\n/// If the value is floating point, round it down\n/// @returns right-aligned byte representation of int\nvar formatInputInt = function (value) {\n var padding = c.ETH_PADDING * 2;\n if (value instanceof BigNumber || typeof value === 'number') {\n if (typeof value === 'number')\n value = new BigNumber(value);\n BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE);\n value = value.round();\n\n if (value.lessThan(0)) \n value = new BigNumber(\"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\", 16).plus(value).plus(1);\n value = value.toString(16);\n }\n else if (value.indexOf('0x') === 0)\n value = value.substr(2);\n else if (typeof value === 'string')\n value = formatInputInt(new BigNumber(value));\n else\n value = (+value).toString(16);\n return padLeft(value, padding);\n};\n\n/// Formats input value to byte representation of string\n/// @returns left-algined byte representation of string\nvar formatInputString = function (value) {\n return utils.fromAscii(value, c.ETH_PADDING).substr(2);\n};\n\n/// Formats input value to byte representation of bool\n/// @returns right-aligned byte representation bool\nvar formatInputBool = function (value) {\n return '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0');\n};\n\n/// Formats input value to byte representation of real\n/// Values are multiplied by 2^m and encoded as integers\n/// @returns byte representation of real\nvar formatInputReal = function (value) {\n return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); \n};\n\n\n/// Check if input value is negative\n/// @param value is hex format\n/// @returns true if it is negative, otherwise false\nvar signedIsNegative = function (value) {\n return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1';\n};\n\n/// Formats input right-aligned input bytes to int\n/// @returns right-aligned input bytes formatted to int\nvar formatOutputInt = function (value) {\n value = value || \"0\";\n // check if it's negative number\n // it it is, return two's complement\n if (signedIsNegative(value)) {\n return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1);\n }\n return new BigNumber(value, 16);\n};\n\n/// Formats big right-aligned input bytes to uint\n/// @returns right-aligned input bytes formatted to uint\nvar formatOutputUInt = function (value) {\n value = value || \"0\";\n return new BigNumber(value, 16);\n};\n\n/// @returns input bytes formatted to real\nvar formatOutputReal = function (value) {\n return formatOutputInt(value).dividedBy(new BigNumber(2).pow(128)); \n};\n\n/// @returns input bytes formatted to ureal\nvar formatOutputUReal = function (value) {\n return formatOutputUInt(value).dividedBy(new BigNumber(2).pow(128)); \n};\n\n/// @returns right-aligned input bytes formatted to hex\nvar formatOutputHash = function (value) {\n return \"0x\" + value;\n};\n\n/// @returns right-aligned input bytes formatted to bool\nvar formatOutputBool = function (value) {\n return value === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false;\n};\n\n/// @returns left-aligned input bytes formatted to ascii string\nvar formatOutputString = function (value) {\n return utils.toAscii(value);\n};\n\n/// @returns right-aligned input bytes formatted to address\nvar formatOutputAddress = function (value) {\n return \"0x\" + value.slice(value.length - 40, value.length);\n};\n\n\nmodule.exports = {\n formatInputInt: formatInputInt,\n formatInputString: formatInputString,\n formatInputBool: formatInputBool,\n formatInputReal: formatInputReal,\n formatOutputInt: formatOutputInt,\n formatOutputUInt: formatOutputUInt,\n formatOutputReal: formatOutputReal,\n formatOutputUReal: formatOutputUReal,\n formatOutputHash: formatOutputHash,\n formatOutputBool: formatOutputBool,\n formatOutputString: formatOutputString,\n formatOutputAddress: formatOutputAddress\n};\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file httpsync.js\n * @authors:\n * Marek Kotewicz \n * Marian Oancea \n * @date 2014\n */\n\nif (\"build\" !== 'build') {/*\n var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line\n*/}\n\nvar HttpSyncProvider = function (host) {\n this.handlers = [];\n this.host = host || 'http://localhost:8080';\n};\n\n/// Transforms inner message to proper jsonrpc object\n/// @param inner message object\n/// @returns jsonrpc object\nfunction formatJsonRpcObject(object) {\n return {\n jsonrpc: '2.0',\n method: object.call,\n params: object.args,\n id: object._id\n };\n}\n\n/// Transforms jsonrpc object to inner message\n/// @param incoming jsonrpc message \n/// @returns inner message object\nfunction formatJsonRpcMessage(message) {\n var object = JSON.parse(message);\n\n return {\n _id: object.id,\n data: object.result,\n error: object.error\n };\n}\n\nHttpSyncProvider.prototype.send = function (payload) {\n var data = formatJsonRpcObject(payload);\n \n var request = new XMLHttpRequest();\n request.open('POST', this.host, false);\n request.send(JSON.stringify(data));\n \n // check request.status\n return request.responseText;\n};\n\nmodule.exports = HttpSyncProvider;\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file providermanager.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nvar web3 = require('./web3'); // jshint ignore:line\n\n/**\n * Provider manager object prototype\n * It's responsible for passing messages to providers\n * If no provider is set it's responsible for queuing requests\n * It's also responsible for polling the ethereum node for incoming messages\n * Default poll timeout is 12 seconds\n * If we are running ethereum.js inside ethereum browser, there are backend based tools responsible for polling,\n * and provider manager polling mechanism is not used\n */\nvar ProviderManager = function() {\n this.polls = [];\n this.provider = undefined;\n this.id = 1;\n\n var self = this;\n var poll = function () {\n if (self.provider) {\n self.polls.forEach(function (data) {\n data.data._id = self.id;\n self.id++;\n var result = self.provider.send(data.data);\n \n result = JSON.parse(result);\n \n // dont call the callback if result is not an array, or empty one\n if (result.error || !(result.result instanceof Array) || result.result.length === 0) {\n return;\n }\n\n data.callback(result.result);\n });\n }\n setTimeout(poll, 1000);\n };\n poll();\n};\n\n/// sends outgoing requests\nProviderManager.prototype.send = function(data) {\n\n data.args = data.args || [];\n data._id = this.id++;\n\n if (this.provider === undefined) {\n console.error('provider is not set');\n return null; \n }\n\n //TODO: handle error here? \n var result = this.provider.send(data);\n result = JSON.parse(result);\n\n if (result.error) {\n console.log(result.error);\n return null;\n }\n\n return result.result;\n};\n\n/// setups provider, which will be used for sending messages\nProviderManager.prototype.set = function(provider) {\n this.provider = provider;\n};\n\n/// this method is only used, when we do not have native qt bindings and have to do polling on our own\n/// should be callled, on start watching for eth/shh changes\nProviderManager.prototype.startPolling = function (data, pollId, callback) {\n this.polls.push({data: data, id: pollId, callback: callback});\n};\n\n/// should be called to stop polling for certain watch changes\nProviderManager.prototype.stopPolling = function (pollId) {\n for (var i = this.polls.length; i--;) {\n var poll = this.polls[i];\n if (poll.id === pollId) {\n this.polls.splice(i, 1);\n }\n }\n};\n\nmodule.exports = ProviderManager;\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file qtsync.js\n * @authors:\n * Marek Kotewicz \n * Marian Oancea \n * @date 2014\n */\n\nvar QtSyncProvider = function () {\n};\n\nQtSyncProvider.prototype.send = function (payload) {\n return navigator.qt.callMethod(JSON.stringify(payload));\n};\n\nmodule.exports = QtSyncProvider;\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file types.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\nvar f = require('./formatters');\n\n/// @param expected type prefix (string)\n/// @returns function which checks if type has matching prefix. if yes, returns true, otherwise false\nvar prefixedType = function (prefix) {\n return function (type) {\n return type.indexOf(prefix) === 0;\n };\n};\n\n/// @param expected type name (string)\n/// @returns function which checks if type is matching expected one. if yes, returns true, otherwise false\nvar namedType = function (name) {\n return function (type) {\n return name === type;\n };\n};\n\n/// Setups input formatters for solidity types\n/// @returns an array of input formatters \nvar inputTypes = function () {\n \n return [\n { type: prefixedType('uint'), format: f.formatInputInt },\n { type: prefixedType('int'), format: f.formatInputInt },\n { type: prefixedType('hash'), format: f.formatInputInt },\n { type: prefixedType('string'), format: f.formatInputString }, \n { type: prefixedType('real'), format: f.formatInputReal },\n { type: prefixedType('ureal'), format: f.formatInputReal },\n { type: namedType('address'), format: f.formatInputInt },\n { type: namedType('bool'), format: f.formatInputBool }\n ];\n};\n\n/// Setups output formaters for solidity types\n/// @returns an array of output formatters\nvar outputTypes = function () {\n\n return [\n { type: prefixedType('uint'), format: f.formatOutputUInt },\n { type: prefixedType('int'), format: f.formatOutputInt },\n { type: prefixedType('hash'), format: f.formatOutputHash },\n { type: prefixedType('string'), format: f.formatOutputString },\n { type: prefixedType('real'), format: f.formatOutputReal },\n { type: prefixedType('ureal'), format: f.formatOutputUReal },\n { type: namedType('address'), format: f.formatOutputAddress },\n { type: namedType('bool'), format: f.formatOutputBool }\n ];\n};\n\nmodule.exports = {\n prefixedType: prefixedType,\n namedType: namedType,\n inputTypes: inputTypes,\n outputTypes: outputTypes\n};\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file utils.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\n/// Finds first index of array element matching pattern\n/// @param array\n/// @param callback pattern\n/// @returns index of element\nvar findIndex = function (array, callback) {\n var end = false;\n var i = 0;\n for (; i < array.length && !end; i++) {\n end = callback(array[i]);\n }\n return end ? i - 1 : -1;\n};\n\n/// @returns ascii string representation of hex value prefixed with 0x\nvar toAscii = function(hex) {\n// Find termination\n var str = \"\";\n var i = 0, l = hex.length;\n if (hex.substring(0, 2) === '0x') {\n i = 2;\n }\n for (; i < l; i+=2) {\n var code = parseInt(hex.substr(i, 2), 16);\n if (code === 0) {\n break;\n }\n\n str += String.fromCharCode(code);\n }\n\n return str;\n};\n \nvar toHex = function(str) {\n var hex = \"\";\n for(var i = 0; i < str.length; i++) {\n var n = str.charCodeAt(i).toString(16);\n hex += n.length < 2 ? '0' + n : n;\n }\n\n return hex;\n};\n\n/// @returns hex representation (prefixed by 0x) of ascii string\nvar fromAscii = function(str, pad) {\n pad = pad === undefined ? 0 : pad;\n var hex = toHex(str);\n while (hex.length < pad*2)\n hex += \"00\";\n return \"0x\" + hex;\n};\n\n/// @returns display name for function/event eg. multiply(uint256) -> multiply\nvar extractDisplayName = function (name) {\n var length = name.indexOf('('); \n return length !== -1 ? name.substr(0, length) : name;\n};\n\n/// @returns overloaded part of function/event name\nvar extractTypeName = function (name) {\n /// TODO: make it invulnerable\n var length = name.indexOf('(');\n return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)) : \"\";\n};\n\n/// Filters all function from input abi\n/// @returns abi array with filtered objects of type 'function'\nvar filterFunctions = function (json) {\n return json.filter(function (current) {\n return current.type === 'function'; \n }); \n};\n\n/// Filters all events form input abi\n/// @returns abi array with filtered objects of type 'event'\nvar filterEvents = function (json) {\n return json.filter(function (current) {\n return current.type === 'event';\n });\n};\n\nmodule.exports = {\n findIndex: findIndex,\n toAscii: toAscii,\n fromAscii: fromAscii,\n extractDisplayName: extractDisplayName,\n extractTypeName: extractTypeName,\n filterFunctions: filterFunctions,\n filterEvents: filterEvents\n};\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file web3.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nif (\"build\" !== 'build') {/*\n var BigNumber = require('bignumber.js');\n*/}\n\nvar utils = require('./utils');\n\nvar ETH_UNITS = [ \n 'wei', \n 'Kwei', \n 'Mwei', \n 'Gwei', \n 'szabo', \n 'finney', \n 'ether', \n 'grand', \n 'Mether', \n 'Gether', \n 'Tether', \n 'Pether', \n 'Eether', \n 'Zether', \n 'Yether', \n 'Nether', \n 'Dether', \n 'Vether', \n 'Uether' \n];\n\n/// @returns an array of objects describing web3 api methods\nvar web3Methods = function () {\n return [\n { name: 'sha3', call: 'web3_sha3' }\n ];\n};\n\n/// @returns an array of objects describing web3.eth api methods\nvar ethMethods = function () {\n var blockCall = function (args) {\n return typeof args[0] === \"string\" ? \"eth_blockByHash\" : \"eth_blockByNumber\";\n };\n\n var transactionCall = function (args) {\n return typeof args[0] === \"string\" ? 'eth_transactionByHash' : 'eth_transactionByNumber';\n };\n\n var uncleCall = function (args) {\n return typeof args[0] === \"string\" ? 'eth_uncleByHash' : 'eth_uncleByNumber';\n };\n\n var methods = [\n { name: 'balanceAt', call: 'eth_balanceAt' },\n { name: 'stateAt', call: 'eth_stateAt' },\n { name: 'storageAt', call: 'eth_storageAt' },\n { name: 'countAt', call: 'eth_countAt'},\n { name: 'codeAt', call: 'eth_codeAt' },\n { name: 'transact', call: 'eth_transact' },\n { name: 'call', call: 'eth_call' },\n { name: 'block', call: blockCall },\n { name: 'transaction', call: transactionCall },\n { name: 'uncle', call: uncleCall },\n { name: 'compilers', call: 'eth_compilers' },\n { name: 'flush', call: 'eth_flush' },\n { name: 'lll', call: 'eth_lll' },\n { name: 'solidity', call: 'eth_solidity' },\n { name: 'serpent', call: 'eth_serpent' },\n { name: 'logs', call: 'eth_logs' }\n ];\n return methods;\n};\n\n/// @returns an array of objects describing web3.eth api properties\nvar ethProperties = function () {\n return [\n { name: 'coinbase', getter: 'eth_coinbase', setter: 'eth_setCoinbase' },\n { name: 'listening', getter: 'eth_listening', setter: 'eth_setListening' },\n { name: 'mining', getter: 'eth_mining', setter: 'eth_setMining' },\n { name: 'gasPrice', getter: 'eth_gasPrice' },\n { name: 'accounts', getter: 'eth_accounts' },\n { name: 'peerCount', getter: 'eth_peerCount' },\n { name: 'defaultBlock', getter: 'eth_defaultBlock', setter: 'eth_setDefaultBlock' },\n { name: 'number', getter: 'eth_number'}\n ];\n};\n\n/// @returns an array of objects describing web3.db api methods\nvar dbMethods = function () {\n return [\n { name: 'put', call: 'db_put' },\n { name: 'get', call: 'db_get' },\n { name: 'putString', call: 'db_putString' },\n { name: 'getString', call: 'db_getString' }\n ];\n};\n\n/// @returns an array of objects describing web3.shh api methods\nvar shhMethods = function () {\n return [\n { name: 'post', call: 'shh_post' },\n { name: 'newIdentity', call: 'shh_newIdentity' },\n { name: 'haveIdentity', call: 'shh_haveIdentity' },\n { name: 'newGroup', call: 'shh_newGroup' },\n { name: 'addToGroup', call: 'shh_addToGroup' }\n ];\n};\n\n/// @returns an array of objects describing web3.eth.watch api methods\nvar ethWatchMethods = function () {\n var newFilter = function (args) {\n return typeof args[0] === 'string' ? 'eth_newFilterString' : 'eth_newFilter';\n };\n\n return [\n { name: 'newFilter', call: newFilter },\n { name: 'uninstallFilter', call: 'eth_uninstallFilter' },\n { name: 'getMessages', call: 'eth_filterLogs' }\n ];\n};\n\n/// @returns an array of objects describing web3.shh.watch api methods\nvar shhWatchMethods = function () {\n return [\n { name: 'newFilter', call: 'shh_newFilter' },\n { name: 'uninstallFilter', call: 'shh_uninstallFilter' },\n { name: 'getMessages', call: 'shh_getMessages' }\n ];\n};\n\n/// creates methods in a given object based on method description on input\n/// setups api calls for these methods\nvar setupMethods = function (obj, methods) {\n methods.forEach(function (method) {\n obj[method.name] = function () {\n var args = Array.prototype.slice.call(arguments);\n var call = typeof method.call === 'function' ? method.call(args) : method.call;\n return web3.provider.send({\n call: call,\n args: args\n });\n };\n });\n};\n\n/// creates properties in a given object based on properties description on input\n/// setups api calls for these properties\nvar setupProperties = function (obj, properties) {\n properties.forEach(function (property) {\n var proto = {};\n proto.get = function () {\n return web3.provider.send({\n call: property.getter\n });\n };\n\n if (property.setter) {\n proto.set = function (val) {\n return web3.provider.send({\n call: property.setter,\n args: [val]\n });\n };\n }\n Object.defineProperty(obj, property.name, proto);\n });\n};\n\n/// setups web3 object, and it's in-browser executed methods\nvar web3 = {\n _callbacks: {},\n _events: {},\n providers: {},\n\n /// @returns ascii string representation of hex value prefixed with 0x\n toAscii: utils.toAscii,\n\n /// @returns hex representation (prefixed by 0x) of ascii string\n fromAscii: utils.fromAscii,\n\n /// @returns decimal representaton of hex value prefixed by 0x\n toDecimal: function (val) {\n // remove 0x and place 0, if it's required\n val = val.length > 2 ? val.substring(2) : \"0\";\n return (new BigNumber(val, 16).toString(10));\n },\n\n /// @returns hex representation (prefixed by 0x) of decimal value\n fromDecimal: function (val) {\n return \"0x\" + (new BigNumber(val).toString(16));\n },\n\n /// used to transform value/string to eth string\n /// TODO: use BigNumber.js to parse int\n toEth: function(str) {\n var val = typeof str === \"string\" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str;\n var unit = 0;\n var units = ETH_UNITS;\n while (val > 3000 && unit < units.length - 1)\n {\n val /= 1000;\n unit++;\n }\n var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2);\n var replaceFunction = function($0, $1, $2) {\n return $1 + ',' + $2;\n };\n\n while (true) {\n var o = s;\n s = s.replace(/(\\d)(\\d\\d\\d[\\.\\,])/, replaceFunction);\n if (o === s)\n break;\n }\n return s + ' ' + units[unit];\n },\n\n /// eth object prototype\n eth: {\n contractFromAbi: function (abi) {\n return function(addr) {\n // Default to address of Config. TODO: rremove prior to genesis.\n addr = addr || '0xc6d9d2cd449a754c494264e1809c50e34d64562b';\n var ret = web3.eth.contract(addr, abi);\n ret.address = addr;\n return ret;\n };\n },\n\n /// @param filter may be a string, object or event\n /// @param indexed is optional, this is an object with optional event indexed params\n /// @param options is optional, this is an object with optional event options ('max'...)\n watch: function (filter, indexed, options) {\n if (filter._isEvent) {\n return filter(indexed, options);\n }\n return new web3.filter(filter, ethWatch);\n }\n },\n\n /// db object prototype\n db: {},\n\n /// shh object prototype\n shh: {\n \n /// @param filter may be a string, object or event\n watch: function (filter, indexed) {\n return new web3.filter(filter, shhWatch);\n }\n },\n\n /// @returns true if provider is installed\n haveProvider: function() {\n return !!web3.provider.provider;\n }\n};\n\n/// setups all api methods\nsetupMethods(web3, web3Methods());\nsetupMethods(web3.eth, ethMethods());\nsetupProperties(web3.eth, ethProperties());\nsetupMethods(web3.db, dbMethods());\nsetupMethods(web3.shh, shhMethods());\n\nvar ethWatch = {\n changed: 'eth_changed'\n};\n\nsetupMethods(ethWatch, ethWatchMethods());\n\nvar shhWatch = {\n changed: 'shh_changed'\n};\n\nsetupMethods(shhWatch, shhWatchMethods());\n\nweb3.setProvider = function(provider) {\n //provider.onmessage = messageHandler; // there will be no async calls, to remove\n web3.provider.set(provider);\n};\n\nmodule.exports = web3;\n\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file utils.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\nvar c = require('./const');\n\n/// Finds first index of array element matching pattern\n/// @param array\n/// @param callback pattern\n/// @returns index of element\nvar findIndex = function (array, callback) {\n var end = false;\n var i = 0;\n for (; i < array.length && !end; i++) {\n end = callback(array[i]);\n }\n return end ? i - 1 : -1;\n};\n\n/// @returns ascii string representation of hex value prefixed with 0x\nvar toAscii = function(hex) {\n// Find termination\n var str = \"\";\n var i = 0, l = hex.length;\n if (hex.substring(0, 2) === '0x') {\n i = 2;\n }\n for (; i < l; i+=2) {\n var code = parseInt(hex.substr(i, 2), 16);\n if (code === 0) {\n break;\n }\n\n str += String.fromCharCode(code);\n }\n\n return str;\n};\n \nvar toHex = function(str) {\n var hex = \"\";\n for(var i = 0; i < str.length; i++) {\n var n = str.charCodeAt(i).toString(16);\n hex += n.length < 2 ? '0' + n : n;\n }\n\n return hex;\n};\n\n/// @returns hex representation (prefixed by 0x) of ascii string\nvar fromAscii = function(str, pad) {\n pad = pad === undefined ? 0 : pad;\n var hex = toHex(str);\n while (hex.length < pad*2)\n hex += \"00\";\n return \"0x\" + hex;\n};\n\n/// @returns display name for function/event eg. multiply(uint256) -> multiply\nvar extractDisplayName = function (name) {\n var length = name.indexOf('('); \n return length !== -1 ? name.substr(0, length) : name;\n};\n\n/// @returns overloaded part of function/event name\nvar extractTypeName = function (name) {\n /// TODO: make it invulnerable\n var length = name.indexOf('(');\n return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)) : \"\";\n};\n\n/// Filters all function from input abi\n/// @returns abi array with filtered objects of type 'function'\nvar filterFunctions = function (json) {\n return json.filter(function (current) {\n return current.type === 'function'; \n }); \n};\n\n/// Filters all events form input abi\n/// @returns abi array with filtered objects of type 'event'\nvar filterEvents = function (json) {\n return json.filter(function (current) {\n return current.type === 'event';\n });\n};\n\n/// used to transform value/string to eth string\n/// TODO: use BigNumber.js to parse int\n/// TODO: add tests for it!\nvar toEth = function (str) {\n var val = typeof str === \"string\" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str;\n var unit = 0;\n var units = c.ETH_UNITS;\n while (val > 3000 && unit < units.length - 1)\n {\n val /= 1000;\n unit++;\n }\n var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2);\n var replaceFunction = function($0, $1, $2) {\n return $1 + ',' + $2;\n };\n\n while (true) {\n var o = s;\n s = s.replace(/(\\d)(\\d\\d\\d[\\.\\,])/, replaceFunction);\n if (o === s)\n break;\n }\n return s + ' ' + units[unit];\n};\n\nmodule.exports = {\n findIndex: findIndex,\n toAscii: toAscii,\n fromAscii: fromAscii,\n extractDisplayName: extractDisplayName,\n extractTypeName: extractTypeName,\n filterFunctions: filterFunctions,\n filterEvents: filterEvents,\n toEth: toEth\n};\n\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file web3.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nif (\"build\" !== 'build') {/*\n var BigNumber = require('bignumber.js');\n*/}\n\nvar utils = require('./utils');\n\n/// @returns an array of objects describing web3 api methods\nvar web3Methods = function () {\n return [\n { name: 'sha3', call: 'web3_sha3' }\n ];\n};\n\n/// @returns an array of objects describing web3.eth api methods\nvar ethMethods = function () {\n var blockCall = function (args) {\n return typeof args[0] === \"string\" ? \"eth_blockByHash\" : \"eth_blockByNumber\";\n };\n\n var transactionCall = function (args) {\n return typeof args[0] === \"string\" ? 'eth_transactionByHash' : 'eth_transactionByNumber';\n };\n\n var uncleCall = function (args) {\n return typeof args[0] === \"string\" ? 'eth_uncleByHash' : 'eth_uncleByNumber';\n };\n\n var methods = [\n { name: 'balanceAt', call: 'eth_balanceAt' },\n { name: 'stateAt', call: 'eth_stateAt' },\n { name: 'storageAt', call: 'eth_storageAt' },\n { name: 'countAt', call: 'eth_countAt'},\n { name: 'codeAt', call: 'eth_codeAt' },\n { name: 'transact', call: 'eth_transact' },\n { name: 'call', call: 'eth_call' },\n { name: 'block', call: blockCall },\n { name: 'transaction', call: transactionCall },\n { name: 'uncle', call: uncleCall },\n { name: 'compilers', call: 'eth_compilers' },\n { name: 'flush', call: 'eth_flush' },\n { name: 'lll', call: 'eth_lll' },\n { name: 'solidity', call: 'eth_solidity' },\n { name: 'serpent', call: 'eth_serpent' },\n { name: 'logs', call: 'eth_logs' }\n ];\n return methods;\n};\n\n/// @returns an array of objects describing web3.eth api properties\nvar ethProperties = function () {\n return [\n { name: 'coinbase', getter: 'eth_coinbase', setter: 'eth_setCoinbase' },\n { name: 'listening', getter: 'eth_listening', setter: 'eth_setListening' },\n { name: 'mining', getter: 'eth_mining', setter: 'eth_setMining' },\n { name: 'gasPrice', getter: 'eth_gasPrice' },\n { name: 'accounts', getter: 'eth_accounts' },\n { name: 'peerCount', getter: 'eth_peerCount' },\n { name: 'defaultBlock', getter: 'eth_defaultBlock', setter: 'eth_setDefaultBlock' },\n { name: 'number', getter: 'eth_number'}\n ];\n};\n\n/// @returns an array of objects describing web3.db api methods\nvar dbMethods = function () {\n return [\n { name: 'put', call: 'db_put' },\n { name: 'get', call: 'db_get' },\n { name: 'putString', call: 'db_putString' },\n { name: 'getString', call: 'db_getString' }\n ];\n};\n\n/// @returns an array of objects describing web3.shh api methods\nvar shhMethods = function () {\n return [\n { name: 'post', call: 'shh_post' },\n { name: 'newIdentity', call: 'shh_newIdentity' },\n { name: 'haveIdentity', call: 'shh_haveIdentity' },\n { name: 'newGroup', call: 'shh_newGroup' },\n { name: 'addToGroup', call: 'shh_addToGroup' }\n ];\n};\n\n/// @returns an array of objects describing web3.eth.watch api methods\nvar ethWatchMethods = function () {\n var newFilter = function (args) {\n return typeof args[0] === 'string' ? 'eth_newFilterString' : 'eth_newFilter';\n };\n\n return [\n { name: 'newFilter', call: newFilter },\n { name: 'uninstallFilter', call: 'eth_uninstallFilter' },\n { name: 'getMessages', call: 'eth_filterLogs' }\n ];\n};\n\n/// @returns an array of objects describing web3.shh.watch api methods\nvar shhWatchMethods = function () {\n return [\n { name: 'newFilter', call: 'shh_newFilter' },\n { name: 'uninstallFilter', call: 'shh_uninstallFilter' },\n { name: 'getMessages', call: 'shh_getMessages' }\n ];\n};\n\n/// creates methods in a given object based on method description on input\n/// setups api calls for these methods\nvar setupMethods = function (obj, methods) {\n methods.forEach(function (method) {\n obj[method.name] = function () {\n var args = Array.prototype.slice.call(arguments);\n var call = typeof method.call === 'function' ? method.call(args) : method.call;\n return web3.provider.send({\n call: call,\n args: args\n });\n };\n });\n};\n\n/// creates properties in a given object based on properties description on input\n/// setups api calls for these properties\nvar setupProperties = function (obj, properties) {\n properties.forEach(function (property) {\n var proto = {};\n proto.get = function () {\n return web3.provider.send({\n call: property.getter\n });\n };\n\n if (property.setter) {\n proto.set = function (val) {\n return web3.provider.send({\n call: property.setter,\n args: [val]\n });\n };\n }\n Object.defineProperty(obj, property.name, proto);\n });\n};\n\n/// setups web3 object, and it's in-browser executed methods\nvar web3 = {\n _callbacks: {},\n _events: {},\n providers: {},\n\n /// @returns ascii string representation of hex value prefixed with 0x\n toAscii: utils.toAscii,\n\n /// @returns hex representation (prefixed by 0x) of ascii string\n fromAscii: utils.fromAscii,\n\n /// @returns decimal representaton of hex value prefixed by 0x\n toDecimal: function (val) {\n // remove 0x and place 0, if it's required\n val = val.length > 2 ? val.substring(2) : \"0\";\n return (new BigNumber(val, 16).toString(10));\n },\n\n /// @returns hex representation (prefixed by 0x) of decimal value\n fromDecimal: function (val) {\n return \"0x\" + (new BigNumber(val).toString(16));\n },\n\n /// used to transform value/string to eth string\n toEth: utils.toEth,\n\n /// eth object prototype\n eth: {\n contractFromAbi: function (abi) {\n return function(addr) {\n // Default to address of Config. TODO: rremove prior to genesis.\n addr = addr || '0xc6d9d2cd449a754c494264e1809c50e34d64562b';\n var ret = web3.eth.contract(addr, abi);\n ret.address = addr;\n return ret;\n };\n },\n\n /// @param filter may be a string, object or event\n /// @param indexed is optional, this is an object with optional event indexed params\n /// @param options is optional, this is an object with optional event options ('max'...)\n watch: function (filter, indexed, options) {\n if (filter._isEvent) {\n return filter(indexed, options);\n }\n return new web3.filter(filter, ethWatch);\n }\n },\n\n /// db object prototype\n db: {},\n\n /// shh object prototype\n shh: {\n \n /// @param filter may be a string, object or event\n watch: function (filter, indexed) {\n return new web3.filter(filter, shhWatch);\n }\n },\n};\n\n/// setups all api methods\nsetupMethods(web3, web3Methods());\nsetupMethods(web3.eth, ethMethods());\nsetupProperties(web3.eth, ethProperties());\nsetupMethods(web3.db, dbMethods());\nsetupMethods(web3.shh, shhMethods());\n\nvar ethWatch = {\n changed: 'eth_changed'\n};\n\nsetupMethods(ethWatch, ethWatchMethods());\n\nvar shhWatch = {\n changed: 'shh_changed'\n};\n\nsetupMethods(shhWatch, shhWatchMethods());\n\nweb3.setProvider = function(provider) {\n web3.provider.set(provider);\n};\n\nmodule.exports = web3;\n\n", "var web3 = require('./lib/web3');\nvar ProviderManager = require('./lib/providermanager');\nweb3.provider = new ProviderManager();\nweb3.filter = require('./lib/filter');\nweb3.providers.HttpSyncProvider = require('./lib/httpsync');\nweb3.providers.QtSyncProvider = require('./lib/qtsync');\nweb3.eth.contract = require('./lib/contract');\nweb3.abi = require('./lib/abi');\n\n\nmodule.exports = web3;\n" ] } \ No newline at end of file diff --git a/dist/ethereum.min.js b/dist/ethereum.min.js index cc9b205d1..49d1f628c 100644 --- a/dist/ethereum.min.js +++ b/dist/ethereum.min.js @@ -1 +1 @@ -require=function t(e,n,r){function i(a,u){if(!n[a]){if(!e[a]){var f="function"==typeof require&&require;if(!u&&f)return f(a,!0);if(o)return o(a,!0);var s=new Error("Cannot find module '"+a+"'");throw s.code="MODULE_NOT_FOUND",s}var c=n[a]={exports:{}};e[a][0].call(c.exports,function(t){var n=e[a][1][t];return i(n?n:t)},c,c.exports,t,e,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;av;v++)g.push(h(e.slice(0,r))),e=e.slice(r);n.push(g)}else i.prefixedType("string")(t[s].type)?(c=c.slice(r),n.push(h(e.slice(0,r))),e=e.slice(r)):(n.push(h(e.slice(0,r))),e=e.slice(r))}),n},d=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(){var e=Array.prototype.slice.call(arguments);return l(t.inputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},g=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(e){return h(t.outputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},v=function(t){return n.sha3(n.fromAscii(t)).slice(0,2+2*o.ETH_SIGNATURE_LENGTH)},y=function(t){return n.sha3(n.fromAscii(t))};e.exports={inputParser:d,outputParser:g,formatInput:l,formatOutput:h,signatureFromAscii:v,eventSignatureFromAscii:y}},{"./const":2,"./formatters":6,"./types":10,"./utils":11,"./web3":12}],2:[function(t,e){e.exports={ETH_PADDING:32,ETH_SIGNATURE_LENGTH:4,ETH_BIGNUMBER_ROUNDING_MODE:{ROUNDING_MODE:BigNumber.ROUND_DOWN}}},{}],3:[function(t,e){var n=t("./web3"),r=t("./abi"),i=t("./utils"),o=t("./event"),a=function(t){n._currentContractAbi=t.abi,n._currentContractAddress=t.address,n._currentContractMethodName=t.method,n._currentContractMethodParams=t.params},u=function(t){t.call=function(e){return t._isTransact=!1,t._options=e,t},t.transact=function(e){return t._isTransact=!0,t._options=e,t},t._options={},["gas","gasPrice","value","from"].forEach(function(e){t[e]=function(n){return t._options[e]=n,t}})},f=function(t,e,o){var u=r.inputParser(e),f=r.outputParser(e);i.filterFunctions(e).forEach(function(s){var c=i.extractDisplayName(s.name),l=i.extractTypeName(s.name),p=function(){var i=Array.prototype.slice.call(arguments),p=r.signatureFromAscii(s.name),m=u[c][l].apply(null,i),h=t._options||{};h.to=o,h.data=p+m;var d=t._isTransact===!0||t._isTransact!==!1&&!s.constant,g=h.collapse!==!1;if(t._options={},t._isTransact=null,d)return a({abi:e,address:o,method:s.name,params:i}),void n.eth.transact(h);var v=n.eth.call(h),y=f[c][l](v);return g&&(1===y.length?y=y[0]:0===y.length&&(y=null)),y};void 0===t[c]&&(t[c]=p),t[c][l]=p})},s=function(t,e,n){t.address=n,Object.defineProperty(t,"topic",{get:function(){return i.filterEvents(e).map(function(t){return r.eventSignatureFromAscii(t.name)})}})},c=function(t,e,a){i.filterEvents(e).forEach(function(e){var u=function(){var t=Array.prototype.slice.call(arguments),i=r.eventSignatureFromAscii(e.name),u=o(a,i,e),f=u.apply(null,t);return n.eth.watch(f)};u._isEvent=!0;var f=i.extractDisplayName(e.name),s=i.extractTypeName(e.name);void 0===t[f]&&(t[f]=u),t[f][s]=u})},l=function(t,e){e.forEach(function(t){if(-1===t.name.indexOf("(")){var e=t.name,n=t.inputs.map(function(t){return t.type}).join();t.name=e+"("+n+")"}});var n={};return u(n),f(n,e,t),s(n,e,t),c(n,e,t),n};e.exports=l},{"./abi":1,"./event":4,"./utils":11,"./web3":12}],4:[function(t,e){var n=t("./abi"),r=t("./utils"),i=function(t,e){var n=r.findIndex(t,function(t){return t.name===e});return-1===n?void console.error("indexed param with name "+e+" not found"):t[n]},o=function(t,e){return Object.keys(e).map(function(r){var o=[i(t.inputs,r)],a=e[r];return a instanceof Array?a.map(function(t){return n.formatInput(o,[t])}):n.formatInput(o,[a])})},a=function(t,e,n){return function(r,i){var a=i||{};return a.address=t,a.topic=[],a.topic.push(e),r&&(a.topic=a.topic.concat(o(n,r))),a}};e.exports=a},{"./abi":1,"./utils":11}],5:[function(t,e){var n=t("./web3"),r=function(t,e){"string"!=typeof t&&(t.topics&&console.warn('"topics" is deprecated, use "topic" instead'),t={to:t.to,topic:t.topic,earliest:t.earliest,latest:t.latest,max:t.max,skip:t.skip,address:t.address}),this.impl=e,this.callbacks=[],this.id=e.newFilter(t),n.provider.startPolling({call:e.changed,args:[this.id]},this.id,this.trigger.bind(this))};r.prototype.arrived=function(t){this.changed(t)},r.prototype.changed=function(t){this.callbacks.push(t)},r.prototype.trigger=function(t){for(var e=0;en;n+=2){var i=parseInt(t.substr(n,2),16);if(0===i)break;e+=String.fromCharCode(i)}return e},i=function(t){for(var e="",n=0;n2?t.substring(2):"0",new BigNumber(t,16).toString(10)},fromDecimal:function(t){return"0x"+new BigNumber(t).toString(16)},toEth:function(t){for(var e="string"==typeof t?0===t.indexOf("0x")?parseInt(t.substr(2),16):parseInt(t):t,n=0,i=r;e>3e3&&nv;v++)g.push(m(e.slice(0,r))),e=e.slice(r);n.push(g)}else i.prefixedType("string")(t[f].type)?(c=c.slice(r),n.push(m(e.slice(0,r))),e=e.slice(r)):(n.push(m(e.slice(0,r))),e=e.slice(r))}),n},d=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(){var e=Array.prototype.slice.call(arguments);return l(t.inputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},g=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(e){return m(t.outputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},v=function(t){return n.sha3(n.fromAscii(t)).slice(0,2+2*o.ETH_SIGNATURE_LENGTH)},y=function(t){return n.sha3(n.fromAscii(t))};e.exports={inputParser:d,outputParser:g,formatInput:l,formatOutput:m,signatureFromAscii:v,eventSignatureFromAscii:y}},{"./const":2,"./formatters":6,"./types":10,"./utils":11,"./web3":12}],2:[function(t,e){var n=["wei","Kwei","Mwei","Gwei","szabo","finney","ether","grand","Mether","Gether","Tether","Pether","Eether","Zether","Yether","Nether","Dether","Vether","Uether"];e.exports={ETH_PADDING:32,ETH_SIGNATURE_LENGTH:4,ETH_UNITS:n,ETH_BIGNUMBER_ROUNDING_MODE:{ROUNDING_MODE:BigNumber.ROUND_DOWN}}},{}],3:[function(t,e){var n=t("./web3"),r=t("./abi"),i=t("./utils"),o=t("./event"),a=function(t){n._currentContractAbi=t.abi,n._currentContractAddress=t.address,n._currentContractMethodName=t.method,n._currentContractMethodParams=t.params},u=function(t){t.call=function(e){return t._isTransact=!1,t._options=e,t},t.transact=function(e){return t._isTransact=!0,t._options=e,t},t._options={},["gas","gasPrice","value","from"].forEach(function(e){t[e]=function(n){return t._options[e]=n,t}})},s=function(t,e,o){var u=r.inputParser(e),s=r.outputParser(e);i.filterFunctions(e).forEach(function(f){var c=i.extractDisplayName(f.name),l=i.extractTypeName(f.name),p=function(){var i=Array.prototype.slice.call(arguments),p=r.signatureFromAscii(f.name),h=u[c][l].apply(null,i),m=t._options||{};m.to=o,m.data=p+h;var d=t._isTransact===!0||t._isTransact!==!1&&!f.constant,g=m.collapse!==!1;if(t._options={},t._isTransact=null,d)return a({abi:e,address:o,method:f.name,params:i}),void n.eth.transact(m);var v=n.eth.call(m),y=s[c][l](v);return g&&(1===y.length?y=y[0]:0===y.length&&(y=null)),y};void 0===t[c]&&(t[c]=p),t[c][l]=p})},f=function(t,e,n){t.address=n,t._onWatchEventResult=function(t){var n=event.getMatchingEvent(i.filterEvents(e)),r=o.outputParser(n);return r(t)},Object.defineProperty(t,"topic",{get:function(){return i.filterEvents(e).map(function(t){return r.eventSignatureFromAscii(t.name)})}})},c=function(t,e,a){i.filterEvents(e).forEach(function(e){var u=function(){var t=Array.prototype.slice.call(arguments),i=r.eventSignatureFromAscii(e.name),u=o.inputParser(a,i,e),s=u.apply(null,t);return s._onWatchEventResult=function(t){var n=o.outputParser(e);return n(t)},n.eth.watch(s)};u._isEvent=!0;var s=i.extractDisplayName(e.name),f=i.extractTypeName(e.name);void 0===t[s]&&(t[s]=u),t[s][f]=u})},l=function(t,e){e.forEach(function(t){if(-1===t.name.indexOf("(")){var e=t.name,n=t.inputs.map(function(t){return t.type}).join();t.name=e+"("+n+")"}});var n={};return u(n),s(n,e,t),f(n,e,t),c(n,e,t),n};e.exports=l},{"./abi":1,"./event":4,"./utils":11,"./web3":12}],4:[function(t,e){var n=t("./abi"),r=t("./utils"),i=function(t,e){return t.filter(function(t){return t.indexed===e})},o=function(t,e){var n=r.findIndex(t,function(t){return t.name===e});return-1===n?void console.error("indexed param with name "+e+" not found"):t[n]},a=function(t,e){return Object.keys(e).map(function(r){var a=[o(i(t.inputs,!0),r)],u=e[r];return u instanceof Array?u.map(function(t){return n.formatInput(a,[t])}):n.formatInput(a,[u])})},u=function(t,e,n){return function(r,i){var o=i||{};return o.address=t,o.topic=[],o.topic.push(e),r&&(o.topic=o.topic.concat(a(n,r))),o}},s=function(t,e,n){e.slice(),n.slice();return t.reduce(function(t,r){var i;return i=r.indexed?e.splice(0,1)[0]:n.splice(0,1)[0],t[r.name]=i,t},{})},f=function(t){return function(e){var o={event:r.extractDisplayName(t.name),number:e.number,args:{}};if(!e.topic)return o;var a=i(t.inputs,!0),u="0x"+e.topic.slice(1,e.topic.length).map(function(t){return t.slice(2)}).join(""),f=n.formatOutput(a,u),c=i(t.inputs,!1),l=n.formatOutput(c,e.data);return o.args=s(t.inputs,f,l),o}},c=function(t,e){for(var r=0;rn;n+=2){var i=parseInt(t.substr(n,2),16);if(0===i)break;e+=String.fromCharCode(i)}return e},o=function(t){for(var e="",n=0;n3e3&&r2?t.substring(2):"0",new BigNumber(t,16).toString(10)},fromDecimal:function(t){return"0x"+new BigNumber(t).toString(16)},toEth:n.toEth,eth:{contractFromAbi:function(t){return function(e){e=e||"0xc6d9d2cd449a754c494264e1809c50e34d64562b";var n=p.eth.contract(e,t);return n.address=e,n}},watch:function(t,e,n){return t._isEvent?t(e,n):new p.filter(t,h)}},db:{},shh:{watch:function(t){return new p.filter(t,m)}}};c(p,r()),c(p.eth,i()),l(p.eth,o()),c(p.db,a()),c(p.shh,u());var h={changed:"eth_changed"};c(h,s());var m={changed:"shh_changed"};c(m,f()),p.setProvider=function(t){p.provider.set(t)},e.exports=p},{"./utils":11}],web3:[function(t,e){var n=t("./lib/web3"),r=t("./lib/providermanager");n.provider=new r,n.filter=t("./lib/filter"),n.providers.HttpSyncProvider=t("./lib/httpsync"),n.providers.QtSyncProvider=t("./lib/qtsync"),n.eth.contract=t("./lib/contract"),n.abi=t("./lib/abi"),e.exports=n},{"./lib/abi":1,"./lib/contract":3,"./lib/filter":5,"./lib/httpsync":7,"./lib/providermanager":8,"./lib/qtsync":9,"./lib/web3":12}]},{},["web3"]); \ No newline at end of file diff --git a/example/event_inc.html b/example/event_inc.html new file mode 100644 index 000000000..17df9d681 --- /dev/null +++ b/example/event_inc.html @@ -0,0 +1,66 @@ + + + + + + + + + +
+ +
+
+ +
+
+
+ + diff --git a/lib/const.js b/lib/const.js index 22f6dc690..8a17b794d 100644 --- a/lib/const.js +++ b/lib/const.js @@ -25,9 +25,32 @@ if (process.env.NODE_ENV !== 'build') { var BigNumber = require('bignumber.js'); // jshint ignore:line } +var ETH_UNITS = [ + 'wei', + 'Kwei', + 'Mwei', + 'Gwei', + 'szabo', + 'finney', + 'ether', + 'grand', + 'Mether', + 'Gether', + 'Tether', + 'Pether', + 'Eether', + 'Zether', + 'Yether', + 'Nether', + 'Dether', + 'Vether', + 'Uether' +]; + module.exports = { ETH_PADDING: 32, ETH_SIGNATURE_LENGTH: 4, + ETH_UNITS: ETH_UNITS, ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN } }; diff --git a/lib/contract.js b/lib/contract.js index 748844fec..a0525bd9d 100644 --- a/lib/contract.js +++ b/lib/contract.js @@ -120,6 +120,11 @@ var addFunctionsToContract = function (contract, desc, address) { var addEventRelatedPropertiesToContract = function (contract, desc, address) { contract.address = address; + contract._onWatchEventResult = function (data) { + var matchingEvent = event.getMatchingEvent(utils.filterEvents(desc)); + var parser = eventImpl.outputParser(matchingEvent); + return parser(data); + }; Object.defineProperty(contract, 'topic', { get: function() { @@ -138,8 +143,12 @@ var addEventsToContract = function (contract, desc, address) { var impl = function () { var params = Array.prototype.slice.call(arguments); var signature = abi.eventSignatureFromAscii(e.name); - var event = eventImpl(address, signature, e); + var event = eventImpl.inputParser(address, signature, e); var o = event.apply(null, params); + o._onWatchEventResult = function (data) { + var parser = eventImpl.outputParser(e); + return parser(data); + }; return web3.eth.watch(o); }; diff --git a/lib/event.js b/lib/event.js index 812ef9115..0c41e0a39 100644 --- a/lib/event.js +++ b/lib/event.js @@ -23,6 +23,16 @@ var abi = require('./abi'); var utils = require('./utils'); +/// filter inputs array && returns only indexed (or not) inputs +/// @param inputs array +/// @param bool if result should be an array of indexed params on not +/// @returns array of (not?) indexed params +var filterInputs = function (inputs, indexed) { + return inputs.filter(function (current) { + return current.indexed === indexed; + }); +}; + var inputWithName = function (inputs, name) { var index = utils.findIndex(inputs, function (input) { return input.name === name; @@ -38,7 +48,7 @@ var inputWithName = function (inputs, name) { var indexedParamsToTopics = function (event, indexed) { // sort keys? return Object.keys(indexed).map(function (key) { - var inputs = [inputWithName(event.inputs, key)]; + var inputs = [inputWithName(filterInputs(event.inputs, true), key)]; var value = indexed[key]; if (value instanceof Array) { @@ -50,7 +60,7 @@ var indexedParamsToTopics = function (event, indexed) { }); }; -var implementationOfEvent = function (address, signature, event) { +var inputParser = function (address, signature, event) { // valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch' return function (indexed, options) { @@ -65,5 +75,61 @@ var implementationOfEvent = function (address, signature, event) { }; }; -module.exports = implementationOfEvent; +var getArgumentsObject = function (inputs, indexed, notIndexed) { + var indexedCopy = indexed.slice(); + var notIndexedCopy = notIndexed.slice(); + return inputs.reduce(function (acc, current) { + var value; + if (current.indexed) + value = indexed.splice(0, 1)[0]; + else + value = notIndexed.splice(0, 1)[0]; + + acc[current.name] = value; + return acc; + }, {}); +}; + +var outputParser = function (event) { + + return function (output) { + var result = { + event: utils.extractDisplayName(event.name), + number: output.number, + args: {} + }; + + if (!output.topic) { + return result; + } + + var indexedOutputs = filterInputs(event.inputs, true); + var indexedData = "0x" + output.topic.slice(1, output.topic.length).map(function (topic) { return topic.slice(2); }).join(""); + var indexedRes = abi.formatOutput(indexedOutputs, indexedData); + + var notIndexedOutputs = filterInputs(event.inputs, false); + var notIndexedRes = abi.formatOutput(notIndexedOutputs, output.data); + + result.args = getArgumentsObject(event.inputs, indexedRes, notIndexedRes); + + return result; + }; +}; + +var getMatchingEvent = function (events, payload) { + for (var i = 0; i < events.length; i++) { + var signature = abi.eventSignatureFromAscii(events[i].name); + if (signature === payload.topic[0]) { + return events[i]; + } + } + return undefined; +}; + + +module.exports = { + inputParser: inputParser, + outputParser: outputParser, + getMatchingEvent: getMatchingEvent +}; diff --git a/lib/filter.js b/lib/filter.js index 4cb297f37..8f7729379 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -36,6 +36,8 @@ var Filter = function(options, impl) { if (options.topics) { console.warn('"topics" is deprecated, use "topic" instead'); } + + this._onWatchResult = options._onWatchEventResult; // evaluate lazy properties options = { @@ -61,6 +63,9 @@ var Filter = function(options, impl) { Filter.prototype.arrived = function(callback) { this.changed(callback); }; +Filter.prototype.happened = function(callback) { + this.changed(callback); +}; /// gets called when there is new eth/shh message Filter.prototype.changed = function(callback) { @@ -71,7 +76,8 @@ Filter.prototype.changed = function(callback) { Filter.prototype.trigger = function(messages) { for (var i = 0; i < this.callbacks.length; i++) { for (var j = 0; j < messages.length; j++) { - this.callbacks[i].call(this, messages[j]); + var message = this._onWatchResult ? this._onWatchResult(messages[j]) : messages[j]; + this.callbacks[i].call(this, message); } } }; diff --git a/lib/utils.js b/lib/utils.js index 5cd6ec8d6..e1265803c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -20,6 +20,8 @@ * @date 2015 */ +var c = require('./const'); + /// Finds first index of array element matching pattern /// @param array /// @param callback pattern @@ -101,6 +103,32 @@ var filterEvents = function (json) { }); }; +/// used to transform value/string to eth string +/// TODO: use BigNumber.js to parse int +/// TODO: add tests for it! +var toEth = function (str) { + var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str; + var unit = 0; + var units = c.ETH_UNITS; + while (val > 3000 && unit < units.length - 1) + { + val /= 1000; + unit++; + } + var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2); + var replaceFunction = function($0, $1, $2) { + return $1 + ',' + $2; + }; + + while (true) { + var o = s; + s = s.replace(/(\d)(\d\d\d[\.\,])/, replaceFunction); + if (o === s) + break; + } + return s + ' ' + units[unit]; +}; + module.exports = { findIndex: findIndex, toAscii: toAscii, @@ -108,6 +136,7 @@ module.exports = { extractDisplayName: extractDisplayName, extractTypeName: extractTypeName, filterFunctions: filterFunctions, - filterEvents: filterEvents + filterEvents: filterEvents, + toEth: toEth }; diff --git a/lib/web3.js b/lib/web3.js index c3126afc4..e868e9412 100644 --- a/lib/web3.js +++ b/lib/web3.js @@ -29,28 +29,6 @@ if (process.env.NODE_ENV !== 'build') { var utils = require('./utils'); -var ETH_UNITS = [ - 'wei', - 'Kwei', - 'Mwei', - 'Gwei', - 'szabo', - 'finney', - 'ether', - 'grand', - 'Mether', - 'Gether', - 'Tether', - 'Pether', - 'Eether', - 'Zether', - 'Yether', - 'Nether', - 'Dether', - 'Vether', - 'Uether' -]; - /// @returns an array of objects describing web3 api methods var web3Methods = function () { return [ @@ -213,29 +191,7 @@ var web3 = { }, /// used to transform value/string to eth string - /// TODO: use BigNumber.js to parse int - toEth: function(str) { - var val = typeof str === "string" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str; - var unit = 0; - var units = ETH_UNITS; - while (val > 3000 && unit < units.length - 1) - { - val /= 1000; - unit++; - } - var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2); - var replaceFunction = function($0, $1, $2) { - return $1 + ',' + $2; - }; - - while (true) { - var o = s; - s = s.replace(/(\d)(\d\d\d[\.\,])/, replaceFunction); - if (o === s) - break; - } - return s + ' ' + units[unit]; - }, + toEth: utils.toEth, /// eth object prototype eth: { @@ -271,11 +227,6 @@ var web3 = { return new web3.filter(filter, shhWatch); } }, - - /// @returns true if provider is installed - haveProvider: function() { - return !!web3.provider.provider; - } }; /// setups all api methods @@ -298,7 +249,6 @@ var shhWatch = { setupMethods(shhWatch, shhWatchMethods()); web3.setProvider = function(provider) { - //provider.onmessage = messageHandler; // there will be no async calls, to remove web3.provider.set(provider); }; diff --git a/test/event.inputParser.js b/test/event.inputParser.js new file mode 100644 index 000000000..8f9790a2d --- /dev/null +++ b/test/event.inputParser.js @@ -0,0 +1,125 @@ +var assert = require('assert'); +var event = require('../lib/event.js'); +var f = require('../lib/formatters.js'); + +describe('event', function () { + describe('inputParser', function () { + it('should create basic filter input object', function () { + + // given + var address = '0x012345'; + var signature = '0x987654'; + var e = { + name: 'Event', + inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] + }; + + // when + var impl = event.inputParser(address, signature, e); + var result = impl(); + + // then + assert.equal(result.address, address); + assert.equal(result.topic.length, 1); + assert.equal(result.topic[0], signature); + + }); + + it('should create filter input object with options', function () { + + // given + var address = '0x012345'; + var signature = '0x987654'; + var options = { + earliest: 1, + latest: 2, + offset: 3, + max: 4 + }; + var e = { + name: 'Event', + inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] + }; + + // when + var impl = event.inputParser(address, signature, e); + var result = impl({}, options); + + // then + assert.equal(result.address, address); + assert.equal(result.topic.length, 1); + assert.equal(result.topic[0], signature); + assert.equal(result.earliest, options.earliest); + assert.equal(result.latest, options.latest); + assert.equal(result.offset, options.offset); + assert.equal(result.max, options.max); + + }); + + it('should create filter input object with indexed params', function () { + + // given + var address = '0x012345'; + var signature = '0x987654'; + var options = { + earliest: 1, + latest: 2, + offset: 3, + max: 4 + }; + var e = { + name: 'Event', + inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] + }; + + // when + var impl = event.inputParser(address, signature, e); + var result = impl({a: 4}, options); + + // then + assert.equal(result.address, address); + assert.equal(result.topic.length, 2); + assert.equal(result.topic[0], signature); + assert.equal(result.topic[1], f.formatInputInt(4)); + assert.equal(result.earliest, options.earliest); + assert.equal(result.latest, options.latest); + assert.equal(result.offset, options.offset); + assert.equal(result.max, options.max); + + }); + + it('should create filter input object with an array of indexed params', function () { + + // given + var address = '0x012345'; + var signature = '0x987654'; + var options = { + earliest: 1, + latest: 2, + offset: 3, + max: 4 + }; + var e = { + name: 'Event', + inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] + }; + + // when + var impl = event.inputParser(address, signature, e); + var result = impl({a: [4, 69]}, options); + + // then + assert.equal(result.address, address); + assert.equal(result.topic.length, 2); + assert.equal(result.topic[0], signature); + assert.equal(result.topic[1][0], f.formatInputInt(4)); + assert.equal(result.topic[1][1], f.formatInputInt(69)); + assert.equal(result.earliest, options.earliest); + assert.equal(result.latest, options.latest); + assert.equal(result.offset, options.offset); + assert.equal(result.max, options.max); + + }); + }); +}); + diff --git a/test/event.js b/test/event.js deleted file mode 100644 index 9edd93ae7..000000000 --- a/test/event.js +++ /dev/null @@ -1,124 +0,0 @@ -var assert = require('assert'); -var event = require('../lib/event.js'); -var f = require('../lib/formatters.js'); - -describe('event', function () { - it('should create basic filter input object', function () { - - // given - var address = '0x012345'; - var signature = '0x987654'; - var e = { - name: 'Event', - inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] - }; - - // when - var impl = event(address, signature, e); - var result = impl(); - - // then - assert.equal(result.address, address); - assert.equal(result.topic.length, 1); - assert.equal(result.topic[0], signature); - - }); - - it('should create filter input object with options', function () { - - // given - var address = '0x012345'; - var signature = '0x987654'; - var options = { - earliest: 1, - latest: 2, - offset: 3, - max: 4 - }; - var e = { - name: 'Event', - inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] - }; - - // when - var impl = event(address, signature, e); - var result = impl({}, options); - - // then - assert.equal(result.address, address); - assert.equal(result.topic.length, 1); - assert.equal(result.topic[0], signature); - assert.equal(result.earliest, options.earliest); - assert.equal(result.latest, options.latest); - assert.equal(result.offset, options.offset); - assert.equal(result.max, options.max); - - }); - - it('should create filter input object with indexed params', function () { - - // given - var address = '0x012345'; - var signature = '0x987654'; - var options = { - earliest: 1, - latest: 2, - offset: 3, - max: 4 - }; - var e = { - name: 'Event', - inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] - }; - - // when - var impl = event(address, signature, e); - var result = impl({a: 4}, options); - - // then - assert.equal(result.address, address); - assert.equal(result.topic.length, 2); - assert.equal(result.topic[0], signature); - assert.equal(result.topic[1], f.formatInputInt(4)); - assert.equal(result.earliest, options.earliest); - assert.equal(result.latest, options.latest); - assert.equal(result.offset, options.offset); - assert.equal(result.max, options.max); - - }); - - it('should create filter input object with an array of indexed params', function () { - - // given - var address = '0x012345'; - var signature = '0x987654'; - var options = { - earliest: 1, - latest: 2, - offset: 3, - max: 4 - }; - var e = { - name: 'Event', - inputs: [{"name":"a","type":"uint256","indexed":true},{"name":"b","type":"hash256","indexed":false}] - }; - - // when - var impl = event(address, signature, e); - var result = impl({a: [4, 69]}, options); - - // then - assert.equal(result.address, address); - assert.equal(result.topic.length, 2); - assert.equal(result.topic[0], signature); - assert.equal(result.topic[1][0], f.formatInputInt(4)); - assert.equal(result.topic[1][1], f.formatInputInt(69)); - assert.equal(result.earliest, options.earliest); - assert.equal(result.latest, options.latest); - assert.equal(result.offset, options.offset); - assert.equal(result.max, options.max); - - }); - -}); - diff --git a/test/event.outputParser.js b/test/event.outputParser.js new file mode 100644 index 000000000..22f4ed395 --- /dev/null +++ b/test/event.outputParser.js @@ -0,0 +1,81 @@ +var assert = require('assert'); +var event = require('../lib/event.js'); + +describe('event', function () { + describe('outputParser', function () { + it('should parse basic event output object', function () { + + // given + var output = { + "address":"0x78dfc5983baecf65f73e3de3a96cee24e6b7981e", + "data":"0x000000000000000000000000000000000000000000000000000000000000004b", + "number":2, + "topic":[ + "0x6e61ef44ac2747ff8b84d353a908eb8bd5c3fb118334d57698c5cfc7041196ad", + "0x0000000000000000000000000000000000000000000000000000000000000001" + ] + }; + + var e = { + name: 'Event', + inputs: [{"name":"a","type":"bool","indexed":true},{"name":"b","type":"uint256","indexed":false}] + }; + + // when + var impl = event.outputParser(e); + var result = impl(output); + + // then + assert.equal(result.event, 'Event'); + assert.equal(result.number, 2); + assert.equal(Object.keys(result.args).length, 2); + assert.equal(result.args.a, true); + assert.equal(result.args.b, 75); + }); + + it('should parse event output object arguments in correct order', function () { + + // given + var output = { + "address":"0x78dfc5983baecf65f73e3de3a96cee24e6b7981e", + "data": "0x" + + "000000000000000000000000000000000000000000000000000000000000004b" + + "000000000000000000000000000000000000000000000000000000000000004c" + + "0000000000000000000000000000000000000000000000000000000000000001", + "number":3, + "topic":[ + "0x6e61ef44ac2747ff8b84d353a908eb8bd5c3fb118334d57698c5cfc7041196ad", + "0x0000000000000000000000000000000000000000000000000000000000000001", + "0x0000000000000000000000000000000000000000000000000000000000000005" + ] + }; + + var e = { + name: 'Event2', + inputs: [ + {"name":"a","type":"bool","indexed":true}, + {"name":"b","type":"int","indexed":false}, + {"name":"c","type":"int","indexed":false}, + {"name":"d","type":"int","indexed":true}, + {"name":"e","type":"bool","indexed":false} + ] + }; + + // when + var impl = event.outputParser(e); + var result = impl(output); + + // then + assert.equal(result.event, 'Event2'); + assert.equal(result.number, 3); + assert.equal(Object.keys(result.args).length, 5); + assert.equal(result.args.a, true); + assert.equal(result.args.b, 75); + assert.equal(result.args.c, 76); + assert.equal(result.args.d, 5); + assert.equal(result.args.e, true); + + }); + }); +}); + From 1045d14ad6c39dcc99743290aebe57ebcb526999 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 3 Feb 2015 16:43:14 +0100 Subject: [PATCH 38/55] fixed indention --- cmake/EthExecutableHelper.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/EthExecutableHelper.cmake b/cmake/EthExecutableHelper.cmake index b8276fe54..6e859bf31 100644 --- a/cmake/EthExecutableHelper.cmake +++ b/cmake/EthExecutableHelper.cmake @@ -86,8 +86,8 @@ macro(eth_install_executable EXECUTABLE) # TODO check, how fixup_bundle works and if it is required install(CODE " include(BundleUtilities) - set(BU_CHMOD_BUNDLE_ITEMS 1) - verify_app(\"${APP_BUNDLE_PATH}\") + set(BU_CHMOD_BUNDLE_ITEMS 1) + verify_app(\"${APP_BUNDLE_PATH}\") " COMPONENT RUNTIME ) # Cleanup duplicate libs from macdeployqt install(CODE " From b0dd99ab13622560d75cf748b2f0e9c3721b822c Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 3 Feb 2015 16:56:56 +0100 Subject: [PATCH 39/55] misc --- mix/qml/StateDialog.qml | 2 -- mix/qml/main.qml | 10 +++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/mix/qml/StateDialog.qml b/mix/qml/StateDialog.qml index a2f9b7fa8..fa48c640e 100644 --- a/mix/qml/StateDialog.qml +++ b/mix/qml/StateDialog.qml @@ -37,7 +37,6 @@ Window { isDefault = setDefault; titleField.focus = true; defaultCheckBox.enabled = !isDefault; - } function close() { @@ -89,7 +88,6 @@ Window { Layout.fillWidth: true } - Label { text: qsTr("Transactions") } diff --git a/mix/qml/main.qml b/mix/qml/main.qml index a90c90feb..720d5070d 100644 --- a/mix/qml/main.qml +++ b/mix/qml/main.qml @@ -92,14 +92,14 @@ ApplicationWindow { Connections { target: projectModel.stateListModel - onDefaultStateChanged: - { - debugRunAction.text = qsTr("Deploy") + " \"" + projectModel.stateListModel.defaultStateName() + "\""; - } - onStateListModelReady: + + function updateRunLabel() { debugRunAction.text = qsTr("Deploy") + " \"" + projectModel.stateListModel.defaultStateName() + "\""; } + + onDefaultStateChanged: updateRunLabel() + onStateListModelReady: updateRunLabel() } Action { From 101915767f61f3b5935e1ac115f92f4c7df240a6 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 3 Feb 2015 08:48:11 -0800 Subject: [PATCH 40/55] Minor typo. --- libsolidity/Types.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsolidity/Types.cpp b/libsolidity/Types.cpp index cfb852c2f..54e701c10 100644 --- a/libsolidity/Types.cpp +++ b/libsolidity/Types.cpp @@ -629,7 +629,7 @@ FunctionType::FunctionType(VariableDeclaration const& _varDecl): auto mappingType = dynamic_cast(varDeclType.get()); auto returnType = varDeclType; - while (mappingType!= nullptr) + while (mappingType != nullptr) { params.push_back(mappingType->getKeyType()); paramNames.push_back(""); From f6955b370e6c8c55436b31a94fd79f87890cce89 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 3 Feb 2015 12:25:08 -0800 Subject: [PATCH 41/55] Fixes for named-args. --- libsolidity/AST.cpp | 2 +- libsolidity/AST.h | 6 +++--- libsolidity/ExpressionCompiler.cpp | 21 ++++++--------------- libsolidity/Parser.cpp | 24 ++++++++---------------- libsolidity/Parser.h | 2 +- 5 files changed, 19 insertions(+), 36 deletions(-) diff --git a/libsolidity/AST.cpp b/libsolidity/AST.cpp index 33cb4ac32..6028c07cf 100644 --- a/libsolidity/AST.cpp +++ b/libsolidity/AST.cpp @@ -513,7 +513,7 @@ void FunctionCall::checkTypeRequirements() for (size_t i = 0; i < m_names.size(); i++) { bool found = false; for (size_t j = 0; j < parameterNames.size(); j++) { - if (parameterNames[j] == m_names[i]) { + if (parameterNames[j] == *m_names[i]) { // check type convertible if (!m_arguments[i]->getType()->isImplicitlyConvertibleTo(*parameterTypes[j])) BOOST_THROW_EXCEPTION(createTypeError("Invalid type for argument in function call.")); diff --git a/libsolidity/AST.h b/libsolidity/AST.h index bd1535138..525907bf4 100755 --- a/libsolidity/AST.h +++ b/libsolidity/AST.h @@ -963,7 +963,7 @@ class FunctionCall: public Expression { public: FunctionCall(Location const& _location, ASTPointer const& _expression, - std::vector> const& _arguments, std::vector const& _names): + std::vector> const& _arguments, std::vector> const& _names): Expression(_location), m_expression(_expression), m_arguments(_arguments), m_names(_names) {} virtual void accept(ASTVisitor& _visitor) override; virtual void accept(ASTConstVisitor& _visitor) const override; @@ -971,7 +971,7 @@ public: Expression const& getExpression() const { return *m_expression; } std::vector> getArguments() const { return {m_arguments.begin(), m_arguments.end()}; } - std::vector const& getNames() const { return m_names; } + std::vector> const& getNames() const { return m_names; } /// Returns true if this is not an actual function call, but an explicit type conversion /// or constructor call. @@ -980,7 +980,7 @@ public: private: ASTPointer m_expression; std::vector> m_arguments; - std::vector m_names; + std::vector> m_names; }; /** diff --git a/libsolidity/ExpressionCompiler.cpp b/libsolidity/ExpressionCompiler.cpp index 13d8ccf12..875e00bc2 100644 --- a/libsolidity/ExpressionCompiler.cpp +++ b/libsolidity/ExpressionCompiler.cpp @@ -204,34 +204,25 @@ bool ExpressionCompiler::visit(FunctionCall const& _functionCall) { FunctionType const& function = dynamic_cast(*_functionCall.getExpression().getType()); TypePointers const& parameterTypes = function.getParameterTypes(); - vector const& parameterNames = function.getParameterNames(); vector> const& callArguments = _functionCall.getArguments(); - vector const& callArgumentNames = _functionCall.getNames(); + vector> const& callArgumentNames = _functionCall.getNames(); solAssert(callArguments.size() == parameterTypes.size(), ""); vector> arguments; if (callArgumentNames.empty()) - { // normal arguments - arguments = {callArguments.begin(), callArguments.end()}; - } + arguments = callArguments; else - { // named arguments - for (size_t i = 0; i < parameterNames.size(); i++) { + for (auto const& parameterName: function.getParameterNames()) + { bool found = false; - for (size_t j = 0; j < callArgumentNames.size(); j++) { - if (parameterNames[i] == callArgumentNames[j]) { + for (size_t j = 0; j < callArgumentNames.size() && !found; j++) + if ((found = (parameterName == *callArgumentNames[j]))) // we found the actual parameter position arguments.push_back(callArguments[j]); - - found = true; - break; - } - } solAssert(found, ""); } - } switch (function.getLocation()) { diff --git a/libsolidity/Parser.cpp b/libsolidity/Parser.cpp index 1cf0bce5f..74d6c982a 100644 --- a/libsolidity/Parser.cpp +++ b/libsolidity/Parser.cpp @@ -592,7 +592,6 @@ ASTPointer Parser::parseBinaryExpression(int _minPrecedence) ASTPointer expression = parseUnaryExpression(); int precedence = Token::precedence(m_scanner->getCurrentToken()); for (; precedence >= _minPrecedence; --precedence) - { while (Token::precedence(m_scanner->getCurrentToken()) == precedence) { Token::Value op = m_scanner->getCurrentToken(); @@ -601,7 +600,6 @@ ASTPointer Parser::parseBinaryExpression(int _minPrecedence) nodeFactory.setEndPositionFromNode(right); expression = nodeFactory.createNode(expression, op, right); } - } return expression; } @@ -668,8 +666,8 @@ ASTPointer Parser::parseLeftHandSideExpression() { m_scanner->next(); vector> arguments; - vector names; - parseFunctionCallArguments(arguments, names); + vector> names; + std::tie(arguments, names) = parseFunctionCallArguments(); nodeFactory.markEndPosition(); expectToken(Token::RPAREN); expression = nodeFactory.createNode(expression, arguments, names); @@ -740,8 +738,9 @@ vector> Parser::parseFunctionCallListArguments() return arguments; } -void Parser::parseFunctionCallArguments(vector>& _arguments, vector& _names) +pair>, vector>> Parser::parseFunctionCallArguments() { + pair>, vector>> ret; Token::Value token = m_scanner->getCurrentToken(); if (token == Token::LBRACE) { @@ -749,28 +748,21 @@ void Parser::parseFunctionCallArguments(vector>& _argumen expectToken(Token::LBRACE); while (m_scanner->getCurrentToken() != Token::RBRACE) { - string identifier = *expectIdentifierToken(); expectToken(Token::COLON); - ASTPointer expression = parseExpression(); - _arguments.push_back(expression); - _names.push_back(identifier); + ret.first.push_back(parseExpression()); + ret.second.push_back(expectIdentifierToken()); if (m_scanner->getCurrentToken() == Token::COMMA) - { expectToken(Token::COMMA); - } else - { break; - } } expectToken(Token::RBRACE); } else - { - _arguments = parseFunctionCallListArguments(); - } + ret.first = parseFunctionCallListArguments(); + return ret; } diff --git a/libsolidity/Parser.h b/libsolidity/Parser.h index e8d521c94..19e0af1aa 100644 --- a/libsolidity/Parser.h +++ b/libsolidity/Parser.h @@ -82,7 +82,7 @@ private: ASTPointer parseLeftHandSideExpression(); ASTPointer parsePrimaryExpression(); std::vector> parseFunctionCallListArguments(); - void parseFunctionCallArguments(std::vector> & _arguments, std::vector & _names); + std::pair>, std::vector>> parseFunctionCallArguments(); ///@} ///@{ From eb8b02d22f06799825a030b806b70ae00eb00426 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 3 Feb 2015 12:45:16 -0800 Subject: [PATCH 42/55] Fixes. --- libsolidity/Parser.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libsolidity/Parser.cpp b/libsolidity/Parser.cpp index 74d6c982a..0ad7bd7ca 100644 --- a/libsolidity/Parser.cpp +++ b/libsolidity/Parser.cpp @@ -748,10 +748,9 @@ pair>, vector>> Parser::pars expectToken(Token::LBRACE); while (m_scanner->getCurrentToken() != Token::RBRACE) { + ret.second.push_back(expectIdentifierToken()); expectToken(Token::COLON); - ret.first.push_back(parseExpression()); - ret.second.push_back(expectIdentifierToken()); if (m_scanner->getCurrentToken() == Token::COMMA) expectToken(Token::COMMA); From f1cf1b28d797f0761c7cf6ea5236396326f0f682 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 3 Feb 2015 23:14:19 +0100 Subject: [PATCH 43/55] Squashed 'libjsqrc/ethereumjs/' changes from f1a5cf9..a0cfa3c a0cfa3c version upgrade e58e2f5 jsonrpc.js tests && jsonrpc response validation is more strict 45134de jsonrpc.js file && batch polling f3ce1f0 simplified polling && jsonrpc payload creation ddc1719 tests && fixes for utils methods fdcc1af clearing tests 4a54b8c version upgrade 0.0.12 git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: a0cfa3ca21163f26f3f71a0e2ce0a1e617554c72 --- bower.json | 2 +- dist/ethereum.js | 183 +++++--- dist/ethereum.js.map | 16 +- dist/ethereum.min.js | 2 +- lib/filter.js | 2 +- lib/httpsync.js | 32 +- lib/jsonrpc.js | 65 +++ lib/providermanager.js | 45 +- lib/qtsync.js | 3 +- lib/utils.js | 2 +- lib/web3.js | 10 +- package.json | 2 +- test/{abi.parsers.js => abi.inputParser.js} | 438 ------------------- test/abi.outputParser.js | 461 ++++++++++++++++++++ test/db.methods.js | 2 +- test/eth.methods.js | 2 +- test/jsonrpc.isValidResponse.js | 128 ++++++ test/jsonrpc.toBatchPayload.js | 47 ++ test/jsonrpc.toPayload.js | 40 ++ test/shh.methods.js | 2 +- test/{utils.js => test.utils.js} | 0 test/utils.extractDisplayName.js | 42 ++ test/utils.extractTypeName.js | 55 +++ test/web3.methods.js | 2 +- 24 files changed, 1012 insertions(+), 571 deletions(-) create mode 100644 lib/jsonrpc.js rename test/{abi.parsers.js => abi.inputParser.js} (52%) create mode 100644 test/abi.outputParser.js create mode 100644 test/jsonrpc.isValidResponse.js create mode 100644 test/jsonrpc.toBatchPayload.js create mode 100644 test/jsonrpc.toPayload.js rename test/{utils.js => test.utils.js} (100%) create mode 100644 test/utils.extractDisplayName.js create mode 100644 test/utils.extractTypeName.js diff --git a/bower.json b/bower.json index 420618390..168f1b39a 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "ethereum.js", "namespace": "ethereum", - "version": "0.0.11", + "version": "0.0.13", "description": "Ethereum Compatible JavaScript API", "main": ["./dist/ethereum.js", "./dist/ethereum.min.js"], "dependencies": { diff --git a/dist/ethereum.js b/dist/ethereum.js index 0a83a3c50..564d59b4a 100644 --- a/dist/ethereum.js +++ b/dist/ethereum.js @@ -210,7 +210,7 @@ module.exports = { }; -},{"./const":2,"./formatters":6,"./types":10,"./utils":11,"./web3":12}],2:[function(require,module,exports){ +},{"./const":2,"./formatters":6,"./types":11,"./utils":12,"./web3":13}],2:[function(require,module,exports){ /* This file is part of ethereum.js. @@ -487,7 +487,7 @@ var contract = function (address, desc) { module.exports = contract; -},{"./abi":1,"./event":4,"./utils":11,"./web3":12}],4:[function(require,module,exports){ +},{"./abi":1,"./event":4,"./utils":12,"./web3":13}],4:[function(require,module,exports){ /* This file is part of ethereum.js. @@ -624,7 +624,7 @@ module.exports = { }; -},{"./abi":1,"./utils":11}],5:[function(require,module,exports){ +},{"./abi":1,"./utils":12}],5:[function(require,module,exports){ /* This file is part of ethereum.js. @@ -683,7 +683,7 @@ var Filter = function(options, impl) { this.callbacks = []; this.id = impl.newFilter(options); - web3.provider.startPolling({call: impl.changed, args: [this.id]}, this.id, this.trigger.bind(this)); + web3.provider.startPolling({method: impl.changed, params: [this.id]}, this.id, this.trigger.bind(this)); }; /// alias for changed* @@ -727,7 +727,7 @@ Filter.prototype.logs = function () { module.exports = Filter; -},{"./web3":12}],6:[function(require,module,exports){ +},{"./web3":13}],6:[function(require,module,exports){ /* This file is part of ethereum.js. @@ -883,7 +883,7 @@ module.exports = { }; -},{"./const":2,"./utils":11}],7:[function(require,module,exports){ +},{"./const":2,"./utils":12}],7:[function(require,module,exports){ /* This file is part of ethereum.js. @@ -916,40 +916,16 @@ var HttpSyncProvider = function (host) { this.host = host || 'http://localhost:8080'; }; -/// Transforms inner message to proper jsonrpc object -/// @param inner message object -/// @returns jsonrpc object -function formatJsonRpcObject(object) { - return { - jsonrpc: '2.0', - method: object.call, - params: object.args, - id: object._id - }; -} - -/// Transforms jsonrpc object to inner message -/// @param incoming jsonrpc message -/// @returns inner message object -function formatJsonRpcMessage(message) { - var object = JSON.parse(message); - - return { - _id: object.id, - data: object.result, - error: object.error - }; -} - HttpSyncProvider.prototype.send = function (payload) { - var data = formatJsonRpcObject(payload); + //var data = formatJsonRpcObject(payload); var request = new XMLHttpRequest(); request.open('POST', this.host, false); - request.send(JSON.stringify(data)); + request.send(JSON.stringify(payload)); // check request.status - return request.responseText; + var result = request.responseText; + return JSON.parse(result); }; module.exports = HttpSyncProvider; @@ -972,6 +948,73 @@ module.exports = HttpSyncProvider; You should have received a copy of the GNU Lesser General Public License along with ethereum.js. If not, see . */ +/** @file jsonrpc.js + * @authors: + * Marek Kotewicz + * @date 2015 + */ + +var messageId = 1; + +/// Should be called to valid json create payload object +/// @param method of jsonrpc call, required +/// @param params, an array of method params, optional +/// @returns valid jsonrpc payload object +var toPayload = function (method, params) { + if (!method) + console.error('jsonrpc method should be specified!'); + + return { + jsonrpc: '2.0', + method: method, + params: params || [], + id: messageId++ + }; +}; + +/// Should be called to check if jsonrpc response is valid +/// @returns true if response is valid, otherwise false +var isValidResponse = function (response) { + return !!response && + !response.error && + response.jsonrpc === '2.0' && + typeof response.id === 'number' && + (!!response.result || typeof response.result === 'boolean'); +}; + +/// Should be called to create batch payload object +/// @param messages, an array of objects with method (required) and params (optional) fields +var toBatchPayload = function (messages) { + return messages.map(function (message) { + return toPayload(message.method, message.params); + }); +}; + +module.exports = { + toPayload: toPayload, + isValidResponse: isValidResponse, + toBatchPayload: toBatchPayload +}; + + + +},{}],9:[function(require,module,exports){ +/* + This file is part of ethereum.js. + + ethereum.js is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ethereum.js is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with ethereum.js. If not, see . +*/ /** @file providermanager.js * @authors: * Jeffrey Wilcke @@ -981,7 +1024,9 @@ module.exports = HttpSyncProvider; * @date 2014 */ -var web3 = require('./web3'); // jshint ignore:line +var web3 = require('./web3'); +var jsonrpc = require('./jsonrpc'); + /** * Provider manager object prototype @@ -995,25 +1040,35 @@ var web3 = require('./web3'); // jshint ignore:line var ProviderManager = function() { this.polls = []; this.provider = undefined; - this.id = 1; var self = this; var poll = function () { if (self.provider) { - self.polls.forEach(function (data) { - data.data._id = self.id; - self.id++; - var result = self.provider.send(data.data); - - result = JSON.parse(result); + var pollsBatch = self.polls.map(function (data) { + return data.data; + }); + + var payload = jsonrpc.toBatchPayload(pollsBatch); + var results = self.provider.send(payload); + + self.polls.forEach(function (data, index) { + var result = results[index]; + if (!jsonrpc.isValidResponse(result)) { + console.log(result); + return; + } + + result = result.result; // dont call the callback if result is not an array, or empty one - if (result.error || !(result.result instanceof Array) || result.result.length === 0) { + if (!(result instanceof Array) || result.length === 0) { return; } - data.callback(result.result); + data.callback(result); + }); + } setTimeout(poll, 1000); }; @@ -1021,22 +1076,19 @@ var ProviderManager = function() { }; /// sends outgoing requests +/// @params data - an object with at least 'method' property ProviderManager.prototype.send = function(data) { - - data.args = data.args || []; - data._id = this.id++; + var payload = jsonrpc.toPayload(data.method, data.params); if (this.provider === undefined) { console.error('provider is not set'); return null; } - //TODO: handle error here? - var result = this.provider.send(data); - result = JSON.parse(result); + var result = this.provider.send(payload); - if (result.error) { - console.log(result.error); + if (!jsonrpc.isValidResponse(result)) { + console.log(result); return null; } @@ -1067,7 +1119,7 @@ ProviderManager.prototype.stopPolling = function (pollId) { module.exports = ProviderManager; -},{"./web3":12}],9:[function(require,module,exports){ +},{"./jsonrpc":8,"./web3":13}],10:[function(require,module,exports){ /* This file is part of ethereum.js. @@ -1095,13 +1147,14 @@ var QtSyncProvider = function () { }; QtSyncProvider.prototype.send = function (payload) { - return navigator.qt.callMethod(JSON.stringify(payload)); + var result = navigator.qt.callMethod(JSON.stringify(payload)); + return JSON.parse(result); }; module.exports = QtSyncProvider; -},{}],10:[function(require,module,exports){ +},{}],11:[function(require,module,exports){ /* This file is part of ethereum.js. @@ -1182,7 +1235,7 @@ module.exports = { }; -},{"./formatters":6}],11:[function(require,module,exports){ +},{"./formatters":6}],12:[function(require,module,exports){ /* This file is part of ethereum.js. @@ -1269,7 +1322,7 @@ var extractDisplayName = function (name) { var extractTypeName = function (name) { /// TODO: make it invulnerable var length = name.indexOf('('); - return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)) : ""; + return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : ""; }; /// Filters all function from input abi @@ -1326,7 +1379,7 @@ module.exports = { }; -},{"./const":2}],12:[function(require,module,exports){ +},{"./const":2}],13:[function(require,module,exports){ /* This file is part of ethereum.js. @@ -1465,8 +1518,8 @@ var setupMethods = function (obj, methods) { var args = Array.prototype.slice.call(arguments); var call = typeof method.call === 'function' ? method.call(args) : method.call; return web3.provider.send({ - call: call, - args: args + method: call, + params: args }); }; }); @@ -1479,15 +1532,15 @@ var setupProperties = function (obj, properties) { var proto = {}; proto.get = function () { return web3.provider.send({ - call: property.getter + method: property.getter }); }; if (property.setter) { proto.set = function (val) { return web3.provider.send({ - call: property.setter, - args: [val] + method: property.setter, + params: [val] }); }; } @@ -1584,7 +1637,7 @@ web3.setProvider = function(provider) { module.exports = web3; -},{"./utils":11}],"web3":[function(require,module,exports){ +},{"./utils":12}],"web3":[function(require,module,exports){ var web3 = require('./lib/web3'); var ProviderManager = require('./lib/providermanager'); web3.provider = new ProviderManager(); @@ -1597,7 +1650,7 @@ web3.abi = require('./lib/abi'); module.exports = web3; -},{"./lib/abi":1,"./lib/contract":3,"./lib/filter":5,"./lib/httpsync":7,"./lib/providermanager":8,"./lib/qtsync":9,"./lib/web3":12}]},{},["web3"]) +},{"./lib/abi":1,"./lib/contract":3,"./lib/filter":5,"./lib/httpsync":7,"./lib/providermanager":9,"./lib/qtsync":10,"./lib/web3":13}]},{},["web3"]) //# sourceMappingURL=ethereum.js.map \ No newline at end of file diff --git a/dist/ethereum.js.map b/dist/ethereum.js.map index 2c1bebd75..1ef0b2f76 100644 --- a/dist/ethereum.js.map +++ b/dist/ethereum.js.map @@ -9,6 +9,7 @@ "lib/filter.js", "lib/formatters.js", "lib/httpsync.js", + "lib/jsonrpc.js", "lib/providermanager.js", "lib/qtsync.js", "lib/types.js", @@ -17,7 +18,7 @@ "index.js" ], "names": [], - "mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1JA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACtEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9IA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA", + "mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AClNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACxDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACzNA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACrGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC1JA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACvHA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ACjCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC/EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9IA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AChQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA", "file": "generated.js", "sourceRoot": "", "sourcesContent": [ @@ -26,14 +27,15 @@ "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file const.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\n/// required to define ETH_BIGNUMBER_ROUNDING_MODE\nif (\"build\" !== 'build') {/*\n var BigNumber = require('bignumber.js'); // jshint ignore:line\n*/}\n\nvar ETH_UNITS = [ \n 'wei', \n 'Kwei', \n 'Mwei', \n 'Gwei', \n 'szabo', \n 'finney', \n 'ether', \n 'grand', \n 'Mether', \n 'Gether', \n 'Tether', \n 'Pether', \n 'Eether', \n 'Zether', \n 'Yether', \n 'Nether', \n 'Dether', \n 'Vether', \n 'Uether' \n];\n\nmodule.exports = {\n ETH_PADDING: 32,\n ETH_SIGNATURE_LENGTH: 4,\n ETH_UNITS: ETH_UNITS,\n ETH_BIGNUMBER_ROUNDING_MODE: { ROUNDING_MODE: BigNumber.ROUND_DOWN }\n};\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file contract.js\n * @authors:\n * Marek Kotewicz \n * @date 2014\n */\n\nvar web3 = require('./web3'); \nvar abi = require('./abi');\nvar utils = require('./utils');\nvar eventImpl = require('./event');\n\nvar exportNatspecGlobals = function (vars) {\n // it's used byt natspec.js\n // TODO: figure out better way to solve this\n web3._currentContractAbi = vars.abi;\n web3._currentContractAddress = vars.address;\n web3._currentContractMethodName = vars.method;\n web3._currentContractMethodParams = vars.params;\n};\n\nvar addFunctionRelatedPropertiesToContract = function (contract) {\n \n contract.call = function (options) {\n contract._isTransact = false;\n contract._options = options;\n return contract;\n };\n\n contract.transact = function (options) {\n contract._isTransact = true;\n contract._options = options;\n return contract;\n };\n\n contract._options = {};\n ['gas', 'gasPrice', 'value', 'from'].forEach(function(p) {\n contract[p] = function (v) {\n contract._options[p] = v;\n return contract;\n };\n });\n\n};\n\nvar addFunctionsToContract = function (contract, desc, address) {\n var inputParser = abi.inputParser(desc);\n var outputParser = abi.outputParser(desc);\n\n // create contract functions\n utils.filterFunctions(desc).forEach(function (method) {\n\n var displayName = utils.extractDisplayName(method.name);\n var typeName = utils.extractTypeName(method.name);\n\n var impl = function () {\n var params = Array.prototype.slice.call(arguments);\n var signature = abi.signatureFromAscii(method.name);\n var parsed = inputParser[displayName][typeName].apply(null, params);\n\n var options = contract._options || {};\n options.to = address;\n options.data = signature + parsed;\n \n var isTransact = contract._isTransact === true || (contract._isTransact !== false && !method.constant);\n var collapse = options.collapse !== false;\n \n // reset\n contract._options = {};\n contract._isTransact = null;\n\n if (isTransact) {\n \n exportNatspecGlobals({\n abi: desc,\n address: address,\n method: method.name,\n params: params\n });\n\n // transactions do not have any output, cause we do not know, when they will be processed\n web3.eth.transact(options);\n return;\n }\n \n var output = web3.eth.call(options);\n var ret = outputParser[displayName][typeName](output);\n if (collapse)\n {\n if (ret.length === 1)\n ret = ret[0];\n else if (ret.length === 0)\n ret = null;\n }\n return ret;\n };\n\n if (contract[displayName] === undefined) {\n contract[displayName] = impl;\n }\n\n contract[displayName][typeName] = impl;\n });\n};\n\nvar addEventRelatedPropertiesToContract = function (contract, desc, address) {\n contract.address = address;\n contract._onWatchEventResult = function (data) {\n var matchingEvent = event.getMatchingEvent(utils.filterEvents(desc));\n var parser = eventImpl.outputParser(matchingEvent);\n return parser(data);\n };\n \n Object.defineProperty(contract, 'topic', {\n get: function() {\n return utils.filterEvents(desc).map(function (e) {\n return abi.eventSignatureFromAscii(e.name);\n });\n }\n });\n\n};\n\nvar addEventsToContract = function (contract, desc, address) {\n // create contract events\n utils.filterEvents(desc).forEach(function (e) {\n\n var impl = function () {\n var params = Array.prototype.slice.call(arguments);\n var signature = abi.eventSignatureFromAscii(e.name);\n var event = eventImpl.inputParser(address, signature, e);\n var o = event.apply(null, params);\n o._onWatchEventResult = function (data) {\n var parser = eventImpl.outputParser(e);\n return parser(data);\n };\n return web3.eth.watch(o); \n };\n \n // this property should be used by eth.filter to check if object is an event\n impl._isEvent = true;\n\n var displayName = utils.extractDisplayName(e.name);\n var typeName = utils.extractTypeName(e.name);\n\n if (contract[displayName] === undefined) {\n contract[displayName] = impl;\n }\n\n contract[displayName][typeName] = impl;\n\n });\n};\n\n\n/**\n * This method should be called when we want to call / transact some solidity method from javascript\n * it returns an object which has same methods available as solidity contract description\n * usage example: \n *\n * var abi = [{\n * name: 'myMethod',\n * inputs: [{ name: 'a', type: 'string' }],\n * outputs: [{name: 'd', type: 'string' }]\n * }]; // contract abi\n *\n * var myContract = web3.eth.contract('0x0123123121', abi); // creation of contract object\n *\n * myContract.myMethod('this is test string param for call'); // myMethod call (implicit, default)\n * myContract.call().myMethod('this is test string param for call'); // myMethod call (explicit)\n * myContract.transact().myMethod('this is test string param for transact'); // myMethod transact\n *\n * @param address - address of the contract, which should be called\n * @param desc - abi json description of the contract, which is being created\n * @returns contract object\n */\n\nvar contract = function (address, desc) {\n\n // workaround for invalid assumption that method.name is the full anonymous prototype of the method.\n // it's not. it's just the name. the rest of the code assumes it's actually the anonymous\n // prototype, so we make it so as a workaround.\n // TODO: we may not want to modify input params, maybe use copy instead?\n desc.forEach(function (method) {\n if (method.name.indexOf('(') === -1) {\n var displayName = method.name;\n var typeName = method.inputs.map(function(i){return i.type; }).join();\n method.name = displayName + '(' + typeName + ')';\n }\n });\n\n var result = {};\n addFunctionRelatedPropertiesToContract(result);\n addFunctionsToContract(result, desc, address);\n addEventRelatedPropertiesToContract(result, desc, address);\n addEventsToContract(result, desc, address);\n\n return result;\n};\n\nmodule.exports = contract;\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file event.js\n * @authors:\n * Marek Kotewicz \n * @date 2014\n */\n\nvar abi = require('./abi');\nvar utils = require('./utils');\n\n/// filter inputs array && returns only indexed (or not) inputs\n/// @param inputs array\n/// @param bool if result should be an array of indexed params on not\n/// @returns array of (not?) indexed params\nvar filterInputs = function (inputs, indexed) {\n return inputs.filter(function (current) {\n return current.indexed === indexed;\n });\n};\n\nvar inputWithName = function (inputs, name) {\n var index = utils.findIndex(inputs, function (input) {\n return input.name === name;\n });\n \n if (index === -1) {\n console.error('indexed param with name ' + name + ' not found');\n return undefined;\n }\n return inputs[index];\n};\n\nvar indexedParamsToTopics = function (event, indexed) {\n // sort keys?\n return Object.keys(indexed).map(function (key) {\n var inputs = [inputWithName(filterInputs(event.inputs, true), key)];\n\n var value = indexed[key];\n if (value instanceof Array) {\n return value.map(function (v) {\n return abi.formatInput(inputs, [v]);\n }); \n }\n return abi.formatInput(inputs, [value]);\n });\n};\n\nvar inputParser = function (address, signature, event) {\n \n // valid options are 'earliest', 'latest', 'offset' and 'max', as defined for 'eth.watch'\n return function (indexed, options) {\n var o = options || {};\n o.address = address;\n o.topic = [];\n o.topic.push(signature);\n if (indexed) {\n o.topic = o.topic.concat(indexedParamsToTopics(event, indexed));\n }\n return o;\n };\n};\n\nvar getArgumentsObject = function (inputs, indexed, notIndexed) {\n var indexedCopy = indexed.slice();\n var notIndexedCopy = notIndexed.slice();\n return inputs.reduce(function (acc, current) {\n var value;\n if (current.indexed)\n value = indexed.splice(0, 1)[0];\n else\n value = notIndexed.splice(0, 1)[0];\n\n acc[current.name] = value;\n return acc;\n }, {}); \n};\n \nvar outputParser = function (event) {\n \n return function (output) {\n var result = {\n event: utils.extractDisplayName(event.name),\n number: output.number,\n args: {}\n };\n\n if (!output.topic) {\n return result;\n }\n \n var indexedOutputs = filterInputs(event.inputs, true);\n var indexedData = \"0x\" + output.topic.slice(1, output.topic.length).map(function (topic) { return topic.slice(2); }).join(\"\");\n var indexedRes = abi.formatOutput(indexedOutputs, indexedData);\n\n var notIndexedOutputs = filterInputs(event.inputs, false);\n var notIndexedRes = abi.formatOutput(notIndexedOutputs, output.data);\n\n result.args = getArgumentsObject(event.inputs, indexedRes, notIndexedRes);\n\n return result;\n };\n};\n\nvar getMatchingEvent = function (events, payload) {\n for (var i = 0; i < events.length; i++) {\n var signature = abi.eventSignatureFromAscii(events[i].name); \n if (signature === payload.topic[0]) {\n return events[i];\n }\n }\n return undefined;\n};\n\n\nmodule.exports = {\n inputParser: inputParser,\n outputParser: outputParser,\n getMatchingEvent: getMatchingEvent\n};\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file filter.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nvar web3 = require('./web3'); // jshint ignore:line\n\n/// should be used when we want to watch something\n/// it's using inner polling mechanism and is notified about changes\n/// TODO: change 'options' name cause it may be not the best matching one, since we have events\nvar Filter = function(options, impl) {\n\n if (typeof options !== \"string\") {\n\n // topics property is deprecated, warn about it!\n if (options.topics) {\n console.warn('\"topics\" is deprecated, use \"topic\" instead');\n }\n \n this._onWatchResult = options._onWatchEventResult;\n\n // evaluate lazy properties\n options = {\n to: options.to,\n topic: options.topic,\n earliest: options.earliest,\n latest: options.latest,\n max: options.max,\n skip: options.skip,\n address: options.address\n };\n\n }\n \n this.impl = impl;\n this.callbacks = [];\n\n this.id = impl.newFilter(options);\n web3.provider.startPolling({call: impl.changed, args: [this.id]}, this.id, this.trigger.bind(this));\n};\n\n/// alias for changed*\nFilter.prototype.arrived = function(callback) {\n this.changed(callback);\n};\nFilter.prototype.happened = function(callback) {\n this.changed(callback);\n};\n\n/// gets called when there is new eth/shh message\nFilter.prototype.changed = function(callback) {\n this.callbacks.push(callback);\n};\n\n/// trigger calling new message from people\nFilter.prototype.trigger = function(messages) {\n for (var i = 0; i < this.callbacks.length; i++) {\n for (var j = 0; j < messages.length; j++) {\n var message = this._onWatchResult ? this._onWatchResult(messages[j]) : messages[j];\n this.callbacks[i].call(this, message);\n }\n }\n};\n\n/// should be called to uninstall current filter\nFilter.prototype.uninstall = function() {\n this.impl.uninstallFilter(this.id);\n web3.provider.stopPolling(this.id);\n};\n\n/// should be called to manually trigger getting latest messages from the client\nFilter.prototype.messages = function() {\n return this.impl.getMessages(this.id);\n};\n\n/// alias for messages\nFilter.prototype.logs = function () {\n return this.messages();\n};\n\nmodule.exports = Filter;\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file filter.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nvar web3 = require('./web3'); // jshint ignore:line\n\n/// should be used when we want to watch something\n/// it's using inner polling mechanism and is notified about changes\n/// TODO: change 'options' name cause it may be not the best matching one, since we have events\nvar Filter = function(options, impl) {\n\n if (typeof options !== \"string\") {\n\n // topics property is deprecated, warn about it!\n if (options.topics) {\n console.warn('\"topics\" is deprecated, use \"topic\" instead');\n }\n \n this._onWatchResult = options._onWatchEventResult;\n\n // evaluate lazy properties\n options = {\n to: options.to,\n topic: options.topic,\n earliest: options.earliest,\n latest: options.latest,\n max: options.max,\n skip: options.skip,\n address: options.address\n };\n\n }\n \n this.impl = impl;\n this.callbacks = [];\n\n this.id = impl.newFilter(options);\n web3.provider.startPolling({method: impl.changed, params: [this.id]}, this.id, this.trigger.bind(this));\n};\n\n/// alias for changed*\nFilter.prototype.arrived = function(callback) {\n this.changed(callback);\n};\nFilter.prototype.happened = function(callback) {\n this.changed(callback);\n};\n\n/// gets called when there is new eth/shh message\nFilter.prototype.changed = function(callback) {\n this.callbacks.push(callback);\n};\n\n/// trigger calling new message from people\nFilter.prototype.trigger = function(messages) {\n for (var i = 0; i < this.callbacks.length; i++) {\n for (var j = 0; j < messages.length; j++) {\n var message = this._onWatchResult ? this._onWatchResult(messages[j]) : messages[j];\n this.callbacks[i].call(this, message);\n }\n }\n};\n\n/// should be called to uninstall current filter\nFilter.prototype.uninstall = function() {\n this.impl.uninstallFilter(this.id);\n web3.provider.stopPolling(this.id);\n};\n\n/// should be called to manually trigger getting latest messages from the client\nFilter.prototype.messages = function() {\n return this.impl.getMessages(this.id);\n};\n\n/// alias for messages\nFilter.prototype.logs = function () {\n return this.messages();\n};\n\nmodule.exports = Filter;\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file formatters.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\nif (\"build\" !== 'build') {/*\n var BigNumber = require('bignumber.js'); // jshint ignore:line\n*/}\n\nvar utils = require('./utils');\nvar c = require('./const');\n\n/// @param string string to be padded\n/// @param number of characters that result string should have\n/// @param sign, by default 0\n/// @returns right aligned string\nvar padLeft = function (string, chars, sign) {\n return new Array(chars - string.length + 1).join(sign ? sign : \"0\") + string;\n};\n\n/// Formats input value to byte representation of int\n/// If value is negative, return it's two's complement\n/// If the value is floating point, round it down\n/// @returns right-aligned byte representation of int\nvar formatInputInt = function (value) {\n var padding = c.ETH_PADDING * 2;\n if (value instanceof BigNumber || typeof value === 'number') {\n if (typeof value === 'number')\n value = new BigNumber(value);\n BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE);\n value = value.round();\n\n if (value.lessThan(0)) \n value = new BigNumber(\"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\", 16).plus(value).plus(1);\n value = value.toString(16);\n }\n else if (value.indexOf('0x') === 0)\n value = value.substr(2);\n else if (typeof value === 'string')\n value = formatInputInt(new BigNumber(value));\n else\n value = (+value).toString(16);\n return padLeft(value, padding);\n};\n\n/// Formats input value to byte representation of string\n/// @returns left-algined byte representation of string\nvar formatInputString = function (value) {\n return utils.fromAscii(value, c.ETH_PADDING).substr(2);\n};\n\n/// Formats input value to byte representation of bool\n/// @returns right-aligned byte representation bool\nvar formatInputBool = function (value) {\n return '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0');\n};\n\n/// Formats input value to byte representation of real\n/// Values are multiplied by 2^m and encoded as integers\n/// @returns byte representation of real\nvar formatInputReal = function (value) {\n return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); \n};\n\n\n/// Check if input value is negative\n/// @param value is hex format\n/// @returns true if it is negative, otherwise false\nvar signedIsNegative = function (value) {\n return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1';\n};\n\n/// Formats input right-aligned input bytes to int\n/// @returns right-aligned input bytes formatted to int\nvar formatOutputInt = function (value) {\n value = value || \"0\";\n // check if it's negative number\n // it it is, return two's complement\n if (signedIsNegative(value)) {\n return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1);\n }\n return new BigNumber(value, 16);\n};\n\n/// Formats big right-aligned input bytes to uint\n/// @returns right-aligned input bytes formatted to uint\nvar formatOutputUInt = function (value) {\n value = value || \"0\";\n return new BigNumber(value, 16);\n};\n\n/// @returns input bytes formatted to real\nvar formatOutputReal = function (value) {\n return formatOutputInt(value).dividedBy(new BigNumber(2).pow(128)); \n};\n\n/// @returns input bytes formatted to ureal\nvar formatOutputUReal = function (value) {\n return formatOutputUInt(value).dividedBy(new BigNumber(2).pow(128)); \n};\n\n/// @returns right-aligned input bytes formatted to hex\nvar formatOutputHash = function (value) {\n return \"0x\" + value;\n};\n\n/// @returns right-aligned input bytes formatted to bool\nvar formatOutputBool = function (value) {\n return value === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false;\n};\n\n/// @returns left-aligned input bytes formatted to ascii string\nvar formatOutputString = function (value) {\n return utils.toAscii(value);\n};\n\n/// @returns right-aligned input bytes formatted to address\nvar formatOutputAddress = function (value) {\n return \"0x\" + value.slice(value.length - 40, value.length);\n};\n\n\nmodule.exports = {\n formatInputInt: formatInputInt,\n formatInputString: formatInputString,\n formatInputBool: formatInputBool,\n formatInputReal: formatInputReal,\n formatOutputInt: formatOutputInt,\n formatOutputUInt: formatOutputUInt,\n formatOutputReal: formatOutputReal,\n formatOutputUReal: formatOutputUReal,\n formatOutputHash: formatOutputHash,\n formatOutputBool: formatOutputBool,\n formatOutputString: formatOutputString,\n formatOutputAddress: formatOutputAddress\n};\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file httpsync.js\n * @authors:\n * Marek Kotewicz \n * Marian Oancea \n * @date 2014\n */\n\nif (\"build\" !== 'build') {/*\n var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line\n*/}\n\nvar HttpSyncProvider = function (host) {\n this.handlers = [];\n this.host = host || 'http://localhost:8080';\n};\n\n/// Transforms inner message to proper jsonrpc object\n/// @param inner message object\n/// @returns jsonrpc object\nfunction formatJsonRpcObject(object) {\n return {\n jsonrpc: '2.0',\n method: object.call,\n params: object.args,\n id: object._id\n };\n}\n\n/// Transforms jsonrpc object to inner message\n/// @param incoming jsonrpc message \n/// @returns inner message object\nfunction formatJsonRpcMessage(message) {\n var object = JSON.parse(message);\n\n return {\n _id: object.id,\n data: object.result,\n error: object.error\n };\n}\n\nHttpSyncProvider.prototype.send = function (payload) {\n var data = formatJsonRpcObject(payload);\n \n var request = new XMLHttpRequest();\n request.open('POST', this.host, false);\n request.send(JSON.stringify(data));\n \n // check request.status\n return request.responseText;\n};\n\nmodule.exports = HttpSyncProvider;\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file providermanager.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nvar web3 = require('./web3'); // jshint ignore:line\n\n/**\n * Provider manager object prototype\n * It's responsible for passing messages to providers\n * If no provider is set it's responsible for queuing requests\n * It's also responsible for polling the ethereum node for incoming messages\n * Default poll timeout is 12 seconds\n * If we are running ethereum.js inside ethereum browser, there are backend based tools responsible for polling,\n * and provider manager polling mechanism is not used\n */\nvar ProviderManager = function() {\n this.polls = [];\n this.provider = undefined;\n this.id = 1;\n\n var self = this;\n var poll = function () {\n if (self.provider) {\n self.polls.forEach(function (data) {\n data.data._id = self.id;\n self.id++;\n var result = self.provider.send(data.data);\n \n result = JSON.parse(result);\n \n // dont call the callback if result is not an array, or empty one\n if (result.error || !(result.result instanceof Array) || result.result.length === 0) {\n return;\n }\n\n data.callback(result.result);\n });\n }\n setTimeout(poll, 1000);\n };\n poll();\n};\n\n/// sends outgoing requests\nProviderManager.prototype.send = function(data) {\n\n data.args = data.args || [];\n data._id = this.id++;\n\n if (this.provider === undefined) {\n console.error('provider is not set');\n return null; \n }\n\n //TODO: handle error here? \n var result = this.provider.send(data);\n result = JSON.parse(result);\n\n if (result.error) {\n console.log(result.error);\n return null;\n }\n\n return result.result;\n};\n\n/// setups provider, which will be used for sending messages\nProviderManager.prototype.set = function(provider) {\n this.provider = provider;\n};\n\n/// this method is only used, when we do not have native qt bindings and have to do polling on our own\n/// should be callled, on start watching for eth/shh changes\nProviderManager.prototype.startPolling = function (data, pollId, callback) {\n this.polls.push({data: data, id: pollId, callback: callback});\n};\n\n/// should be called to stop polling for certain watch changes\nProviderManager.prototype.stopPolling = function (pollId) {\n for (var i = this.polls.length; i--;) {\n var poll = this.polls[i];\n if (poll.id === pollId) {\n this.polls.splice(i, 1);\n }\n }\n};\n\nmodule.exports = ProviderManager;\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file qtsync.js\n * @authors:\n * Marek Kotewicz \n * Marian Oancea \n * @date 2014\n */\n\nvar QtSyncProvider = function () {\n};\n\nQtSyncProvider.prototype.send = function (payload) {\n return navigator.qt.callMethod(JSON.stringify(payload));\n};\n\nmodule.exports = QtSyncProvider;\n\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file httpsync.js\n * @authors:\n * Marek Kotewicz \n * Marian Oancea \n * @date 2014\n */\n\nif (\"build\" !== 'build') {/*\n var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line\n*/}\n\nvar HttpSyncProvider = function (host) {\n this.handlers = [];\n this.host = host || 'http://localhost:8080';\n};\n\nHttpSyncProvider.prototype.send = function (payload) {\n //var data = formatJsonRpcObject(payload);\n \n var request = new XMLHttpRequest();\n request.open('POST', this.host, false);\n request.send(JSON.stringify(payload));\n \n // check request.status\n var result = request.responseText;\n return JSON.parse(result);\n};\n\nmodule.exports = HttpSyncProvider;\n\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file jsonrpc.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\nvar messageId = 1;\n\n/// Should be called to valid json create payload object\n/// @param method of jsonrpc call, required\n/// @param params, an array of method params, optional\n/// @returns valid jsonrpc payload object\nvar toPayload = function (method, params) {\n if (!method)\n console.error('jsonrpc method should be specified!');\n\n return {\n jsonrpc: '2.0',\n method: method,\n params: params || [],\n id: messageId++\n }; \n};\n\n/// Should be called to check if jsonrpc response is valid\n/// @returns true if response is valid, otherwise false \nvar isValidResponse = function (response) {\n return !!response &&\n !response.error &&\n response.jsonrpc === '2.0' &&\n typeof response.id === 'number' &&\n (!!response.result || typeof response.result === 'boolean');\n};\n\n/// Should be called to create batch payload object\n/// @param messages, an array of objects with method (required) and params (optional) fields\nvar toBatchPayload = function (messages) {\n return messages.map(function (message) {\n return toPayload(message.method, message.params);\n }); \n};\n\nmodule.exports = {\n toPayload: toPayload,\n isValidResponse: isValidResponse,\n toBatchPayload: toBatchPayload\n};\n\n\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file providermanager.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nvar web3 = require('./web3'); \nvar jsonrpc = require('./jsonrpc');\n\n\n/**\n * Provider manager object prototype\n * It's responsible for passing messages to providers\n * If no provider is set it's responsible for queuing requests\n * It's also responsible for polling the ethereum node for incoming messages\n * Default poll timeout is 12 seconds\n * If we are running ethereum.js inside ethereum browser, there are backend based tools responsible for polling,\n * and provider manager polling mechanism is not used\n */\nvar ProviderManager = function() {\n this.polls = [];\n this.provider = undefined;\n\n var self = this;\n var poll = function () {\n if (self.provider) {\n var pollsBatch = self.polls.map(function (data) {\n return data.data;\n });\n\n var payload = jsonrpc.toBatchPayload(pollsBatch);\n var results = self.provider.send(payload);\n\n self.polls.forEach(function (data, index) {\n var result = results[index];\n \n if (!jsonrpc.isValidResponse(result)) {\n console.log(result);\n return;\n }\n\n result = result.result;\n // dont call the callback if result is not an array, or empty one\n if (!(result instanceof Array) || result.length === 0) {\n return;\n }\n\n data.callback(result);\n\n });\n\n }\n setTimeout(poll, 1000);\n };\n poll();\n};\n\n/// sends outgoing requests\n/// @params data - an object with at least 'method' property\nProviderManager.prototype.send = function(data) {\n var payload = jsonrpc.toPayload(data.method, data.params);\n\n if (this.provider === undefined) {\n console.error('provider is not set');\n return null; \n }\n\n var result = this.provider.send(payload);\n\n if (!jsonrpc.isValidResponse(result)) {\n console.log(result);\n return null;\n }\n\n return result.result;\n};\n\n/// setups provider, which will be used for sending messages\nProviderManager.prototype.set = function(provider) {\n this.provider = provider;\n};\n\n/// this method is only used, when we do not have native qt bindings and have to do polling on our own\n/// should be callled, on start watching for eth/shh changes\nProviderManager.prototype.startPolling = function (data, pollId, callback) {\n this.polls.push({data: data, id: pollId, callback: callback});\n};\n\n/// should be called to stop polling for certain watch changes\nProviderManager.prototype.stopPolling = function (pollId) {\n for (var i = this.polls.length; i--;) {\n var poll = this.polls[i];\n if (poll.id === pollId) {\n this.polls.splice(i, 1);\n }\n }\n};\n\nmodule.exports = ProviderManager;\n\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file qtsync.js\n * @authors:\n * Marek Kotewicz \n * Marian Oancea \n * @date 2014\n */\n\nvar QtSyncProvider = function () {\n};\n\nQtSyncProvider.prototype.send = function (payload) {\n var result = navigator.qt.callMethod(JSON.stringify(payload));\n return JSON.parse(result);\n};\n\nmodule.exports = QtSyncProvider;\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file types.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\nvar f = require('./formatters');\n\n/// @param expected type prefix (string)\n/// @returns function which checks if type has matching prefix. if yes, returns true, otherwise false\nvar prefixedType = function (prefix) {\n return function (type) {\n return type.indexOf(prefix) === 0;\n };\n};\n\n/// @param expected type name (string)\n/// @returns function which checks if type is matching expected one. if yes, returns true, otherwise false\nvar namedType = function (name) {\n return function (type) {\n return name === type;\n };\n};\n\n/// Setups input formatters for solidity types\n/// @returns an array of input formatters \nvar inputTypes = function () {\n \n return [\n { type: prefixedType('uint'), format: f.formatInputInt },\n { type: prefixedType('int'), format: f.formatInputInt },\n { type: prefixedType('hash'), format: f.formatInputInt },\n { type: prefixedType('string'), format: f.formatInputString }, \n { type: prefixedType('real'), format: f.formatInputReal },\n { type: prefixedType('ureal'), format: f.formatInputReal },\n { type: namedType('address'), format: f.formatInputInt },\n { type: namedType('bool'), format: f.formatInputBool }\n ];\n};\n\n/// Setups output formaters for solidity types\n/// @returns an array of output formatters\nvar outputTypes = function () {\n\n return [\n { type: prefixedType('uint'), format: f.formatOutputUInt },\n { type: prefixedType('int'), format: f.formatOutputInt },\n { type: prefixedType('hash'), format: f.formatOutputHash },\n { type: prefixedType('string'), format: f.formatOutputString },\n { type: prefixedType('real'), format: f.formatOutputReal },\n { type: prefixedType('ureal'), format: f.formatOutputUReal },\n { type: namedType('address'), format: f.formatOutputAddress },\n { type: namedType('bool'), format: f.formatOutputBool }\n ];\n};\n\nmodule.exports = {\n prefixedType: prefixedType,\n namedType: namedType,\n inputTypes: inputTypes,\n outputTypes: outputTypes\n};\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file utils.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\nvar c = require('./const');\n\n/// Finds first index of array element matching pattern\n/// @param array\n/// @param callback pattern\n/// @returns index of element\nvar findIndex = function (array, callback) {\n var end = false;\n var i = 0;\n for (; i < array.length && !end; i++) {\n end = callback(array[i]);\n }\n return end ? i - 1 : -1;\n};\n\n/// @returns ascii string representation of hex value prefixed with 0x\nvar toAscii = function(hex) {\n// Find termination\n var str = \"\";\n var i = 0, l = hex.length;\n if (hex.substring(0, 2) === '0x') {\n i = 2;\n }\n for (; i < l; i+=2) {\n var code = parseInt(hex.substr(i, 2), 16);\n if (code === 0) {\n break;\n }\n\n str += String.fromCharCode(code);\n }\n\n return str;\n};\n \nvar toHex = function(str) {\n var hex = \"\";\n for(var i = 0; i < str.length; i++) {\n var n = str.charCodeAt(i).toString(16);\n hex += n.length < 2 ? '0' + n : n;\n }\n\n return hex;\n};\n\n/// @returns hex representation (prefixed by 0x) of ascii string\nvar fromAscii = function(str, pad) {\n pad = pad === undefined ? 0 : pad;\n var hex = toHex(str);\n while (hex.length < pad*2)\n hex += \"00\";\n return \"0x\" + hex;\n};\n\n/// @returns display name for function/event eg. multiply(uint256) -> multiply\nvar extractDisplayName = function (name) {\n var length = name.indexOf('('); \n return length !== -1 ? name.substr(0, length) : name;\n};\n\n/// @returns overloaded part of function/event name\nvar extractTypeName = function (name) {\n /// TODO: make it invulnerable\n var length = name.indexOf('(');\n return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)) : \"\";\n};\n\n/// Filters all function from input abi\n/// @returns abi array with filtered objects of type 'function'\nvar filterFunctions = function (json) {\n return json.filter(function (current) {\n return current.type === 'function'; \n }); \n};\n\n/// Filters all events form input abi\n/// @returns abi array with filtered objects of type 'event'\nvar filterEvents = function (json) {\n return json.filter(function (current) {\n return current.type === 'event';\n });\n};\n\n/// used to transform value/string to eth string\n/// TODO: use BigNumber.js to parse int\n/// TODO: add tests for it!\nvar toEth = function (str) {\n var val = typeof str === \"string\" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str;\n var unit = 0;\n var units = c.ETH_UNITS;\n while (val > 3000 && unit < units.length - 1)\n {\n val /= 1000;\n unit++;\n }\n var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2);\n var replaceFunction = function($0, $1, $2) {\n return $1 + ',' + $2;\n };\n\n while (true) {\n var o = s;\n s = s.replace(/(\\d)(\\d\\d\\d[\\.\\,])/, replaceFunction);\n if (o === s)\n break;\n }\n return s + ' ' + units[unit];\n};\n\nmodule.exports = {\n findIndex: findIndex,\n toAscii: toAscii,\n fromAscii: fromAscii,\n extractDisplayName: extractDisplayName,\n extractTypeName: extractTypeName,\n filterFunctions: filterFunctions,\n filterEvents: filterEvents,\n toEth: toEth\n};\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file web3.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nif (\"build\" !== 'build') {/*\n var BigNumber = require('bignumber.js');\n*/}\n\nvar utils = require('./utils');\n\n/// @returns an array of objects describing web3 api methods\nvar web3Methods = function () {\n return [\n { name: 'sha3', call: 'web3_sha3' }\n ];\n};\n\n/// @returns an array of objects describing web3.eth api methods\nvar ethMethods = function () {\n var blockCall = function (args) {\n return typeof args[0] === \"string\" ? \"eth_blockByHash\" : \"eth_blockByNumber\";\n };\n\n var transactionCall = function (args) {\n return typeof args[0] === \"string\" ? 'eth_transactionByHash' : 'eth_transactionByNumber';\n };\n\n var uncleCall = function (args) {\n return typeof args[0] === \"string\" ? 'eth_uncleByHash' : 'eth_uncleByNumber';\n };\n\n var methods = [\n { name: 'balanceAt', call: 'eth_balanceAt' },\n { name: 'stateAt', call: 'eth_stateAt' },\n { name: 'storageAt', call: 'eth_storageAt' },\n { name: 'countAt', call: 'eth_countAt'},\n { name: 'codeAt', call: 'eth_codeAt' },\n { name: 'transact', call: 'eth_transact' },\n { name: 'call', call: 'eth_call' },\n { name: 'block', call: blockCall },\n { name: 'transaction', call: transactionCall },\n { name: 'uncle', call: uncleCall },\n { name: 'compilers', call: 'eth_compilers' },\n { name: 'flush', call: 'eth_flush' },\n { name: 'lll', call: 'eth_lll' },\n { name: 'solidity', call: 'eth_solidity' },\n { name: 'serpent', call: 'eth_serpent' },\n { name: 'logs', call: 'eth_logs' }\n ];\n return methods;\n};\n\n/// @returns an array of objects describing web3.eth api properties\nvar ethProperties = function () {\n return [\n { name: 'coinbase', getter: 'eth_coinbase', setter: 'eth_setCoinbase' },\n { name: 'listening', getter: 'eth_listening', setter: 'eth_setListening' },\n { name: 'mining', getter: 'eth_mining', setter: 'eth_setMining' },\n { name: 'gasPrice', getter: 'eth_gasPrice' },\n { name: 'accounts', getter: 'eth_accounts' },\n { name: 'peerCount', getter: 'eth_peerCount' },\n { name: 'defaultBlock', getter: 'eth_defaultBlock', setter: 'eth_setDefaultBlock' },\n { name: 'number', getter: 'eth_number'}\n ];\n};\n\n/// @returns an array of objects describing web3.db api methods\nvar dbMethods = function () {\n return [\n { name: 'put', call: 'db_put' },\n { name: 'get', call: 'db_get' },\n { name: 'putString', call: 'db_putString' },\n { name: 'getString', call: 'db_getString' }\n ];\n};\n\n/// @returns an array of objects describing web3.shh api methods\nvar shhMethods = function () {\n return [\n { name: 'post', call: 'shh_post' },\n { name: 'newIdentity', call: 'shh_newIdentity' },\n { name: 'haveIdentity', call: 'shh_haveIdentity' },\n { name: 'newGroup', call: 'shh_newGroup' },\n { name: 'addToGroup', call: 'shh_addToGroup' }\n ];\n};\n\n/// @returns an array of objects describing web3.eth.watch api methods\nvar ethWatchMethods = function () {\n var newFilter = function (args) {\n return typeof args[0] === 'string' ? 'eth_newFilterString' : 'eth_newFilter';\n };\n\n return [\n { name: 'newFilter', call: newFilter },\n { name: 'uninstallFilter', call: 'eth_uninstallFilter' },\n { name: 'getMessages', call: 'eth_filterLogs' }\n ];\n};\n\n/// @returns an array of objects describing web3.shh.watch api methods\nvar shhWatchMethods = function () {\n return [\n { name: 'newFilter', call: 'shh_newFilter' },\n { name: 'uninstallFilter', call: 'shh_uninstallFilter' },\n { name: 'getMessages', call: 'shh_getMessages' }\n ];\n};\n\n/// creates methods in a given object based on method description on input\n/// setups api calls for these methods\nvar setupMethods = function (obj, methods) {\n methods.forEach(function (method) {\n obj[method.name] = function () {\n var args = Array.prototype.slice.call(arguments);\n var call = typeof method.call === 'function' ? method.call(args) : method.call;\n return web3.provider.send({\n call: call,\n args: args\n });\n };\n });\n};\n\n/// creates properties in a given object based on properties description on input\n/// setups api calls for these properties\nvar setupProperties = function (obj, properties) {\n properties.forEach(function (property) {\n var proto = {};\n proto.get = function () {\n return web3.provider.send({\n call: property.getter\n });\n };\n\n if (property.setter) {\n proto.set = function (val) {\n return web3.provider.send({\n call: property.setter,\n args: [val]\n });\n };\n }\n Object.defineProperty(obj, property.name, proto);\n });\n};\n\n/// setups web3 object, and it's in-browser executed methods\nvar web3 = {\n _callbacks: {},\n _events: {},\n providers: {},\n\n /// @returns ascii string representation of hex value prefixed with 0x\n toAscii: utils.toAscii,\n\n /// @returns hex representation (prefixed by 0x) of ascii string\n fromAscii: utils.fromAscii,\n\n /// @returns decimal representaton of hex value prefixed by 0x\n toDecimal: function (val) {\n // remove 0x and place 0, if it's required\n val = val.length > 2 ? val.substring(2) : \"0\";\n return (new BigNumber(val, 16).toString(10));\n },\n\n /// @returns hex representation (prefixed by 0x) of decimal value\n fromDecimal: function (val) {\n return \"0x\" + (new BigNumber(val).toString(16));\n },\n\n /// used to transform value/string to eth string\n toEth: utils.toEth,\n\n /// eth object prototype\n eth: {\n contractFromAbi: function (abi) {\n return function(addr) {\n // Default to address of Config. TODO: rremove prior to genesis.\n addr = addr || '0xc6d9d2cd449a754c494264e1809c50e34d64562b';\n var ret = web3.eth.contract(addr, abi);\n ret.address = addr;\n return ret;\n };\n },\n\n /// @param filter may be a string, object or event\n /// @param indexed is optional, this is an object with optional event indexed params\n /// @param options is optional, this is an object with optional event options ('max'...)\n watch: function (filter, indexed, options) {\n if (filter._isEvent) {\n return filter(indexed, options);\n }\n return new web3.filter(filter, ethWatch);\n }\n },\n\n /// db object prototype\n db: {},\n\n /// shh object prototype\n shh: {\n \n /// @param filter may be a string, object or event\n watch: function (filter, indexed) {\n return new web3.filter(filter, shhWatch);\n }\n },\n};\n\n/// setups all api methods\nsetupMethods(web3, web3Methods());\nsetupMethods(web3.eth, ethMethods());\nsetupProperties(web3.eth, ethProperties());\nsetupMethods(web3.db, dbMethods());\nsetupMethods(web3.shh, shhMethods());\n\nvar ethWatch = {\n changed: 'eth_changed'\n};\n\nsetupMethods(ethWatch, ethWatchMethods());\n\nvar shhWatch = {\n changed: 'shh_changed'\n};\n\nsetupMethods(shhWatch, shhWatchMethods());\n\nweb3.setProvider = function(provider) {\n web3.provider.set(provider);\n};\n\nmodule.exports = web3;\n\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file utils.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\nvar c = require('./const');\n\n/// Finds first index of array element matching pattern\n/// @param array\n/// @param callback pattern\n/// @returns index of element\nvar findIndex = function (array, callback) {\n var end = false;\n var i = 0;\n for (; i < array.length && !end; i++) {\n end = callback(array[i]);\n }\n return end ? i - 1 : -1;\n};\n\n/// @returns ascii string representation of hex value prefixed with 0x\nvar toAscii = function(hex) {\n// Find termination\n var str = \"\";\n var i = 0, l = hex.length;\n if (hex.substring(0, 2) === '0x') {\n i = 2;\n }\n for (; i < l; i+=2) {\n var code = parseInt(hex.substr(i, 2), 16);\n if (code === 0) {\n break;\n }\n\n str += String.fromCharCode(code);\n }\n\n return str;\n};\n \nvar toHex = function(str) {\n var hex = \"\";\n for(var i = 0; i < str.length; i++) {\n var n = str.charCodeAt(i).toString(16);\n hex += n.length < 2 ? '0' + n : n;\n }\n\n return hex;\n};\n\n/// @returns hex representation (prefixed by 0x) of ascii string\nvar fromAscii = function(str, pad) {\n pad = pad === undefined ? 0 : pad;\n var hex = toHex(str);\n while (hex.length < pad*2)\n hex += \"00\";\n return \"0x\" + hex;\n};\n\n/// @returns display name for function/event eg. multiply(uint256) -> multiply\nvar extractDisplayName = function (name) {\n var length = name.indexOf('('); \n return length !== -1 ? name.substr(0, length) : name;\n};\n\n/// @returns overloaded part of function/event name\nvar extractTypeName = function (name) {\n /// TODO: make it invulnerable\n var length = name.indexOf('(');\n return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : \"\";\n};\n\n/// Filters all function from input abi\n/// @returns abi array with filtered objects of type 'function'\nvar filterFunctions = function (json) {\n return json.filter(function (current) {\n return current.type === 'function'; \n }); \n};\n\n/// Filters all events form input abi\n/// @returns abi array with filtered objects of type 'event'\nvar filterEvents = function (json) {\n return json.filter(function (current) {\n return current.type === 'event';\n });\n};\n\n/// used to transform value/string to eth string\n/// TODO: use BigNumber.js to parse int\n/// TODO: add tests for it!\nvar toEth = function (str) {\n var val = typeof str === \"string\" ? str.indexOf('0x') === 0 ? parseInt(str.substr(2), 16) : parseInt(str) : str;\n var unit = 0;\n var units = c.ETH_UNITS;\n while (val > 3000 && unit < units.length - 1)\n {\n val /= 1000;\n unit++;\n }\n var s = val.toString().length < val.toFixed(2).length ? val.toString() : val.toFixed(2);\n var replaceFunction = function($0, $1, $2) {\n return $1 + ',' + $2;\n };\n\n while (true) {\n var o = s;\n s = s.replace(/(\\d)(\\d\\d\\d[\\.\\,])/, replaceFunction);\n if (o === s)\n break;\n }\n return s + ' ' + units[unit];\n};\n\nmodule.exports = {\n findIndex: findIndex,\n toAscii: toAscii,\n fromAscii: fromAscii,\n extractDisplayName: extractDisplayName,\n extractTypeName: extractTypeName,\n filterFunctions: filterFunctions,\n filterEvents: filterEvents,\n toEth: toEth\n};\n\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file web3.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nif (\"build\" !== 'build') {/*\n var BigNumber = require('bignumber.js');\n*/}\n\nvar utils = require('./utils');\n\n/// @returns an array of objects describing web3 api methods\nvar web3Methods = function () {\n return [\n { name: 'sha3', call: 'web3_sha3' }\n ];\n};\n\n/// @returns an array of objects describing web3.eth api methods\nvar ethMethods = function () {\n var blockCall = function (args) {\n return typeof args[0] === \"string\" ? \"eth_blockByHash\" : \"eth_blockByNumber\";\n };\n\n var transactionCall = function (args) {\n return typeof args[0] === \"string\" ? 'eth_transactionByHash' : 'eth_transactionByNumber';\n };\n\n var uncleCall = function (args) {\n return typeof args[0] === \"string\" ? 'eth_uncleByHash' : 'eth_uncleByNumber';\n };\n\n var methods = [\n { name: 'balanceAt', call: 'eth_balanceAt' },\n { name: 'stateAt', call: 'eth_stateAt' },\n { name: 'storageAt', call: 'eth_storageAt' },\n { name: 'countAt', call: 'eth_countAt'},\n { name: 'codeAt', call: 'eth_codeAt' },\n { name: 'transact', call: 'eth_transact' },\n { name: 'call', call: 'eth_call' },\n { name: 'block', call: blockCall },\n { name: 'transaction', call: transactionCall },\n { name: 'uncle', call: uncleCall },\n { name: 'compilers', call: 'eth_compilers' },\n { name: 'flush', call: 'eth_flush' },\n { name: 'lll', call: 'eth_lll' },\n { name: 'solidity', call: 'eth_solidity' },\n { name: 'serpent', call: 'eth_serpent' },\n { name: 'logs', call: 'eth_logs' }\n ];\n return methods;\n};\n\n/// @returns an array of objects describing web3.eth api properties\nvar ethProperties = function () {\n return [\n { name: 'coinbase', getter: 'eth_coinbase', setter: 'eth_setCoinbase' },\n { name: 'listening', getter: 'eth_listening', setter: 'eth_setListening' },\n { name: 'mining', getter: 'eth_mining', setter: 'eth_setMining' },\n { name: 'gasPrice', getter: 'eth_gasPrice' },\n { name: 'accounts', getter: 'eth_accounts' },\n { name: 'peerCount', getter: 'eth_peerCount' },\n { name: 'defaultBlock', getter: 'eth_defaultBlock', setter: 'eth_setDefaultBlock' },\n { name: 'number', getter: 'eth_number'}\n ];\n};\n\n/// @returns an array of objects describing web3.db api methods\nvar dbMethods = function () {\n return [\n { name: 'put', call: 'db_put' },\n { name: 'get', call: 'db_get' },\n { name: 'putString', call: 'db_putString' },\n { name: 'getString', call: 'db_getString' }\n ];\n};\n\n/// @returns an array of objects describing web3.shh api methods\nvar shhMethods = function () {\n return [\n { name: 'post', call: 'shh_post' },\n { name: 'newIdentity', call: 'shh_newIdentity' },\n { name: 'haveIdentity', call: 'shh_haveIdentity' },\n { name: 'newGroup', call: 'shh_newGroup' },\n { name: 'addToGroup', call: 'shh_addToGroup' }\n ];\n};\n\n/// @returns an array of objects describing web3.eth.watch api methods\nvar ethWatchMethods = function () {\n var newFilter = function (args) {\n return typeof args[0] === 'string' ? 'eth_newFilterString' : 'eth_newFilter';\n };\n\n return [\n { name: 'newFilter', call: newFilter },\n { name: 'uninstallFilter', call: 'eth_uninstallFilter' },\n { name: 'getMessages', call: 'eth_filterLogs' }\n ];\n};\n\n/// @returns an array of objects describing web3.shh.watch api methods\nvar shhWatchMethods = function () {\n return [\n { name: 'newFilter', call: 'shh_newFilter' },\n { name: 'uninstallFilter', call: 'shh_uninstallFilter' },\n { name: 'getMessages', call: 'shh_getMessages' }\n ];\n};\n\n/// creates methods in a given object based on method description on input\n/// setups api calls for these methods\nvar setupMethods = function (obj, methods) {\n methods.forEach(function (method) {\n obj[method.name] = function () {\n var args = Array.prototype.slice.call(arguments);\n var call = typeof method.call === 'function' ? method.call(args) : method.call;\n return web3.provider.send({\n method: call,\n params: args\n });\n };\n });\n};\n\n/// creates properties in a given object based on properties description on input\n/// setups api calls for these properties\nvar setupProperties = function (obj, properties) {\n properties.forEach(function (property) {\n var proto = {};\n proto.get = function () {\n return web3.provider.send({\n method: property.getter\n });\n };\n\n if (property.setter) {\n proto.set = function (val) {\n return web3.provider.send({\n method: property.setter,\n params: [val]\n });\n };\n }\n Object.defineProperty(obj, property.name, proto);\n });\n};\n\n/// setups web3 object, and it's in-browser executed methods\nvar web3 = {\n _callbacks: {},\n _events: {},\n providers: {},\n\n /// @returns ascii string representation of hex value prefixed with 0x\n toAscii: utils.toAscii,\n\n /// @returns hex representation (prefixed by 0x) of ascii string\n fromAscii: utils.fromAscii,\n\n /// @returns decimal representaton of hex value prefixed by 0x\n toDecimal: function (val) {\n // remove 0x and place 0, if it's required\n val = val.length > 2 ? val.substring(2) : \"0\";\n return (new BigNumber(val, 16).toString(10));\n },\n\n /// @returns hex representation (prefixed by 0x) of decimal value\n fromDecimal: function (val) {\n return \"0x\" + (new BigNumber(val).toString(16));\n },\n\n /// used to transform value/string to eth string\n toEth: utils.toEth,\n\n /// eth object prototype\n eth: {\n contractFromAbi: function (abi) {\n return function(addr) {\n // Default to address of Config. TODO: rremove prior to genesis.\n addr = addr || '0xc6d9d2cd449a754c494264e1809c50e34d64562b';\n var ret = web3.eth.contract(addr, abi);\n ret.address = addr;\n return ret;\n };\n },\n\n /// @param filter may be a string, object or event\n /// @param indexed is optional, this is an object with optional event indexed params\n /// @param options is optional, this is an object with optional event options ('max'...)\n watch: function (filter, indexed, options) {\n if (filter._isEvent) {\n return filter(indexed, options);\n }\n return new web3.filter(filter, ethWatch);\n }\n },\n\n /// db object prototype\n db: {},\n\n /// shh object prototype\n shh: {\n \n /// @param filter may be a string, object or event\n watch: function (filter, indexed) {\n return new web3.filter(filter, shhWatch);\n }\n },\n};\n\n/// setups all api methods\nsetupMethods(web3, web3Methods());\nsetupMethods(web3.eth, ethMethods());\nsetupProperties(web3.eth, ethProperties());\nsetupMethods(web3.db, dbMethods());\nsetupMethods(web3.shh, shhMethods());\n\nvar ethWatch = {\n changed: 'eth_changed'\n};\n\nsetupMethods(ethWatch, ethWatchMethods());\n\nvar shhWatch = {\n changed: 'shh_changed'\n};\n\nsetupMethods(shhWatch, shhWatchMethods());\n\nweb3.setProvider = function(provider) {\n web3.provider.set(provider);\n};\n\nmodule.exports = web3;\n\n", "var web3 = require('./lib/web3');\nvar ProviderManager = require('./lib/providermanager');\nweb3.provider = new ProviderManager();\nweb3.filter = require('./lib/filter');\nweb3.providers.HttpSyncProvider = require('./lib/httpsync');\nweb3.providers.QtSyncProvider = require('./lib/qtsync');\nweb3.eth.contract = require('./lib/contract');\nweb3.abi = require('./lib/abi');\n\n\nmodule.exports = web3;\n" ] } \ No newline at end of file diff --git a/dist/ethereum.min.js b/dist/ethereum.min.js index 49d1f628c..a2524c0ce 100644 --- a/dist/ethereum.min.js +++ b/dist/ethereum.min.js @@ -1 +1 @@ -require=function t(e,n,r){function i(a,u){if(!n[a]){if(!e[a]){var s="function"==typeof require&&require;if(!u&&s)return s(a,!0);if(o)return o(a,!0);var f=new Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[a]={exports:{}};e[a][0].call(c.exports,function(t){var n=e[a][1][t];return i(n?n:t)},c,c.exports,t,e,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;av;v++)g.push(m(e.slice(0,r))),e=e.slice(r);n.push(g)}else i.prefixedType("string")(t[f].type)?(c=c.slice(r),n.push(m(e.slice(0,r))),e=e.slice(r)):(n.push(m(e.slice(0,r))),e=e.slice(r))}),n},d=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(){var e=Array.prototype.slice.call(arguments);return l(t.inputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},g=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(e){return m(t.outputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},v=function(t){return n.sha3(n.fromAscii(t)).slice(0,2+2*o.ETH_SIGNATURE_LENGTH)},y=function(t){return n.sha3(n.fromAscii(t))};e.exports={inputParser:d,outputParser:g,formatInput:l,formatOutput:m,signatureFromAscii:v,eventSignatureFromAscii:y}},{"./const":2,"./formatters":6,"./types":10,"./utils":11,"./web3":12}],2:[function(t,e){var n=["wei","Kwei","Mwei","Gwei","szabo","finney","ether","grand","Mether","Gether","Tether","Pether","Eether","Zether","Yether","Nether","Dether","Vether","Uether"];e.exports={ETH_PADDING:32,ETH_SIGNATURE_LENGTH:4,ETH_UNITS:n,ETH_BIGNUMBER_ROUNDING_MODE:{ROUNDING_MODE:BigNumber.ROUND_DOWN}}},{}],3:[function(t,e){var n=t("./web3"),r=t("./abi"),i=t("./utils"),o=t("./event"),a=function(t){n._currentContractAbi=t.abi,n._currentContractAddress=t.address,n._currentContractMethodName=t.method,n._currentContractMethodParams=t.params},u=function(t){t.call=function(e){return t._isTransact=!1,t._options=e,t},t.transact=function(e){return t._isTransact=!0,t._options=e,t},t._options={},["gas","gasPrice","value","from"].forEach(function(e){t[e]=function(n){return t._options[e]=n,t}})},s=function(t,e,o){var u=r.inputParser(e),s=r.outputParser(e);i.filterFunctions(e).forEach(function(f){var c=i.extractDisplayName(f.name),l=i.extractTypeName(f.name),p=function(){var i=Array.prototype.slice.call(arguments),p=r.signatureFromAscii(f.name),h=u[c][l].apply(null,i),m=t._options||{};m.to=o,m.data=p+h;var d=t._isTransact===!0||t._isTransact!==!1&&!f.constant,g=m.collapse!==!1;if(t._options={},t._isTransact=null,d)return a({abi:e,address:o,method:f.name,params:i}),void n.eth.transact(m);var v=n.eth.call(m),y=s[c][l](v);return g&&(1===y.length?y=y[0]:0===y.length&&(y=null)),y};void 0===t[c]&&(t[c]=p),t[c][l]=p})},f=function(t,e,n){t.address=n,t._onWatchEventResult=function(t){var n=event.getMatchingEvent(i.filterEvents(e)),r=o.outputParser(n);return r(t)},Object.defineProperty(t,"topic",{get:function(){return i.filterEvents(e).map(function(t){return r.eventSignatureFromAscii(t.name)})}})},c=function(t,e,a){i.filterEvents(e).forEach(function(e){var u=function(){var t=Array.prototype.slice.call(arguments),i=r.eventSignatureFromAscii(e.name),u=o.inputParser(a,i,e),s=u.apply(null,t);return s._onWatchEventResult=function(t){var n=o.outputParser(e);return n(t)},n.eth.watch(s)};u._isEvent=!0;var s=i.extractDisplayName(e.name),f=i.extractTypeName(e.name);void 0===t[s]&&(t[s]=u),t[s][f]=u})},l=function(t,e){e.forEach(function(t){if(-1===t.name.indexOf("(")){var e=t.name,n=t.inputs.map(function(t){return t.type}).join();t.name=e+"("+n+")"}});var n={};return u(n),s(n,e,t),f(n,e,t),c(n,e,t),n};e.exports=l},{"./abi":1,"./event":4,"./utils":11,"./web3":12}],4:[function(t,e){var n=t("./abi"),r=t("./utils"),i=function(t,e){return t.filter(function(t){return t.indexed===e})},o=function(t,e){var n=r.findIndex(t,function(t){return t.name===e});return-1===n?void console.error("indexed param with name "+e+" not found"):t[n]},a=function(t,e){return Object.keys(e).map(function(r){var a=[o(i(t.inputs,!0),r)],u=e[r];return u instanceof Array?u.map(function(t){return n.formatInput(a,[t])}):n.formatInput(a,[u])})},u=function(t,e,n){return function(r,i){var o=i||{};return o.address=t,o.topic=[],o.topic.push(e),r&&(o.topic=o.topic.concat(a(n,r))),o}},s=function(t,e,n){e.slice(),n.slice();return t.reduce(function(t,r){var i;return i=r.indexed?e.splice(0,1)[0]:n.splice(0,1)[0],t[r.name]=i,t},{})},f=function(t){return function(e){var o={event:r.extractDisplayName(t.name),number:e.number,args:{}};if(!e.topic)return o;var a=i(t.inputs,!0),u="0x"+e.topic.slice(1,e.topic.length).map(function(t){return t.slice(2)}).join(""),f=n.formatOutput(a,u),c=i(t.inputs,!1),l=n.formatOutput(c,e.data);return o.args=s(t.inputs,f,l),o}},c=function(t,e){for(var r=0;rn;n+=2){var i=parseInt(t.substr(n,2),16);if(0===i)break;e+=String.fromCharCode(i)}return e},o=function(t){for(var e="",n=0;n3e3&&r2?t.substring(2):"0",new BigNumber(t,16).toString(10)},fromDecimal:function(t){return"0x"+new BigNumber(t).toString(16)},toEth:n.toEth,eth:{contractFromAbi:function(t){return function(e){e=e||"0xc6d9d2cd449a754c494264e1809c50e34d64562b";var n=p.eth.contract(e,t);return n.address=e,n}},watch:function(t,e,n){return t._isEvent?t(e,n):new p.filter(t,h)}},db:{},shh:{watch:function(t){return new p.filter(t,m)}}};c(p,r()),c(p.eth,i()),l(p.eth,o()),c(p.db,a()),c(p.shh,u());var h={changed:"eth_changed"};c(h,s());var m={changed:"shh_changed"};c(m,f()),p.setProvider=function(t){p.provider.set(t)},e.exports=p},{"./utils":11}],web3:[function(t,e){var n=t("./lib/web3"),r=t("./lib/providermanager");n.provider=new r,n.filter=t("./lib/filter"),n.providers.HttpSyncProvider=t("./lib/httpsync"),n.providers.QtSyncProvider=t("./lib/qtsync"),n.eth.contract=t("./lib/contract"),n.abi=t("./lib/abi"),e.exports=n},{"./lib/abi":1,"./lib/contract":3,"./lib/filter":5,"./lib/httpsync":7,"./lib/providermanager":8,"./lib/qtsync":9,"./lib/web3":12}]},{},["web3"]); \ No newline at end of file +require=function t(e,n,r){function i(a,u){if(!n[a]){if(!e[a]){var s="function"==typeof require&&require;if(!u&&s)return s(a,!0);if(o)return o(a,!0);var f=new Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[a]={exports:{}};e[a][0].call(c.exports,function(t){var n=e[a][1][t];return i(n?n:t)},c,c.exports,t,e,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;av;v++)g.push(h(e.slice(0,r))),e=e.slice(r);n.push(g)}else i.prefixedType("string")(t[f].type)?(c=c.slice(r),n.push(h(e.slice(0,r))),e=e.slice(r)):(n.push(h(e.slice(0,r))),e=e.slice(r))}),n},d=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(){var e=Array.prototype.slice.call(arguments);return l(t.inputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},g=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(e){return h(t.outputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},v=function(t){return n.sha3(n.fromAscii(t)).slice(0,2+2*o.ETH_SIGNATURE_LENGTH)},y=function(t){return n.sha3(n.fromAscii(t))};e.exports={inputParser:d,outputParser:g,formatInput:l,formatOutput:h,signatureFromAscii:v,eventSignatureFromAscii:y}},{"./const":2,"./formatters":6,"./types":11,"./utils":12,"./web3":13}],2:[function(t,e){var n=["wei","Kwei","Mwei","Gwei","szabo","finney","ether","grand","Mether","Gether","Tether","Pether","Eether","Zether","Yether","Nether","Dether","Vether","Uether"];e.exports={ETH_PADDING:32,ETH_SIGNATURE_LENGTH:4,ETH_UNITS:n,ETH_BIGNUMBER_ROUNDING_MODE:{ROUNDING_MODE:BigNumber.ROUND_DOWN}}},{}],3:[function(t,e){var n=t("./web3"),r=t("./abi"),i=t("./utils"),o=t("./event"),a=function(t){n._currentContractAbi=t.abi,n._currentContractAddress=t.address,n._currentContractMethodName=t.method,n._currentContractMethodParams=t.params},u=function(t){t.call=function(e){return t._isTransact=!1,t._options=e,t},t.transact=function(e){return t._isTransact=!0,t._options=e,t},t._options={},["gas","gasPrice","value","from"].forEach(function(e){t[e]=function(n){return t._options[e]=n,t}})},s=function(t,e,o){var u=r.inputParser(e),s=r.outputParser(e);i.filterFunctions(e).forEach(function(f){var c=i.extractDisplayName(f.name),l=i.extractTypeName(f.name),p=function(){var i=Array.prototype.slice.call(arguments),p=r.signatureFromAscii(f.name),m=u[c][l].apply(null,i),h=t._options||{};h.to=o,h.data=p+m;var d=t._isTransact===!0||t._isTransact!==!1&&!f.constant,g=h.collapse!==!1;if(t._options={},t._isTransact=null,d)return a({abi:e,address:o,method:f.name,params:i}),void n.eth.transact(h);var v=n.eth.call(h),y=s[c][l](v);return g&&(1===y.length?y=y[0]:0===y.length&&(y=null)),y};void 0===t[c]&&(t[c]=p),t[c][l]=p})},f=function(t,e,n){t.address=n,t._onWatchEventResult=function(t){var n=event.getMatchingEvent(i.filterEvents(e)),r=o.outputParser(n);return r(t)},Object.defineProperty(t,"topic",{get:function(){return i.filterEvents(e).map(function(t){return r.eventSignatureFromAscii(t.name)})}})},c=function(t,e,a){i.filterEvents(e).forEach(function(e){var u=function(){var t=Array.prototype.slice.call(arguments),i=r.eventSignatureFromAscii(e.name),u=o.inputParser(a,i,e),s=u.apply(null,t);return s._onWatchEventResult=function(t){var n=o.outputParser(e);return n(t)},n.eth.watch(s)};u._isEvent=!0;var s=i.extractDisplayName(e.name),f=i.extractTypeName(e.name);void 0===t[s]&&(t[s]=u),t[s][f]=u})},l=function(t,e){e.forEach(function(t){if(-1===t.name.indexOf("(")){var e=t.name,n=t.inputs.map(function(t){return t.type}).join();t.name=e+"("+n+")"}});var n={};return u(n),s(n,e,t),f(n,e,t),c(n,e,t),n};e.exports=l},{"./abi":1,"./event":4,"./utils":12,"./web3":13}],4:[function(t,e){var n=t("./abi"),r=t("./utils"),i=function(t,e){return t.filter(function(t){return t.indexed===e})},o=function(t,e){var n=r.findIndex(t,function(t){return t.name===e});return-1===n?void console.error("indexed param with name "+e+" not found"):t[n]},a=function(t,e){return Object.keys(e).map(function(r){var a=[o(i(t.inputs,!0),r)],u=e[r];return u instanceof Array?u.map(function(t){return n.formatInput(a,[t])}):n.formatInput(a,[u])})},u=function(t,e,n){return function(r,i){var o=i||{};return o.address=t,o.topic=[],o.topic.push(e),r&&(o.topic=o.topic.concat(a(n,r))),o}},s=function(t,e,n){e.slice(),n.slice();return t.reduce(function(t,r){var i;return i=r.indexed?e.splice(0,1)[0]:n.splice(0,1)[0],t[r.name]=i,t},{})},f=function(t){return function(e){var o={event:r.extractDisplayName(t.name),number:e.number,args:{}};if(!e.topic)return o;var a=i(t.inputs,!0),u="0x"+e.topic.slice(1,e.topic.length).map(function(t){return t.slice(2)}).join(""),f=n.formatOutput(a,u),c=i(t.inputs,!1),l=n.formatOutput(c,e.data);return o.args=s(t.inputs,f,l),o}},c=function(t,e){for(var r=0;rn;n+=2){var i=parseInt(t.substr(n,2),16);if(0===i)break;e+=String.fromCharCode(i)}return e},o=function(t){for(var e="",n=0;n3e3&&r2?t.substring(2):"0",new BigNumber(t,16).toString(10)},fromDecimal:function(t){return"0x"+new BigNumber(t).toString(16)},toEth:n.toEth,eth:{contractFromAbi:function(t){return function(e){e=e||"0xc6d9d2cd449a754c494264e1809c50e34d64562b";var n=p.eth.contract(e,t);return n.address=e,n}},watch:function(t,e,n){return t._isEvent?t(e,n):new p.filter(t,m)}},db:{},shh:{watch:function(t){return new p.filter(t,h)}}};c(p,r()),c(p.eth,i()),l(p.eth,o()),c(p.db,a()),c(p.shh,u());var m={changed:"eth_changed"};c(m,s());var h={changed:"shh_changed"};c(h,f()),p.setProvider=function(t){p.provider.set(t)},e.exports=p},{"./utils":12}],web3:[function(t,e){var n=t("./lib/web3"),r=t("./lib/providermanager");n.provider=new r,n.filter=t("./lib/filter"),n.providers.HttpSyncProvider=t("./lib/httpsync"),n.providers.QtSyncProvider=t("./lib/qtsync"),n.eth.contract=t("./lib/contract"),n.abi=t("./lib/abi"),e.exports=n},{"./lib/abi":1,"./lib/contract":3,"./lib/filter":5,"./lib/httpsync":7,"./lib/providermanager":9,"./lib/qtsync":10,"./lib/web3":13}]},{},["web3"]); \ No newline at end of file diff --git a/lib/filter.js b/lib/filter.js index 8f7729379..6ab2b7edc 100644 --- a/lib/filter.js +++ b/lib/filter.js @@ -56,7 +56,7 @@ var Filter = function(options, impl) { this.callbacks = []; this.id = impl.newFilter(options); - web3.provider.startPolling({call: impl.changed, args: [this.id]}, this.id, this.trigger.bind(this)); + web3.provider.startPolling({method: impl.changed, params: [this.id]}, this.id, this.trigger.bind(this)); }; /// alias for changed* diff --git a/lib/httpsync.js b/lib/httpsync.js index a638cfe94..06e410ca8 100644 --- a/lib/httpsync.js +++ b/lib/httpsync.js @@ -30,40 +30,16 @@ var HttpSyncProvider = function (host) { this.host = host || 'http://localhost:8080'; }; -/// Transforms inner message to proper jsonrpc object -/// @param inner message object -/// @returns jsonrpc object -function formatJsonRpcObject(object) { - return { - jsonrpc: '2.0', - method: object.call, - params: object.args, - id: object._id - }; -} - -/// Transforms jsonrpc object to inner message -/// @param incoming jsonrpc message -/// @returns inner message object -function formatJsonRpcMessage(message) { - var object = JSON.parse(message); - - return { - _id: object.id, - data: object.result, - error: object.error - }; -} - HttpSyncProvider.prototype.send = function (payload) { - var data = formatJsonRpcObject(payload); + //var data = formatJsonRpcObject(payload); var request = new XMLHttpRequest(); request.open('POST', this.host, false); - request.send(JSON.stringify(data)); + request.send(JSON.stringify(payload)); // check request.status - return request.responseText; + var result = request.responseText; + return JSON.parse(result); }; module.exports = HttpSyncProvider; diff --git a/lib/jsonrpc.js b/lib/jsonrpc.js new file mode 100644 index 000000000..63afa3229 --- /dev/null +++ b/lib/jsonrpc.js @@ -0,0 +1,65 @@ +/* + This file is part of ethereum.js. + + ethereum.js is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + ethereum.js is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with ethereum.js. If not, see . +*/ +/** @file jsonrpc.js + * @authors: + * Marek Kotewicz + * @date 2015 + */ + +var messageId = 1; + +/// Should be called to valid json create payload object +/// @param method of jsonrpc call, required +/// @param params, an array of method params, optional +/// @returns valid jsonrpc payload object +var toPayload = function (method, params) { + if (!method) + console.error('jsonrpc method should be specified!'); + + return { + jsonrpc: '2.0', + method: method, + params: params || [], + id: messageId++ + }; +}; + +/// Should be called to check if jsonrpc response is valid +/// @returns true if response is valid, otherwise false +var isValidResponse = function (response) { + return !!response && + !response.error && + response.jsonrpc === '2.0' && + typeof response.id === 'number' && + (!!response.result || typeof response.result === 'boolean'); +}; + +/// Should be called to create batch payload object +/// @param messages, an array of objects with method (required) and params (optional) fields +var toBatchPayload = function (messages) { + return messages.map(function (message) { + return toPayload(message.method, message.params); + }); +}; + +module.exports = { + toPayload: toPayload, + isValidResponse: isValidResponse, + toBatchPayload: toBatchPayload +}; + + diff --git a/lib/providermanager.js b/lib/providermanager.js index 25cd14288..55f166bcd 100644 --- a/lib/providermanager.js +++ b/lib/providermanager.js @@ -23,7 +23,9 @@ * @date 2014 */ -var web3 = require('./web3'); // jshint ignore:line +var web3 = require('./web3'); +var jsonrpc = require('./jsonrpc'); + /** * Provider manager object prototype @@ -37,25 +39,35 @@ var web3 = require('./web3'); // jshint ignore:line var ProviderManager = function() { this.polls = []; this.provider = undefined; - this.id = 1; var self = this; var poll = function () { if (self.provider) { - self.polls.forEach(function (data) { - data.data._id = self.id; - self.id++; - var result = self.provider.send(data.data); - - result = JSON.parse(result); + var pollsBatch = self.polls.map(function (data) { + return data.data; + }); + + var payload = jsonrpc.toBatchPayload(pollsBatch); + var results = self.provider.send(payload); + + self.polls.forEach(function (data, index) { + var result = results[index]; + if (!jsonrpc.isValidResponse(result)) { + console.log(result); + return; + } + + result = result.result; // dont call the callback if result is not an array, or empty one - if (result.error || !(result.result instanceof Array) || result.result.length === 0) { + if (!(result instanceof Array) || result.length === 0) { return; } - data.callback(result.result); + data.callback(result); + }); + } setTimeout(poll, 1000); }; @@ -63,22 +75,19 @@ var ProviderManager = function() { }; /// sends outgoing requests +/// @params data - an object with at least 'method' property ProviderManager.prototype.send = function(data) { - - data.args = data.args || []; - data._id = this.id++; + var payload = jsonrpc.toPayload(data.method, data.params); if (this.provider === undefined) { console.error('provider is not set'); return null; } - //TODO: handle error here? - var result = this.provider.send(data); - result = JSON.parse(result); + var result = this.provider.send(payload); - if (result.error) { - console.log(result.error); + if (!jsonrpc.isValidResponse(result)) { + console.log(result); return null; } diff --git a/lib/qtsync.js b/lib/qtsync.js index a287a7172..75dcb43ab 100644 --- a/lib/qtsync.js +++ b/lib/qtsync.js @@ -25,7 +25,8 @@ var QtSyncProvider = function () { }; QtSyncProvider.prototype.send = function (payload) { - return navigator.qt.callMethod(JSON.stringify(payload)); + var result = navigator.qt.callMethod(JSON.stringify(payload)); + return JSON.parse(result); }; module.exports = QtSyncProvider; diff --git a/lib/utils.js b/lib/utils.js index e1265803c..7cc1917e1 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -84,7 +84,7 @@ var extractDisplayName = function (name) { var extractTypeName = function (name) { /// TODO: make it invulnerable var length = name.indexOf('('); - return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)) : ""; + return length !== -1 ? name.substr(length + 1, name.length - 1 - (length + 1)).replace(' ', '') : ""; }; /// Filters all function from input abi diff --git a/lib/web3.js b/lib/web3.js index e868e9412..41df75051 100644 --- a/lib/web3.js +++ b/lib/web3.js @@ -136,8 +136,8 @@ var setupMethods = function (obj, methods) { var args = Array.prototype.slice.call(arguments); var call = typeof method.call === 'function' ? method.call(args) : method.call; return web3.provider.send({ - call: call, - args: args + method: call, + params: args }); }; }); @@ -150,15 +150,15 @@ var setupProperties = function (obj, properties) { var proto = {}; proto.get = function () { return web3.provider.send({ - call: property.getter + method: property.getter }); }; if (property.setter) { proto.set = function (val) { return web3.provider.send({ - call: property.setter, - args: [val] + method: property.setter, + params: [val] }); }; } diff --git a/package.json b/package.json index a61ffc76a..8102a2592 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ethereum.js", "namespace": "ethereum", - "version": "0.0.11", + "version": "0.0.13", "description": "Ethereum Compatible JavaScript API", "main": "./index.js", "directories": { diff --git a/test/abi.parsers.js b/test/abi.inputParser.js similarity index 52% rename from test/abi.parsers.js rename to test/abi.inputParser.js index 12bccf5a5..12b735153 100644 --- a/test/abi.parsers.js +++ b/test/abi.inputParser.js @@ -423,443 +423,5 @@ describe('abi', function() { }); }); - - describe('outputParser', function() { - it('should parse output string', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: "string" } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal( - parser.test("0x" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "68656c6c6f000000000000000000000000000000000000000000000000000000")[0], - 'hello' - ); - assert.equal( - parser.test("0x" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "776f726c64000000000000000000000000000000000000000000000000000000")[0], - 'world' - ); - - }); - - it('should parse output uint', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'uint' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), - new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) - ); - assert.equal( - parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), - new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) - ); - }); - - it('should parse output uint256', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'uint256' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), - new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) - ); - assert.equal( - parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), - new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) - ); - }); - - it('should parse output uint128', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'uint128' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal( - parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), - new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) - ); - assert.equal( - parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), - new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) - ); - }); - - it('should parse output int', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'int' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal(parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); - assert.equal(parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); - }); - - it('should parse output int256', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'int256' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal(parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); - assert.equal(parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); - }); - - it('should parse output int128', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'int128' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); - assert.equal(parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); - assert.equal(parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); - }); - - it('should parse output hash', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'hash' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal( - parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], - "0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1" - ); - }); - - it('should parse output hash256', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'hash256' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal( - parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], - "0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1" - ); - }); - - it('should parse output hash160', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'hash160' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal( - parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], - "0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1" - ); - // TODO shouldnt' the expected hash be shorter? - }); - - it('should parse output address', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'address' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal( - parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], - "0x407d73d8a49eeb85d32cf465507dd71d507100c1" - ); - }); - - it('should parse output bool', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'bool' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], true); - assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000000")[0], false); - - - }); - - it('should parse output real', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'real' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x0000000000000000000000000000000100000000000000000000000000000000")[0], 1); - assert.equal(parser.test("0x0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); - assert.equal(parser.test("0x0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); - assert.equal(parser.test("0xffffffffffffffffffffffffffffffff00000000000000000000000000000000")[0], -1); - - }); - - it('should parse output ureal', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: 'ureal' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x0000000000000000000000000000000100000000000000000000000000000000")[0], 1); - assert.equal(parser.test("0x0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); - assert.equal(parser.test("0x0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); - - }); - - - it('should parse multiple output strings', function() { - - // given - var d = clone(description); - - d[0].outputs = [ - { type: "string" }, - { type: "string" } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal( - parser.test("0x" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "68656c6c6f000000000000000000000000000000000000000000000000000000" + - "776f726c64000000000000000000000000000000000000000000000000000000")[0], - 'hello' - ); - assert.equal( - parser.test("0x" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "68656c6c6f000000000000000000000000000000000000000000000000000000" + - "776f726c64000000000000000000000000000000000000000000000000000000")[1], - 'world' - ); - - }); - - it('should use proper method name', function () { - - // given - var d = clone(description); - d[0].name = 'helloworld(int)'; - d[0].outputs = [ - { type: "int" } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.helloworld("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.helloworld['int']("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - - }); - - - it('should parse multiple methods', function () { - - // given - var d = [{ - name: "test", - type: "function", - inputs: [{ type: "int" }], - outputs: [{ type: "int" }] - },{ - name: "test2", - type: "function", - inputs: [{ type: "string" }], - outputs: [{ type: "string" }] - }]; - - // when - var parser = abi.outputParser(d); - - //then - assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); - assert.equal(parser.test2("0x" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "68656c6c6f000000000000000000000000000000000000000000000000000000")[0], - "hello" - ); - - }); - - it('should parse output array', function () { - - // given - var d = clone(description); - d[0].outputs = [ - { type: 'int[]' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000006")[0][0], - 5 - ); - assert.equal(parser.test("0x" + - "0000000000000000000000000000000000000000000000000000000000000002" + - "0000000000000000000000000000000000000000000000000000000000000005" + - "0000000000000000000000000000000000000000000000000000000000000006")[0][1], - 6 - ); - - }); - - it('should parse 0x value', function () { - - // given - var d = clone(description); - d[0].outputs = [ - { type: 'int' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x")[0], 0); - - }); - - it('should parse 0x value', function () { - - // given - var d = clone(description); - d[0].outputs = [ - { type: 'uint' } - ]; - - // when - var parser = abi.outputParser(d); - - // then - assert.equal(parser.test("0x")[0], 0); - - }); - - }); }); diff --git a/test/abi.outputParser.js b/test/abi.outputParser.js new file mode 100644 index 000000000..723c408f0 --- /dev/null +++ b/test/abi.outputParser.js @@ -0,0 +1,461 @@ +var assert = require('assert'); +var BigNumber = require('bignumber.js'); +var abi = require('../lib/abi.js'); +var clone = function (object) { return JSON.parse(JSON.stringify(object)); }; + +var description = [{ + "name": "test", + "type": "function", + "inputs": [{ + "name": "a", + "type": "uint256" + } + ], + "outputs": [ + { + "name": "d", + "type": "uint256" + } + ] +}]; + +describe('abi', function() { + describe('outputParser', function() { + it('should parse output string', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: "string" } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal( + parser.test("0x" + + "0000000000000000000000000000000000000000000000000000000000000005" + + "68656c6c6f000000000000000000000000000000000000000000000000000000")[0], + 'hello' + ); + assert.equal( + parser.test("0x" + + "0000000000000000000000000000000000000000000000000000000000000005" + + "776f726c64000000000000000000000000000000000000000000000000000000")[0], + 'world' + ); + + }); + + it('should parse output uint', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: 'uint' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal( + parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), + new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) + ); + assert.equal( + parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), + new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) + ); + }); + + it('should parse output uint256', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: 'uint256' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal( + parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), + new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) + ); + assert.equal( + parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), + new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) + ); + }); + + it('should parse output uint128', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: 'uint128' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal( + parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0].toString(10), + new BigNumber("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16).toString(10) + ); + assert.equal( + parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0].toString(10), + new BigNumber("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0", 16).toString(10) + ); + }); + + it('should parse output int', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: 'int' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); + assert.equal(parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); + }); + + it('should parse output int256', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: 'int256' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); + assert.equal(parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); + }); + + it('should parse output int128', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: 'int128' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test("0x000000000000000000000000000000000000000000000000000000000000000a")[0], 10); + assert.equal(parser.test("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")[0], -1); + assert.equal(parser.test("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0")[0], -16); + }); + + it('should parse output hash', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: 'hash' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal( + parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], + "0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1" + ); + }); + + it('should parse output hash256', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: 'hash256' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal( + parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], + "0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1" + ); + }); + + it('should parse output hash160', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: 'hash160' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal( + parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], + "0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1" + ); + // TODO shouldnt' the expected hash be shorter? + }); + + it('should parse output address', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: 'address' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal( + parser.test("0x000000000000000000000000407d73d8a49eeb85d32cf465507dd71d507100c1")[0], + "0x407d73d8a49eeb85d32cf465507dd71d507100c1" + ); + }); + + it('should parse output bool', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: 'bool' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000001")[0], true); + assert.equal(parser.test("0x0000000000000000000000000000000000000000000000000000000000000000")[0], false); + + + }); + + it('should parse output real', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: 'real' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x0000000000000000000000000000000100000000000000000000000000000000")[0], 1); + assert.equal(parser.test("0x0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); + assert.equal(parser.test("0x0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); + assert.equal(parser.test("0xffffffffffffffffffffffffffffffff00000000000000000000000000000000")[0], -1); + + }); + + it('should parse output ureal', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: 'ureal' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x0000000000000000000000000000000100000000000000000000000000000000")[0], 1); + assert.equal(parser.test("0x0000000000000000000000000000000220000000000000000000000000000000")[0], 2.125); + assert.equal(parser.test("0x0000000000000000000000000000000880000000000000000000000000000000")[0], 8.5); + + }); + + + it('should parse multiple output strings', function() { + + // given + var d = clone(description); + + d[0].outputs = [ + { type: "string" }, + { type: "string" } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal( + parser.test("0x" + + "0000000000000000000000000000000000000000000000000000000000000005" + + "0000000000000000000000000000000000000000000000000000000000000005" + + "68656c6c6f000000000000000000000000000000000000000000000000000000" + + "776f726c64000000000000000000000000000000000000000000000000000000")[0], + 'hello' + ); + assert.equal( + parser.test("0x" + + "0000000000000000000000000000000000000000000000000000000000000005" + + "0000000000000000000000000000000000000000000000000000000000000005" + + "68656c6c6f000000000000000000000000000000000000000000000000000000" + + "776f726c64000000000000000000000000000000000000000000000000000000")[1], + 'world' + ); + + }); + + it('should use proper method name', function () { + + // given + var d = clone(description); + d[0].name = 'helloworld(int)'; + d[0].outputs = [ + { type: "int" } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.helloworld("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.helloworld['int']("0x0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + + }); + + + it('should parse multiple methods', function () { + + // given + var d = [{ + name: "test", + type: "function", + inputs: [{ type: "int" }], + outputs: [{ type: "int" }] + },{ + name: "test2", + type: "function", + inputs: [{ type: "string" }], + outputs: [{ type: "string" }] + }]; + + // when + var parser = abi.outputParser(d); + + //then + assert.equal(parser.test("0000000000000000000000000000000000000000000000000000000000000001")[0], 1); + assert.equal(parser.test2("0x" + + "0000000000000000000000000000000000000000000000000000000000000005" + + "68656c6c6f000000000000000000000000000000000000000000000000000000")[0], + "hello" + ); + + }); + + it('should parse output array', function () { + + // given + var d = clone(description); + d[0].outputs = [ + { type: 'int[]' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000000000000000000000000000000000000000000005" + + "0000000000000000000000000000000000000000000000000000000000000006")[0][0], + 5 + ); + assert.equal(parser.test("0x" + + "0000000000000000000000000000000000000000000000000000000000000002" + + "0000000000000000000000000000000000000000000000000000000000000005" + + "0000000000000000000000000000000000000000000000000000000000000006")[0][1], + 6 + ); + + }); + + it('should parse 0x value', function () { + + // given + var d = clone(description); + d[0].outputs = [ + { type: 'int' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x")[0], 0); + + }); + + it('should parse 0x value', function () { + + // given + var d = clone(description); + d[0].outputs = [ + { type: 'uint' } + ]; + + // when + var parser = abi.outputParser(d); + + // then + assert.equal(parser.test("0x")[0], 0); + + }); + + }); +}); + diff --git a/test/db.methods.js b/test/db.methods.js index 8f8f5409f..2ad384579 100644 --- a/test/db.methods.js +++ b/test/db.methods.js @@ -1,7 +1,7 @@ var assert = require('assert'); var web3 = require('../index.js'); -var u = require('./utils.js'); +var u = require('./test.utils.js'); describe('web3', function() { describe('db', function() { diff --git a/test/eth.methods.js b/test/eth.methods.js index 7a031c4c8..8f10b441d 100644 --- a/test/eth.methods.js +++ b/test/eth.methods.js @@ -1,6 +1,6 @@ var assert = require('assert'); var web3 = require('../index.js'); -var u = require('./utils.js'); +var u = require('./test.utils.js'); describe('web3', function() { describe('eth', function() { diff --git a/test/jsonrpc.isValidResponse.js b/test/jsonrpc.isValidResponse.js new file mode 100644 index 000000000..2fe200496 --- /dev/null +++ b/test/jsonrpc.isValidResponse.js @@ -0,0 +1,128 @@ +var assert = require('assert'); +var jsonrpc = require('../lib/jsonrpc'); + +describe('jsonrpc', function () { + describe('isValidResponse', function () { + it('should validate basic jsonrpc response', function () { + + // given + var response = { + jsonrpc: '2.0', + id: 1, + result: [] + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, true); + }); + + it('should validate basic undefined response', function () { + + // given + var response = undefined; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, false); + }); + + it('should validate jsonrpc response without jsonrpc field', function () { + + // given + var response = { + id: 1, + result: [] + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, false); + }); + + it('should validate jsonrpc response with wrong jsonrpc version', function () { + + // given + var response = { + jsonrpc: '1.0', + id: 1, + result: [] + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, false); + }); + + it('should validate jsonrpc response without id number', function () { + + // given + var response = { + jsonrpc: '2.0', + result: [] + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, false); + }); + + it('should validate jsonrpc response with wrong id field', function () { + + // given + var response = { + jsonrpc: '2.0', + id: 'x', + result: [] + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, false); + }); + + it('should validate jsonrpc response without result field', function () { + + // given + var response = { + jsonrpc: '2.0', + id: 1 + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, false); + }); + + it('should validate jsonrpc response with result field === false', function () { + + // given + var response = { + jsonrpc: '2.0', + id: 1, + result: false + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, true); + }); + + }); +}); diff --git a/test/jsonrpc.toBatchPayload.js b/test/jsonrpc.toBatchPayload.js new file mode 100644 index 000000000..1c1aafebb --- /dev/null +++ b/test/jsonrpc.toBatchPayload.js @@ -0,0 +1,47 @@ +var assert = require('assert'); +var jsonrpc = require('../lib/jsonrpc'); + +describe('jsonrpc', function () { + describe('toBatchPayload', function () { + it('should create basic batch payload', function () { + + // given + var messages = [{ + method: 'helloworld' + }, { + method: 'test2', + params: [1] + }]; + + // when + var payload = jsonrpc.toBatchPayload(messages); + + // then + assert.equal(payload instanceof Array, true); + assert.equal(payload.length, 2); + assert.equal(payload[0].jsonrpc, '2.0'); + assert.equal(payload[1].jsonrpc, '2.0'); + assert.equal(payload[0].method, 'helloworld'); + assert.equal(payload[1].method, 'test2'); + assert.equal(payload[0].params instanceof Array, true); + assert.equal(payload[1].params.length, 1); + assert.equal(payload[1].params[0], 1); + assert.equal(typeof payload[0].id, 'number'); + assert.equal(typeof payload[1].id, 'number'); + assert.equal(payload[0].id + 1, payload[1].id); + }); + + it('should create batch payload for empty input array', function () { + + // given + var messages = []; + + // when + var payload = jsonrpc.toBatchPayload(messages); + + // then + assert.equal(payload instanceof Array, true); + assert.equal(payload.length, 0); + }); + }); +}); diff --git a/test/jsonrpc.toPayload.js b/test/jsonrpc.toPayload.js new file mode 100644 index 000000000..6d6f003bb --- /dev/null +++ b/test/jsonrpc.toPayload.js @@ -0,0 +1,40 @@ +var assert = require('assert'); +var jsonrpc = require('../lib/jsonrpc'); + +describe('jsonrpc', function () { + describe('toPayload', function () { + it('should create basic payload', function () { + + // given + var method = 'helloworld'; + + // when + var payload = jsonrpc.toPayload(method); + + // then + assert.equal(payload.jsonrpc, '2.0'); + assert.equal(payload.method, method); + assert.equal(payload.params instanceof Array, true); + assert.equal(payload.params.length, 0); + assert.equal(typeof payload.id, 'number'); + }); + + it('should create payload with params', function () { + + // given + var method = 'helloworld1'; + var params = [123, 'test']; + + // when + var payload = jsonrpc.toPayload(method, params); + + // then + assert.equal(payload.jsonrpc, '2.0'); + assert.equal(payload.method, method); + assert.equal(payload.params.length, 2); + assert.equal(payload.params[0], params[0]); + assert.equal(payload.params[1], params[1]); + assert.equal(typeof payload.id, 'number'); + }); + }); +}); diff --git a/test/shh.methods.js b/test/shh.methods.js index fe2dae71d..91ca3caba 100644 --- a/test/shh.methods.js +++ b/test/shh.methods.js @@ -1,6 +1,6 @@ var assert = require('assert'); var web3 = require('../index.js'); -var u = require('./utils.js'); +var u = require('./test.utils.js'); describe('web3', function() { describe('shh', function() { diff --git a/test/utils.js b/test/test.utils.js similarity index 100% rename from test/utils.js rename to test/test.utils.js diff --git a/test/utils.extractDisplayName.js b/test/utils.extractDisplayName.js new file mode 100644 index 000000000..148653ab2 --- /dev/null +++ b/test/utils.extractDisplayName.js @@ -0,0 +1,42 @@ +var assert = require('assert'); +var utils = require('../lib/utils.js'); + +describe('utils', function () { + describe('extractDisplayName', function () { + it('should extract display name from method with no params', function () { + + // given + var test = 'helloworld()'; + + // when + var displayName = utils.extractDisplayName(test); + + // then + assert.equal(displayName, 'helloworld'); + }); + + it('should extract display name from method with one param' , function () { + + // given + var test = 'helloworld1(int)'; + + // when + var displayName = utils.extractDisplayName(test); + + // then + assert.equal(displayName, 'helloworld1'); + }); + + it('should extract display name from method with two params' , function () { + + // given + var test = 'helloworld2(int,string)'; + + // when + var displayName = utils.extractDisplayName(test); + + // then + assert.equal(displayName, 'helloworld2'); + }); + }); +}); diff --git a/test/utils.extractTypeName.js b/test/utils.extractTypeName.js new file mode 100644 index 000000000..2b4bbe767 --- /dev/null +++ b/test/utils.extractTypeName.js @@ -0,0 +1,55 @@ +var assert = require('assert'); +var utils = require('../lib/utils.js'); + +describe('utils', function () { + describe('extractTypeName', function () { + it('should extract type name from method with no params', function () { + + // given + var test = 'helloworld()'; + + // when + var typeName = utils.extractTypeName(test); + + // then + assert.equal(typeName, ''); + }); + + it('should extract type name from method with one param', function () { + + // given + var test = 'helloworld1(int)'; + + // when + var typeName = utils.extractTypeName(test); + + // then + assert.equal(typeName, 'int'); + }); + + it('should extract type name from method with two params', function () { + + // given + var test = 'helloworld2(int,string)'; + + // when + var typeName = utils.extractTypeName(test); + + // then + assert.equal(typeName, 'int,string'); + }); + + it('should extract type name from method with spaces between params', function () { + + // given + var test = 'helloworld3(int, string)'; + + // when + var typeName = utils.extractTypeName(test); + + // then + assert.equal(typeName, 'int,string'); + }); + + }); +}); diff --git a/test/web3.methods.js b/test/web3.methods.js index d08495dd9..06de41da4 100644 --- a/test/web3.methods.js +++ b/test/web3.methods.js @@ -1,6 +1,6 @@ var assert = require('assert'); var web3 = require('../index.js'); -var u = require('./utils.js'); +var u = require('./test.utils.js'); describe('web3', function() { u.methodExists(web3, 'sha3'); From 534f29e24623c3fe0e630b4a88beb9552ed09a70 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Tue, 3 Feb 2015 23:23:10 +0100 Subject: [PATCH 44/55] removed redundant code --- libqwebthree/QWebThree.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/libqwebthree/QWebThree.cpp b/libqwebthree/QWebThree.cpp index 804766563..31f2f6b92 100644 --- a/libqwebthree/QWebThree.cpp +++ b/libqwebthree/QWebThree.cpp @@ -41,20 +41,9 @@ void QWebThree::clientDieing() this->disconnect(); } -static QString formatInput(QJsonObject const& _object) -{ - QJsonObject res; - res["jsonrpc"] = QString::fromStdString("2.0"); - res["method"] = _object["call"]; - res["params"] = _object["args"]; - res["id"] = _object["_id"]; - return QString::fromUtf8(QJsonDocument(res).toJson()); -} - QString QWebThree::callMethod(QString _json) { - QJsonObject f = QJsonDocument::fromJson(_json.toUtf8()).object(); - emit processData(formatInput(f), ""); // it's synchronous + emit processData(_json, ""); // it's synchronous return m_response; } From 11203141a45e4ff5083ffa3c823121e0b4791187 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 3 Feb 2015 14:28:49 -0800 Subject: [PATCH 45/55] Fix #940 --- libethereum/State.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libethereum/State.cpp b/libethereum/State.cpp index ecb5b2606..3f81cd4c9 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -800,7 +800,7 @@ void State::completeMine() ret.appendRaw(m_currentTxs); ret.appendRaw(m_currentUncles); ret.swapOut(m_currentBytes); - m_currentBlock.hash = sha3(m_currentBytes); + m_currentBlock.hash = sha3(RLP(m_currentBytes)[0].data()); cnote << "Mined " << m_currentBlock.hash.abridged() << "(parent: " << m_currentBlock.parentHash.abridged() << ")"; // Quickly reset the transactions. From 3846cbf8d86ddc6f415aace87b542e78375398a5 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Wed, 4 Feb 2015 01:17:15 +0100 Subject: [PATCH 46/55] Fixing accesors test after visibility merge --- test/SolidityEndToEndTest.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/SolidityEndToEndTest.cpp b/test/SolidityEndToEndTest.cpp index ced9785ef..d1b332e89 100644 --- a/test/SolidityEndToEndTest.cpp +++ b/test/SolidityEndToEndTest.cpp @@ -921,10 +921,10 @@ BOOST_AUTO_TEST_CASE(multiple_elementary_accessors) BOOST_AUTO_TEST_CASE(complex_accessors) { char const* sourceCode = "contract test {\n" - " mapping(uint256 => string4) to_string_map;\n" - " mapping(uint256 => bool) to_bool_map;\n" - " mapping(uint256 => uint256) to_uint_map;\n" - " mapping(uint256 => mapping(uint256 => uint256)) to_multiple_map;\n" + " mapping(uint256 => string4) public to_string_map;\n" + " mapping(uint256 => bool) public to_bool_map;\n" + " mapping(uint256 => uint256) public to_uint_map;\n" + " mapping(uint256 => mapping(uint256 => uint256)) public to_multiple_map;\n" " function test() {\n" " to_string_map[42] = \"24\";\n" " to_bool_map[42] = false;\n" From 0d315f81bfcc3a9791b4fb2f5685315cc50054e9 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 3 Feb 2015 16:29:31 -0800 Subject: [PATCH 47/55] Test for named args. --- test/SolidityEndToEndTest.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/SolidityEndToEndTest.cpp b/test/SolidityEndToEndTest.cpp index ced9785ef..e019137e5 100644 --- a/test/SolidityEndToEndTest.cpp +++ b/test/SolidityEndToEndTest.cpp @@ -92,6 +92,16 @@ BOOST_AUTO_TEST_CASE(multiple_functions) BOOST_CHECK(callContractFunction("i_am_not_there()", bytes()) == bytes()); } +BOOST_AUTO_TEST_CASE(named_args) +{ + char const* sourceCode = "contract test {\n" + " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n" + " function b() returns (uint r) { r = a({a: 1, b: 2, c: 3}); }\n" + "}\n"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("b()", bytes()) == toBigEndian(u256(123))); +} + BOOST_AUTO_TEST_CASE(while_loop) { char const* sourceCode = "contract test {\n" From 295cc08f9cd9d4e54fdf964ec2d41422dff2c6d6 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 3 Feb 2015 18:19:34 -0800 Subject: [PATCH 48/55] BlockChain split into CanonBlockChain and just BlockChain. --- libethereum/CanonBlockChain.cpp | 12 ++++++++++++ libethereum/CanonBlockChain.h | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 libethereum/CanonBlockChain.cpp create mode 100644 libethereum/CanonBlockChain.h diff --git a/libethereum/CanonBlockChain.cpp b/libethereum/CanonBlockChain.cpp new file mode 100644 index 000000000..04713dc7e --- /dev/null +++ b/libethereum/CanonBlockChain.cpp @@ -0,0 +1,12 @@ +#include "CanonBlockChain.h" + +CanonBlockChain::CanonBlockChain() +{ + +} + +CanonBlockChain::~CanonBlockChain() +{ + +} + diff --git a/libethereum/CanonBlockChain.h b/libethereum/CanonBlockChain.h new file mode 100644 index 000000000..bc17e23ac --- /dev/null +++ b/libethereum/CanonBlockChain.h @@ -0,0 +1,12 @@ +#ifndef CANONBLOCKCHAIN_H +#define CANONBLOCKCHAIN_H + + +class CanonBlockChain +{ +public: + CanonBlockChain(); + ~CanonBlockChain(); +}; + +#endif // CANONBLOCKCHAIN_H From c0c6e23b8ca28b2587804d67ab1b0937fb0fd7e6 Mon Sep 17 00:00:00 2001 From: arkpar Date: Wed, 4 Feb 2015 10:30:07 +0100 Subject: [PATCH 49/55] fixed msvc build --- mix/ClientModel.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mix/ClientModel.h b/mix/ClientModel.h index 63731badf..37fbfbbc5 100644 --- a/mix/ClientModel.h +++ b/mix/ClientModel.h @@ -26,7 +26,7 @@ #include #include #include -#include "MixClient.h" +#include "MachineStates.h" namespace dev { @@ -38,6 +38,7 @@ class Web3Server; class RpcConnector; class QEther; class QDebugData; +class MixClient; /// Backend transaction config class struct TransactionSettings From 0f0b91e610cbb6bc8544dcf4e5fb6d1b0c907caa Mon Sep 17 00:00:00 2001 From: arkpar Date: Wed, 4 Feb 2015 10:54:11 +0100 Subject: [PATCH 50/55] fixed msvc build --- mix/AppContext.cpp | 7 ++++--- mix/ClientModel.cpp | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mix/AppContext.cpp b/mix/AppContext.cpp index e27eac9fd..4f7c494e8 100644 --- a/mix/AppContext.cpp +++ b/mix/AppContext.cpp @@ -27,15 +27,16 @@ #include #include #include -#include +#include #include "CodeModel.h" #include "FileIo.h" #include "ClientModel.h" #include "CodeEditorExtensionManager.h" #include "Exceptions.h" -#include "AppContext.h" #include "QEther.h" +#include "QVariableDefinition.h" #include "HttpServer.h" +#include "AppContext.h" using namespace dev; using namespace dev::eth; @@ -82,7 +83,7 @@ void AppContext::load() qmlRegisterType("CodeEditorExtensionManager", 1, 0, "CodeEditorExtensionManager"); qmlRegisterType("HttpServer", 1, 0, "HttpServer"); m_applicationEngine->load(QUrl("qrc:/qml/main.qml")); - QQuickWindow *window = qobject_cast(m_applicationEngine->rootObjects().at(0)); + QWindow *window = qobject_cast(m_applicationEngine->rootObjects().at(0)); window->setIcon(QIcon(":/res/mix_256x256x32.png")); appLoaded(); } diff --git a/mix/ClientModel.cpp b/mix/ClientModel.cpp index 365dce9a9..4ce7b7755 100644 --- a/mix/ClientModel.cpp +++ b/mix/ClientModel.cpp @@ -30,6 +30,7 @@ #include "Exceptions.h" #include "QContractDefinition.h" #include "QVariableDeclaration.h" +#include "QVariableDefinition.h" #include "ContractCallDataEncoder.h" #include "CodeModel.h" #include "ClientModel.h" From 2d09638fdec853d0d303141ad5ce97b1289153e0 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 4 Feb 2015 11:24:10 +0100 Subject: [PATCH 51/55] Squashed 'libjsqrc/ethereumjs/' changes from a0cfa3c..f3e1797 f3e1797 fixed jsonrpc response 0 not handled properly git-subtree-dir: libjsqrc/ethereumjs git-subtree-split: f3e1797153ebf5b19ca3e154cf1240be738e4f08 --- dist/ethereum.js | 2 +- dist/ethereum.js.map | 2 +- dist/ethereum.min.js | 2 +- lib/jsonrpc.js | 2 +- test/jsonrpc.isValidResponse.js | 15 +++++++++++++++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/dist/ethereum.js b/dist/ethereum.js index 564d59b4a..fa4bcc591 100644 --- a/dist/ethereum.js +++ b/dist/ethereum.js @@ -979,7 +979,7 @@ var isValidResponse = function (response) { !response.error && response.jsonrpc === '2.0' && typeof response.id === 'number' && - (!!response.result || typeof response.result === 'boolean'); + response.result !== undefined; // only undefined is not valid json object }; /// Should be called to create batch payload object diff --git a/dist/ethereum.js.map b/dist/ethereum.js.map index 1ef0b2f76..118372970 100644 --- a/dist/ethereum.js.map +++ b/dist/ethereum.js.map @@ -30,7 +30,7 @@ "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file filter.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nvar web3 = require('./web3'); // jshint ignore:line\n\n/// should be used when we want to watch something\n/// it's using inner polling mechanism and is notified about changes\n/// TODO: change 'options' name cause it may be not the best matching one, since we have events\nvar Filter = function(options, impl) {\n\n if (typeof options !== \"string\") {\n\n // topics property is deprecated, warn about it!\n if (options.topics) {\n console.warn('\"topics\" is deprecated, use \"topic\" instead');\n }\n \n this._onWatchResult = options._onWatchEventResult;\n\n // evaluate lazy properties\n options = {\n to: options.to,\n topic: options.topic,\n earliest: options.earliest,\n latest: options.latest,\n max: options.max,\n skip: options.skip,\n address: options.address\n };\n\n }\n \n this.impl = impl;\n this.callbacks = [];\n\n this.id = impl.newFilter(options);\n web3.provider.startPolling({method: impl.changed, params: [this.id]}, this.id, this.trigger.bind(this));\n};\n\n/// alias for changed*\nFilter.prototype.arrived = function(callback) {\n this.changed(callback);\n};\nFilter.prototype.happened = function(callback) {\n this.changed(callback);\n};\n\n/// gets called when there is new eth/shh message\nFilter.prototype.changed = function(callback) {\n this.callbacks.push(callback);\n};\n\n/// trigger calling new message from people\nFilter.prototype.trigger = function(messages) {\n for (var i = 0; i < this.callbacks.length; i++) {\n for (var j = 0; j < messages.length; j++) {\n var message = this._onWatchResult ? this._onWatchResult(messages[j]) : messages[j];\n this.callbacks[i].call(this, message);\n }\n }\n};\n\n/// should be called to uninstall current filter\nFilter.prototype.uninstall = function() {\n this.impl.uninstallFilter(this.id);\n web3.provider.stopPolling(this.id);\n};\n\n/// should be called to manually trigger getting latest messages from the client\nFilter.prototype.messages = function() {\n return this.impl.getMessages(this.id);\n};\n\n/// alias for messages\nFilter.prototype.logs = function () {\n return this.messages();\n};\n\nmodule.exports = Filter;\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file formatters.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\nif (\"build\" !== 'build') {/*\n var BigNumber = require('bignumber.js'); // jshint ignore:line\n*/}\n\nvar utils = require('./utils');\nvar c = require('./const');\n\n/// @param string string to be padded\n/// @param number of characters that result string should have\n/// @param sign, by default 0\n/// @returns right aligned string\nvar padLeft = function (string, chars, sign) {\n return new Array(chars - string.length + 1).join(sign ? sign : \"0\") + string;\n};\n\n/// Formats input value to byte representation of int\n/// If value is negative, return it's two's complement\n/// If the value is floating point, round it down\n/// @returns right-aligned byte representation of int\nvar formatInputInt = function (value) {\n var padding = c.ETH_PADDING * 2;\n if (value instanceof BigNumber || typeof value === 'number') {\n if (typeof value === 'number')\n value = new BigNumber(value);\n BigNumber.config(c.ETH_BIGNUMBER_ROUNDING_MODE);\n value = value.round();\n\n if (value.lessThan(0)) \n value = new BigNumber(\"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff\", 16).plus(value).plus(1);\n value = value.toString(16);\n }\n else if (value.indexOf('0x') === 0)\n value = value.substr(2);\n else if (typeof value === 'string')\n value = formatInputInt(new BigNumber(value));\n else\n value = (+value).toString(16);\n return padLeft(value, padding);\n};\n\n/// Formats input value to byte representation of string\n/// @returns left-algined byte representation of string\nvar formatInputString = function (value) {\n return utils.fromAscii(value, c.ETH_PADDING).substr(2);\n};\n\n/// Formats input value to byte representation of bool\n/// @returns right-aligned byte representation bool\nvar formatInputBool = function (value) {\n return '000000000000000000000000000000000000000000000000000000000000000' + (value ? '1' : '0');\n};\n\n/// Formats input value to byte representation of real\n/// Values are multiplied by 2^m and encoded as integers\n/// @returns byte representation of real\nvar formatInputReal = function (value) {\n return formatInputInt(new BigNumber(value).times(new BigNumber(2).pow(128))); \n};\n\n\n/// Check if input value is negative\n/// @param value is hex format\n/// @returns true if it is negative, otherwise false\nvar signedIsNegative = function (value) {\n return (new BigNumber(value.substr(0, 1), 16).toString(2).substr(0, 1)) === '1';\n};\n\n/// Formats input right-aligned input bytes to int\n/// @returns right-aligned input bytes formatted to int\nvar formatOutputInt = function (value) {\n value = value || \"0\";\n // check if it's negative number\n // it it is, return two's complement\n if (signedIsNegative(value)) {\n return new BigNumber(value, 16).minus(new BigNumber('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16)).minus(1);\n }\n return new BigNumber(value, 16);\n};\n\n/// Formats big right-aligned input bytes to uint\n/// @returns right-aligned input bytes formatted to uint\nvar formatOutputUInt = function (value) {\n value = value || \"0\";\n return new BigNumber(value, 16);\n};\n\n/// @returns input bytes formatted to real\nvar formatOutputReal = function (value) {\n return formatOutputInt(value).dividedBy(new BigNumber(2).pow(128)); \n};\n\n/// @returns input bytes formatted to ureal\nvar formatOutputUReal = function (value) {\n return formatOutputUInt(value).dividedBy(new BigNumber(2).pow(128)); \n};\n\n/// @returns right-aligned input bytes formatted to hex\nvar formatOutputHash = function (value) {\n return \"0x\" + value;\n};\n\n/// @returns right-aligned input bytes formatted to bool\nvar formatOutputBool = function (value) {\n return value === '0000000000000000000000000000000000000000000000000000000000000001' ? true : false;\n};\n\n/// @returns left-aligned input bytes formatted to ascii string\nvar formatOutputString = function (value) {\n return utils.toAscii(value);\n};\n\n/// @returns right-aligned input bytes formatted to address\nvar formatOutputAddress = function (value) {\n return \"0x\" + value.slice(value.length - 40, value.length);\n};\n\n\nmodule.exports = {\n formatInputInt: formatInputInt,\n formatInputString: formatInputString,\n formatInputBool: formatInputBool,\n formatInputReal: formatInputReal,\n formatOutputInt: formatOutputInt,\n formatOutputUInt: formatOutputUInt,\n formatOutputReal: formatOutputReal,\n formatOutputUReal: formatOutputUReal,\n formatOutputHash: formatOutputHash,\n formatOutputBool: formatOutputBool,\n formatOutputString: formatOutputString,\n formatOutputAddress: formatOutputAddress\n};\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file httpsync.js\n * @authors:\n * Marek Kotewicz \n * Marian Oancea \n * @date 2014\n */\n\nif (\"build\" !== 'build') {/*\n var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest; // jshint ignore:line\n*/}\n\nvar HttpSyncProvider = function (host) {\n this.handlers = [];\n this.host = host || 'http://localhost:8080';\n};\n\nHttpSyncProvider.prototype.send = function (payload) {\n //var data = formatJsonRpcObject(payload);\n \n var request = new XMLHttpRequest();\n request.open('POST', this.host, false);\n request.send(JSON.stringify(payload));\n \n // check request.status\n var result = request.responseText;\n return JSON.parse(result);\n};\n\nmodule.exports = HttpSyncProvider;\n\n", - "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file jsonrpc.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\nvar messageId = 1;\n\n/// Should be called to valid json create payload object\n/// @param method of jsonrpc call, required\n/// @param params, an array of method params, optional\n/// @returns valid jsonrpc payload object\nvar toPayload = function (method, params) {\n if (!method)\n console.error('jsonrpc method should be specified!');\n\n return {\n jsonrpc: '2.0',\n method: method,\n params: params || [],\n id: messageId++\n }; \n};\n\n/// Should be called to check if jsonrpc response is valid\n/// @returns true if response is valid, otherwise false \nvar isValidResponse = function (response) {\n return !!response &&\n !response.error &&\n response.jsonrpc === '2.0' &&\n typeof response.id === 'number' &&\n (!!response.result || typeof response.result === 'boolean');\n};\n\n/// Should be called to create batch payload object\n/// @param messages, an array of objects with method (required) and params (optional) fields\nvar toBatchPayload = function (messages) {\n return messages.map(function (message) {\n return toPayload(message.method, message.params);\n }); \n};\n\nmodule.exports = {\n toPayload: toPayload,\n isValidResponse: isValidResponse,\n toBatchPayload: toBatchPayload\n};\n\n\n", + "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file jsonrpc.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\nvar messageId = 1;\n\n/// Should be called to valid json create payload object\n/// @param method of jsonrpc call, required\n/// @param params, an array of method params, optional\n/// @returns valid jsonrpc payload object\nvar toPayload = function (method, params) {\n if (!method)\n console.error('jsonrpc method should be specified!');\n\n return {\n jsonrpc: '2.0',\n method: method,\n params: params || [],\n id: messageId++\n }; \n};\n\n/// Should be called to check if jsonrpc response is valid\n/// @returns true if response is valid, otherwise false \nvar isValidResponse = function (response) {\n return !!response &&\n !response.error &&\n response.jsonrpc === '2.0' &&\n typeof response.id === 'number' &&\n response.result !== undefined; // only undefined is not valid json object\n};\n\n/// Should be called to create batch payload object\n/// @param messages, an array of objects with method (required) and params (optional) fields\nvar toBatchPayload = function (messages) {\n return messages.map(function (message) {\n return toPayload(message.method, message.params);\n }); \n};\n\nmodule.exports = {\n toPayload: toPayload,\n isValidResponse: isValidResponse,\n toBatchPayload: toBatchPayload\n};\n\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file providermanager.js\n * @authors:\n * Jeffrey Wilcke \n * Marek Kotewicz \n * Marian Oancea \n * Gav Wood \n * @date 2014\n */\n\nvar web3 = require('./web3'); \nvar jsonrpc = require('./jsonrpc');\n\n\n/**\n * Provider manager object prototype\n * It's responsible for passing messages to providers\n * If no provider is set it's responsible for queuing requests\n * It's also responsible for polling the ethereum node for incoming messages\n * Default poll timeout is 12 seconds\n * If we are running ethereum.js inside ethereum browser, there are backend based tools responsible for polling,\n * and provider manager polling mechanism is not used\n */\nvar ProviderManager = function() {\n this.polls = [];\n this.provider = undefined;\n\n var self = this;\n var poll = function () {\n if (self.provider) {\n var pollsBatch = self.polls.map(function (data) {\n return data.data;\n });\n\n var payload = jsonrpc.toBatchPayload(pollsBatch);\n var results = self.provider.send(payload);\n\n self.polls.forEach(function (data, index) {\n var result = results[index];\n \n if (!jsonrpc.isValidResponse(result)) {\n console.log(result);\n return;\n }\n\n result = result.result;\n // dont call the callback if result is not an array, or empty one\n if (!(result instanceof Array) || result.length === 0) {\n return;\n }\n\n data.callback(result);\n\n });\n\n }\n setTimeout(poll, 1000);\n };\n poll();\n};\n\n/// sends outgoing requests\n/// @params data - an object with at least 'method' property\nProviderManager.prototype.send = function(data) {\n var payload = jsonrpc.toPayload(data.method, data.params);\n\n if (this.provider === undefined) {\n console.error('provider is not set');\n return null; \n }\n\n var result = this.provider.send(payload);\n\n if (!jsonrpc.isValidResponse(result)) {\n console.log(result);\n return null;\n }\n\n return result.result;\n};\n\n/// setups provider, which will be used for sending messages\nProviderManager.prototype.set = function(provider) {\n this.provider = provider;\n};\n\n/// this method is only used, when we do not have native qt bindings and have to do polling on our own\n/// should be callled, on start watching for eth/shh changes\nProviderManager.prototype.startPolling = function (data, pollId, callback) {\n this.polls.push({data: data, id: pollId, callback: callback});\n};\n\n/// should be called to stop polling for certain watch changes\nProviderManager.prototype.stopPolling = function (pollId) {\n for (var i = this.polls.length; i--;) {\n var poll = this.polls[i];\n if (poll.id === pollId) {\n this.polls.splice(i, 1);\n }\n }\n};\n\nmodule.exports = ProviderManager;\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file qtsync.js\n * @authors:\n * Marek Kotewicz \n * Marian Oancea \n * @date 2014\n */\n\nvar QtSyncProvider = function () {\n};\n\nQtSyncProvider.prototype.send = function (payload) {\n var result = navigator.qt.callMethod(JSON.stringify(payload));\n return JSON.parse(result);\n};\n\nmodule.exports = QtSyncProvider;\n\n", "/*\n This file is part of ethereum.js.\n\n ethereum.js is free software: you can redistribute it and/or modify\n it under the terms of the GNU Lesser General Public License as published by\n the Free Software Foundation, either version 3 of the License, or\n (at your option) any later version.\n\n ethereum.js is distributed in the hope that it will be useful,\n but WITHOUT ANY WARRANTY; without even the implied warranty of\n MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n GNU Lesser General Public License for more details.\n\n You should have received a copy of the GNU Lesser General Public License\n along with ethereum.js. If not, see .\n*/\n/** @file types.js\n * @authors:\n * Marek Kotewicz \n * @date 2015\n */\n\nvar f = require('./formatters');\n\n/// @param expected type prefix (string)\n/// @returns function which checks if type has matching prefix. if yes, returns true, otherwise false\nvar prefixedType = function (prefix) {\n return function (type) {\n return type.indexOf(prefix) === 0;\n };\n};\n\n/// @param expected type name (string)\n/// @returns function which checks if type is matching expected one. if yes, returns true, otherwise false\nvar namedType = function (name) {\n return function (type) {\n return name === type;\n };\n};\n\n/// Setups input formatters for solidity types\n/// @returns an array of input formatters \nvar inputTypes = function () {\n \n return [\n { type: prefixedType('uint'), format: f.formatInputInt },\n { type: prefixedType('int'), format: f.formatInputInt },\n { type: prefixedType('hash'), format: f.formatInputInt },\n { type: prefixedType('string'), format: f.formatInputString }, \n { type: prefixedType('real'), format: f.formatInputReal },\n { type: prefixedType('ureal'), format: f.formatInputReal },\n { type: namedType('address'), format: f.formatInputInt },\n { type: namedType('bool'), format: f.formatInputBool }\n ];\n};\n\n/// Setups output formaters for solidity types\n/// @returns an array of output formatters\nvar outputTypes = function () {\n\n return [\n { type: prefixedType('uint'), format: f.formatOutputUInt },\n { type: prefixedType('int'), format: f.formatOutputInt },\n { type: prefixedType('hash'), format: f.formatOutputHash },\n { type: prefixedType('string'), format: f.formatOutputString },\n { type: prefixedType('real'), format: f.formatOutputReal },\n { type: prefixedType('ureal'), format: f.formatOutputUReal },\n { type: namedType('address'), format: f.formatOutputAddress },\n { type: namedType('bool'), format: f.formatOutputBool }\n ];\n};\n\nmodule.exports = {\n prefixedType: prefixedType,\n namedType: namedType,\n inputTypes: inputTypes,\n outputTypes: outputTypes\n};\n\n", diff --git a/dist/ethereum.min.js b/dist/ethereum.min.js index a2524c0ce..a724e6261 100644 --- a/dist/ethereum.min.js +++ b/dist/ethereum.min.js @@ -1 +1 @@ -require=function t(e,n,r){function i(a,u){if(!n[a]){if(!e[a]){var s="function"==typeof require&&require;if(!u&&s)return s(a,!0);if(o)return o(a,!0);var f=new Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[a]={exports:{}};e[a][0].call(c.exports,function(t){var n=e[a][1][t];return i(n?n:t)},c,c.exports,t,e,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;av;v++)g.push(h(e.slice(0,r))),e=e.slice(r);n.push(g)}else i.prefixedType("string")(t[f].type)?(c=c.slice(r),n.push(h(e.slice(0,r))),e=e.slice(r)):(n.push(h(e.slice(0,r))),e=e.slice(r))}),n},d=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(){var e=Array.prototype.slice.call(arguments);return l(t.inputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},g=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(e){return h(t.outputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},v=function(t){return n.sha3(n.fromAscii(t)).slice(0,2+2*o.ETH_SIGNATURE_LENGTH)},y=function(t){return n.sha3(n.fromAscii(t))};e.exports={inputParser:d,outputParser:g,formatInput:l,formatOutput:h,signatureFromAscii:v,eventSignatureFromAscii:y}},{"./const":2,"./formatters":6,"./types":11,"./utils":12,"./web3":13}],2:[function(t,e){var n=["wei","Kwei","Mwei","Gwei","szabo","finney","ether","grand","Mether","Gether","Tether","Pether","Eether","Zether","Yether","Nether","Dether","Vether","Uether"];e.exports={ETH_PADDING:32,ETH_SIGNATURE_LENGTH:4,ETH_UNITS:n,ETH_BIGNUMBER_ROUNDING_MODE:{ROUNDING_MODE:BigNumber.ROUND_DOWN}}},{}],3:[function(t,e){var n=t("./web3"),r=t("./abi"),i=t("./utils"),o=t("./event"),a=function(t){n._currentContractAbi=t.abi,n._currentContractAddress=t.address,n._currentContractMethodName=t.method,n._currentContractMethodParams=t.params},u=function(t){t.call=function(e){return t._isTransact=!1,t._options=e,t},t.transact=function(e){return t._isTransact=!0,t._options=e,t},t._options={},["gas","gasPrice","value","from"].forEach(function(e){t[e]=function(n){return t._options[e]=n,t}})},s=function(t,e,o){var u=r.inputParser(e),s=r.outputParser(e);i.filterFunctions(e).forEach(function(f){var c=i.extractDisplayName(f.name),l=i.extractTypeName(f.name),p=function(){var i=Array.prototype.slice.call(arguments),p=r.signatureFromAscii(f.name),m=u[c][l].apply(null,i),h=t._options||{};h.to=o,h.data=p+m;var d=t._isTransact===!0||t._isTransact!==!1&&!f.constant,g=h.collapse!==!1;if(t._options={},t._isTransact=null,d)return a({abi:e,address:o,method:f.name,params:i}),void n.eth.transact(h);var v=n.eth.call(h),y=s[c][l](v);return g&&(1===y.length?y=y[0]:0===y.length&&(y=null)),y};void 0===t[c]&&(t[c]=p),t[c][l]=p})},f=function(t,e,n){t.address=n,t._onWatchEventResult=function(t){var n=event.getMatchingEvent(i.filterEvents(e)),r=o.outputParser(n);return r(t)},Object.defineProperty(t,"topic",{get:function(){return i.filterEvents(e).map(function(t){return r.eventSignatureFromAscii(t.name)})}})},c=function(t,e,a){i.filterEvents(e).forEach(function(e){var u=function(){var t=Array.prototype.slice.call(arguments),i=r.eventSignatureFromAscii(e.name),u=o.inputParser(a,i,e),s=u.apply(null,t);return s._onWatchEventResult=function(t){var n=o.outputParser(e);return n(t)},n.eth.watch(s)};u._isEvent=!0;var s=i.extractDisplayName(e.name),f=i.extractTypeName(e.name);void 0===t[s]&&(t[s]=u),t[s][f]=u})},l=function(t,e){e.forEach(function(t){if(-1===t.name.indexOf("(")){var e=t.name,n=t.inputs.map(function(t){return t.type}).join();t.name=e+"("+n+")"}});var n={};return u(n),s(n,e,t),f(n,e,t),c(n,e,t),n};e.exports=l},{"./abi":1,"./event":4,"./utils":12,"./web3":13}],4:[function(t,e){var n=t("./abi"),r=t("./utils"),i=function(t,e){return t.filter(function(t){return t.indexed===e})},o=function(t,e){var n=r.findIndex(t,function(t){return t.name===e});return-1===n?void console.error("indexed param with name "+e+" not found"):t[n]},a=function(t,e){return Object.keys(e).map(function(r){var a=[o(i(t.inputs,!0),r)],u=e[r];return u instanceof Array?u.map(function(t){return n.formatInput(a,[t])}):n.formatInput(a,[u])})},u=function(t,e,n){return function(r,i){var o=i||{};return o.address=t,o.topic=[],o.topic.push(e),r&&(o.topic=o.topic.concat(a(n,r))),o}},s=function(t,e,n){e.slice(),n.slice();return t.reduce(function(t,r){var i;return i=r.indexed?e.splice(0,1)[0]:n.splice(0,1)[0],t[r.name]=i,t},{})},f=function(t){return function(e){var o={event:r.extractDisplayName(t.name),number:e.number,args:{}};if(!e.topic)return o;var a=i(t.inputs,!0),u="0x"+e.topic.slice(1,e.topic.length).map(function(t){return t.slice(2)}).join(""),f=n.formatOutput(a,u),c=i(t.inputs,!1),l=n.formatOutput(c,e.data);return o.args=s(t.inputs,f,l),o}},c=function(t,e){for(var r=0;rn;n+=2){var i=parseInt(t.substr(n,2),16);if(0===i)break;e+=String.fromCharCode(i)}return e},o=function(t){for(var e="",n=0;n3e3&&r2?t.substring(2):"0",new BigNumber(t,16).toString(10)},fromDecimal:function(t){return"0x"+new BigNumber(t).toString(16)},toEth:n.toEth,eth:{contractFromAbi:function(t){return function(e){e=e||"0xc6d9d2cd449a754c494264e1809c50e34d64562b";var n=p.eth.contract(e,t);return n.address=e,n}},watch:function(t,e,n){return t._isEvent?t(e,n):new p.filter(t,m)}},db:{},shh:{watch:function(t){return new p.filter(t,h)}}};c(p,r()),c(p.eth,i()),l(p.eth,o()),c(p.db,a()),c(p.shh,u());var m={changed:"eth_changed"};c(m,s());var h={changed:"shh_changed"};c(h,f()),p.setProvider=function(t){p.provider.set(t)},e.exports=p},{"./utils":12}],web3:[function(t,e){var n=t("./lib/web3"),r=t("./lib/providermanager");n.provider=new r,n.filter=t("./lib/filter"),n.providers.HttpSyncProvider=t("./lib/httpsync"),n.providers.QtSyncProvider=t("./lib/qtsync"),n.eth.contract=t("./lib/contract"),n.abi=t("./lib/abi"),e.exports=n},{"./lib/abi":1,"./lib/contract":3,"./lib/filter":5,"./lib/httpsync":7,"./lib/providermanager":9,"./lib/qtsync":10,"./lib/web3":13}]},{},["web3"]); \ No newline at end of file +require=function t(e,n,r){function i(a,u){if(!n[a]){if(!e[a]){var s="function"==typeof require&&require;if(!u&&s)return s(a,!0);if(o)return o(a,!0);var f=new Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",f}var c=n[a]={exports:{}};e[a][0].call(c.exports,function(t){var n=e[a][1][t];return i(n?n:t)},c,c.exports,t,e,n,r)}return n[a].exports}for(var o="function"==typeof require&&require,a=0;av;v++)g.push(h(e.slice(0,r))),e=e.slice(r);n.push(g)}else i.prefixedType("string")(t[f].type)?(c=c.slice(r),n.push(h(e.slice(0,r))),e=e.slice(r)):(n.push(h(e.slice(0,r))),e=e.slice(r))}),n},d=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(){var e=Array.prototype.slice.call(arguments);return l(t.inputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},g=function(t){var e={};return t.forEach(function(t){var n=r.extractDisplayName(t.name),i=r.extractTypeName(t.name),o=function(e){return h(t.outputs,e)};void 0===e[n]&&(e[n]=o),e[n][i]=o}),e},v=function(t){return n.sha3(n.fromAscii(t)).slice(0,2+2*o.ETH_SIGNATURE_LENGTH)},y=function(t){return n.sha3(n.fromAscii(t))};e.exports={inputParser:d,outputParser:g,formatInput:l,formatOutput:h,signatureFromAscii:v,eventSignatureFromAscii:y}},{"./const":2,"./formatters":6,"./types":11,"./utils":12,"./web3":13}],2:[function(t,e){var n=["wei","Kwei","Mwei","Gwei","szabo","finney","ether","grand","Mether","Gether","Tether","Pether","Eether","Zether","Yether","Nether","Dether","Vether","Uether"];e.exports={ETH_PADDING:32,ETH_SIGNATURE_LENGTH:4,ETH_UNITS:n,ETH_BIGNUMBER_ROUNDING_MODE:{ROUNDING_MODE:BigNumber.ROUND_DOWN}}},{}],3:[function(t,e){var n=t("./web3"),r=t("./abi"),i=t("./utils"),o=t("./event"),a=function(t){n._currentContractAbi=t.abi,n._currentContractAddress=t.address,n._currentContractMethodName=t.method,n._currentContractMethodParams=t.params},u=function(t){t.call=function(e){return t._isTransact=!1,t._options=e,t},t.transact=function(e){return t._isTransact=!0,t._options=e,t},t._options={},["gas","gasPrice","value","from"].forEach(function(e){t[e]=function(n){return t._options[e]=n,t}})},s=function(t,e,o){var u=r.inputParser(e),s=r.outputParser(e);i.filterFunctions(e).forEach(function(f){var c=i.extractDisplayName(f.name),l=i.extractTypeName(f.name),p=function(){var i=Array.prototype.slice.call(arguments),p=r.signatureFromAscii(f.name),m=u[c][l].apply(null,i),h=t._options||{};h.to=o,h.data=p+m;var d=t._isTransact===!0||t._isTransact!==!1&&!f.constant,g=h.collapse!==!1;if(t._options={},t._isTransact=null,d)return a({abi:e,address:o,method:f.name,params:i}),void n.eth.transact(h);var v=n.eth.call(h),y=s[c][l](v);return g&&(1===y.length?y=y[0]:0===y.length&&(y=null)),y};void 0===t[c]&&(t[c]=p),t[c][l]=p})},f=function(t,e,n){t.address=n,t._onWatchEventResult=function(t){var n=event.getMatchingEvent(i.filterEvents(e)),r=o.outputParser(n);return r(t)},Object.defineProperty(t,"topic",{get:function(){return i.filterEvents(e).map(function(t){return r.eventSignatureFromAscii(t.name)})}})},c=function(t,e,a){i.filterEvents(e).forEach(function(e){var u=function(){var t=Array.prototype.slice.call(arguments),i=r.eventSignatureFromAscii(e.name),u=o.inputParser(a,i,e),s=u.apply(null,t);return s._onWatchEventResult=function(t){var n=o.outputParser(e);return n(t)},n.eth.watch(s)};u._isEvent=!0;var s=i.extractDisplayName(e.name),f=i.extractTypeName(e.name);void 0===t[s]&&(t[s]=u),t[s][f]=u})},l=function(t,e){e.forEach(function(t){if(-1===t.name.indexOf("(")){var e=t.name,n=t.inputs.map(function(t){return t.type}).join();t.name=e+"("+n+")"}});var n={};return u(n),s(n,e,t),f(n,e,t),c(n,e,t),n};e.exports=l},{"./abi":1,"./event":4,"./utils":12,"./web3":13}],4:[function(t,e){var n=t("./abi"),r=t("./utils"),i=function(t,e){return t.filter(function(t){return t.indexed===e})},o=function(t,e){var n=r.findIndex(t,function(t){return t.name===e});return-1===n?void console.error("indexed param with name "+e+" not found"):t[n]},a=function(t,e){return Object.keys(e).map(function(r){var a=[o(i(t.inputs,!0),r)],u=e[r];return u instanceof Array?u.map(function(t){return n.formatInput(a,[t])}):n.formatInput(a,[u])})},u=function(t,e,n){return function(r,i){var o=i||{};return o.address=t,o.topic=[],o.topic.push(e),r&&(o.topic=o.topic.concat(a(n,r))),o}},s=function(t,e,n){e.slice(),n.slice();return t.reduce(function(t,r){var i;return i=r.indexed?e.splice(0,1)[0]:n.splice(0,1)[0],t[r.name]=i,t},{})},f=function(t){return function(e){var o={event:r.extractDisplayName(t.name),number:e.number,args:{}};if(!e.topic)return o;var a=i(t.inputs,!0),u="0x"+e.topic.slice(1,e.topic.length).map(function(t){return t.slice(2)}).join(""),f=n.formatOutput(a,u),c=i(t.inputs,!1),l=n.formatOutput(c,e.data);return o.args=s(t.inputs,f,l),o}},c=function(t,e){for(var r=0;rn;n+=2){var i=parseInt(t.substr(n,2),16);if(0===i)break;e+=String.fromCharCode(i)}return e},o=function(t){for(var e="",n=0;n3e3&&r2?t.substring(2):"0",new BigNumber(t,16).toString(10)},fromDecimal:function(t){return"0x"+new BigNumber(t).toString(16)},toEth:n.toEth,eth:{contractFromAbi:function(t){return function(e){e=e||"0xc6d9d2cd449a754c494264e1809c50e34d64562b";var n=p.eth.contract(e,t);return n.address=e,n}},watch:function(t,e,n){return t._isEvent?t(e,n):new p.filter(t,m)}},db:{},shh:{watch:function(t){return new p.filter(t,h)}}};c(p,r()),c(p.eth,i()),l(p.eth,o()),c(p.db,a()),c(p.shh,u());var m={changed:"eth_changed"};c(m,s());var h={changed:"shh_changed"};c(h,f()),p.setProvider=function(t){p.provider.set(t)},e.exports=p},{"./utils":12}],web3:[function(t,e){var n=t("./lib/web3"),r=t("./lib/providermanager");n.provider=new r,n.filter=t("./lib/filter"),n.providers.HttpSyncProvider=t("./lib/httpsync"),n.providers.QtSyncProvider=t("./lib/qtsync"),n.eth.contract=t("./lib/contract"),n.abi=t("./lib/abi"),e.exports=n},{"./lib/abi":1,"./lib/contract":3,"./lib/filter":5,"./lib/httpsync":7,"./lib/providermanager":9,"./lib/qtsync":10,"./lib/web3":13}]},{},["web3"]); \ No newline at end of file diff --git a/lib/jsonrpc.js b/lib/jsonrpc.js index 63afa3229..b2d6922c0 100644 --- a/lib/jsonrpc.js +++ b/lib/jsonrpc.js @@ -45,7 +45,7 @@ var isValidResponse = function (response) { !response.error && response.jsonrpc === '2.0' && typeof response.id === 'number' && - (!!response.result || typeof response.result === 'boolean'); + response.result !== undefined; // only undefined is not valid json object }; /// Should be called to create batch payload object diff --git a/test/jsonrpc.isValidResponse.js b/test/jsonrpc.isValidResponse.js index 2fe200496..920b5f3a9 100644 --- a/test/jsonrpc.isValidResponse.js +++ b/test/jsonrpc.isValidResponse.js @@ -124,5 +124,20 @@ describe('jsonrpc', function () { assert.equal(valid, true); }); + it('should validate jsonrpc response with result field === 0', function () { + + // given + var response = { + jsonrpc: '2.0', + id: 1, + result: 0 + }; + + // when + var valid = jsonrpc.isValidResponse(response); + + // then + assert.equal(valid, true); + }); }); }); From b5c8999b5ab759c0d96a40bdbd80f801bb7f3fa3 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 4 Feb 2015 16:29:09 +0100 Subject: [PATCH 52/55] fixed natspec.js --- libjsqrc/natspec.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libjsqrc/natspec.js b/libjsqrc/natspec.js index d0bbdff17..c8cf07496 100644 --- a/libjsqrc/natspec.js +++ b/libjsqrc/natspec.js @@ -29,10 +29,20 @@ var getContractMethods = function (address, abi) { return web3.eth.contract(address, abi); }; +var getMethodWithName = function(abi, name) { + for (var i = 0; i < abi.length; i++) { + if (abi[i].name === name) { + return abi[i]; + } + } + console.warn('could not find method with name: ' + name); + return undefined; +}; + /// Function called to get all contract method input variables /// @returns hashmap with all contract's method input variables var getContractInputParams = function (abi, methodName, params) { - var method = web3.abi.getMethodWithName(abi, methodName); + var method = getMethodWithName(abi, methodName); return method.inputs.reduce(function (acc, current, index) { acc[current.name] = params[index]; return acc; From 81d8a14a7b020016506d1010ec8d33f7e54cfe8c Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Thu, 5 Feb 2015 00:06:35 +0800 Subject: [PATCH 53/55] add a test case for disorder named args --- test/SolidityEndToEndTest.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/SolidityEndToEndTest.cpp b/test/SolidityEndToEndTest.cpp index d0d501677..f248a5a07 100644 --- a/test/SolidityEndToEndTest.cpp +++ b/test/SolidityEndToEndTest.cpp @@ -102,6 +102,16 @@ BOOST_AUTO_TEST_CASE(named_args) BOOST_CHECK(callContractFunction("b()", bytes()) == toBigEndian(u256(123))); } +BOOST_AUTO_TEST_CASE(disorder_named_args) +{ + char const* sourceCode = "contract test {\n" + " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n" + " function b() returns (uint r) { r = a({c: 3, a: 1, b: 2}); }\n" + "}\n"; + compileAndRun(sourceCode); + BOOST_CHECK(callContractFunction("b()", bytes()) == toBigEndian(u256(123))); +} + BOOST_AUTO_TEST_CASE(while_loop) { char const* sourceCode = "contract test {\n" From 544c9ef09e40e680aee3da8aa32b21535d08b866 Mon Sep 17 00:00:00 2001 From: Lu Guanqun Date: Thu, 5 Feb 2015 00:06:54 +0800 Subject: [PATCH 54/55] add two test cases parser error for named args --- test/SolidityParser.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/SolidityParser.cpp b/test/SolidityParser.cpp index 4ccdcd57a..9ba38a4a1 100644 --- a/test/SolidityParser.cpp +++ b/test/SolidityParser.cpp @@ -124,6 +124,24 @@ BOOST_AUTO_TEST_CASE(single_function_param) BOOST_CHECK_NO_THROW(parseText(text)); } +BOOST_AUTO_TEST_CASE(missing_parameter_name_in_named_args) +{ + char const* text = "contract test {\n" + " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n" + " function b() returns (uint r) { r = a({: 1, : 2, : 3}); }\n" + "}\n"; + BOOST_CHECK_THROW(parseText(text), ParserError); +} + +BOOST_AUTO_TEST_CASE(missing_argument_in_named_args) +{ + char const* text = "contract test {\n" + " function a(uint a, uint b, uint c) returns (uint r) { r = a * 100 + b * 10 + c * 1; }\n" + " function b() returns (uint r) { r = a({a: , b: , c: }); }\n" + "}\n"; + BOOST_CHECK_THROW(parseText(text), ParserError); +} + BOOST_AUTO_TEST_CASE(function_natspec_documentation) { ASTPointer contract; From 8bdf589117461f8ef21ca510960ccdfb65ec3bc7 Mon Sep 17 00:00:00 2001 From: Marek Kotewicz Date: Wed, 4 Feb 2015 17:37:30 +0100 Subject: [PATCH 55/55] we do not have duplicate libs now, so we cant remove them --- cmake/EthExecutableHelper.cmake | 8 -------- 1 file changed, 8 deletions(-) diff --git a/cmake/EthExecutableHelper.cmake b/cmake/EthExecutableHelper.cmake index 6e859bf31..427e0a9c4 100644 --- a/cmake/EthExecutableHelper.cmake +++ b/cmake/EthExecutableHelper.cmake @@ -83,19 +83,11 @@ macro(eth_install_executable EXECUTABLE) set(APP_BUNDLE_PATH "${CMAKE_CURRENT_BINARY_DIR}/\$ENV{CONFIGURATION}/${EXECUTABLE}.app") endif () - # TODO check, how fixup_bundle works and if it is required install(CODE " include(BundleUtilities) set(BU_CHMOD_BUNDLE_ITEMS 1) verify_app(\"${APP_BUNDLE_PATH}\") " COMPONENT RUNTIME ) - # Cleanup duplicate libs from macdeployqt - install(CODE " - file(GLOB LINGER_RM \"${APP_BUNDLE_PATH}/Contents/Frameworks/*.dylib\") - if (LINGER_RM) - file(REMOVE \${LINGER_RM}) - endif () - ") elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") # copy all dlls to executable directory