From 28556f42ecb9142eaa7afce3edee03f5b4e7cf58 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 12 Dec 2014 21:51:54 +0100 Subject: [PATCH 1/6] Remove unneeded files. --- libethereum/Manifest.cpp | 0 libethereum/Manifest.h | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 libethereum/Manifest.cpp delete mode 100644 libethereum/Manifest.h diff --git a/libethereum/Manifest.cpp b/libethereum/Manifest.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/libethereum/Manifest.h b/libethereum/Manifest.h deleted file mode 100644 index e69de29bb..000000000 From 82d29fa979dffabd9a76ddb1c7b0ae513404c251 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 12 Dec 2014 21:54:29 +0100 Subject: [PATCH 2/6] Rename headers. --- alethzero/MainWin.h | 1 - libethereum/BlockDetails.h | 1 - libethereum/Client.h | 4 +- libethereum/Interface.h | 7 +-- libethereum/MessageFilter.cpp | 81 -------------------------------- libethereum/MessageFilter.h | 69 --------------------------- libethereum/TransactionReceipt.h | 1 - 7 files changed, 2 insertions(+), 162 deletions(-) delete mode 100644 libethereum/MessageFilter.cpp delete mode 100644 libethereum/MessageFilter.h diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index fffc5843f..f2d632cd4 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -44,7 +44,6 @@ class Main; namespace dev { namespace eth { class Client; class State; -class MessageFilter; }} class QQuickView; diff --git a/libethereum/BlockDetails.h b/libethereum/BlockDetails.h index 2fd0d3048..bbfd48e56 100644 --- a/libethereum/BlockDetails.h +++ b/libethereum/BlockDetails.h @@ -28,7 +28,6 @@ #include #include -#include "Manifest.h" #include "TransactionReceipt.h" namespace ldb = leveldb; diff --git a/libethereum/Client.h b/libethereum/Client.h index 283251e24..477ea43e5 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -37,7 +37,7 @@ #include "State.h" #include "CommonNet.h" #include "PastMessage.h" -#include "MessageFilter.h" +#include "LogFilter.h" #include "Miner.h" #include "Interface.h" @@ -79,8 +79,6 @@ static const int GenesisBlock = INT_MIN; struct InstalledFilter { -// InstalledFilter(MessageFilter const& _f): filter(_f) {} -// MessageFilter filter; InstalledFilter(LogFilter const& _f): filter(_f) {} LogFilter filter; diff --git a/libethereum/Interface.h b/libethereum/Interface.h index d598e1f9b..28ac26819 100644 --- a/libethereum/Interface.h +++ b/libethereum/Interface.h @@ -26,7 +26,7 @@ #include #include #include -#include "MessageFilter.h" +#include "LogFilter.h" #include "Transaction.h" #include "AccountDiff.h" #include "BlockDetails.h" @@ -84,11 +84,6 @@ public: virtual bytes codeAt(Address _a, int _block) const = 0; virtual std::map storageAt(Address _a, int _block) const = 0; -// // [MESSAGE API] -// -// virtual PastMessages messages(unsigned _watchId) const = 0; -// virtual PastMessages messages(MessageFilter const& _filter) const = 0; - // [LOGS API] virtual LogEntries logs(unsigned _watchId) const = 0; diff --git a/libethereum/MessageFilter.cpp b/libethereum/MessageFilter.cpp deleted file mode 100644 index f44587620..000000000 --- a/libethereum/MessageFilter.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* - 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 MessageFilter.cpp - * @author Gav Wood - * @date 2014 - */ - -#include "MessageFilter.h" - -#include -#include "State.h" -using namespace std; -using namespace dev; -using namespace dev::eth; - -void LogFilter::streamRLP(RLPStream& _s) const -{ - _s.appendList(6) << m_addresses << m_topics << m_earliest << m_latest << m_max << m_skip; -} - -h256 LogFilter::sha3() const -{ - RLPStream s; - streamRLP(s); - return dev::sha3(s.out()); -} - -bool LogFilter::matches(LogBloom _bloom) const -{ - if (m_addresses.size()) - { - for (auto i: m_addresses) - if (_bloom.containsBloom<3>(dev::sha3(i))) - goto OK1; - return false; - } - OK1: - if (m_topics.size()) - { - for (auto i: m_topics) - if (_bloom.containsBloom<3>(dev::sha3(i))) - goto OK2; - return false; - } - OK2: - return true; -} - -bool LogFilter::matches(State const& _s, unsigned _i) const -{ - return matches(_s.receipt(_i)).size() > 0; -} - -LogEntries LogFilter::matches(TransactionReceipt const& _m) const -{ - LogEntries ret; - for (LogEntry const& e: _m.log()) - { - if (!m_addresses.empty() && !m_addresses.count(e.address)) - continue; - for (auto const& t: m_topics) - if (!std::count(e.topics.begin(), e.topics.end(), t)) - continue; - ret.push_back(e); - } - return ret; -} diff --git a/libethereum/MessageFilter.h b/libethereum/MessageFilter.h deleted file mode 100644 index e2c26d214..000000000 --- a/libethereum/MessageFilter.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - 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 MessageFilter.h - * @author Gav Wood - * @date 2014 - */ - -#pragma once - -#include -#include -#include -#include "TransactionReceipt.h" - -namespace dev -{ -namespace eth -{ - -class State; - -class LogFilter -{ -public: - LogFilter(int _earliest = 0, int _latest = -1, unsigned _max = 10, unsigned _skip = 0): m_earliest(_earliest), m_latest(_latest), m_max(_max), m_skip(_skip) {} - - void streamRLP(RLPStream& _s) const; - h256 sha3() const; - - int earliest() const { return m_earliest; } - int latest() const { return m_latest; } - unsigned max() const { return m_max; } - unsigned skip() const { return m_skip; } - bool matches(LogBloom _bloom) const; - bool matches(State const& _s, unsigned _i) const; - LogEntries matches(TransactionReceipt const& _r) const; - - LogFilter address(Address _a) { m_addresses.insert(_a); return *this; } - LogFilter topic(h256 const& _t) { m_topics.insert(_t); return *this; } - LogFilter withMax(unsigned _m) { m_max = _m; return *this; } - LogFilter withSkip(unsigned _m) { m_skip = _m; return *this; } - LogFilter withEarliest(int _e) { m_earliest = _e; return *this; } - LogFilter withLatest(int _e) { m_latest = _e; return *this; } - -private: - AddressSet m_addresses; - h256Set m_topics; - int m_earliest = 0; - int m_latest = -1; - unsigned m_max; - unsigned m_skip; -}; - -} -} diff --git a/libethereum/TransactionReceipt.h b/libethereum/TransactionReceipt.h index b990459d9..feb26dad3 100644 --- a/libethereum/TransactionReceipt.h +++ b/libethereum/TransactionReceipt.h @@ -26,7 +26,6 @@ #include #include #include -#include "Manifest.h" namespace dev { From 94dc92edabb917e2e02dba003678ed95c8ce4663 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 12 Dec 2014 21:56:26 +0100 Subject: [PATCH 3/6] Remove unneeded files. --- libethereum/Client.h | 1 - libethereum/LogFilter.cpp | 81 +++++++++++++++++++++++++++++++++++++ libethereum/LogFilter.h | 69 +++++++++++++++++++++++++++++++ libethereum/PastMessage.cpp | 0 libethereum/PastMessage.h | 0 5 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 libethereum/LogFilter.cpp create mode 100644 libethereum/LogFilter.h delete mode 100644 libethereum/PastMessage.cpp delete mode 100644 libethereum/PastMessage.h diff --git a/libethereum/Client.h b/libethereum/Client.h index 477ea43e5..e8c460093 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -36,7 +36,6 @@ #include "TransactionQueue.h" #include "State.h" #include "CommonNet.h" -#include "PastMessage.h" #include "LogFilter.h" #include "Miner.h" #include "Interface.h" diff --git a/libethereum/LogFilter.cpp b/libethereum/LogFilter.cpp new file mode 100644 index 000000000..81cb439ba --- /dev/null +++ b/libethereum/LogFilter.cpp @@ -0,0 +1,81 @@ +/* + 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 LogFilter.cpp + * @author Gav Wood + * @date 2014 + */ + +#include "LogFilter.h" + +#include +#include "State.h" +using namespace std; +using namespace dev; +using namespace dev::eth; + +void LogFilter::streamRLP(RLPStream& _s) const +{ + _s.appendList(6) << m_addresses << m_topics << m_earliest << m_latest << m_max << m_skip; +} + +h256 LogFilter::sha3() const +{ + RLPStream s; + streamRLP(s); + return dev::sha3(s.out()); +} + +bool LogFilter::matches(LogBloom _bloom) const +{ + if (m_addresses.size()) + { + for (auto i: m_addresses) + if (_bloom.containsBloom<3>(dev::sha3(i))) + goto OK1; + return false; + } + OK1: + if (m_topics.size()) + { + for (auto i: m_topics) + if (_bloom.containsBloom<3>(dev::sha3(i))) + goto OK2; + return false; + } + OK2: + return true; +} + +bool LogFilter::matches(State const& _s, unsigned _i) const +{ + return matches(_s.receipt(_i)).size() > 0; +} + +LogEntries LogFilter::matches(TransactionReceipt const& _m) const +{ + LogEntries ret; + for (LogEntry const& e: _m.log()) + { + if (!m_addresses.empty() && !m_addresses.count(e.address)) + continue; + for (auto const& t: m_topics) + if (!std::count(e.topics.begin(), e.topics.end(), t)) + continue; + ret.push_back(e); + } + return ret; +} diff --git a/libethereum/LogFilter.h b/libethereum/LogFilter.h new file mode 100644 index 000000000..bda8e46a2 --- /dev/null +++ b/libethereum/LogFilter.h @@ -0,0 +1,69 @@ +/* + 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 LogFilter.h + * @author Gav Wood + * @date 2014 + */ + +#pragma once + +#include +#include +#include +#include "TransactionReceipt.h" + +namespace dev +{ +namespace eth +{ + +class State; + +class LogFilter +{ +public: + LogFilter(int _earliest = 0, int _latest = -1, unsigned _max = 10, unsigned _skip = 0): m_earliest(_earliest), m_latest(_latest), m_max(_max), m_skip(_skip) {} + + void streamRLP(RLPStream& _s) const; + h256 sha3() const; + + int earliest() const { return m_earliest; } + int latest() const { return m_latest; } + unsigned max() const { return m_max; } + unsigned skip() const { return m_skip; } + bool matches(LogBloom _bloom) const; + bool matches(State const& _s, unsigned _i) const; + LogEntries matches(TransactionReceipt const& _r) const; + + LogFilter address(Address _a) { m_addresses.insert(_a); return *this; } + LogFilter topic(h256 const& _t) { m_topics.insert(_t); return *this; } + LogFilter withMax(unsigned _m) { m_max = _m; return *this; } + LogFilter withSkip(unsigned _m) { m_skip = _m; return *this; } + LogFilter withEarliest(int _e) { m_earliest = _e; return *this; } + LogFilter withLatest(int _e) { m_latest = _e; return *this; } + +private: + AddressSet m_addresses; + h256Set m_topics; + int m_earliest = 0; + int m_latest = -1; + unsigned m_max; + unsigned m_skip; +}; + +} +} diff --git a/libethereum/PastMessage.cpp b/libethereum/PastMessage.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/libethereum/PastMessage.h b/libethereum/PastMessage.h deleted file mode 100644 index e69de29bb..000000000 From b364a8110b384d46ea452c33e8141eb15f54cd4e Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 12 Dec 2014 22:00:20 +0100 Subject: [PATCH 4/6] Repotting. --- libethereum/TransactionReceipt.cpp | 51 ++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 libethereum/TransactionReceipt.cpp diff --git a/libethereum/TransactionReceipt.cpp b/libethereum/TransactionReceipt.cpp new file mode 100644 index 000000000..0fb104490 --- /dev/null +++ b/libethereum/TransactionReceipt.cpp @@ -0,0 +1,51 @@ +/* + 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 TransactionReceipt.cpp + * @author Gav Wood + * @date 2014 + */ + +#include "TransactionReceipt.h" + +using namespace std; +using namespace dev; +using namespace dev::eth; + +TransactionReceipt::TransactionReceipt(bytesConstRef _rlp) +{ + RLP r(_rlp); + m_stateRoot = (h256)r[0]; + m_gasUsed = (u256)r[1]; + m_bloom = (LogBloom)r[2]; + for (auto const& i: r[3]) + m_log.emplace_back(i); +} + +TransactionReceipt::TransactionReceipt(h256 _root, u256 _gasUsed, LogEntries const& _log): + m_stateRoot(_root), + m_gasUsed(_gasUsed), + m_bloom(eth::bloom(_log)), + m_log(_log) +{} + +void TransactionReceipt::streamRLP(RLPStream& _s) const +{ + _s.appendList(4) << m_stateRoot << m_gasUsed << m_bloom; + _s.appendList(m_log.size()); + for (LogEntry const& l: m_log) + l.streamRLP(_s); +} From b52e9cae5a015e822a3f315cb84af96b0f12ec2c Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 12 Dec 2014 22:00:40 +0100 Subject: [PATCH 5/6] Add file. --- libethereum/TransactionReceipt.h | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/libethereum/TransactionReceipt.h b/libethereum/TransactionReceipt.h index feb26dad3..23995c75a 100644 --- a/libethereum/TransactionReceipt.h +++ b/libethereum/TransactionReceipt.h @@ -36,21 +36,15 @@ namespace eth class TransactionReceipt { public: - TransactionReceipt(bytesConstRef _rlp) { RLP r(_rlp); m_stateRoot = (h256)r[0]; m_gasUsed = (u256)r[1]; m_bloom = (LogBloom)r[2]; for (auto const& i: r[3]) m_log.emplace_back(i); } - TransactionReceipt(h256 _root, u256 _gasUsed, LogEntries const& _log): m_stateRoot(_root), m_gasUsed(_gasUsed), m_bloom(eth::bloom(_log)), m_log(_log) {} + TransactionReceipt(bytesConstRef _rlp); + TransactionReceipt(h256 _root, u256 _gasUsed, LogEntries const& _log); h256 const& stateRoot() const { return m_stateRoot; } u256 const& gasUsed() const { return m_gasUsed; } LogBloom const& bloom() const { return m_bloom; } LogEntries const& log() const { return m_log; } - void streamRLP(RLPStream& _s) const - { - _s.appendList(4) << m_stateRoot << m_gasUsed << m_bloom; - _s.appendList(m_log.size()); - for (LogEntry const& l: m_log) - l.streamRLP(_s); - } + void streamRLP(RLPStream& _s) const; bytes rlp() const { RLPStream s; streamRLP(s); return s.out(); } From 1b8f9fdc3b44503890ed1bcb5da8bd5cb8dd83a5 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Fri, 12 Dec 2014 22:08:48 +0100 Subject: [PATCH 6/6] Deduplication. --- alethzero/MainWin.cpp | 57 +++---------------------------------------- 1 file changed, 3 insertions(+), 54 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 0e36c7737..fa489ffeb 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include @@ -1500,58 +1501,6 @@ void Main::on_destination_currentTextChanged() // updateFee(); } -static bytes dataFromText(QString _s) -{ - bytes ret; - while (_s.size()) - { - QRegExp r("(@|\\$)?\"([^\"]*)\"(\\s.*)?"); - QRegExp d("(@|\\$)?([0-9]+)(\\s*(ether)|(finney)|(szabo))?(\\s.*)?"); - QRegExp h("(@|\\$)?(0x)?(([a-fA-F0-9])+)(\\s.*)?"); - if (r.exactMatch(_s)) - { - for (auto i: r.cap(2)) - ret.push_back((byte)i.toLatin1()); - if (r.cap(1) != "$") - for (int i = r.cap(2).size(); i < 32; ++i) - ret.push_back(0); - else - ret.push_back(0); - _s = r.cap(3); - } - else if (d.exactMatch(_s)) - { - u256 v(d.cap(2).toStdString()); - if (d.cap(6) == "szabo") - v *= dev::eth::szabo; - else if (d.cap(5) == "finney") - v *= dev::eth::finney; - else if (d.cap(4) == "ether") - v *= dev::eth::ether; - bytes bs = dev::toCompactBigEndian(v); - if (d.cap(1) != "$") - for (auto i = bs.size(); i < 32; ++i) - ret.push_back(0); - for (auto b: bs) - ret.push_back(b); - _s = d.cap(7); - } - else if (h.exactMatch(_s)) - { - bytes bs = fromHex((((h.cap(3).size() & 1) ? "0" : "") + h.cap(3)).toStdString()); - if (h.cap(1) != "$") - for (auto i = bs.size(); i < 32; ++i) - ret.push_back(0); - for (auto b: bs) - ret.push_back(b); - _s = h.cap(5); - } - else - _s = _s.mid(1); - } - return ret; -} - static shh::Topic topicFromText(QString _s) { shh::BuildTopic ret; @@ -1679,7 +1628,7 @@ void Main::on_data_textChanged() } else { - m_data = dataFromText(ui->data->toPlainText()); + m_data = parseData(ui->data->toPlainText().toStdString()); ui->code->setHtml(QString::fromStdString(dev::memDump(m_data, 8, true))); if (ethereum()->codeAt(fromString(ui->destination->currentText()), 0).size()) { @@ -2207,7 +2156,7 @@ void Main::on_post_clicked() { shh::Message m; m.setTo(stringToPublic(ui->shhTo->currentText())); - m.setPayload(dataFromText(ui->shhData->toPlainText())); + m.setPayload(parseData(ui->shhData->toPlainText().toStdString())); Public f = stringToPublic(ui->shhFrom->currentText()); Secret from; if (m_server->ids().count(f))