Browse Source

- Catch events for each incoming transaction.

cl-refactor
yann300 10 years ago
parent
commit
799ff95c28
  1. 52
      mix/ClientModel.cpp
  2. 7
      mix/ClientModel.h
  3. 12
      mix/ContractCallDataEncoder.cpp
  4. 4
      mix/ContractCallDataEncoder.h
  5. 1
      mix/MachineStates.h
  6. 35
      mix/MixClient.cpp
  7. 2
      mix/MixClient.h
  8. 15
      mix/QContractDefinition.cpp
  9. 8
      mix/QContractDefinition.h
  10. 32
      mix/QFunctionDefinition.cpp
  11. 7
      mix/QFunctionDefinition.h
  12. 13
      mix/QVariableDeclaration.cpp
  13. 9
      mix/QVariableDeclaration.h
  14. 28
      mix/qml/Block.qml
  15. 11
      mix/qml/BlockChain.qml

52
mix/ClientModel.cpp

@ -30,6 +30,7 @@
#include <jsonrpccpp/server.h> #include <jsonrpccpp/server.h>
#include <libethcore/CommonJS.h> #include <libethcore/CommonJS.h>
#include <libethereum/Transaction.h> #include <libethereum/Transaction.h>
#include <libdevcore/FixedHash.h>
#include "DebuggingStateWrapper.h" #include "DebuggingStateWrapper.h"
#include "Exceptions.h" #include "Exceptions.h"
#include "QContractDefinition.h" #include "QContractDefinition.h"
@ -668,7 +669,7 @@ RecordLogEntry* ClientModel::lastBlock() const
strGas << blockInfo.gasUsed; strGas << blockInfo.gasUsed;
stringstream strNumber; stringstream strNumber;
strNumber << blockInfo.number; strNumber << blockInfo.number;
RecordLogEntry* record = new RecordLogEntry(0, QString::fromStdString(strNumber.str()), tr(" - Block - "), tr("Hash: ") + QString(QString::fromStdString(dev::toHex(blockInfo.hash().ref()))), QString(), QString(), QString(), false, RecordLogEntry::RecordType::Block, QString::fromStdString(strGas.str()), QString(), tr("Block"), QVariantMap()); RecordLogEntry* record = new RecordLogEntry(0, QString::fromStdString(strNumber.str()), tr(" - Block - "), tr("Hash: ") + QString(QString::fromStdString(dev::toHex(blockInfo.hash().ref()))), QString(), QString(), QString(), false, RecordLogEntry::RecordType::Block, QString::fromStdString(strGas.str()), QString(), tr("Block"), QVariantMap(), QVariantList());
QQmlEngine::setObjectOwnership(record, QQmlEngine::JavaScriptOwnership); QQmlEngine::setObjectOwnership(record, QQmlEngine::JavaScriptOwnership);
return record; return record;
} }
@ -728,8 +729,10 @@ void ClientModel::onNewTransaction()
Address contractAddress = (bool)tr.address ? tr.address : tr.contractAddress; Address contractAddress = (bool)tr.address ? tr.address : tr.contractAddress;
auto contractAddressIter = m_contractNames.find(contractAddress); auto contractAddressIter = m_contractNames.find(contractAddress);
QVariantMap inputParameters; QVariantMap inputParameters;
QVariantList logs;
if (contractAddressIter != m_contractNames.end()) if (contractAddressIter != m_contractNames.end())
{ {
ContractCallDataEncoder encoder;
CompiledContract const& compilerRes = m_codeModel->contract(contractAddressIter->second); CompiledContract const& compilerRes = m_codeModel->contract(contractAddressIter->second);
const QContractDefinition* def = compilerRes.contract(); const QContractDefinition* def = compilerRes.contract();
contract = def->name(); contract = def->name();
@ -739,7 +742,6 @@ void ClientModel::onNewTransaction()
if (funcDef) if (funcDef)
{ {
function = funcDef->name(); function = funcDef->name();
ContractCallDataEncoder encoder;
QStringList returnValues = encoder.decode(funcDef->returnParameters(), tr.result.output); QStringList returnValues = encoder.decode(funcDef->returnParameters(), tr.result.output);
returned += "("; returned += "(";
returned += returnValues.join(", "); returned += returnValues.join(", ");
@ -751,13 +753,53 @@ void ClientModel::onNewTransaction()
inputParameters.insert(funcDef->parametersList().at(k)->name(), parameters.at(k)); inputParameters.insert(funcDef->parametersList().at(k)->name(), parameters.at(k));
} }
} }
}
LocalisedLogEntries logs = m_client->logs(); // Fill generated logs and decode parameters
for (auto const& log: tr.logs)
{
QVariantMap l;
l.insert("address", QString::fromStdString(log.address.hex()));
auto const& sign = log.topics.front(); // first hash supposed to be the event signature. To check
auto dataIterator = log.data.begin();
int topicDataIndex = 1;
for (auto const& event: def->eventsList())
{
if (sign == event->fullHash())
{
QVariantList paramsList;
l.insert("name", event->name());
for (auto const& e: event->parametersList())
{
bytes data;
QString param;
if (!e->isIndexed())
{
data = bytes(dataIterator, dataIterator + 32);
dataIterator = dataIterator + 32;
}
else
{
data = log.topics.at(topicDataIndex).asBytes();
topicDataIndex++;
}
param = encoder.decode(e, data);
QVariantMap p;
p.insert("indexed", e->isIndexed());
p.insert("value", param);
p.insert("name", e->name());
paramsList.push_back(p);
}
l.insert("param", paramsList);
break;
}
}
logs.push_back(l);
}
}
QString sender = QString::fromStdString(dev::toHex(tr.sender.ref())); QString sender = QString::fromStdString(dev::toHex(tr.sender.ref()));
QString label = contract + "." + function + "()"; QString label = contract + "." + function + "()";
RecordLogEntry* log = new RecordLogEntry(recordIndex, transactionIndex, contract, function, value, address, returned, tr.isCall(), RecordLogEntry::RecordType::Transaction, RecordLogEntry* log = new RecordLogEntry(recordIndex, transactionIndex, contract, function, value, address, returned, tr.isCall(), RecordLogEntry::RecordType::Transaction,
gasUsed, sender, label, inputParameters); gasUsed, sender, label, inputParameters, logs);
QQmlEngine::setObjectOwnership(log, QQmlEngine::JavaScriptOwnership); QQmlEngine::setObjectOwnership(log, QQmlEngine::JavaScriptOwnership);
emit newRecord(log); emit newRecord(log);
} }

7
mix/ClientModel.h

@ -115,6 +115,8 @@ class RecordLogEntry: public QObject
Q_PROPERTY(QString label MEMBER m_label CONSTANT) Q_PROPERTY(QString label MEMBER m_label CONSTANT)
/// input parameters /// input parameters
Q_PROPERTY(QVariantMap parameters MEMBER m_inputParameters CONSTANT) Q_PROPERTY(QVariantMap parameters MEMBER m_inputParameters CONSTANT)
/// logs
Q_PROPERTY(QVariantList logs MEMBER m_logs CONSTANT)
public: public:
enum RecordType enum RecordType
@ -126,9 +128,9 @@ public:
RecordLogEntry(): RecordLogEntry():
m_recordIndex(0), m_call(false), m_type(RecordType::Transaction) {} m_recordIndex(0), m_call(false), m_type(RecordType::Transaction) {}
RecordLogEntry(unsigned _recordIndex, QString _transactionIndex, QString _contract, QString _function, QString _value, QString _address, QString _returned, bool _call, RecordType _type, QString _gasUsed, RecordLogEntry(unsigned _recordIndex, QString _transactionIndex, QString _contract, QString _function, QString _value, QString _address, QString _returned, bool _call, RecordType _type, QString _gasUsed,
QString _sender, QString _label, QVariantMap _inputParameters): QString _sender, QString _label, QVariantMap _inputParameters, QVariantList _logs):
m_recordIndex(_recordIndex), m_transactionIndex(_transactionIndex), m_contract(_contract), m_function(_function), m_value(_value), m_address(_address), m_returned(_returned), m_call(_call), m_type(_type), m_gasUsed(_gasUsed), m_recordIndex(_recordIndex), m_transactionIndex(_transactionIndex), m_contract(_contract), m_function(_function), m_value(_value), m_address(_address), m_returned(_returned), m_call(_call), m_type(_type), m_gasUsed(_gasUsed),
m_sender(_sender), m_label(_label), m_inputParameters(_inputParameters) {} m_sender(_sender), m_label(_label), m_inputParameters(_inputParameters), m_logs(_logs) {}
private: private:
unsigned m_recordIndex; unsigned m_recordIndex;
@ -144,6 +146,7 @@ private:
QString m_sender; QString m_sender;
QString m_label; QString m_label;
QVariantMap m_inputParameters; QVariantMap m_inputParameters;
QVariantList m_logs;
}; };
/** /**

12
mix/ContractCallDataEncoder.cpp

@ -228,16 +228,10 @@ QVariant ContractCallDataEncoder::decode(SolidityType const& _type, bytes const&
BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Parameter declaration not found")); BOOST_THROW_EXCEPTION(Exception() << errinfo_comment("Parameter declaration not found"));
} }
QStringList ContractCallDataEncoder::decode(QList<QVariableDeclaration*> const& _returnParameters, vector<bytes> _value) QString ContractCallDataEncoder::decode(QVariableDeclaration* const& _param, bytes _value)
{ {
QStringList r; SolidityType const& type = _param->type()->type();
for (int k = 0; k <_returnParameters.length(); k++) return decode(type, _value).toString();
{
QVariableDeclaration* dec = static_cast<QVariableDeclaration*>(_returnParameters.at(k));
SolidityType const& type = dec->type()->type();
r.append(decode(type, _value.at(k)).toString());
}
return r;
} }
QStringList ContractCallDataEncoder::decode(QList<QVariableDeclaration*> const& _returnParameters, bytes _value) QStringList ContractCallDataEncoder::decode(QList<QVariableDeclaration*> const& _returnParameters, bytes _value)

4
mix/ContractCallDataEncoder.h

@ -48,8 +48,8 @@ public:
void encode(QVariant const& _data, SolidityType const& _type); void encode(QVariant const& _data, SolidityType const& _type);
/// Decode variable in order to be sent to QML view. /// Decode variable in order to be sent to QML view.
QStringList decode(QList<QVariableDeclaration*> const& _dec, bytes _value); QStringList decode(QList<QVariableDeclaration*> const& _dec, bytes _value);
/// Decode @param _parameters /// Decode @param _parameter
QStringList decode(QList<QVariableDeclaration*> const& _parameters, std::vector<bytes> _value); QString decode(QVariableDeclaration* const& _param, bytes _value);
/// Decode single variable /// Decode single variable
QVariant decode(SolidityType const& _type, bytes const& _value); QVariant decode(SolidityType const& _type, bytes const& _value);
/// Get all encoded data encoded by encode function. /// Get all encoded data encoded by encode function.

1
mix/MachineStates.h

@ -84,6 +84,7 @@ namespace mix
unsigned transactionIndex; unsigned transactionIndex;
unsigned executonIndex = 0; unsigned executonIndex = 0;
bytes inputParameters; bytes inputParameters;
eth::LocalisedLogEntries logs;
bool isCall() const { return transactionIndex == std::numeric_limits<unsigned>::max(); } bool isCall() const { return transactionIndex == std::numeric_limits<unsigned>::max(); }
bool isConstructor() const { return !isCall() && !address; } bool isConstructor() const { return !isCall() && !address; }

35
mix/MixClient.cpp

@ -89,9 +89,9 @@ void MixClient::resetState(std::unordered_map<Address, Account> const& _accounts
Guard fl(x_filtersWatches); Guard fl(x_filtersWatches);
m_filters.clear(); m_filters.clear();
m_watches.clear(); m_watches.clear();
LogFilter filter; //LogFilter filter;
m_filters.insert(std::make_pair(filter.sha3(), filter)); //m_filters.insert(std::make_pair(filter.sha3(), filter));
m_watches.insert(std::make_pair(0, ClientWatch(filter.sha3(), Reaping::Automatic))); //m_watches.insert(std::make_pair(0, ClientWatch(filter.sha3(), Reaping::Automatic)));
m_stateDB = OverlayDB(); m_stateDB = OverlayDB();
SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB); SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB);
@ -249,8 +249,22 @@ void MixClient::executeTransaction(Transaction const& _t, State& _state, bool _c
// collect watches // collect watches
h256Set changed; h256Set changed;
Guard l(x_filtersWatches); Guard l(x_filtersWatches);
for (std::pair<h256 const, eth::InstalledFilter>& i: m_filters) LocalisedLogEntries logs;
if ((unsigned)i.second.filter.latest() > bc().number()) //for (unsigned i = 0; i < _state.pending().size(); ++i)
//{
TransactionReceipt const& tr = _state.receipt(_state.pending().size() - 1);
auto trHash = _state.pending().at(_state.pending().size() - 1).sha3();
//for (std::pair<h256 const, eth::InstalledFilter>& installedFilter: m_filters)
//{
LogEntries le = tr.log(); // installedFilter.second.filter.matches(tr);
if (le.size())
for (unsigned j = 0; j < le.size(); ++j)
logs.insert(logs.begin(), LocalisedLogEntry(le[j], bc().number() + 1, trHash));
//}
//}
/*if ((unsigned)i.second.filter.latest() > bc().number())
{ {
// acceptable number. // acceptable number.
auto m = i.second.filter.matches(_state.receipt(_state.pending().size() - 1)); auto m = i.second.filter.matches(_state.receipt(_state.pending().size() - 1));
@ -261,9 +275,10 @@ void MixClient::executeTransaction(Transaction const& _t, State& _state, bool _c
i.second.changes.push_back(LocalisedLogEntry(l, bc().number() + 1)); i.second.changes.push_back(LocalisedLogEntry(l, bc().number() + 1));
changed.insert(i.first); changed.insert(i.first);
} }
} }*/
changed.insert(dev::eth::PendingChangedFilter); changed.insert(dev::eth::PendingChangedFilter);
noteChanged(changed); d.logs = logs;
//noteChanged(changed);
} }
WriteGuard l(x_executions); WriteGuard l(x_executions);
m_executions.emplace_back(std::move(d)); m_executions.emplace_back(std::move(d));
@ -278,7 +293,7 @@ void MixClient::mine()
m_state.sync(bc()); m_state.sync(bc());
m_startState = m_state; m_startState = m_state;
h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter }; h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter };
noteChanged(changed); //noteChanged(changed);
} }
ExecutionResult MixClient::lastExecution() const ExecutionResult MixClient::lastExecution() const
@ -365,7 +380,7 @@ dev::eth::ExecutionResult MixClient::create(Address const& _from, u256 _value, b
return lastExecution().result; return lastExecution().result;
} }
void MixClient::noteChanged(h256Set const& _filters) /*void MixClient::noteChanged(h256Set const& _filters)
{ {
for (auto& i: m_watches) for (auto& i: m_watches)
if (_filters.count(i.second.id)) if (_filters.count(i.second.id))
@ -377,7 +392,7 @@ void MixClient::noteChanged(h256Set const& _filters)
} }
for (auto& i: m_filters) for (auto& i: m_filters)
i.second.changes.clear(); i.second.changes.clear();
} }*/
eth::BlockInfo MixClient::blockInfo() const eth::BlockInfo MixClient::blockInfo() const
{ {

2
mix/MixClient.h

@ -91,7 +91,7 @@ protected:
private: private:
void executeTransaction(dev::eth::Transaction const& _t, eth::State& _state, bool _call, bool _gasAuto, dev::Secret const& _secret = dev::Secret()); void executeTransaction(dev::eth::Transaction const& _t, eth::State& _state, bool _call, bool _gasAuto, dev::Secret const& _secret = dev::Secret());
void noteChanged(h256Set const& _filters); //void noteChanged(h256Set const& _filters);
dev::eth::Transaction replaceGas(dev::eth::Transaction const& _t, dev::u256 const& _gas, dev::Secret const& _secret = dev::Secret()); dev::eth::Transaction replaceGas(dev::eth::Transaction const& _t, dev::u256 const& _gas, dev::Secret const& _secret = dev::Secret());
eth::State m_state; eth::State m_state;

15
mix/QContractDefinition.cpp

@ -39,10 +39,25 @@ QContractDefinition::QContractDefinition(QObject* _parent, dev::solidity::Contra
else else
m_constructor = new QFunctionDefinition(parent); m_constructor = new QFunctionDefinition(parent);
std::vector<std::string> found;
for (auto const& f: _contract->getDefinedFunctions())
{
m_functions.append(new QFunctionDefinition(parent, f));
found.push_back(f->getName());
}
for (auto const& it: _contract->getInterfaceFunctions()) for (auto const& it: _contract->getInterfaceFunctions())
{
if (std::find(found.begin(), found.end(), it.second->getDeclaration().getName()) == found.end())
m_functions.append(new QFunctionDefinition(parent, it.second)); m_functions.append(new QFunctionDefinition(parent, it.second));
} }
for (auto const& it: _contract->getEvents())
m_events.append(new QFunctionDefinition(parent, it));
}
QFunctionDefinition const* QContractDefinition::getFunction(dev::FixedHash<4> _hash) const QFunctionDefinition const* QContractDefinition::getFunction(dev::FixedHash<4> _hash) const
{ {
for (auto const& f: m_functions) for (auto const& f: m_functions)

8
mix/QContractDefinition.h

@ -37,6 +37,7 @@ class QContractDefinition: public QBasicNodeDefinition
Q_OBJECT Q_OBJECT
Q_PROPERTY(QQmlListProperty<dev::mix::QFunctionDefinition> functions READ functions CONSTANT) Q_PROPERTY(QQmlListProperty<dev::mix::QFunctionDefinition> functions READ functions CONSTANT)
Q_PROPERTY(dev::mix::QFunctionDefinition* constructor READ constructor CONSTANT) Q_PROPERTY(dev::mix::QFunctionDefinition* constructor READ constructor CONSTANT)
Q_PROPERTY(QQmlListProperty<dev::mix::QFunctionDefinition> events READ events CONSTANT)
public: public:
QContractDefinition(QObject* _parent, solidity::ContractDefinition const* _contract); QContractDefinition(QObject* _parent, solidity::ContractDefinition const* _contract);
@ -44,12 +45,19 @@ public:
QQmlListProperty<QFunctionDefinition> functions() const { return QQmlListProperty<QFunctionDefinition>(const_cast<QContractDefinition*>(this), const_cast<QContractDefinition*>(this)->m_functions); } QQmlListProperty<QFunctionDefinition> functions() const { return QQmlListProperty<QFunctionDefinition>(const_cast<QContractDefinition*>(this), const_cast<QContractDefinition*>(this)->m_functions); }
/// Get the constructor of the contract. /// Get the constructor of the contract.
QFunctionDefinition* constructor() const { return m_constructor; } QFunctionDefinition* constructor() const { return m_constructor; }
/// Get all the functions of the contract.
QList<QFunctionDefinition*> const& functionsList() const { return m_functions; } QList<QFunctionDefinition*> const& functionsList() const { return m_functions; }
/// Find function by hash, returns nullptr if not found /// Find function by hash, returns nullptr if not found
QFunctionDefinition const* getFunction(dev::FixedHash<4> _hash) const; QFunctionDefinition const* getFunction(dev::FixedHash<4> _hash) const;
/// Get events
QQmlListProperty<QFunctionDefinition> events() const { return QQmlListProperty<QFunctionDefinition>(const_cast<QContractDefinition*>(this), const_cast<QContractDefinition*>(this)->m_events); }
/// Get events
QList<QFunctionDefinition*> const& eventsList() const { return m_events; }
private: private:
QList<QFunctionDefinition*> m_functions; QList<QFunctionDefinition*> m_functions;
QFunctionDefinition* m_constructor; QFunctionDefinition* m_constructor;
QList<QFunctionDefinition*> m_events;
}; };
} }

32
mix/QFunctionDefinition.cpp

@ -28,15 +28,41 @@
using namespace dev::solidity; using namespace dev::solidity;
using namespace dev::mix; using namespace dev::mix;
QFunctionDefinition::QFunctionDefinition(QObject* _parent, dev::solidity::FunctionTypePointer const& _f): QBasicNodeDefinition(_parent, &_f->getDeclaration()), m_hash(dev::sha3(_f->externalSignature())) QFunctionDefinition::QFunctionDefinition(QObject* _parent, dev::solidity::FunctionTypePointer const& _f): QBasicNodeDefinition(_parent, &_f->getDeclaration()), m_hash(dev::sha3(_f->externalSignature())),
m_fullHash(dev::sha3(_f->externalSignature()))
{
init(_f);
}
QFunctionDefinition::QFunctionDefinition(QObject* _parent, ASTPointer<FunctionDefinition> const& _f): QBasicNodeDefinition(_parent, _f.get()), m_hash(dev::sha3(_f->externalSignature())),
m_fullHash(dev::sha3(_f->externalSignature()))
{
for (unsigned i = 0; i < _f->getParameters().size(); ++i)
m_parameters.append(new QVariableDeclaration(parent(), _f->getParameters().at(i)));
for (unsigned i = 0; i < _f->getReturnParameters().size(); ++i)
m_returnParameters.append(new QVariableDeclaration(parent(), _f->getReturnParameters().at(i)));
}
QFunctionDefinition::QFunctionDefinition(QObject* _parent, ASTPointer<dev::solidity::EventDefinition> const& _e): QBasicNodeDefinition(_parent, _e.get())
{
for (unsigned i = 0; i < _e->getParameters().size(); ++i)
m_parameters.append(new QVariableDeclaration(parent(), _e->getParameters().at(i)));
FunctionTypePointer _f = std::make_shared<FunctionType>(*_e);
m_hash = (FixedHash<4>)dev::sha3(_f->externalSignature(_e->getName()));
m_fullHash = dev::sha3(_f->externalSignature(_e->getName()));
}
void QFunctionDefinition::init(dev::solidity::FunctionTypePointer _f)
{ {
auto paramNames = _f->getParameterNames(); auto paramNames = _f->getParameterNames();
auto paramTypes = _f->getParameterTypes(); auto paramTypes = _f->getParameterTypes();
auto returnNames = _f->getReturnParameterNames(); auto returnNames = _f->getReturnParameterNames();
auto returnTypes = _f->getReturnParameterTypes(); auto returnTypes = _f->getReturnParameterTypes();
for (unsigned i = 0; i < paramNames.size(); ++i) for (unsigned i = 0; i < paramNames.size(); ++i)
m_parameters.append(new QVariableDeclaration(_parent, paramNames[i], paramTypes[i].get())); m_parameters.append(new QVariableDeclaration(parent(), paramNames[i], paramTypes[i].get()));
for (unsigned i = 0; i < returnNames.size(); ++i) for (unsigned i = 0; i < returnNames.size(); ++i)
m_returnParameters.append(new QVariableDeclaration(_parent, returnNames[i], returnTypes[i].get())); m_returnParameters.append(new QVariableDeclaration(parent(), returnNames[i], returnTypes[i].get()));
} }

7
mix/QFunctionDefinition.h

@ -41,6 +41,10 @@ public:
QFunctionDefinition(){} QFunctionDefinition(){}
QFunctionDefinition(QObject* _parent): QBasicNodeDefinition(_parent) {} QFunctionDefinition(QObject* _parent): QBasicNodeDefinition(_parent) {}
QFunctionDefinition(QObject* _parent, solidity::FunctionTypePointer const& _f); QFunctionDefinition(QObject* _parent, solidity::FunctionTypePointer const& _f);
QFunctionDefinition(QObject* _parent, solidity::ASTPointer<solidity::EventDefinition> const& _f);
QFunctionDefinition(QObject* _parent, solidity::ASTPointer<solidity::FunctionDefinition> const& _f);
/// Init members
void init(dev::solidity::FunctionTypePointer _f);
/// Get all input parameters of this function. /// Get all input parameters of this function.
QList<QVariableDeclaration*> const& parametersList() const { return m_parameters; } QList<QVariableDeclaration*> const& parametersList() const { return m_parameters; }
/// Get all input parameters of this function as QML property. /// Get all input parameters of this function as QML property.
@ -49,10 +53,13 @@ public:
QList<QVariableDeclaration*> returnParameters() const { return m_returnParameters; } QList<QVariableDeclaration*> returnParameters() const { return m_returnParameters; }
/// Get the hash of this function declaration on the contract ABI. /// Get the hash of this function declaration on the contract ABI.
FixedHash<4> hash() const { return m_hash; } FixedHash<4> hash() const { return m_hash; }
/// Get the full hash of this function declaration on the contract ABI.
FixedHash<32> fullHash() const { return m_fullHash; }
private: private:
int m_index; int m_index;
FixedHash<4> m_hash; FixedHash<4> m_hash;
FixedHash<32> m_fullHash;
QList<QVariableDeclaration*> m_parameters; QList<QVariableDeclaration*> m_parameters;
QList<QVariableDeclaration*> m_returnParameters; QList<QVariableDeclaration*> m_returnParameters;
void initQParameters(); void initQParameters();

13
mix/QVariableDeclaration.cpp

@ -24,27 +24,32 @@
#include <libsolidity/AST.h> #include <libsolidity/AST.h>
#include "CodeModel.h" #include "CodeModel.h"
using namespace solidity;
namespace dev namespace dev
{ {
namespace mix namespace mix
{ {
QVariableDeclaration::QVariableDeclaration(QObject* _parent, solidity::VariableDeclaration const* _v): QVariableDeclaration::QVariableDeclaration(QObject* _parent, ASTPointer<VariableDeclaration> const _v):
QBasicNodeDefinition(_parent, _v), QBasicNodeDefinition(_parent, _v.get()),
m_type(new QSolidityType(this, CodeModel::nodeType(_v->getType().get()))) m_type(new QSolidityType(this, CodeModel::nodeType(_v->getType().get())))
{ {
m_isIndexed = _v->isIndexed();
} }
QVariableDeclaration::QVariableDeclaration(QObject* _parent, std::string const& _name, SolidityType const& _type): QVariableDeclaration::QVariableDeclaration(QObject* _parent, std::string const& _name, SolidityType const& _type, bool _isIndexed):
QBasicNodeDefinition(_parent, _name), QBasicNodeDefinition(_parent, _name),
m_type(new QSolidityType(_parent, _type)) m_type(new QSolidityType(_parent, _type))
{ {
m_isIndexed = _isIndexed;
} }
QVariableDeclaration::QVariableDeclaration(QObject* _parent, std::string const& _name, solidity::Type const* _type): QVariableDeclaration::QVariableDeclaration(QObject* _parent, std::string const& _name, solidity::Type const* _type, bool _isIndexed):
QBasicNodeDefinition(_parent, _name), QBasicNodeDefinition(_parent, _name),
m_type(new QSolidityType(this, CodeModel::nodeType(_type))) m_type(new QSolidityType(this, CodeModel::nodeType(_type)))
{ {
m_isIndexed = _isIndexed;
} }
QSolidityType::QSolidityType(QObject* _parent, SolidityType const& _type): QSolidityType::QSolidityType(QObject* _parent, SolidityType const& _type):

9
mix/QVariableDeclaration.h

@ -21,6 +21,7 @@
#include <QDebug> #include <QDebug>
#include <QVariantList> #include <QVariantList>
#include <libsolidity/AST.h>
#include "QBasicNodeDefinition.h" #include "QBasicNodeDefinition.h"
#include "SolidityType.h" #include "SolidityType.h"
@ -82,14 +83,16 @@ class QVariableDeclaration: public QBasicNodeDefinition
public: public:
QVariableDeclaration() {} QVariableDeclaration() {}
QVariableDeclaration(QObject* _parent, solidity::VariableDeclaration const* _v); QVariableDeclaration(QObject* _parent, solidity::ASTPointer<solidity::VariableDeclaration> const _v);
QVariableDeclaration(QObject* _parent, std::string const& _name, SolidityType const& _type); QVariableDeclaration(QObject* _parent, std::string const& _name, SolidityType const& _type, bool _isIndexed = false);
QVariableDeclaration(QObject* _parent, std::string const& _name, solidity::Type const* _type); QVariableDeclaration(QObject* _parent, std::string const& _name, solidity::Type const* _type, bool _isIndexed = false);
QSolidityType* type() const { return m_type; } QSolidityType* type() const { return m_type; }
void setType(QSolidityType* _type) { m_type = _type; } void setType(QSolidityType* _type) { m_type = _type; }
bool isIndexed() { return m_isIndexed; }
private: private:
QSolidityType* m_type; QSolidityType* m_type;
bool m_isIndexed;
}; };

28
mix/qml/Block.qml

@ -121,22 +121,36 @@ ColumnLayout
clip: true clip: true
} }
Label
{
id: logs
width: logsWidth
text: {
if (index >= 0 && transactions.get(index).logs)
{
for (var k in transactions.get(index).logs)
{
console.log("_________________________")
console.log(JSON.stringify(transactions.get(index).logs[k]))
console.log("_________________________")
}
return transactions.get(index).logs.length
}
else
return 0
}
}
Button Button
{ {
id: debug id: debug
width: logsWidth width: debugActionWidth
text: "debug" text: "debug"
onClicked: onClicked:
{ {
clientModel.debugRecord(transactions.get(index).recordIndex); clientModel.debugRecord(transactions.get(index).recordIndex);
} }
} }
Label
{
id: logs
width: logsWidth
}
} }
} }
} }

11
mix/qml/BlockChain.qml

@ -30,8 +30,9 @@ Column {
property int statusWidth: 50 property int statusWidth: 50
property int fromWidth: 100 property int fromWidth: 100
property int toWidth: 250 property int toWidth: 250
property int valueWidth: 100 property int valueWidth: 50
property int logsWidth: 50 property int logsWidth: 50
property int debugActionWidth: 50
Row Row
{ {
@ -62,6 +63,11 @@ Column {
text: "Logs" text: "Logs"
width: logsWidth width: logsWidth
} }
Label
{
text: "Action"
width: debugActionWidth
}
} }
Rectangle Rectangle
@ -253,6 +259,8 @@ Column {
blockModel.getTransaction(blockIndex, trIndex).returned = _r.returned; blockModel.getTransaction(blockIndex, trIndex).returned = _r.returned;
tr.recordIndex = _r.recordIndex; tr.recordIndex = _r.recordIndex;
blockModel.getTransaction(blockIndex, trIndex).recordIndex = _r.recordIndex; blockModel.getTransaction(blockIndex, trIndex).recordIndex = _r.recordIndex;
tr.logs = _r.logs;
blockModel.getTransaction(blockIndex, trIndex).logs = _r.logs;
return; return;
} }
} }
@ -270,6 +278,7 @@ Column {
itemTr.value = QEtherHelper.createEther(_r.value, QEther.Wei) itemTr.value = QEtherHelper.createEther(_r.value, QEther.Wei)
itemTr.sender = _r.sender itemTr.sender = _r.sender
itemTr.recordIndex = _r.recordIndex itemTr.recordIndex = _r.recordIndex
itemTr.logs = _r.logs
model.blocks[model.blocks.length - 1].transactions.push(itemTr) model.blocks[model.blocks.length - 1].transactions.push(itemTr)
blockModel.appendTransaction(itemTr) blockModel.appendTransaction(itemTr)

Loading…
Cancel
Save